Skip to content
Merged
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
20 changes: 17 additions & 3 deletions scripts/cold-start-contract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,26 @@ function requireExactArrayValues(actual, expected, label) {
}
}

function requireEvidenceFiles(actual) {
const paths = Array.isArray(actual)
? actual.map((value) => String(value).replaceAll("\\", "/"))
: [];
const complete = REQUIRED_EVIDENCE_FILES.every((relativePath) =>
paths.some((value) => value === relativePath || value.endsWith(`/${relativePath}`))
);
if (!complete) throw new Error("cold-start response is missing required evidence files");
}

function leadingGitCommit(value) {
return String(value || "").match(/^([0-9a-f]{40})(?:\s|$)/)?.[1] || null;
}

export function verifyColdStartResponse(
response,
{ expectedSourceCommit = CANDIDATE_SOURCE_BASE_COMMIT } = {}
) {
requireRecord(response);
if (response.source_commit !== expectedSourceCommit) {
if (leadingGitCommit(response.source_commit) !== expectedSourceCommit) {
throw new Error("cold-start response reported the wrong source commit");
}
if (response.frozen_baseline_commit !== FROZEN_BASELINE_COMMIT) {
Expand All @@ -77,10 +91,10 @@ export function verifyColdStartResponse(
}
requireExactArrayValues(response.proof_commands, REQUIRED_PROOF_COMMANDS, "proof commands");
const boundary = String(response.branch_boundary || "").toLowerCase();
if (!/(branch|worktree)/.test(boundary) || !boundary.includes("main") || !/(do not|don't|avoid|not edit)/.test(boundary)) {
if (!/(branch|worktree)/.test(boundary) || !boundary.includes("main") || !/(do not|don't|avoid|not edit|prohibit)/.test(boundary)) {
throw new Error("cold-start response did not preserve the protected branch boundary");
}
requireExactArrayValues(response.evidence_files, REQUIRED_EVIDENCE_FILES, "evidence files");
requireEvidenceFiles(response.evidence_files);

return {
source_commit_matches: true,
Expand Down
4 changes: 2 additions & 2 deletions scripts/run-cold-start-smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const errors = [];
let response = null;
let contractAssertions = null;
let traceAssertions = null;
if (execution.status !== 0) {
if (execution.status !== 0 || execution.error) {
const detail = execution.error?.code === "ETIMEDOUT"
? `timed out after ${timeout}ms`
: (execution.stderr || execution.stdout || `exit ${execution.status}`).trim();
Expand All @@ -108,7 +108,7 @@ try {

const statusAfter = run("git", ["status", "--porcelain"], 15000);
const assertions = {
codex_exit_zero: execution.status === 0,
codex_exit_zero: execution.status === 0 && !execution.error,
codex_not_timed_out: execution.error?.code !== "ETIMEDOUT",
repository_unchanged: statusBefore.status === 0
&& statusAfter.status === 0
Expand Down
25 changes: 25 additions & 0 deletions scripts/test-cold-start-contract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,36 @@ assert.equal(
}).next_task_matches,
true
);
assert.equal(
verifyColdStartResponse({
...valid,
source_commit: `${CANDIDATE_SOURCE_BASE_COMMIT} (Merge pull request #8)`
}).source_commit_matches,
true
);
assert.equal(
verifyColdStartResponse({
...valid,
evidence_files: valid.evidence_files.map((relativePath) => `/tmp/loopspine/${relativePath}`)
}).source_evidence_complete,
true
);
assert.equal(
verifyColdStartResponse({
...valid,
branch_boundary: "Meaningful edits remain prohibited on main; use this worktree."
}).protected_branch_boundary,
true
);

assert.throws(
() => verifyColdStartResponse({ ...valid, source_commit: FROZEN_BASELINE_COMMIT }),
/source commit/
);
assert.throws(
() => verifyColdStartResponse({ ...valid, source_commit: `HEAD ${CANDIDATE_SOURCE_BASE_COMMIT}` }),
/source commit/
);
assert.throws(
() => verifyColdStartResponse({ ...valid, promotion_status: "approved" }),
/promotion status/
Expand Down
Loading