Skip to content

Commit fbd910d

Browse files
authored
fix(ci): enforce env budget before merge (#125189)
1 parent 1487b45 commit fbd910d

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎docs/ci.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dispatch.
3737
| `pnpm-store-warmup` | Warm the lockfile-pinned Actions cache for fork PRs, manual runs, and same-repo docs-only PRs | Node or docs-check lanes without an exact-cache writer |
3838
| `build-artifacts` | Build `dist/`, Control UI, built-CLI smoke checks, startup memory, and embedded built-artifact checks | Node-relevant changes |
3939
| `control-ui-i18n` | Verify generated Control UI locale bundles, metadata, and translation memory; advisory on automatic runs, blocking on manual release CI | Control UI i18n-relevant changes and manual CI |
40-
| `checks-fast-core` | Fast Linux correctness lanes: max-lines and assertion-safety baseline ratchets, bundled + protocol, Bun launcher, and the CI-routing fast task | Node-relevant changes |
40+
| `checks-fast-core` | Fast Linux correctness lanes: environment-variable, max-lines, and assertion-safety baseline ratchets, bundled + protocol, Bun launcher, and the CI-routing fast task | Node-relevant changes |
4141
| `qa-smoke-ci-profile` | Self-contained balanced parts of the automatic QA Smoke coverage set; one private-overlay build per part (the smoke set has no docker-lane or Control UI scenarios; the run step fails closed if one returns) | Pushes and manual runs; PRs only on QA-owned surfaces |
4242
| `checks-fast-contracts-plugins-*` | Two weighted plugin contract shards | Node-relevant changes |
4343
| `checks-fast-contracts-channels-*` | Two weighted channel contract shards | Node-relevant changes |
@@ -173,7 +173,7 @@ Barnacle treats bug-labeled issues as verification candidates rather than inacti
173173

174174
Ordinary manual CI dispatches run the same job graph as normal CI but force every non-Android scoped lane on: Linux Node shards, bundled-plugin shards, plugin and channel contract shards, Node 22 compatibility, `check-*`, `check-additional-*`, built-artifact smoke checks, docs checks, Python skills, Windows, macOS, iOS build, and Control UI/native app i18n. Node 22 compatibility runs in Full Release Validation and manual dispatches only; push and pull request CI skip it. The exact-head `release_gate` fallback instead keeps the pull request's macOS and iOS scope, including conservative release screenshot capture for screenshot-pipeline owners. Automatic source PRs verify native extraction inventory and Android/Apple localization safety without requiring translated or platform-generated output in the same PR. The serialized Native App Locale Refresh workflow rebuilds those artifacts in one isolated PR and enables exact-head auto-merge after required checks pass. Full native parity remains blocking for generated-artifact PRs, manual CI, Full Release Validation, and release prep. Control UI locale parity remains advisory on automatic PR and `main` runs and blocking on manual/release CI. Standalone manual CI dispatches run Android only with `include_android=true` (the `release_gate` input also forces Android); the full release umbrella enables Android by passing `include_android=true`. Plugin prerelease static checks, the release-only `agentic-plugins` shard, the full extension batch sweep, and plugin prerelease Docker lanes are excluded from CI. The Docker prerelease suite runs only when `Full Release Validation` dispatches the separate `Plugin Prerelease` workflow with the release-validation gate enabled.
175175

176-
PR baseline ratchets derive their comparison state from the checked-out synthetic merge tree and verify its head parent against the event head. Manual runs use a unique concurrency group so a release-candidate full suite is not cancelled by another push or PR run on the same ref. The optional `target_ref` input lets a trusted caller run that graph against a branch, tag, or full commit SHA while using the workflow file from the selected dispatch ref; ratchet baselines are compared with the target's merge base against the default-branch head resolved for that run. The `release_gate` input is an exact-SHA maintainer fallback for capacity-stalled PR CI: it requires `target_ref` to be a full commit SHA that matches the dispatched branch head and `pull_request_number` to identify the open PR whose merge tree is validated.
176+
PR baseline ratchets derive their comparison state from the checked-out synthetic merge tree and verify its head parent against the event head. The max-lines entry chains the environment-variable budget with the same fork-point ref before the assertion-safety check, so production source growth cannot first surface on `main`. Manual runs use a unique concurrency group so a release-candidate full suite is not cancelled by another push or PR run on the same ref. The optional `target_ref` input lets a trusted caller run that graph against a branch, tag, or full commit SHA while using the workflow file from the selected dispatch ref; ratchet baselines are compared with the target's merge base against the default-branch head resolved for that run. The `release_gate` input is an exact-SHA maintainer fallback for capacity-stalled PR CI: it requires `target_ref` to be a full commit SHA that matches the dispatched branch head and `pull_request_number` to identify the open PR whose merge tree is validated.
177177

178178
```bash
179179
gh workflow run ci.yml --ref release/YYYY.M.PATCH

‎scripts/check-max-lines-ratchet.mts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "node:fs";
33
import path from "node:path";
44
import { pathToFileURL } from "node:url";
55
import ts from "typescript";
6+
import { main as checkEnvVarCount } from "./check-env-var-count.mts";
67
import { resolveRatchetBase } from "./lib/ratchet-base.mts";
78

89
const BASELINE_PATH = "config/max-lines-baseline.txt";
@@ -314,6 +315,11 @@ function parseArgs(argv: string[]) {
314315
return args;
315316
}
316317

318+
function envVarCountArgs(argv: string[]) {
319+
const args = parseArgs(argv);
320+
return [...(args.staged ? ["--staged"] : []), ...(args.base ? ["--base", args.base] : [])];
321+
}
322+
317323
function printEntries(title: string, entries: string[]) {
318324
console.error(title);
319325
for (const entry of entries) {
@@ -381,6 +387,22 @@ export function main(root = process.cwd(), argv: string[] = process.argv.slice(2
381387
}
382388
}
383389

390+
function runBaselineRatchets(root = process.cwd(), argv: string[] = process.argv.slice(2)) {
391+
const maxLinesStatus = main(root, argv);
392+
if (maxLinesStatus !== 0) {
393+
return maxLinesStatus;
394+
}
395+
try {
396+
// CI invokes this entry with its frozen fork-point ref. Carry the same snapshot
397+
// into the env budget so every baseline ratchet judges one tested tree.
398+
checkEnvVarCount(envVarCountArgs(argv), root);
399+
return 0;
400+
} catch (error) {
401+
console.error(error instanceof Error ? error.message : String(error));
402+
return 1;
403+
}
404+
}
405+
384406
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
385-
process.exitCode = main();
407+
process.exitCode = runBaselineRatchets();
386408
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5725,8 +5725,9 @@ printf '%s\n' "\${CURL_SUCCESS_IP:-203.0.113.7}"
57255725
).toContain("--only=core --split-core --core-stripe=${{ matrix.stripe }}/5 --threads=1");
57265726
});
57275727

5728-
it("runs both baseline ratchets against the exact tested tree", () => {
5728+
it("runs all baseline ratchets against the exact tested tree", () => {
57295729
const workflow = readCiWorkflow();
5730+
const maxLinesRatchet = readFileSync("scripts/check-max-lines-ratchet.mts", "utf8");
57305731
const checksFastJob = workflow.jobs["checks-fast-core"];
57315732
const checksFastSteps = checksFastJob.steps;
57325733
const checkout = checksFastSteps.find((step: WorkflowStep) => step.name === "Checkout");
@@ -5827,6 +5828,10 @@ printf '%s\n' "\${CURL_SUCCESS_IP:-203.0.113.7}"
58275828
expect(checksFastRun.run).not.toContain("+${merge_base}:refs/remotes/origin/ci-ratchet-base");
58285829
expect(checksFastRun.run).toContain('pnpm check:max-lines-ratchet --base "$base_ref"');
58295830
expect(checksFastRun.run).toContain('pnpm check:assertion-safety --base "$base_ref"');
5831+
expect(maxLinesRatchet).toContain(
5832+
'import { main as checkEnvVarCount } from "./check-env-var-count.mts";',
5833+
);
5834+
expect(maxLinesRatchet).toContain("checkEnvVarCount(envVarCountArgs(argv), root);");
58305835
expect(checksFastRun.run).toContain(
58315836
'if [[ "${RATCHET_RELEASE_MERGE_TREE:-}" == "true" ]]; then',
58325837
);

0 commit comments

Comments
 (0)