MCPcopy Create free account
hub / github.com/ByteYellow/AgentProvenance / TestDiffAndBlameJSON

Function TestDiffAndBlameJSON

internal/provenance/diff_test.go:101–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestDiffAndBlameJSON(t *testing.T) {
102 root := t.TempDir()
103 paths, err := store.Init(filepath.Join(root, ".agentprov"))
104 if err != nil {
105 t.Fatal(err)
106 }
107 db, err := store.Open(paths)
108 if err != nil {
109 t.Fatal(err)
110 }
111 defer db.Close()
112
113 now := time.Now().UTC().Format(time.RFC3339Nano)
114 base := filepath.Join(root, "base")
115 attempt1 := filepath.Join(root, "attempt-1")
116 attempt2 := filepath.Join(root, "attempt-2")
117 for _, dir := range []string{base, attempt1, attempt2} {
118 if err := os.MkdirAll(dir, 0o755); err != nil {
119 t.Fatal(err)
120 }
121 }
122 if err := os.WriteFile(filepath.Join(base, "calculator.py"), []byte("def add(a, b):\n return a - b\n"), 0o644); err != nil {
123 t.Fatal(err)
124 }
125 if err := os.WriteFile(filepath.Join(base, "old.txt"), []byte("remove me\n"), 0o644); err != nil {
126 t.Fatal(err)
127 }
128 if err := os.WriteFile(filepath.Join(attempt1, "calculator.py"), []byte("def add(a, b):\n return a - b\n"), 0o644); err != nil {
129 t.Fatal(err)
130 }
131 if err := os.WriteFile(filepath.Join(attempt1, "old.txt"), []byte("remove me\n"), 0o644); err != nil {
132 t.Fatal(err)
133 }
134 if err := os.WriteFile(filepath.Join(attempt2, "calculator.py"), []byte("def add(a, b):\n return a + b\n"), 0o644); err != nil {
135 t.Fatal(err)
136 }
137 if err := os.WriteFile(filepath.Join(attempt2, "new.txt"), []byte("created\n"), 0o644); err != nil {
138 t.Fatal(err)
139 }
140 insertDiffSnapshot(t, db, "snap-1", base, now)
141 if _, err := db.Exec(`INSERT INTO rollouts (id, run_id, base_snapshot_id, status, fanout, winner_attempt_id, created_at, updated_at)
142 VALUES ('rollout-1', 'run-1', 'snap-1', 'completed', 2, 'attempt-2', ?, ?)`, now, now); err != nil {
143 t.Fatal(err)
144 }
145 insertDiffAttempt(t, db, "attempt-1", "tool-1", attempt1, "noop", "cat calculator.py", 0, now)
146 insertDiffAttempt(t, db, "attempt-2", "tool-2", attempt2, "correct-add", "sed fix", 1, now)
147
148 var diffOut bytes.Buffer
149 if err := DiffFileJSON(db, "run-1", "calculator.py", &diffOut); err != nil {
150 t.Fatal(err)
151 }
152 var diffManifest FileDiffManifest
153 if err := json.Unmarshal(diffOut.Bytes(), &diffManifest); err != nil {
154 t.Fatalf("invalid diff json: %v\n%s", err, diffOut.String())
155 }
156 if diffManifest.SchemaVersion != "agentprovenance.diff/v1" || len(diffManifest.Attempts) != 2 {
157 t.Fatalf("unexpected diff manifest: %+v", diffManifest)
158 }

Callers

nothing calls this directly

Calls 9

InitFunction · 0.92
OpenFunction · 0.92
insertDiffSnapshotFunction · 0.85
insertDiffAttemptFunction · 0.85
DiffFileJSONFunction · 0.85
BlameFileJSONFunction · 0.85
WriteFileMethod · 0.80
ExecMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected