Skip to content

Commit 6a0e546

Browse files
authored
fix(test): filter recall evidence log capture to recall lines (#1266)
The seven recall-evidence tests in `internal/db/recall_evidence_window_test.go` capture the global `log` output via `captureRecallEvidenceLog` and assert on the whole buffer — mostly exact-equality against a single expected `recall: revoked provenance ...` line, plus two empty-buffer checks on rollback paths. That is stricter than the tests' intent: any unrelated line written to the global logger inside the capture window fails them. One such line exists in practice: `ReplaceSessionMessages` logs a `db: ReplaceSessionMessages ...` diagnostic when the call exceeds `slowOpThreshold` (100ms). Under the coverage job's instrumentation the call crossed the threshold and the diagnostic landed in the captured buffer, failing `TestRecallEvidenceReconciliationLogsStableReason/missing_digest` on an unrelated PR (run 30135996204). This change filters at the capture point instead of loosening assertions: `captureRecallEvidenceLog` now returns a writer that retains only `recall: `-prefixed lines (the only prefix the revocation flush emits) and discards everything else. Since the writer embeds `bytes.Buffer`, all seven call sites — `String()`, `Reset()`, the `assert.Empty` checks — are unchanged, and the exact-equality assertions keep their full strength for recall lines specifically. A small regression test replays the pollution scenario directly. The slow-op diagnostics themselves are intentional production instrumentation and are untouched. Other log-capture helpers in the repo (`cmd/agentsview`, `internal/config`, `internal/parser`, `internal/duckdb`) already use substring/count-based assertions and are not affected by this failure mode, so they are deliberately left alone. Reviewers should look at the `recallEvidenceLogBuffer.Write` prefix check: it relies on the stdlib `log` package issuing one `Write` per formatted line, which holds because the helper clears flags and prefix while installed.
1 parent 9e5324c commit 6a0e546

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

internal/db/recall_evidence_window_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,27 @@ func requireRecallEntry(t *testing.T, d *DB, id string) *RecallEntry {
11891189
return entry
11901190
}
11911191

1192-
func captureRecallEvidenceLog(t *testing.T) *bytes.Buffer {
1192+
// recallEvidenceLogBuffer keeps only "recall: " prefixed lines written to the
1193+
// global logger while installed, discarding unrelated lines — e.g. the
1194+
// "db: <Op> ..." slow-op diagnostics gated on slowOpThreshold — so a
1195+
// coincidentally slow operation (coverage instrumentation, a loaded CI
1196+
// runner) cannot pollute the exact-equality assertions on revocation lines.
1197+
// The stdlib log package with flags and prefix cleared issues exactly one
1198+
// Write call per formatted line, so matching the prefix per Write is exact.
1199+
type recallEvidenceLogBuffer struct {
1200+
bytes.Buffer
1201+
}
1202+
1203+
func (b *recallEvidenceLogBuffer) Write(p []byte) (int, error) {
1204+
if bytes.HasPrefix(p, []byte("recall: ")) {
1205+
return b.Buffer.Write(p)
1206+
}
1207+
return len(p), nil
1208+
}
1209+
1210+
func captureRecallEvidenceLog(t *testing.T) *recallEvidenceLogBuffer {
11931211
t.Helper()
1194-
var output bytes.Buffer
1212+
var output recallEvidenceLogBuffer
11951213
previousWriter := log.Writer()
11961214
previousFlags := log.Flags()
11971215
previousPrefix := log.Prefix()
@@ -1205,3 +1223,16 @@ func captureRecallEvidenceLog(t *testing.T) *bytes.Buffer {
12051223
})
12061224
return &output
12071225
}
1226+
1227+
func TestRecallEvidenceLogCaptureIgnoresUnrelatedLines(t *testing.T) {
1228+
logs := captureRecallEvidenceLog(t)
1229+
1230+
log.Printf("db: ReplaceSessionMessages s1 (3 msgs): 180ms")
1231+
log.Printf("recall: revoked provenance for entry-1: missing digest")
1232+
1233+
assert.Equal(
1234+
t,
1235+
"recall: revoked provenance for entry-1: missing digest",
1236+
strings.TrimSpace(logs.String()),
1237+
)
1238+
}

0 commit comments

Comments
 (0)