Skip to content

Commit 672e26f

Browse files
authored
fix: retain sanitized drift evidence across retries (#510)
## Problem and behavior The post-merge drift run [37893558052](https://github.com/CopilotKit/aimock/actions/runs/37893558052) retained only the final report. Successful/skipped assertions and earlier retry failures were unavailable for diagnosing provider outcomes. This change writes a unique sanitized evidence sidecar for every collector invocation, including failure paths, and uploads every sidecar with the existing final report. It records assertion identities/statuses plus strictly allowlisted provider metadata where the installed Vitest reporter authenticates the originating test or suite. Missing, ambiguous, malformed, wrong-context, and stderr markers cannot certify a native provider outcome. Failed assertions retain precedence. Raw provider bodies, arbitrary text, and secrets are excluded; identity redaction runs before clipping. The collector launches the candidate-installed Vitest directly and receives context over a private in-memory reporter channel. Existing grading, exit codes, provider contracts, schedule, permissions, versions, and release behavior are unchanged. The Unreleased changelog documents evidence retention. ## Real local RED/GREEN proof All reproduction fixtures exercised the actual collector CLI, installed Vitest subprocess, reporter channel, and finalized JSON sidecars offline; these are metadata-consumer tests, not new native-provider acceptance. - Assertion retention: original collector with the final identical test selection failed 5 cases (exit 1); corrected collector passed the same 5 (exit 0). Two real invocations produced distinct sidecars, preserving pass/skip/failure identities and earlier attempts. Failure-finalization and write-error controls also passed. - Provider metadata: each adapter's real collector/Vitest fixture failed before its projection and passed afterward, including native target, native non-trigger, local/captured, wrong-context, unknown-field, and failed-assertion controls where applicable. - Vertex privacy mutation: the original assertion allowed a sidecar containing the actual fixture canary (test exit 0). With only the assertion corrected, the identical leak mutation failed at that assertion (exit 1); the unmutated collector passed (exit 0). - Stream-origin mutation: forcing the actual reporter to label stderr as stdout initially survived 3 tests. The added valid native-context stderr marker made that mutant fail (1 failed, 2 passed); the correct reporter passed all 3. Independent boundary confirmation repeated the rejection and restoration through actual Vitest. - Upload selection: the original workflow path selected only the final report; the corrected path selected that report and both actual invocation sidecars. Independent offline execution of the pinned upload consumer accepted the three-file set and preserved relative paths. This does not claim hosted upload execution. Representative terminal output from the actual proof runs: ```text Retention original: Tests 5 failed | 292 skipped; exit 1 Retention corrected: Tests 5 passed | 292 skipped; exit 0 Vertex mutant, old assertion: Vitest exit 0; actual fixture canary leaked true Vertex mutant, corrected assertion: Tests 1 failed | 315 skipped; exit 1 Vertex unmutated candidate: Tests 1 passed | 315 skipped; exit 0 Independent stream mutant: Tests 1 failed | 1 passed | 314 skipped Independent restored reporter: Tests 1 passed | 315 skipped Final combined corrected cases: Tests 2 passed | 314 skipped; exit 0 ``` ## Validation and limits - Full affected collector/workflow integration: 341 tests passed, zero skipped/unhandled/RPC errors. The final two test-only corrections passed together; unchanged full-suite proof was reused rather than represented as a fresh rerun. - Formatting and lint passed for changed files. Explicit production, test-tree, and scripts TypeScript checks passed. Full package build passed. - Structural workflow lint passed. Full actionlint retains the identical pre-existing SC2086 informational diagnostic; no new workflow diagnostic was introduced. - Independent review covered all seven required roles and both runtime boundaries; mandatory findings were corrected and confirmed. Two inherited main-report grading defects remain separate backlog items; this change retains their failed evidence but does not fix their grading. - Two signed commits preserve the exact reviewed tree. No version was changed and no release or additional provider run was performed. CI is still required after push before merge readiness can be claimed.
2 parents 83556d0 + f96e979 commit 672e26f

6 files changed

Lines changed: 2348 additions & 30 deletions

File tree

‎.github/workflows/test-drift.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ jobs:
391391
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
392392
with:
393393
name: drift-report
394-
path: drift-report.json
394+
path: |
395+
drift-report.json
396+
drift-evidence/*.json
395397
if-no-files-found: warn
396398
retention-days: 30
397399

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
### Fixed
2323

24+
- Retain sanitized drift evidence for each test and retry attempt in CI artifacts.
2425
- Align Cohere streaming length-stop faults with captured tool closure, `TOOL_CALL`, and terminal `[DONE]` framing while preserving incomplete argument bytes. Object length stops retain modeled `MAX_TOKENS`; recurring comparisons distinguish valid object nontriggers from failures.
2526
- Preserve malformed tool-call argument strings on string-based response wires instead of silently replacing them with `{}`. Object-based wires now return an explicit error (HTTP 500, or a Gemini Live WebSocket error) before response content. Valid JSON, empty or omitted legacy arguments, and fixture validation retain their existing behavior.
2627

‎scripts/drift-evidence-reporter.ts‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { writeFileSync } from "node:fs";
2+
import type { Reporter } from "vitest/reporters";
3+
4+
type TestCase = Parameters<NonNullable<Reporter["onTestCaseResult"]>>[0];
5+
type TestSuite = Parameters<NonNullable<Reporter["onTestSuiteResult"]>>[0];
6+
type TestModule = Parameters<NonNullable<Reporter["onTestModuleEnd"]>>[0];
7+
8+
export type EvidenceReporterRecord =
9+
| { kind: "console"; taskId: string; stream: "stdout" | "stderr"; content: string }
10+
| {
11+
kind: "identity";
12+
id: string;
13+
entity: "test" | "suite" | "module";
14+
file: string;
15+
ancestors: string[];
16+
title: string;
17+
}
18+
| { kind: "unavailable" }
19+
| { kind: "complete" };
20+
21+
export const MAX_EVIDENCE_RECORD_BYTES = 256 * 1024;
22+
23+
// Private parent pipe only. No stdout, disk artifacts, provider interpretation,
24+
// or header-text parsing: console content cannot mint an entity identity.
25+
export default class DriftEvidenceReporter implements Reporter {
26+
private broken = false;
27+
28+
private emit(record: EvidenceReporterRecord) {
29+
if (this.broken) return;
30+
try {
31+
const encoded = JSON.stringify(record);
32+
writeFileSync(
33+
3,
34+
(Buffer.byteLength(encoded) <= MAX_EVIDENCE_RECORD_BYTES
35+
? encoded
36+
: '{"kind":"unavailable"}') + "\n",
37+
);
38+
} catch {
39+
this.broken = true;
40+
// A missing completion record makes the parent mark the channel unavailable.
41+
}
42+
}
43+
44+
private identity(entity: TestCase | TestSuite | TestModule) {
45+
try {
46+
const ancestors: string[] = [];
47+
if (entity.type !== "module") {
48+
let parent = entity.parent;
49+
while (parent.type !== "module") {
50+
ancestors.unshift(parent.name);
51+
parent = parent.parent;
52+
}
53+
}
54+
this.emit({
55+
kind: "identity",
56+
id: entity.id,
57+
entity: entity.type,
58+
file: entity.type === "module" ? entity.moduleId : entity.module.moduleId,
59+
ancestors,
60+
title: entity.type === "module" ? "" : entity.name,
61+
});
62+
} catch {
63+
this.emit({ kind: "unavailable" });
64+
}
65+
}
66+
67+
onUserConsoleLog: NonNullable<Reporter["onUserConsoleLog"]> = (log) => {
68+
this.emit({
69+
kind: "console",
70+
taskId: log.taskId ?? "",
71+
stream: log.type,
72+
content: log.content,
73+
});
74+
};
75+
76+
onTestCaseResult(test: TestCase) {
77+
this.identity(test);
78+
}
79+
onTestSuiteResult(suite: TestSuite) {
80+
this.identity(suite);
81+
}
82+
onTestModuleEnd(module: TestModule) {
83+
this.identity(module);
84+
}
85+
onFinished() {
86+
this.emit({ kind: "complete" });
87+
}
88+
}

0 commit comments

Comments
 (0)