package app import ( "bytes" "encoding/json" "os" "testing" "gitea.maximumdirect.net/eric/narratio/internal/adapters/storage" "gitea.maximumdirect.net/eric/narratio/internal/artifacts" "go.maximumdirect.net/commandkit" ) func decodeRestoreCommandReport(t *testing.T, data []byte) restoreCommandReport { t.Helper() var report restoreCommandReport // DecodeYAMLReport normalizes YAML through the same JSON representation. normalized, err := commandkit.DecodeYAMLReport(bytes.NewReader(data)) if err != nil { t.Fatal(err) } encoded, err := json.Marshal(normalized) if err != nil { t.Fatal(err) } if err := json.Unmarshal(encoded, &report); err != nil { t.Fatal(err) } return report } func TestRestoreCommandDryRunLeavesMissingWorkspaceAbsent(t *testing.T) { pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir()) fake := &storage.FakeBackend{} cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipeline, campaign, session) seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"artifacts/recap.md": []byte("synthetic recap\n")}) paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID) if _, err := os.Stat(paths.Root); !os.IsNotExist(err) { t.Fatalf("fixture session root=%v", err) } var out, diagnostic bytes.Buffer code := restoreCommandExecutor(fake)([]string{"session", "restore", cfg.Session.SessionID, "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--dry-run"}, &out, &diagnostic) if code != 0 { t.Fatalf("status=%d diagnostics=%s", code, diagnostic.String()) } report := decodeRestoreCommandReport(t, out.Bytes()) if !report.DryRun || report.Complete || len(report.Actions) == 0 { t.Fatalf("report=%#v", report) } if _, err := os.Stat(paths.Root); !os.IsNotExist(err) { t.Fatalf("dry run created workspace: %v", err) } if len(fake.Downloads) != 0 { t.Fatal("dry run installed remote payloads") } }