feat(shellconfig): implement PlanForce

This commit is contained in:
MDietermann
2026-04-14 22:06:57 +02:00
parent 4ed257bbd1
commit b2cbd4f640
2 changed files with 54 additions and 2 deletions

View File

@@ -55,4 +55,42 @@ func TestShellConfigIdempotent(t *testing.T) {
}
}
func TestPlanForceRewritesBlocks(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
cfg := config.ShellConfigSection{Blocks: []config.ShellConfigBlock{
{Name: "path", File: ".zshrc", Content: `export PATH="$HOME/.local/bin:$PATH"`},
}}
m := New(cfg)
st, _ := m.Detect(context.Background())
p, _ := m.Plan(context.Background(), st)
if err := m.Apply(context.Background(), p, nop{}); err != nil {
t.Fatal(err)
}
st2, _ := m.Detect(context.Background())
p2, _ := m.Plan(context.Background(), st2)
if !p2.IsEmpty() {
t.Fatalf("precondition: regular plan should be empty")
}
plan, err := m.PlanForce(context.Background())
if err != nil {
t.Fatalf("PlanForce: %v", err)
}
if plan.IsEmpty() {
t.Fatal("force plan must not be empty")
}
for _, a := range plan.Actions {
if err := a.Exec(context.Background()); err != nil {
t.Fatalf("Exec: %v", err)
}
}
data, _ := os.ReadFile(filepath.Join(home, ".zshrc"))
if !strings.Contains(string(data), `export PATH="$HOME/.local/bin:$PATH"`) {
t.Fatalf("content missing after force: %q", data)
}
if !strings.Contains(string(data), ">>> path >>>") {
t.Fatalf("block marker missing: %q", data)
}
}
var _ module.Module = Module{}