/** * THE SCHEDULED LANES, AND THE WORK THEY ARE NOT ALLOWED TO REPEAT — OR SKIP. * * There is ONE build Mac and ONE Linux CI box, and the crons that spend them: * * * `build-prod-dryrun.yml` walks the shipping archive path when it is * dispatched, ungated — its nightly cron went on 6 Oct 2026 (no automated * builds). It used to be gated: `build-main.yml` had a cron at * 20:30 UTC and on a day the phone moved both archived THE SAME COMMIT on * the same capacity-1 Mac, so the dry-run ran only on the days the * TestFlight build did not, by that lane's own gate inverted. On 28 Sep * 2026 the TestFlight cron was retired (a build is a dispatch now), and a * gate keyed to it would skip the dry-run on precisely the days nothing * else builds — so the gate went with the cron it mirrored. * * `rust-deep.yml`'s 03:00 UTC nightly ran the full pass — MuPDF from C * source, a 150-minute ceiling — whether or not main had moved since the * last one that went green. A quiet week was six re-runs of one commit. * * Each rule is held here by the property that makes it safe rather than by its * text: the dry-run has NO gate job and its failure issue fires on any red run; * the deep pass's marker is written by the pass ITSELF on success, never * derived from "the last run that exited zero". * * And the thing the deep gate may not take with it: the nightly cache sweep, * which is the only thing bounding the runner's disk on a quiet week. */ import { readFileSync } from "node:fs"; import path from "node:path"; import { parse as parseYaml } from "yaml"; import { describe, expect, it } from "vitest"; const ROOT = path.resolve(__dirname, "../.."); const WORKFLOWS = path.join(ROOT, ".forgejo/workflows"); type Step = { id?: string; name?: string; run?: string; uses?: string; if?: string; with?: Record }; type Job = { steps?: Step[]; if?: string; needs?: string | string[]; outputs?: Record }; type Workflow = { on?: Record; jobs: Record }; function load(file: string): { source: string; workflow: Workflow } { const p = path.join(WORKFLOWS, file); const source = readFileSync(p, "utf8"); // The loud-null rule: every assertion below reads this file by path. expect(source.length, `${p} is empty or missing`).toBeGreaterThan(0); return { source, workflow: parseYaml(source) as Workflow }; } const crons = (w: Workflow): string[] => ((w.on?.schedule as Array<{ cron: string }> | undefined) ?? []).map((s) => s.cron); describe("the dry-run runs on demand, ungated — no build is queued by a timer", () => { const dryrun = load("build-prod-dryrun.yml"); const main = load("build-main.yml"); // RULE: Neither the prod dry-run nor the Cotton Dev build has a cron or a push trigger; each runs only when the coordinator or the owner dispatches it (owner, 6 Oct 2026: no automated builds). it("the dry-run and the Cotton Dev build start only from a dispatch — no timer, no push (2026-10-06)", () => { // The dry-run's 20:00 UTC cron queued run 4449 the night the rule was in // force; a build is asked for, never queued by a timer. for (const { name, workflow } of [ { name: "build-prod-dryrun.yml", workflow: dryrun.workflow }, { name: "build-main.yml", workflow: main.workflow }, ]) { expect(Object.keys(workflow.on ?? {}), name).toEqual(["workflow_dispatch"]); expect(crons(workflow), name).toEqual([]); } }); // RULE: The prod dry-run has no gate: with no nightly TestFlight build to avoid duplicating, a "did the phone move" rule would skip it on exactly the days nothing else builds. it("has NO gate job and no 'did the phone move' rule — that rule belonged to the retired nightly TestFlight build", () => { expect(dryrun.workflow.jobs.gate, "build-prod-dryrun.yml grew a gate job back").toBeUndefined(); const archive = dryrun.workflow.jobs.dryrun; expect(archive, "build-prod-dryrun.yml has no dryrun job").toBeDefined(); expect(archive.needs, "the archive must not wait on anything").toBeUndefined(); expect(archive.if, "the archive must not be conditional").toBeUndefined(); expect(dryrun.source).not.toMatch(/ci-detect-changes\.sh/); expect(dryrun.source).not.toMatch(/needs\.gate/); expect(dryrun.source).not.toMatch(/20:30/); }); // RULE: The dry-run's failure issue fires on every red run, because no run is ever skipped. it("the failure issue fires on any red run — nothing is skipped any more", () => { // A STEP of the archive job, not a job behind it: Cotton's CI never runs a // job whose `needs` failed, so a `report-failure` job was never reached. expect(dryrun.workflow.jobs["report-failure"], "the reporter is a step, never a job again").toBeUndefined(); const report = (dryrun.workflow.jobs.dryrun.steps ?? []).find((s) => /report-dryrun-failure\.ts/.test(s.run ?? "")); expect(report?.if).toBe("failure()"); }); it("the archive, and the issue step inside it, run on the build Mac", () => { expect(String((dryrun.workflow.jobs.dryrun as { "runs-on"?: string })["runs-on"])).toBe("tinmen-build-mac"); expect(Object.keys(dryrun.workflow.jobs)).toEqual(["dryrun"]); }); }); describe("the deep nightly runs only when main has moved", () => { const deep = load("rust-deep.yml"); const gateRun = String( (deep.workflow.jobs.deep.steps ?? []).find((s) => /Did anything cargo reads move/.test(s.name ?? ""))!.run, ); it("compares HEAD against a marker the PASS ITSELF wrote, not a run that exited zero", () => { // The distinction is the whole point: a run can succeed having SKIPPED the // pass on its own push gate, and that run proved nothing about its commit. expect(gateRun).toMatch(/last-deep-green/); expect(gateRun).toMatch(/if \[ "\$proved" = "\$head" \]; then/); }); it("writes that marker on success and ONLY after the pass really ran", () => { const steps = deep.workflow.jobs.deep.steps ?? []; const at = steps.findIndex((s) => /record the commit this pass proved/.test(s.name ?? "")); expect(at, "rust-deep.yml has no marker step").toBeGreaterThanOrEqual(0); expect(steps[at]!.if).toBe("success() && steps.gate.outputs.run == 'true'"); expect(String(steps[at]!.run)).toMatch(/git rev-parse HEAD > "\$marker"/); // Last, so `success()` covers every step of the pass. const lastReal = steps.findLastIndex((s) => /with-cargo-lock\.sh/.test(s.run ?? "")); expect(at).toBeGreaterThan(lastReal); }); it("a missing marker RUNS — 'never proved' is the honest default on a new runner", () => { expect(gateRun).toMatch(/proved=""/); expect(gateRun).toMatch(/\$\{proved:-nothing\}/); }); it("a push still asks the path gate, and a dispatch is never gated", () => { expect(gateRun).toMatch(/if \[ "\$EVENT" != "push" \]; then\s*\n\s*echo "run=true"/); expect(gateRun).toMatch(/sed -n 's\/\^rust=\/\/p'/); }); it("the nightly CACHE SWEEP is untouched — it is the only thing bounding a quiet week", () => { // Gating the sweep on the deep job would mean the runner's disk is bounded // only on days somebody merged, which is the hole that job was created to // close. const sweep = deep.workflow.jobs.sweep; expect(sweep, "rust-deep.yml has no sweep job").toBeDefined(); expect(sweep.if).toBe("github.event_name == 'schedule'"); expect(sweep.needs, "the sweep must not wait on the deep job").toBeUndefined(); expect(String((sweep.steps ?? []).find((s) => /sweep-cargo-targets/.test(s.run ?? ""))!.run)).toContain( "--budget-gb 20", ); }); it("still never runs on pull_request — the four required contexts stay four", () => { // Branch protection's globs are all `(pull_request)`; a trigger here would // add a fifth context, which AGENTS.md says is an ORDERED change. expect(Object.keys(deep.workflow.on ?? {})).not.toContain("pull_request"); }); });