@decohere/ci-tools 0.0.1-dev.20261123.401 → 0.0.1-dev.20261123.406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,15 +3,15 @@
3
3
  Node scripts the repo's GitHub workflows and root `package.json` scripts run. Plain `.mjs`, run from source with `node`. One folder per job, under `src/`:
4
4
 
5
5
  - `audit/`: summarize `npm audit`, fail on findings (`enforce`), and open or close the audit issue (`upsert-issue`). Run by CI (`ci.yml`) and the nightly `npm-audit.yml`.
6
- - `badges/`: the CI status badge (`ci-status`). Run by `pages.yml`, `bench.yml` and `clear-benchmark-history.yml`.
6
+ - `badges/`: main's status badge (`ci-status`, from Publish's last run on `main`). Run by `pages.yml`, `bench.yml` and `clear-benchmark-history.yml`.
7
7
  - `bench/`: build benchmarks (`pnpm bench`, `pnpm bench:save`, `pnpm perf:trace`), and the nightly run and its regression issues. Run by `bench.yml`.
8
8
  - `changeset/`: changeset status and changelog scripts behind `pnpm changeset:check` and `pnpm version:aggregate`. No workflow runs them.
9
9
  - `coverage/`: the coverage report (`pnpm test:coverage:report`) and its badge, run by `pages.yml`.
10
10
  - `github/`: GitHub and npm checks (`ensure-metadata` is used by `publish-verify`): `first-publish-check` (CI), `publish-verify` (`publish.yml`), `failure-report` (the `failure-report` action, used by `ci.yml` and `clear-benchmark-history.yml`), and `npm-bootstrap` (`pnpm npm:bootstrap`, run by hand).
11
11
  - `lib/`: what the scripts share: SVG badges, LCOV parsing, GitHub issues, the workspace's packages. Nothing runs it directly.
12
12
  - `pages/`: the GitHub Pages site (badges, bench history, the artifact). Run by `pages.yml`, `bench.yml` and `clear-benchmark-history.yml`.
13
- - `release/`: publishing: `check-patch-release`, `find-publish-base` and `restamp-build` (`publish.yml`), `promote-latest` (`promote-latest.yml`, the "Promote to latest" workflow), and `publish-to-temporary-registry` (the `verify-release` action).
13
+ - `release/`: publishing: `check-patch-release`, `find-publish-base` and `restamp-build` (`publish.yml`), `tested-build` (the CI run whose build ships a commit: the merge queue's on `main`; `publish.yml` and `pages.yml`), `promote-latest` (`promote-latest.yml`, the "Promote to latest" workflow), and `publish-to-temporary-registry` (the `verify-release` action).
14
14
 
15
15
  ## Working on this package
16
16
 
17
- Tests are in `tests/`, in folders named like the `src/` folders they test: `*.test.mjs` and, under `release/`, `*.spec.ts`. `pnpm test` runs both. `tests/github/ci-workflow.test.mjs` and `publish-workflow.test.mjs` check the workflow files themselves. There is no canonical suite for ci-tools in the [testing table](../../docs/contributing/testing/README.md#canonical-suite-ownership).
17
+ Most tests are in `tests/`, in folders named like the `src/` folders they test: `*.test.mjs` and, under `release/`, `*.spec.ts`. New specs sit beside their code, as `release/tested-build.service.spec.ts` does ([ADR 0027](../../docs/contributing/adr/0027-code-design.md)). `pnpm test` runs them all. `tests/github/ci-workflow.test.mjs` and `publish-workflow.test.mjs` check the workflow files themselves. There is no canonical suite for ci-tools in the [testing table](../../docs/contributing/testing/README.md#canonical-suite-ownership).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/ci-tools",
3
- "version": "0.0.1-dev.20261123.401",
3
+ "version": "0.0.1-dev.20261123.406",
4
4
  "description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
5
5
  "keywords": [
6
6
  "typescript",
@@ -11,9 +11,11 @@ if (repo == null || token == null) {
11
11
  throw new Error("GITHUB_REPOSITORY and GITHUB_TOKEN are required");
12
12
  }
13
13
 
14
- const workflowFileName = "ci.yml";
14
+ // CI doesn't run on main: the merge queue tests each commit before it lands, and Publish ships it.
15
+ // So main's state is whether Publish's last run passed.
16
+ const workflowFileName = "publish.yml";
15
17
 
16
- const branches = [{ branch: "main", label: "CI Main", file: "ci-main.svg" }];
18
+ const branches = [{ branch: "main", label: "Main", file: "ci-main.svg" }];
17
19
 
18
20
  async function getLatestWorkflowRun(branch) {
19
21
  const url =
@@ -6,37 +6,7 @@
6
6
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
7
7
  import { basename, join, relative } from "node:path";
8
8
  import ts from "typescript";
9
-
10
- /** The roles a file's name may end in, from ADR 0027. */
11
- export const ROLES = new Set([
12
- "entity",
13
- "value",
14
- "service",
15
- "strategy",
16
- "factory",
17
- "repository",
18
- "port",
19
- "adapter",
20
- "provider",
21
- "plugin",
22
- "controller",
23
- "handler",
24
- "command",
25
- "action",
26
- "decorator",
27
- "event",
28
- "error",
29
- "const",
30
- "config",
31
- "module",
32
- "model",
33
- "mapping",
34
- "contract",
35
- "registry",
36
- "builder",
37
- "host",
38
- "cases",
39
- ]);
9
+ import { FileRoles } from "./file-roles.registry.mjs";
40
10
 
41
11
  /** The rules counted, and what each count means. */
42
12
  export const RULES = {
@@ -57,6 +27,8 @@ export class CodeDesign {
57
27
  /** @param {string} root the workspace root */
58
28
  constructor(root) {
59
29
  this.root = root;
30
+ /** @private */
31
+ this.roles = new FileRoles(root);
60
32
  }
61
33
 
62
34
  /**
@@ -102,7 +74,8 @@ export class CodeDesign {
102
74
  const base = basename(file).replace(/\.(ts|mts)$/, "");
103
75
  if (BANNED.test(base)) add("bannedNames", rel);
104
76
  const role = base.split(".");
105
- if (base !== "index" && (role.length < 2 || !ROLES.has(role.at(-1)))) add("noRole", rel);
77
+ if (base !== "index" && (role.length < 2 || !this.roles.has(role.at(-1))))
78
+ add("noRole", rel);
106
79
  const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
107
80
  const isPluginFile = role.at(-1) === "plugin";
108
81
  if (name !== "config" && !bins.has(relative(this.root, file))) {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The file roles (`<thing>.<role>.ts`) the shared rules allow, read from the installed
3
+ * `@decohere/standards`, so Decohere keeps no copy of its own that can drift from them.
4
+ */
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { join } from "node:path";
7
+
8
+ /** Where the standards' table of file roles sits, from the workspace root. */
9
+ export const STANDARD_ROLES = "node_modules/@decohere/standards/rules/files-and-folders.md";
10
+
11
+ /** A row of the table: its first cell names one role or several, as `.role.ts`. */
12
+ const ROW = /^\|([^|]*)\|/;
13
+ const ROLE = /`\.([a-z][a-z-]*)\.ts`/g;
14
+
15
+ export class FileRoles {
16
+ /** @param {string} root the workspace root */
17
+ constructor(root) {
18
+ const path = join(root, STANDARD_ROLES);
19
+ if (!existsSync(path)) {
20
+ throw new Error(
21
+ `design: ${STANDARD_ROLES} is missing, so the file roles are unknown. Run pnpm install.`,
22
+ );
23
+ }
24
+ /** @private */
25
+ this.roles = new Set();
26
+ for (const line of readFileSync(path, "utf8").split("\n")) {
27
+ const cell = ROW.exec(line)?.[1] ?? "";
28
+ for (const [, role] of cell.matchAll(ROLE)) this.roles.add(role);
29
+ }
30
+ if (this.roles.size === 0) {
31
+ throw new Error(
32
+ `design: ${STANDARD_ROLES} lists no file roles; its table has changed shape.`,
33
+ );
34
+ }
35
+ }
36
+
37
+ /** @param {string} role a file name's last part before `.ts`, such as `service` */
38
+ has(role) {
39
+ return this.roles.has(role);
40
+ }
41
+ }
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Prints the id of the CI run whose release build ships a commit (see tested-build.service.mjs).
4
+ * Exits 1 with a reason when there's none: Publish ships only what CI tested, never a new build.
5
+ *
6
+ * GH_TOKEN=… GITHUB_REPOSITORY=owner/repo node tested-build.command.mjs <sha> <event>[,<event>…]
7
+ */
8
+ import { pathToFileURL } from "node:url";
9
+ import { TestedBuildError } from "./tested-build.error.mjs";
10
+ import { TestedBuild } from "./tested-build.service.mjs";
11
+
12
+ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
13
+ const [sha, events] = process.argv.slice(2);
14
+ const repo = process.env.GITHUB_REPOSITORY;
15
+ const token = process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN;
16
+ const base = process.env.GITHUB_API_URL ?? "https://api.github.com";
17
+ if (!sha || !events || !repo || !token) {
18
+ console.error(
19
+ "Usage: GH_TOKEN=… GITHUB_REPOSITORY=owner/repo tested-build.command.mjs <sha> <event>[,<event>…]",
20
+ );
21
+ process.exit(1);
22
+ }
23
+
24
+ const api = async (path) => {
25
+ const response = await fetch(`${base}/${path}`, {
26
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json" },
27
+ });
28
+ if (!response.ok) throw new Error(`GitHub answered ${response.status} to GET ${path}`);
29
+ return response.json();
30
+ };
31
+
32
+ try {
33
+ const found = await new TestedBuild({ repo, api }).find(sha, events.split(","));
34
+ console.error(`Tested by ${found.url} (${found.event})`);
35
+ console.log(found.runId);
36
+ } catch (error) {
37
+ if (!(error instanceof TestedBuildError)) throw error;
38
+ console.error(`::error::${error.message}`);
39
+ process.exit(1);
40
+ }
41
+ }
@@ -0,0 +1,8 @@
1
+ /** There's no tested build to ship for a commit: no CI run passed for it, or its build is gone. */
2
+ export class TestedBuildError extends Error {
3
+ /** @param {string} message */
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "TestedBuildError";
7
+ }
8
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Finds the CI run that tested a commit and holds its release build, `forge-release-beta-<run id>`,
3
+ * so Publish ships what was tested instead of building again. On `main` that's the merge queue's
4
+ * run: the queue tests the exact commit that lands. A patch branch's is its push run.
5
+ */
6
+ import { TestedBuildError } from "./tested-build.error.mjs";
7
+
8
+ /** How each event's run is named in a message. */
9
+ const WHERE = {
10
+ merge_group: "the merge queue",
11
+ push: "a push",
12
+ workflow_dispatch: "a run started by hand",
13
+ };
14
+
15
+ /**
16
+ * @typedef {{ id: number, status: string, conclusion: string | null, html_url: string }} WorkflowRun
17
+ * @typedef {{ runId: number, event: string, url: string }} Found
18
+ */
19
+
20
+ export class TestedBuild {
21
+ /**
22
+ * @param {{
23
+ * repo: string,
24
+ * api: (path: string) => Promise<any>,
25
+ * now?: () => number,
26
+ * wait?: (ms: number) => Promise<void>,
27
+ * log?: (message: string) => void,
28
+ * patienceMs?: number,
29
+ * pollMs?: number,
30
+ * }} options
31
+ */
32
+ constructor(options) {
33
+ this.repo = options.repo;
34
+ this.api = options.api;
35
+ this.now = options.now ?? Date.now;
36
+ this.wait = options.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
37
+ this.log = options.log ?? console.error;
38
+ // The queue merges as soon as the `ci` job passes, a moment before its run is marked done.
39
+ this.patienceMs = options.patienceMs ?? 10 * 60_000;
40
+ this.pollMs = options.pollMs ?? 15_000;
41
+ }
42
+
43
+ /**
44
+ * @param {string} sha the commit to ship
45
+ * @param {string[]} events the CI events whose runs count, in the order to try them
46
+ * @returns {Promise<Found>}
47
+ */
48
+ async find(sha, events) {
49
+ /** @type {string[]} */
50
+ const notes = [];
51
+ for (const event of events) {
52
+ const deadline = this.now() + this.patienceMs;
53
+ for (;;) {
54
+ const runs = await this.runs(sha, event);
55
+ const passed = runs.find((run) => run.conclusion === "success");
56
+ if (passed != null) return this.withBuild(sha, passed, event);
57
+ const running = runs.filter((run) => run.status !== "completed");
58
+ if (running.length === 0) {
59
+ notes.push(
60
+ ...runs.map((run) => `${run.html_url} (${run.conclusion ?? run.status})`),
61
+ );
62
+ break;
63
+ }
64
+ if (this.now() >= deadline) {
65
+ notes.push(...running.map((run) => `${run.html_url} (still running)`));
66
+ break;
67
+ }
68
+ this.log(`Waiting for ${running.map((run) => run.html_url).join(", ")} to finish`);
69
+ await this.wait(this.pollMs);
70
+ }
71
+ }
72
+ const where = events.map((event) => WHERE[event] ?? event).join(" or ");
73
+ const queue = events.includes("merge_group")
74
+ ? " A commit reaches main without one when the merge queue is bypassed (an admin merge or a direct push). Land the change through a pull request and the merge queue."
75
+ : "";
76
+ const runs = notes.length > 0 ? ` Runs for it: ${notes.join(", ")}.` : "";
77
+ throw new TestedBuildError(
78
+ `No CI run in ${where} passed for ${sha}, so there's no tested build to ship. Nothing was published.${queue}${runs}`,
79
+ );
80
+ }
81
+
82
+ /**
83
+ * @private
84
+ * @returns {Promise<WorkflowRun[]>} newest first
85
+ */
86
+ async runs(sha, event) {
87
+ const page = await this.api(
88
+ `repos/${this.repo}/actions/workflows/ci.yml/runs?head_sha=${sha}&event=${event}&per_page=100`,
89
+ );
90
+ return page.workflow_runs ?? [];
91
+ }
92
+
93
+ /**
94
+ * @private
95
+ * @param {string} sha
96
+ * @param {WorkflowRun} run
97
+ * @param {string} event
98
+ * @returns {Promise<Found>}
99
+ */
100
+ async withBuild(sha, run, event) {
101
+ const name = `forge-release-beta-${run.id}`;
102
+ const page = await this.api(
103
+ `repos/${this.repo}/actions/runs/${run.id}/artifacts?name=${name}`,
104
+ );
105
+ const build = (page.artifacts ?? []).find((artifact) => artifact.name === name);
106
+ if (build == null || build.expired) {
107
+ const why = build == null ? `has no build ${name}` : `its build ${name} has expired`;
108
+ throw new TestedBuildError(
109
+ `CI run ${run.html_url} passed for ${sha}, but ${why}: CI keeps a build 14 days. Nothing was published.`,
110
+ );
111
+ }
112
+ return { runId: run.id, event, url: run.html_url };
113
+ }
114
+ }
@@ -1,9 +1,22 @@
1
1
  import { vol } from "memfs";
2
2
  import { afterEach, describe, expect, it } from "vitest";
3
3
  import { BASELINE, runDesignCheck } from "../../src/design/design-check.command.mjs";
4
+ import { STANDARD_ROLES } from "../../src/design/file-roles.registry.mjs";
4
5
 
5
6
  const root = "/workspace";
6
7
 
8
+ /** The file roles the installed @decohere/standards lists, in the table's own format. */
9
+ const STANDARDS = [
10
+ "# Files and folders",
11
+ "",
12
+ "| Role | Holds | Example |",
13
+ "| --- | --- | --- |",
14
+ "| `.service.ts` | a class that does one job | `trading.service.ts` |",
15
+ "| `.value.ts` | a value with no identity | `money.value.ts` |",
16
+ "| `.plugin.ts`, `.state.ts` | a plugin factory; one state of a State pattern | `memory.plugin.ts` |",
17
+ "",
18
+ ].join("\n");
19
+
7
20
  /** A workspace with one package, `http`, holding these files under projects/http. */
8
21
  function seed(files, baseline) {
9
22
  vol.fromJSON({
@@ -12,6 +25,7 @@ function seed(files, baseline) {
12
25
  Object.entries(files).map(([path, text]) => [`${root}/projects/http/${path}`, text]),
13
26
  ),
14
27
  ...(baseline ? { [`${root}/${BASELINE}`]: JSON.stringify(baseline) } : {}),
28
+ [`${root}/${STANDARD_ROLES}`]: STANDARDS,
15
29
  });
16
30
  }
17
31
 
@@ -119,4 +133,23 @@ describe("design:check", () => {
119
133
  run(["--update"]);
120
134
  expect(run().code).toBe(0);
121
135
  });
136
+
137
+ it("takes the file roles from the installed standards, so a role they add needs no change here", () => {
138
+ seed({ ...CLEAN, "src/holding.state.ts": "export class HoldingState {}\n" });
139
+ expect(run()).toEqual({ code: 0, output: expect.stringContaining("design: 0 breaks") });
140
+ });
141
+
142
+ it("counts a role the installed standards don't list as a file with no role", () => {
143
+ seed({ ...CLEAN, "src/order.widget.ts": "export class OrderWidget {}\n" });
144
+ run(["--update"]);
145
+ expect(JSON.parse(vol.readFileSync(`${root}/${BASELINE}`, "utf8"))).toEqual({
146
+ http: { noRole: 1 },
147
+ });
148
+ });
149
+
150
+ it("stops when the standards aren't installed, rather than accept every name", () => {
151
+ seed(CLEAN);
152
+ vol.unlinkSync(`${root}/${STANDARD_ROLES}`);
153
+ expect(() => run()).toThrow("pnpm install");
154
+ });
122
155
  });
@@ -8,6 +8,12 @@ describe("ci.yml and the merge queue", () => {
8
8
  const yml = fs.readFileSync(CI_YML, "utf8");
9
9
  const triggers = yml.slice(yml.indexOf("\non:"), yml.indexOf("\nconcurrency:"));
10
10
  const gate = yml.slice(yml.indexOf("- id: gate"), yml.indexOf("# Static gates"));
11
+ const jobs = yml.slice(yml.indexOf("\njobs:"));
12
+ /** A job's heading: its needs, `if` and outputs, up to its steps. */
13
+ const heading = (job) => {
14
+ const start = jobs.indexOf(`\n ${job}:`);
15
+ return jobs.slice(start, jobs.indexOf("steps:", start));
16
+ };
11
17
 
12
18
  it("runs for queued pull requests, or the queue waits forever for the required check", () => {
13
19
  expect(triggers).toMatch(/^\s+merge_group:/m);
@@ -17,19 +23,31 @@ describe("ci.yml and the merge queue", () => {
17
23
  expect(gate).toContain('"${{ github.event_name }}" == "merge_group"');
18
24
  });
19
25
 
20
- it("runs the whole suite on a patch branch, whose commits weren't tested on main", () => {
21
- const jobs = yml.slice(yml.indexOf("\njobs:"));
22
- expect(triggers).toContain('branches: [main, "release/**"]');
23
- for (const job of ["coverage", "build", "verify-release"]) {
24
- const start = jobs.indexOf(`\n ${job}:`);
25
- expect(jobs.slice(start, jobs.indexOf("runs-on:", start)), job).toContain(
26
- "startsWith(github.ref, 'refs/heads/release/')",
27
- );
26
+ it("runs nothing on a push to main: the queue tested that same commit, and Publish ships its build", () => {
27
+ expect(triggers).toContain('branches: ["release/**"]');
28
+ expect(triggers).not.toMatch(/branches: \[.*\bmain\b/);
29
+ expect(jobs).not.toContain("refs/heads/main");
30
+ });
31
+
32
+ it("makes the full run in the queue, on a patch branch, and when started by hand", () => {
33
+ const full = gate.slice(0, gate.indexOf('echo "full=true"'));
34
+ expect(full).toContain('"${{ github.event_name }}" == "merge_group"');
35
+ expect(full).toContain('"${{ github.event_name }}" == "workflow_dispatch"');
36
+ expect(full).toContain("refs/heads/release/");
37
+ expect(heading("changes")).toContain("full: ${{ steps.gate.outputs.full }}");
38
+ });
39
+
40
+ it("builds, verifies the release, and runs coverage and Docker tests in the full run", () => {
41
+ for (const job of ["build", "verify-release", "coverage", "test-docker"]) {
42
+ expect(heading(job), job).toContain("needs.changes.outputs.full == 'true'");
28
43
  }
29
44
  });
30
45
 
46
+ it("runs the unit test shards only outside the full run, where coverage runs the same tests", () => {
47
+ expect(heading("test")).toContain("needs.changes.outputs.full != 'true'");
48
+ });
49
+
31
50
  it("makes the required check wait for every job, so a failing job can't be missed", () => {
32
- const jobs = yml.slice(yml.indexOf("\njobs:"));
33
51
  const names = [...jobs.matchAll(/^ {2}([a-z-]+):$/gm)].map((match) => match[1]);
34
52
  const needs = /^ {2}ci:\n {4}needs: \[(.+)\]$/m.exec(jobs)?.[1].split(", ");
35
53
 
@@ -64,3 +82,24 @@ describe("the release build passed between jobs", () => {
64
82
  }
65
83
  });
66
84
  });
85
+
86
+ describe("pages.yml", () => {
87
+ const yml = fs.readFileSync(
88
+ fileURLToPath(new URL("../../../../.github/workflows/pages.yml", import.meta.url)),
89
+ "utf8",
90
+ );
91
+ const on = yml.slice(yml.indexOf("\non:"), yml.indexOf("\nconcurrency:"));
92
+
93
+ it("deploys on a push to main, without waiting for a CI run there", () => {
94
+ expect(on).toMatch(/push:\n\s+branches: \[main\]/);
95
+ expect(yml).not.toContain("workflow_run");
96
+ });
97
+
98
+ it("takes the coverage the merge queue measured for that commit", () => {
99
+ expect(yml).toContain('tested-build.command.mjs "$SHA" merge_group');
100
+ const download = yml.slice(yml.indexOf("name: coverage-data"));
101
+ expect(download.slice(0, download.indexOf("path:"))).toContain(
102
+ "run-id: ${{ steps.tested.outputs.run_id }}",
103
+ );
104
+ });
105
+ });
@@ -47,13 +47,59 @@ describe("publish.yml", () => {
47
47
  expect(guard).not.toContain("HEAD^1");
48
48
  });
49
49
 
50
- it("only releases a patch whose commit passed full CI", () => {
50
+ it("only releases a patch whose commit passed full CI on its branch", () => {
51
51
  const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
52
+ const find = guard.indexOf('tested-build.command.mjs "$sha" "$events"');
52
53
 
53
- expect(guard).toContain("event=push&status=success");
54
- expect(guard.indexOf("git/ref/heads/")).toBeLessThan(
55
- guard.indexOf("event=push&status=success"),
54
+ expect(find).toBeGreaterThan(-1);
55
+ expect(guard).toMatch(/if \[\[ -n "\$PATCH_BRANCH" \]\]; then\n\s+events=push\n/);
56
+ expect(guard.indexOf("git/ref/heads/")).toBeLessThan(find);
57
+ });
58
+
59
+ it("releases a tested version from the queue's build, or main's for a version from before", () => {
60
+ const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
61
+
62
+ expect(guard).toMatch(/else\n\s+events=merge_group,push\n/);
63
+ });
64
+
65
+ it("starts on a push to main, not when a CI run finishes", () => {
66
+ const on = yml.slice(0, yml.indexOf("workflow_dispatch:"));
67
+
68
+ expect(on).toMatch(/push:\n\s+branches: \[main\]/);
69
+ expect(yml).not.toContain("workflow_run");
70
+ });
71
+
72
+ it("ships the build the merge queue tested for this same commit", () => {
73
+ const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
74
+ const queue = guard.slice(guard.indexOf("- name: Find the merge queue's build"));
75
+
76
+ expect(queue).toContain("if: steps.check.outputs.should_publish == 'true'");
77
+ expect(queue).toContain('tested-build.command.mjs "$SHA" merge_group');
78
+ expect(guard).toContain(
79
+ "build_run_id: ${{ steps.release.outputs.build_run_id || steps.queue.outputs.run_id }}",
80
+ );
81
+ });
82
+
83
+ it("gives the guard longer than the wait for a queue run that's still finishing", () => {
84
+ const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
85
+ const minutes = Number(/timeout-minutes: (\d+)/.exec(guard)?.[1]);
86
+ const service = fs.readFileSync(
87
+ fileURLToPath(new URL("../../src/release/tested-build.service.mjs", import.meta.url)),
88
+ "utf8",
56
89
  );
90
+ const patience = Number(/patienceMs \?\? (\d+) \* 60_000/.exec(service)?.[1]);
91
+
92
+ expect(patience).toBeGreaterThan(0);
93
+ expect(minutes).toBeGreaterThan(patience);
94
+ });
95
+
96
+ it("refuses a commit with no tested build rather than building one", () => {
97
+ const queue = yml.slice(yml.indexOf("- name: Find the merge queue's build"));
98
+
99
+ expect(queue.slice(0, queue.indexOf("\n - "))).not.toContain("continue-on-error");
100
+ // Only CI stamps and builds. A stable release only changes the version of a tested build.
101
+ expect(yml).not.toMatch(/forge [^\n]*\bbuild --configuration/);
102
+ expect(yml).not.toMatch(/forge [^\n]*\bversion --channel/);
57
103
  });
58
104
 
59
105
  it("reads a patch's tested version from its build", () => {
@@ -76,7 +122,7 @@ describe("publish.yml", () => {
76
122
  const guard = yml.slice(yml.indexOf("\n guard:"), yml.indexOf("\n release-build:"));
77
123
 
78
124
  expect(on).toContain("branches: [main]");
79
- expect(guard).toContain("head_branch == 'main'");
125
+ expect(guard).toContain("github.ref == 'refs/heads/main'");
80
126
  });
81
127
 
82
128
  it("only tags a version once npm and the images have shipped", () => {