Skip to content

Commit e33606e

Browse files
authored
fix(release): verify focused candidate checkout (#129201)
* fix(release): verify focused candidate checkout * fix(release): ignore unselected historical validation children
1 parent a6b8eb5 commit e33606e

5 files changed

Lines changed: 505 additions & 10 deletions

‎.github/workflows/docker-release.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ jobs:
292292
--source-digest "${PRODUCER_WORKFLOW_SHA}" \
293293
--source-ref "${PRODUCER_WORKFLOW_FULL_REF}" \
294294
--deny-self-hosted-runners
295-
node .release-harness/scripts/validate-authorized-beta-focused-evidence.mts verify \
296-
--candidate-root . \
295+
node .release-harness/scripts/verify-authorized-beta-focused-candidate.mjs \
296+
--repository-root . \
297+
--validator .release-harness/scripts/validate-authorized-beta-focused-evidence.mts \
298+
--policy .release-harness/scripts/authorized-beta-focused-policy.json \
297299
--artifact "${evidence}" \
298300
--producer-run-id "${FOCUSED_RELEASE_EVIDENCE_RUN_ID}" \
299301
--producer-run-attempt "${FOCUSED_RELEASE_EVIDENCE_RUN_ATTEMPT}" \

‎.github/workflows/openclaw-release-publish.yml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ jobs:
535535
--jq .content | base64 --decode > "${tooling_dir}/plugin-sdk-api-release-evidence.mjs"
536536
gh api "repos/${GITHUB_REPOSITORY}/contents/scripts/validate-authorized-beta-focused-evidence.mts?ref=${WORKFLOW_SHA}" \
537537
--jq .content | base64 --decode > "${tooling_dir}/validate-authorized-beta-focused-evidence.mts"
538+
gh api "repos/${GITHUB_REPOSITORY}/contents/scripts/verify-authorized-beta-focused-candidate.mjs?ref=${WORKFLOW_SHA}" \
539+
--jq .content | base64 --decode > "${tooling_dir}/verify-authorized-beta-focused-candidate.mjs"
538540
gh api "repos/${GITHUB_REPOSITORY}/contents/scripts/authorized-beta-focused-policy.json?ref=${WORKFLOW_SHA}" \
539541
--jq .content | base64 --decode > "${tooling_dir}/authorized-beta-focused-policy.json"
540542
gh api "repos/${GITHUB_REPOSITORY}/contents/scripts/lib/record-shared.mjs?ref=${WORKFLOW_SHA}" \
@@ -814,8 +816,11 @@ jobs:
814816
--source-digest "${PRODUCER_WORKFLOW_SHA}" \
815817
--source-ref "${PRODUCER_WORKFLOW_FULL_REF}" \
816818
--deny-self-hosted-runners
817-
node "${RUNNER_TEMP}/release-validation-tooling/validate-authorized-beta-focused-evidence.mts" verify \
818-
--candidate-root . \
819+
tooling_dir="${RUNNER_TEMP}/release-validation-tooling"
820+
node "${tooling_dir}/verify-authorized-beta-focused-candidate.mjs" \
821+
--repository-root . \
822+
--validator "${tooling_dir}/validate-authorized-beta-focused-evidence.mts" \
823+
--policy "${tooling_dir}/authorized-beta-focused-policy.json" \
819824
--artifact "${evidence}" \
820825
--producer-run-id "${FOCUSED_RELEASE_EVIDENCE_RUN_ID}" \
821826
--producer-run-attempt "${FOCUSED_RELEASE_EVIDENCE_RUN_ATTEMPT}" \
@@ -950,8 +955,10 @@ jobs:
950955
--source-digest "${PRODUCER_WORKFLOW_SHA}" \
951956
--source-ref "${PRODUCER_WORKFLOW_FULL_REF}" \
952957
--deny-self-hosted-runners
953-
node .release-harness/scripts/validate-authorized-beta-focused-evidence.mts verify \
954-
--candidate-root . \
958+
node .release-harness/scripts/verify-authorized-beta-focused-candidate.mjs \
959+
--repository-root . \
960+
--validator .release-harness/scripts/validate-authorized-beta-focused-evidence.mts \
961+
--policy .release-harness/scripts/authorized-beta-focused-policy.json \
955962
--artifact "${evidence}" \
956963
--producer-run-id "${FOCUSED_RELEASE_EVIDENCE_RUN_ID}" \
957964
--producer-run-attempt "${FOCUSED_RELEASE_EVIDENCE_RUN_ATTEMPT}" \

‎scripts/validate-authorized-beta-focused-evidence.mts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,18 @@ function requireHistoricalExecutionPlan(policy: AuthorizedBetaFocusedPolicy) {
350350
fail("historical execution plan children must be an array");
351351
}
352352
const childRuns = new Map(
353-
plan.children.map((entry: unknown) => {
353+
plan.children.flatMap((entry: unknown) => {
354354
if (!isRecord(entry)) {
355355
fail("historical execution plan child must be an object");
356356
}
357+
if (entry.selected !== true) {
358+
return [];
359+
}
357360
return [
358-
exactString(entry.key, "historical execution plan child key"),
359-
exactJsonId(entry.runId, "historical execution plan child run id"),
361+
[
362+
exactString(entry.key, "historical execution plan child key"),
363+
exactJsonId(entry.runId, "historical execution plan child run id"),
364+
],
360365
];
361366
}),
362367
);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env node
2+
import { execFileSync, spawnSync } from "node:child_process";
3+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { dirname, join, resolve } from "node:path";
6+
7+
const FORWARDED_OPTIONS = new Set([
8+
"--artifact",
9+
"--producer-run-id",
10+
"--producer-run-attempt",
11+
"--producer-workflow-full-ref",
12+
"--producer-workflow-sha",
13+
]);
14+
15+
function main() {
16+
const [rootFlag, root, validatorFlag, validator, policyFlag, policyFile, ...forwarded] =
17+
process.argv.slice(2);
18+
if (
19+
rootFlag !== "--repository-root" ||
20+
!root ||
21+
validatorFlag !== "--validator" ||
22+
!validator ||
23+
policyFlag !== "--policy" ||
24+
!policyFile
25+
) {
26+
throw new Error("expected --repository-root <path> --validator <path> --policy <path>");
27+
}
28+
const seen = new Set();
29+
for (let index = 0; index < forwarded.length; index += 2) {
30+
const option = forwarded[index];
31+
const value = forwarded[index + 1];
32+
if (!FORWARDED_OPTIONS.has(option) || seen.has(option) || !value || value.startsWith("--")) {
33+
throw new Error(`invalid focused evidence verifier option: ${option ?? "<missing>"}`);
34+
}
35+
seen.add(option);
36+
}
37+
38+
const repositoryRoot = resolve(root);
39+
const validatorPath = resolve(validator);
40+
const policyPath = resolve(policyFile);
41+
if (policyPath !== join(dirname(validatorPath), "authorized-beta-focused-policy.json")) {
42+
throw new Error("focused evidence policy must be the trusted validator's adjacent policy");
43+
}
44+
const policy = JSON.parse(readFileSync(policyPath, "utf8"));
45+
if (
46+
policy === null ||
47+
typeof policy !== "object" ||
48+
Array.isArray(policy) ||
49+
policy.schema !== "openclaw.authorized-beta-focused-policy.v1" ||
50+
policy.mode !== "authorized-beta-focused-v1" ||
51+
typeof policy.candidateSha !== "string" ||
52+
!/^[a-f0-9]{40}$/u.test(policy.candidateSha)
53+
) {
54+
throw new Error("invalid trusted focused evidence policy or candidate SHA");
55+
}
56+
57+
const candidateSha = policy.candidateSha;
58+
const git = (args, options = {}) =>
59+
execFileSync("git", ["-C", repositoryRoot, ...args], { stdio: "inherit", ...options });
60+
const hasCandidate = () =>
61+
spawnSync("git", ["-C", repositoryRoot, "cat-file", "-e", `${candidateSha}^{commit}`], {
62+
stdio: "ignore",
63+
}).status === 0;
64+
if (!hasCandidate()) {
65+
git(["fetch", "--no-tags", "origin", candidateSha], { timeout: 120_000 });
66+
if (!hasCandidate()) {
67+
throw new Error(`trusted focused evidence candidate is unavailable: ${candidateSha}`);
68+
}
69+
}
70+
71+
const directory = mkdtempSync(join(tmpdir(), "authorized-beta-focused-candidate-"));
72+
const candidateRoot = join(directory, "candidate");
73+
let worktreeAdded = false;
74+
try {
75+
// Verification reads Git objects only; no checkout also prevents candidate checkout hooks.
76+
git(["worktree", "add", "--detach", "--no-checkout", candidateRoot, candidateSha]);
77+
worktreeAdded = true;
78+
execFileSync(
79+
process.execPath,
80+
[validatorPath, "verify", "--candidate-root", candidateRoot, ...forwarded],
81+
{ cwd: repositoryRoot, stdio: "inherit" },
82+
);
83+
} finally {
84+
try {
85+
if (worktreeAdded) {
86+
git(["worktree", "remove", "--force", candidateRoot]);
87+
}
88+
} finally {
89+
try {
90+
rmSync(directory, { force: true, recursive: true });
91+
} finally {
92+
git(["worktree", "prune", "--expire", "now"]);
93+
}
94+
}
95+
}
96+
}
97+
98+
try {
99+
main();
100+
} catch (error) {
101+
console.error(error instanceof Error ? error.message : "unknown error");
102+
console.error("[authorized-beta-focused-candidate] FAILED (exit 1)");
103+
process.exitCode = 1;
104+
}

0 commit comments

Comments
 (0)