| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "reasonix/internal/agent" |
| 11 | "reasonix/internal/store" |
| 12 | ) |
| 13 | |
| 14 | func TestRecordRecoveryLifecycleAcceptsOnlyRedactedKnownOutcomes(t *testing.T) { |
| 15 | dir := t.TempDir() |
| 16 | path := filepath.Join(dir, "private-session.jsonl") |
| 17 | if err := agent.SaveBranchMeta(path, agent.BranchMeta{ |
| 18 | ID: agent.BranchID(path), Scope: "project", WorkspaceRoot: "/private/workspace", |
| 19 | TopicID: "private-topic", TopicTitle: "private title", CustomTitle: "private note", |
| 20 | }); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | |
| 24 | RecordRecoveryLifecycle(path, "classified_diverged") |
| 25 | RecordRecoveryLifecycle(path, "classified_diverged") |
| 26 | RecordRecoveryLifecycle(path, "private user-controlled outcome") |
| 27 | |
| 28 | file, err := os.Open(store.SessionConflictLog(path)) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | defer file.Close() |
| 33 | scanner := bufio.NewScanner(file) |
| 34 | lines := []string{} |
| 35 | for scanner.Scan() { |
| 36 | lines = append(lines, scanner.Text()) |
| 37 | } |
| 38 | if err := scanner.Err(); err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | if len(lines) != 1 || !strings.Contains(lines[0], `"mode":"catalog"`) || |
| 42 | !strings.Contains(lines[0], `"outcome":"classified_diverged"`) { |
| 43 | t.Fatalf("lifecycle records = %+v", lines) |
| 44 | } |
| 45 | for _, secret := range []string{dir, "/private/workspace", "private-topic", "private title", "private note", "user-controlled"} { |
| 46 | if strings.Contains(lines[0], secret) { |
| 47 | t.Fatalf("lifecycle diagnostic leaked %q: %s", secret, lines[0]) |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |