Skip to content

Commit 4ea4595

Browse files
committed
improve(ci): enforce temp path guard in hosted checks
1 parent 7c71d41 commit 4ea4595

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,14 @@ jobs:
26602660
fi
26612661
pnpm tool-display:check
26622662
pnpm check:host-env-policy:swift
2663+
if has_package_script "check:temp-path-guardrails"; then
2664+
pnpm check:temp-path-guardrails
2665+
elif [[ "$FROZEN_TARGET" == "true" ]]; then
2666+
echo "[skip] frozen target predates the temp path guardrails"
2667+
else
2668+
echo "Current CI targets must provide the check:temp-path-guardrails package script." >&2
2669+
exit 1
2670+
fi
26632671
if [[ "$FROZEN_TARGET" == "true" ]]; then
26642672
pnpm dup:check:coverage
26652673
else

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,52 @@ function runProtocolSinceFixture(checkout: string, baseSha: string) {
11561156
});
11571157
}
11581158

1159+
function runGuardCheckFixture(options: { frozenTarget: boolean; scripts: string[] }): {
1160+
calls: string[];
1161+
output: string;
1162+
status: number | null;
1163+
} {
1164+
const root = tempDirs.make("openclaw-ci-guards-");
1165+
const fakeBin = path.join(root, "bin");
1166+
const callsPath = path.join(root, "pnpm-calls.txt");
1167+
mkdirSync(fakeBin);
1168+
writeFileSync(
1169+
path.join(root, "package.json"),
1170+
`${JSON.stringify({
1171+
scripts: Object.fromEntries(options.scripts.map((name) => [name, "true"])),
1172+
})}\n`,
1173+
);
1174+
writeExecutable(path.join(fakeBin, "pnpm"), [
1175+
"#!/usr/bin/env bash",
1176+
"set -euo pipefail",
1177+
'printf "%s\\n" "$*" >> "$PNPM_CALLS"',
1178+
]);
1179+
const checkShardRun = readCiWorkflow().jobs["check-shard"].steps.find(
1180+
(step: WorkflowStep) => step.name === "Run check shard",
1181+
).run;
1182+
const run = spawnSync("bash", ["-c", checkShardRun], {
1183+
cwd: root,
1184+
encoding: "utf8",
1185+
env: {
1186+
...process.env,
1187+
FROZEN_TARGET: options.frozenTarget ? "true" : "false",
1188+
FORMAT_CHECK: "false",
1189+
HISTORICAL_TARGET: options.frozenTarget ? "true" : "false",
1190+
PATH: `${fakeBin}:${process.env.PATH ?? ""}`,
1191+
PNPM_CALLS: callsPath,
1192+
PR_BASE_SHA: "",
1193+
TASK: "guards",
1194+
},
1195+
});
1196+
return {
1197+
calls: existsSync(callsPath)
1198+
? readFileSync(callsPath, "utf8").trim().split("\n").filter(Boolean)
1199+
: [],
1200+
output: `${run.stdout}${run.stderr}`,
1201+
status: run.status,
1202+
};
1203+
}
1204+
11591205
function runDependencyCheckFixture(options: {
11601206
historicalTarget: boolean;
11611207
releaseToolingEntry?: boolean;
@@ -6192,6 +6238,50 @@ printf '%s\n' "\${CURL_SUCCESS_IP:-203.0.113.7}"
61926238
);
61936239
});
61946240

6241+
it("runs temp path guardrails in the hosted guard shard", () => {
6242+
const requiredScripts = ["check:doctor-deprecation-registry", "check:coercion-helpers"];
6243+
const current = runGuardCheckFixture({
6244+
frozenTarget: false,
6245+
scripts: [...requiredScripts, "check:temp-path-guardrails"],
6246+
});
6247+
expect(current.status, current.output).toBe(0);
6248+
expect(current.calls).toContain("check:temp-path-guardrails");
6249+
expect(current.calls.indexOf("check:temp-path-guardrails")).toBeLessThan(
6250+
current.calls.indexOf("dup:check"),
6251+
);
6252+
6253+
const frozenMissing = runGuardCheckFixture({
6254+
frozenTarget: true,
6255+
scripts: requiredScripts,
6256+
});
6257+
expect(frozenMissing.status, frozenMissing.output).toBe(0);
6258+
expect(frozenMissing.calls).not.toContain("check:temp-path-guardrails");
6259+
expect(frozenMissing.calls).toContain("dup:check:coverage");
6260+
expect(frozenMissing.output).toContain(
6261+
"[skip] frozen target predates the temp path guardrails",
6262+
);
6263+
6264+
const currentMissing = runGuardCheckFixture({
6265+
frozenTarget: false,
6266+
scripts: requiredScripts,
6267+
});
6268+
expect(currentMissing.status).toBe(1);
6269+
expect(currentMissing.calls).not.toContain("check:temp-path-guardrails");
6270+
expect(currentMissing.calls).not.toContain("dup:check");
6271+
expect(currentMissing.output).toContain(
6272+
"Current CI targets must provide the check:temp-path-guardrails package script.",
6273+
);
6274+
6275+
const workflow = readFileSync(".github/workflows/ci.yml", "utf8");
6276+
const preflightGuards = workflow.slice(
6277+
workflow.indexOf("guards)"),
6278+
workflow.indexOf("npm-lock)"),
6279+
);
6280+
expect(preflightGuards.indexOf("pnpm check:temp-path-guardrails")).toBeLessThan(
6281+
preflightGuards.indexOf("pnpm dup:check"),
6282+
);
6283+
});
6284+
61956285
it("rejects ambiguous zero-before main pushes and preserves concrete bases", () => {
61966286
const zeroSha = "0".repeat(40);
61976287
const threeCommit = runPushDiffBaseFixture({ commitCount: 3, eventBaseSha: zeroSha });

0 commit comments

Comments
 (0)