Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/openai-provider-option-final-gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface GateSpec {
command: string[];
cwd?: string;
env?: Record<string, string>;
successExitCodes?: number[];
}

export interface GateResult {
Expand All @@ -31,7 +32,9 @@ export async function runGateSequence(plan: GateSpec[], deps: GateDeps): Promise
const lines = ["schemaVersion=1", "verdict=PASS"];
for (const [index, gate] of plan.entries()) {
const result = await deps.run(gate);
if (result.exitCode !== 0) throw new Error(`gate failed: ${gate.name} (${result.exitCode})`);
if (!(gate.successExitCodes ?? [0]).includes(result.exitCode)) {
throw new Error(`gate failed: ${gate.name} (${result.exitCode})`);
}
lines.push(summaryLine(index, gate, result));
}
const summary = lines.join("\n") + "\n";
Expand Down Expand Up @@ -87,6 +90,7 @@ export function finalGatePlan(root: string, evidenceDir: string, unitRoot = dirn
"src", "gui/src", "tests", "scripts", "README.md", "readme/README.ko.md", "readme/README.zh-CN.md",
"structure", "docs-site/src/content/docs"],
cwd: root,
successExitCodes: [1],
},
{
name: "scoped-diff-check",
Expand Down
15 changes: 14 additions & 1 deletion tests/openai-provider-option-tooling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "nod
import { tmpdir } from "node:os";
import { join } from "node:path";
import { evidenceDenyFindings, scanEvidence } from "../scripts/openai-provider-option-evidence-scan";
import { runGateSequence, type GateResult, type GateSpec } from "../scripts/openai-provider-option-final-gates";
import { finalGatePlan, runGateSequence, type GateResult, type GateSpec } from "../scripts/openai-provider-option-final-gates";
import { evaluateLivePolicy, type LiveOutcome } from "../scripts/openai-hardening-live-policy";
import { buildSanitizedRuntimeEnv } from "../scripts/openai-hardening-runtime-env";
import { buildUnixCodexShim } from "../src/codex/shim";
Expand Down Expand Up @@ -159,6 +159,19 @@ describe("OpenAI provider-option evidence scanner", () => {
});

describe("OpenAI provider-option final gate runner", () => {
test("passes the stale-contract scan only when ripgrep finds no matches", async () => {
const gate = finalGatePlan("/repo", "/repo/evidence").find(candidate => candidate.name === "stale-contract-scan")!;
const deps = (exitCode: number) => ({
run: async () => ({ exitCode, output: "" }),
writeSummary: () => {},
scan: () => [],
});

await expect(runGateSequence([gate], deps(0))).rejects.toThrow("gate failed: stale-contract-scan (0)");
await expect(runGateSequence([gate], deps(1))).resolves.toContain("verdict=PASS");
await expect(runGateSequence([gate], deps(2))).rejects.toThrow("gate failed: stale-contract-scan (2)");
});

test("runs once in order, writes one sanitized summary, then scans", async () => {
const order: string[] = [];
const writes: string[] = [];
Expand Down
Loading