fix: split github contracts from script check

This commit is contained in:
Codex
2026-06-10 14:36:00 +00:00
parent 420a9a9e85
commit 4ee3a67089
12 changed files with 233 additions and 94 deletions
+30 -15
View File
@@ -49,6 +49,20 @@ function deterministicSteerId(taskId: string, prompt: string): string {
return `steer_${Bun.SHA256.hash(`unidesk-code-queue-steer:v1\0${taskId}\0${prompt}`, "hex").slice(0, 24)}`;
}
function assertLegacyFrozenWrite(result: { status: number | null; stdout: string; stderr: string; json: JsonRecord | null }, command: string): void {
assertCondition(result.status !== 0 && result.json?.ok === false, `${command} should be frozen`, result.json ?? { stdout: result.stdout, stderr: result.stderr });
const data = nestedRecord(result.json?.data, []);
assertCondition(data.ok === false, `${command} frozen payload should be ok=false`, data);
assertCondition(data.frozen === true, `${command} frozen payload should expose frozen=true`, data);
assertCondition(data.mutation === false, `${command} frozen payload should be non-mutating`, data);
assertCondition(data.degradedReason === "legacy-code-queue-frozen", `${command} should use the legacy frozen reason`, data);
assertCondition(data.command === command, `${command} frozen payload should identify the command`, data);
const replacement = nestedRecord(data, ["replacement"]);
assertCondition(String(replacement.sessionsSteer || "").includes("agentrun v01 sessions steer"), `${command} should point to AgentRun sessions steer`, replacement);
const legacy = nestedRecord(data, ["legacy"]);
assertCondition(legacy.noDoubleWrite === true, `${command} should document no double-write`, legacy);
}
function assertDryRunPrompt(response: JsonRecord, expectedText: string): void {
assertCondition(response.ok === true, "CLI dry-run should succeed", response);
const data = nestedRecord(response.data, []);
@@ -82,31 +96,29 @@ function assertReason(result: unknown, reason: string, status: number | null): v
export function runCodeQueueCliSteerContract(): JsonRecord {
const positional = runCli(["codex", "steer", "codex_test_task", "correct the running task", "--dry-run"]);
assertDryRunPrompt(positional.json ?? {}, "correct the running task");
assertLegacyFrozenWrite(positional, "codex steer");
assertCondition(String(positional.json?.command || "").includes("<prompt:redacted>"), "outer command should redact positional steer prompt", positional.json ?? {});
assertCondition(!String(positional.json?.command || "").includes("correct the running task"), "outer command must not echo positional steer prompt", positional.json ?? {});
const stdin = runCli(["codex", "steer", "codex_test_task", "--prompt-stdin", "--dry-run"], "stdin steer prompt\n");
assertDryRunPrompt(stdin.json ?? {}, "stdin steer prompt\n");
assertLegacyFrozenWrite(stdin, "codex steer");
assertCondition(!stdin.stdout.includes("stdin steer prompt"), "frozen steer must not echo stdin prompt", { stdout: stdin.stdout });
const promptFile = join(tmpdir(), `unidesk-code-queue-steer-${process.pid}.txt`);
writeFileSync(promptFile, "file steer prompt", "utf8");
try {
const fromFile = runCli(["codex", "steer", "codex_test_task", "--prompt-file", promptFile, "--dry-run"]);
assertDryRunPrompt(fromFile.json ?? {}, "file steer prompt");
assertLegacyFrozenWrite(fromFile, "codex steer");
assertCondition(!fromFile.stdout.includes("file steer prompt"), "frozen steer must not echo file prompt", { stdout: fromFile.stdout });
} finally {
unlinkSync(promptFile);
}
const duplicateSource = runCli(["codex", "steer", "codex_test_task", "positional", "--prompt-stdin", "--dry-run"], "stdin\n");
assertCondition(duplicateSource.status !== 0, "duplicate prompt source should fail", duplicateSource.json ?? { stdout: duplicateSource.stdout });
const duplicateMessage = String(nestedRecord(duplicateSource.json, ["error"]).message || "");
assertCondition(duplicateMessage.includes("exactly one prompt source"), "duplicate prompt source error should be explicit", { duplicateMessage });
assertLegacyFrozenWrite(duplicateSource, "codex steer");
const unknownOption = runCli(["codex", "steer", "codex_test_task", "--queue", "default", "prompt", "--dry-run"]);
assertCondition(unknownOption.status !== 0, "unknown steer option should fail", unknownOption.json ?? { stdout: unknownOption.stdout });
const unknownMessage = String(nestedRecord(unknownOption.json, ["error"]).message || "");
assertCondition(unknownMessage.includes("unsupported codex steer option: --queue"), "unknown option error should name option", { unknownMessage });
assertLegacyFrozenWrite(unknownOption, "codex steer");
const help = runCli(["codex", "help"]);
assertCondition(help.status === 0 && help.json?.ok === true, "codex help should succeed", help.json ?? { stdout: help.stdout });
@@ -118,7 +130,10 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
assertCondition(!("error" in (advertisedConfirm.json ?? {})), "advertised steer-confirm command must not fall through to top-level error", advertisedConfirm.json ?? {});
const advertisedDeliveryStatus = String(nestedRecord(advertisedConfirm.json?.data, ["delivery"]).status || "");
assertCondition(["confirmed", "pending", "unknown", "not-supported"].includes(advertisedDeliveryStatus), "advertised steer-confirm command should return structured delivery status", { advertisedDeliveryStatus, json: advertisedConfirm.json });
assertCondition(!String(JSON.stringify(advertisedConfirm.json)).includes("\"message\":\"not found\""), "advertised steer-confirm command must not return top-level not found", advertisedConfirm.json ?? {});
if (advertisedDeliveryStatus === "not-supported") {
const diagnostics = nestedRecord(advertisedConfirm.json?.data, ["diagnostics"]);
assertCondition(diagnostics.reason === "steer-confirmation-endpoint-not-supported", "unsupported steer-confirm should use structured diagnostics", diagnostics);
}
let dryRunFetchCount = 0;
const dryRunDirect = codexSteerTaskForTest("direct_task", ["do not send", "--dry-run"], () => {
@@ -501,11 +516,11 @@ export function runCodeQueueCliSteerContract(): JsonRecord {
return {
ok: true,
checks: [
"steer positional dry-run",
"steer stdin dry-run",
"steer prompt-file dry-run",
"duplicate prompt source failure",
"unsupported option failure",
"legacy steer positional dry-run is frozen",
"legacy steer stdin dry-run is frozen",
"legacy steer prompt-file dry-run is frozen",
"legacy steer duplicate prompt source is frozen",
"legacy steer unsupported option is frozen",
"codex help lists steer",
"advertised steer-confirm CLI command returns structured status",
"outer command redacts positional steer prompt",