@intentius/chant 0.124.61 → 0.124.63

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.
Files changed (234) hide show
  1. package/dist/cli/handlers/approve.d.ts +18 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +142 -16
  4. package/dist/cli/handlers/plan.d.ts +10 -0
  5. package/dist/cli/handlers/plan.d.ts.map +1 -0
  6. package/dist/cli/handlers/plan.js +71 -0
  7. package/dist/cli/handlers/release.d.ts +6 -4
  8. package/dist/cli/handlers/release.d.ts.map +1 -1
  9. package/dist/cli/handlers/release.js +13 -7
  10. package/dist/cli/main.d.ts.map +1 -1
  11. package/dist/cli/main.js +34 -5
  12. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  13. package/dist/cli/mcp/workspace-tools.js +2 -1
  14. package/dist/cli/parse-args.d.ts.map +1 -1
  15. package/dist/cli/parse-args.js +31 -0
  16. package/dist/cli/registry.d.ts +13 -1
  17. package/dist/cli/registry.d.ts.map +1 -1
  18. package/dist/config.d.ts +32 -0
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/gate-decision.d.ts +1 -1
  21. package/dist/gate-decision.d.ts.map +1 -1
  22. package/dist/gate-decision.js +4 -2
  23. package/dist/gate-statement.schema.json +44 -0
  24. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
  25. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  26. package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
  27. package/dist/lifecycle/gate-ledger.d.ts +17 -3
  28. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  29. package/dist/lifecycle/gate-seal.d.ts +39 -3
  30. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  31. package/dist/lifecycle/gate-seal.js +50 -10
  32. package/dist/lifecycle/gate-statement.d.ts +70 -0
  33. package/dist/lifecycle/gate-statement.d.ts.map +1 -0
  34. package/dist/lifecycle/gate-statement.js +74 -0
  35. package/dist/lifecycle/gate-webauthn.d.ts +79 -0
  36. package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
  37. package/dist/lifecycle/gate-webauthn.js +105 -0
  38. package/dist/lifecycle/git.d.ts +1 -1
  39. package/dist/lifecycle/git.d.ts.map +1 -1
  40. package/dist/lifecycle/git.js +24 -19
  41. package/dist/lifecycle/ledger-remote.d.ts +37 -0
  42. package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
  43. package/dist/lifecycle/ledger-remote.js +42 -0
  44. package/dist/lifecycle/plan-stale.d.ts +76 -0
  45. package/dist/lifecycle/plan-stale.d.ts.map +1 -0
  46. package/dist/lifecycle/plan-stale.js +121 -0
  47. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  48. package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
  49. package/dist/lifecycle/publish-credentials.js +2 -0
  50. package/dist/lifecycle/publish-declaration.d.ts +87 -0
  51. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  52. package/dist/lifecycle/publish-declaration.js +87 -1
  53. package/dist/lifecycle/publish-forge.d.ts +5 -1
  54. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  55. package/dist/lifecycle/publish-forge.js +14 -4
  56. package/dist/lifecycle/publish-github.d.ts +69 -0
  57. package/dist/lifecycle/publish-github.d.ts.map +1 -0
  58. package/dist/lifecycle/publish-github.js +153 -0
  59. package/dist/lifecycle/publish-homebrew.d.ts +66 -0
  60. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
  61. package/dist/lifecycle/publish-homebrew.js +173 -0
  62. package/dist/lifecycle/publish-marketplace.d.ts +51 -0
  63. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
  64. package/dist/lifecycle/publish-marketplace.js +254 -0
  65. package/dist/lifecycle/publish-targets.d.ts +6 -0
  66. package/dist/lifecycle/publish-targets.d.ts.map +1 -1
  67. package/dist/lifecycle/publish-targets.js +15 -0
  68. package/dist/lifecycle/publish-tauri.d.ts +61 -0
  69. package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
  70. package/dist/lifecycle/publish-tauri.js +182 -0
  71. package/dist/lifecycle/release-publish.d.ts +5 -2
  72. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  73. package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
  74. package/dist/lifecycle/snapshot-store.js +17 -9
  75. package/dist/lifecycle/test-passkey.d.ts +25 -0
  76. package/dist/lifecycle/test-passkey.d.ts.map +1 -0
  77. package/dist/lifecycle/test-passkey.js +39 -0
  78. package/dist/notify.d.ts +23 -3
  79. package/dist/notify.d.ts.map +1 -1
  80. package/dist/notify.js +8 -2
  81. package/dist/notify.schema.json +12 -3
  82. package/dist/op/activities/activity-contracts.d.ts +4 -4
  83. package/dist/pr-forge.d.ts +20 -0
  84. package/dist/pr-forge.d.ts.map +1 -1
  85. package/dist/pr-forge.js +61 -2
  86. package/dist/release-floors.d.ts +1 -1
  87. package/dist/release-floors.js +1 -1
  88. package/dist/wave-runtime.mjs +331 -330
  89. package/dist/workspace/ci-builds.d.ts +21 -0
  90. package/dist/workspace/ci-builds.d.ts.map +1 -1
  91. package/dist/workspace/ci-builds.js +14 -0
  92. package/dist/workspace/ci-green-workflow.d.ts +2 -0
  93. package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
  94. package/dist/workspace/ci-green-workflow.js +9 -0
  95. package/dist/workspace/ci-green.d.ts +45 -2
  96. package/dist/workspace/ci-green.d.ts.map +1 -1
  97. package/dist/workspace/ci-green.js +127 -9
  98. package/dist/workspace/ci-quarantine-report.d.ts +80 -0
  99. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
  100. package/dist/workspace/ci-quarantine-report.js +205 -0
  101. package/dist/workspace/ci-quarantine.d.ts +73 -0
  102. package/dist/workspace/ci-quarantine.d.ts.map +1 -0
  103. package/dist/workspace/ci-quarantine.js +171 -0
  104. package/dist/workspace/ci-serve.d.ts.map +1 -1
  105. package/dist/workspace/ci-serve.js +7 -4
  106. package/dist/workspace/class-data.d.ts +3 -1
  107. package/dist/workspace/class-data.d.ts.map +1 -1
  108. package/dist/workspace/class-data.js +4 -1
  109. package/dist/workspace/declaration.d.ts +45 -2
  110. package/dist/workspace/declaration.d.ts.map +1 -1
  111. package/dist/workspace/declaration.js +45 -2
  112. package/dist/workspace/declaration.schema.json +51 -3
  113. package/dist/workspace/forge-work.d.ts +76 -0
  114. package/dist/workspace/forge-work.d.ts.map +1 -0
  115. package/dist/workspace/forge-work.js +160 -0
  116. package/dist/workspace/identity-gate-rule.d.ts +3 -2
  117. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  118. package/dist/workspace/identity-gate-rule.js +5 -7
  119. package/dist/workspace/identity.d.ts +3 -2
  120. package/dist/workspace/identity.d.ts.map +1 -1
  121. package/dist/workspace/identity.js +6 -3
  122. package/dist/workspace/intent-cli.d.ts +3 -2
  123. package/dist/workspace/intent-cli.d.ts.map +1 -1
  124. package/dist/workspace/intent-cli.js +26 -5
  125. package/dist/workspace/intent-record.d.ts +3 -0
  126. package/dist/workspace/intent-record.d.ts.map +1 -1
  127. package/dist/workspace/intent-record.schema.json +32 -0
  128. package/dist/workspace/intent.d.ts +9 -0
  129. package/dist/workspace/intent.d.ts.map +1 -1
  130. package/dist/workspace/intent.js +3 -0
  131. package/dist/workspace/intent.schema.json +32 -0
  132. package/dist/workspace/kind-readers.d.ts.map +1 -1
  133. package/dist/workspace/kind-readers.js +2 -1
  134. package/dist/workspace/kinds.d.ts +6 -1
  135. package/dist/workspace/kinds.d.ts.map +1 -1
  136. package/dist/workspace/kinds.js +8 -3
  137. package/dist/workspace/plan-stale.schema.json +286 -0
  138. package/dist/workspace/release-candidates.d.ts +33 -6
  139. package/dist/workspace/release-candidates.d.ts.map +1 -1
  140. package/dist/workspace/release-candidates.js +49 -20
  141. package/dist/workspace/release-candidates.schema.json +48 -2
  142. package/dist/workspace/trust/policy.d.ts +10 -0
  143. package/dist/workspace/trust/policy.d.ts.map +1 -1
  144. package/dist/workspace/trust/policy.js +19 -1
  145. package/dist/workspace/trust/run-commits.d.ts.map +1 -1
  146. package/dist/workspace/trust/run-commits.js +2 -1
  147. package/dist/workspace/trust/seal.d.ts.map +1 -1
  148. package/dist/workspace/trust/seal.js +34 -3
  149. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  150. package/dist/workspace/trust/trust-files.js +6 -1
  151. package/package.json +2 -1
  152. package/src/cli/handlers/approve-external-signature.test.ts +226 -0
  153. package/src/cli/handlers/approve.ts +174 -16
  154. package/src/cli/handlers/plan.ts +74 -0
  155. package/src/cli/handlers/release.ts +12 -7
  156. package/src/cli/main.ts +34 -5
  157. package/src/cli/mcp/workspace-tools.ts +2 -1
  158. package/src/cli/parse-args.ts +24 -0
  159. package/src/cli/registry.ts +13 -1
  160. package/src/gate-decision-bundle.test.ts +4 -2
  161. package/src/gate-decision.ts +11 -2
  162. package/src/gate-statement.schema.json +44 -0
  163. package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
  164. package/src/lifecycle/gate-ledger.ts +17 -3
  165. package/src/lifecycle/gate-seal.ts +62 -9
  166. package/src/lifecycle/gate-statement.ts +107 -0
  167. package/src/lifecycle/gate-webauthn.test.ts +77 -0
  168. package/src/lifecycle/gate-webauthn.ts +133 -0
  169. package/src/lifecycle/git.ts +23 -19
  170. package/src/lifecycle/ledger-remote.test.ts +183 -0
  171. package/src/lifecycle/ledger-remote.ts +46 -0
  172. package/src/lifecycle/plan-stale.test.ts +150 -0
  173. package/src/lifecycle/plan-stale.ts +173 -0
  174. package/src/lifecycle/publish-credentials.ts +2 -0
  175. package/src/lifecycle/publish-declaration.ts +93 -1
  176. package/src/lifecycle/publish-forge.ts +15 -4
  177. package/src/lifecycle/publish-github.ts +174 -0
  178. package/src/lifecycle/publish-homebrew.test.ts +179 -0
  179. package/src/lifecycle/publish-homebrew.ts +187 -0
  180. package/src/lifecycle/publish-marketplace.test.ts +254 -0
  181. package/src/lifecycle/publish-marketplace.ts +259 -0
  182. package/src/lifecycle/publish-target-context.test.ts +2 -2
  183. package/src/lifecycle/publish-targets.test.ts +23 -0
  184. package/src/lifecycle/publish-targets.ts +15 -0
  185. package/src/lifecycle/publish-tauri.test.ts +163 -0
  186. package/src/lifecycle/publish-tauri.ts +199 -0
  187. package/src/lifecycle/release-publish.ts +5 -3
  188. package/src/lifecycle/snapshot-store.ts +16 -9
  189. package/src/lifecycle/test-passkey.ts +55 -0
  190. package/src/notify-bundle.test.ts +3 -1
  191. package/src/notify.schema.json +12 -3
  192. package/src/notify.ts +20 -3
  193. package/src/override-gate-bundle.test.ts +2 -0
  194. package/src/pr-forge-bundle.test.ts +2 -2
  195. package/src/pr-forge.test.ts +38 -0
  196. package/src/pr-forge.ts +68 -5
  197. package/src/release-floors.ts +1 -1
  198. package/src/stage-hooks-bundle.test.ts +2 -0
  199. package/src/wave-runtime-bundle.test.ts +3 -2
  200. package/src/workspace/ci-builds.ts +27 -0
  201. package/src/workspace/ci-green-stale.test.ts +193 -0
  202. package/src/workspace/ci-green-workflow.test.ts +9 -0
  203. package/src/workspace/ci-green-workflow.ts +9 -0
  204. package/src/workspace/ci-green.ts +141 -10
  205. package/src/workspace/ci-quarantine-report.test.ts +146 -0
  206. package/src/workspace/ci-quarantine-report.ts +235 -0
  207. package/src/workspace/ci-quarantine.test.ts +161 -0
  208. package/src/workspace/ci-quarantine.ts +189 -0
  209. package/src/workspace/ci-serve.ts +7 -4
  210. package/src/workspace/class-data.ts +5 -1
  211. package/src/workspace/declaration.schema.json +51 -3
  212. package/src/workspace/declaration.test.ts +1 -0
  213. package/src/workspace/declaration.ts +88 -5
  214. package/src/workspace/forge-work.test.ts +143 -0
  215. package/src/workspace/forge-work.ts +195 -0
  216. package/src/workspace/identity-gate-rule.ts +6 -8
  217. package/src/workspace/identity.ts +6 -3
  218. package/src/workspace/intent-cli.ts +24 -5
  219. package/src/workspace/intent-record.schema.json +32 -0
  220. package/src/workspace/intent-record.ts +3 -0
  221. package/src/workspace/intent.schema.json +32 -0
  222. package/src/workspace/intent.ts +10 -0
  223. package/src/workspace/kind-readers.ts +2 -1
  224. package/src/workspace/kinds.test.ts +13 -0
  225. package/src/workspace/kinds.ts +12 -3
  226. package/src/workspace/plan-stale.schema.json +286 -0
  227. package/src/workspace/release-candidates.schema.json +48 -2
  228. package/src/workspace/release-candidates.test.ts +77 -4
  229. package/src/workspace/release-candidates.ts +62 -20
  230. package/src/workspace/trust/policy.ts +24 -1
  231. package/src/workspace/trust/run-commits.ts +2 -1
  232. package/src/workspace/trust/seal.ts +35 -3
  233. package/src/workspace/trust/trust-files.test.ts +5 -0
  234. package/src/workspace/trust/trust-files.ts +15 -1
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The Tauri updater target (#4676): the updater manifest a Tauri v2 app reads
3
+ * (`latest.json`), and a rolling GitHub release under a fixed tag, such as
4
+ * `app-latest`, that holds the release's bundles and that manifest. Each
5
+ * publish replaces what the rolling release held.
6
+ *
7
+ * The manifest is the updater's static JSON:
8
+ *
9
+ * ```json
10
+ * {
11
+ * "version": "1.4.0",
12
+ * "notes": "...",
13
+ * "pub_date": "2026-10-17T10:00:00.000Z",
14
+ * "platforms": {
15
+ * "darwin-aarch64": { "signature": "<the .sig file's text>", "url": "https://.../Acme_aarch64.app.tar.gz" }
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * `version` is the release's label from its first digit on; `notes` is the
21
+ * text of the declared `notes` file, left out without one; `pub_date` is the
22
+ * time of the cut whose signature the publish carries, left out when none is
23
+ * known, so the manifest is the same bytes on every run. Each platform's
24
+ * `signature` is the text of the `.sig` file the Tauri build wrote beside its
25
+ * updater bundle, and `url` is the `url` pattern for that bundle, by default
26
+ * its download URL on the rolling release.
27
+ *
28
+ * GitHub can't replace a release's contents in one request, so the two steps
29
+ * (#4048) are a draft and a swap:
30
+ *
31
+ * - The stage makes a draft release for the rolling tag named
32
+ * `<tag> <version>` at the release's commit, or finds the one an earlier
33
+ * stage made, and uploads each bundle, each declared asset and the manifest
34
+ * to it. A file already on the draft with the same digest is not sent
35
+ * again; one that differs is refused (`publish-tauri-asset-exists`). The
36
+ * published rolling release is untouched, so the updater sees nothing new.
37
+ * A rolling release that already holds every file with the same digests is
38
+ * what an earlier reveal left, and the stage does nothing.
39
+ * - The reveal deletes the published rolling release, deletes the tag so it
40
+ * is made again at the release's commit, and publishes the draft with
41
+ * `make_latest` from `latest` (default `false`: a rolling release is not
42
+ * the repository's latest). Between the delete and the publish, a few
43
+ * requests apart, the rolling release's URLs answer 404, which an updater
44
+ * treats as no update.
45
+ */
46
+
47
+ import { readFileSync } from "node:fs";
48
+ import { basename } from "node:path";
49
+ import { readCredential } from "./publish-credentials";
50
+ import type { TauriUpdaterPublishDeclaration } from "./publish-declaration";
51
+ import { GitHubRepo, githubApi, type GitHubRelease } from "./publish-github";
52
+ import { fillUrl, releaseVersion } from "./publish-homebrew";
53
+ import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
54
+ import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget, type StagedTarget } from "./release-publish";
55
+ import { NEXT_RELEASE } from "../release-floors";
56
+
57
+ /** The first chant that publishes a `tauri-updater` target (#4676). */
58
+ export const PUBLISH_TAURI_UPDATER_FLOOR = NEXT_RELEASE;
59
+
60
+ interface File {
61
+ path: string;
62
+ name: string;
63
+ bytes: Uint8Array;
64
+ digest: string;
65
+ }
66
+
67
+ /** The updater manifest's bytes: 2-space JSON with a trailing newline, keys in the order Tauri's docs show them. */
68
+ export function tauriManifest(m: { version: string; notes: string | null; pubDate: string | null; platforms: Record<string, { signature: string; url: string }> }): Uint8Array {
69
+ const platforms: Record<string, { signature: string; url: string }> = {};
70
+ for (const key of Object.keys(m.platforms).sort()) platforms[key] = { signature: m.platforms[key]!.signature, url: m.platforms[key]!.url };
71
+ const doc = { version: m.version, ...(m.notes !== null ? { notes: m.notes } : {}), ...(m.pubDate !== null ? { pub_date: m.pubDate } : {}), platforms };
72
+ return new Uint8Array(Buffer.from(`${JSON.stringify(doc, null, 2)}\n`, "utf-8"));
73
+ }
74
+
75
+ export function tauriUpdaterTarget(decl: TauriUpdaterPublishDeclaration, deps: PublishDeps): PublishTarget {
76
+ const fetchImpl: PublishFetch = deps.fetch ?? ((url, init) => fetch(url, init as RequestInit));
77
+ const tokenNames = [decl.tokenEnv ?? "GITHUB_TOKEN"];
78
+ const manifestName = decl.manifest ?? "latest.json";
79
+ const urlPattern = decl.url ?? `https://github.com/${decl.repo}/releases/download/{tag}/{name}`;
80
+
81
+ const read = (ctx: PublishContext, path: string): File => {
82
+ const bytes = new Uint8Array(readFileSync(memberFile(ctx.cwd, path)));
83
+ const digest = bytesDigest(bytes);
84
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, path, [digest]);
85
+ return { path, name: basename(path), bytes, digest };
86
+ };
87
+
88
+ const setup = (ctx: PublishContext) => {
89
+ const version = releaseVersion(ctx.label);
90
+ if (!version || !ctx.label) {
91
+ throw new PublishTargetError(
92
+ "publish-tauri-no-version",
93
+ `the updater manifest's version is the release's label from its first digit, and release ${ctx.release.releaseDigest} has ${ctx.label ? `the label ${ctx.label}, which has no digit` : "no label"}`,
94
+ "Cut the release with a label such as app-v1.4.0.",
95
+ );
96
+ }
97
+ const token = readCredential(ctx.env, tokenNames, ctx.redactor);
98
+ if (!token) {
99
+ throw new PublishTargetError("publish-credentials-missing", `the tauri-updater target reads its token from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]} to a token that may write releases on ${decl.repo}.`);
100
+ }
101
+ const files: File[] = [];
102
+ const platforms: Record<string, { signature: string; url: string }> = {};
103
+ for (const [platform, path] of Object.entries(decl.platforms)) {
104
+ const bundle = read(ctx, path);
105
+ const sig = read(ctx, `${path}.sig`);
106
+ const signature = Buffer.from(sig.bytes).toString("utf-8").trim();
107
+ if (!signature) throw new PublishTargetError("publish-tauri-signature-missing", `${path}.sig is empty, and the updater installs only a signed bundle`);
108
+ if (!files.some((f) => f.name === bundle.name)) files.push(bundle);
109
+ platforms[platform] = { signature, url: fillUrl(urlPattern, { tag: decl.tag, label: ctx.label, version, name: bundle.name }) };
110
+ }
111
+ for (const path of decl.assets ?? []) files.push(read(ctx, path));
112
+ const notes = decl.notes ? readFileSync(memberFile(ctx.cwd, decl.notes), "utf-8").trim() : null;
113
+ const bytes = tauriManifest({ version, notes, pubDate: ctx.cut?.timestamp ?? null, platforms });
114
+ files.push({ path: manifestName, name: manifestName, bytes, digest: bytesDigest(bytes) });
115
+ const names = new Set<string>();
116
+ for (const f of files) {
117
+ if (names.has(f.name)) throw new PublishTargetError("publish-tauri-asset-name-taken", `two files are named ${f.name}, and a release holds one asset per name`);
118
+ names.add(f.name);
119
+ }
120
+ const repo = new GitHubRepo(githubApi(decl.api, ctx.env), decl.repo, token, fetchImpl, ctx, "publish-tauri-failed");
121
+ return { version, token, files, repo, draftName: `${decl.tag} ${version}` };
122
+ };
123
+ const where = (name: string) => `github ${decl.repo} release ${decl.tag}, asset ${name}`;
124
+ const itemOf = (f: File, present = false): PublishItem => ({ name: f.path, destination: where(f.name), digest: f.digest, ...(present ? { present: true } : {}) });
125
+ const holdsAll = (rel: GitHubRelease, files: File[]) => rel.assets.size === files.length && files.every((f) => rel.assets.get(f.name) === f.digest);
126
+
127
+ const target: PublishTarget = {
128
+ kind: "tauri-updater",
129
+ name: `tauri updater ${decl.repo} ${decl.tag}`,
130
+ destination: `github ${decl.repo} release ${decl.tag}`,
131
+ credentialEnv: tokenNames,
132
+ key: publishTargetKey(decl),
133
+ async plan(ctx) {
134
+ return setup(ctx).files.map((f) => itemOf(f));
135
+ },
136
+ async stage(ctx): Promise<StagedTarget> {
137
+ const { version, token, files, repo, draftName } = setup(ctx);
138
+ ctx.log(`using the token from ${token.from}`);
139
+ const done = (items: PublishItem[], state: Record<string, string>): StagedTarget => ({ target: target.name, destination: target.destination, items, state });
140
+ const published = await repo.publishedRelease(decl.tag);
141
+ if (published && holdsAll(published, files)) {
142
+ ctx.log(`release ${decl.tag} already holds ${version}'s files`);
143
+ return done(
144
+ files.map((f) => itemOf(f, true)),
145
+ { published: published.id },
146
+ );
147
+ }
148
+ let draft = await repo.draftRelease(decl.tag, draftName);
149
+ if (draft) ctx.log(`using the draft release ${draftName}`);
150
+ else {
151
+ ctx.log(`creating a draft release ${draftName} at ${ctx.release.commit.slice(0, 12)}`);
152
+ draft = await repo.createDraft(decl.tag, ctx.release.commit, draftName);
153
+ }
154
+ const items: PublishItem[] = [];
155
+ for (const f of files) {
156
+ if (draft.assets.has(f.name)) {
157
+ const theirs = draft.assets.get(f.name);
158
+ if (theirs !== f.digest) {
159
+ throw new PublishTargetError(
160
+ "publish-tauri-asset-exists",
161
+ `the draft release ${draftName} on ${decl.repo} already has ${f.name}${theirs ? ` with digest ${theirs}, not ${f.digest}` : ", and GitHub reports no digest to compare"}`,
162
+ "Delete the draft on GitHub so the stage makes it again.",
163
+ );
164
+ }
165
+ items.push(itemOf(f, true));
166
+ continue;
167
+ }
168
+ ctx.log(`uploading ${f.name} (${f.bytes.byteLength} bytes) to the draft`);
169
+ await repo.uploadAsset(draft, f.name, f.bytes);
170
+ items.push(itemOf(f));
171
+ }
172
+ return done(items, { releaseId: draft.id });
173
+ },
174
+ async reveal(ctx, staged) {
175
+ const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
176
+ if (staged.state.published) return { target: target.name, destination: target.destination, items: items.map((i) => ({ ...i, present: true })) };
177
+ const id = staged.state.releaseId;
178
+ if (!id) throw new PublishTargetError("publish-tauri-failed", `the staged release for ${decl.tag} has no draft id to publish`);
179
+ const { repo } = setup(ctx);
180
+ const old = await repo.publishedRelease(decl.tag);
181
+ if (old?.id === id) {
182
+ ctx.log(`release ${decl.tag} is already the staged draft, published`);
183
+ return { target: target.name, destination: target.destination, items };
184
+ }
185
+ if (old) {
186
+ ctx.log(`deleting the published release ${decl.tag} (${old.id}) and its tag`);
187
+ await repo.deleteRelease(old.id);
188
+ }
189
+ // A tag that is there stays where it is when a release is published on it, so it goes, and the publish makes it at the release's commit.
190
+ await repo.deleteRef(`tags/${decl.tag}`);
191
+ const makeLatest = String(decl.latest ?? false);
192
+ ctx.log(`publishing the draft as ${decl.tag} with make_latest ${makeLatest}`);
193
+ const res = await repo.publishDraft(id, makeLatest);
194
+ if (res.status !== 200) repo.fail(`publishing the draft release ${decl.tag}`, res);
195
+ return { target: target.name, destination: target.destination, items };
196
+ },
197
+ };
198
+ return target;
199
+ }
@@ -125,10 +125,12 @@ export interface PublishedTarget {
125
125
 
126
126
  /** Injected into the targets, so tests drive them with fakes. */
127
127
  export interface PublishDeps {
128
- /** The HTTP client the OCI and forge targets use. Default: the global `fetch`. */
128
+ /** The HTTP client the OCI, forge, homebrew, marketplace and tauri-updater targets use. Default: the global `fetch`. */
129
129
  fetch?: PublishFetch;
130
130
  /** The npm executable. Default: `npm` on `PATH`. */
131
131
  npm?: string;
132
+ /** The vsce executable the VS Code Marketplace target runs (#4676). Default: `vsce` on `PATH`. */
133
+ vsce?: string;
132
134
  /** How a target waits between polls of a registry (#4244). Default: a timer. */
133
135
  sleep?: (ms: number) => Promise<void>;
134
136
  /** The clock a target's wait reads (#4244). Default: `Date.now`. */
@@ -139,7 +141,7 @@ export interface PublishDeps {
139
141
  export type PublishFetch = (
140
142
  url: string,
141
143
  init: { method: string; headers: Record<string, string>; body?: Uint8Array | string; redirect?: "follow" | "manual" },
142
- ) => Promise<{ ok: boolean; status: number; headers: { get(name: string): string | null }; text(): Promise<string> }>;
144
+ ) => Promise<{ ok: boolean; status: number; headers: { get(name: string): string | null }; text(): Promise<string>; arrayBuffer?(): Promise<ArrayBuffer> }>;
143
145
 
144
146
  /**
145
147
  * The part of a target's context every kind of target is given, whatever it
@@ -200,7 +202,7 @@ export class PublishTargetError extends Error {
200
202
  }
201
203
 
202
204
  /** The kinds `release.publish` declares and `createPublishTargets` makes. */
203
- export type ReleasePublishKind = "npm" | "oci" | "forge";
205
+ export type ReleasePublishKind = "npm" | "oci" | "forge" | "homebrew" | "marketplace" | "tauri-updater";
204
206
 
205
207
  /** The npm dist-tag a set of packages is staged under before `latest` moves (#4048), as chant's own releases do (#3903). */
206
208
  export const NPM_STAGE_TAG = "next";
@@ -71,6 +71,7 @@ import {
71
71
  type LedgerLocation,
72
72
  } from "./git";
73
73
  import { ledgerRecordingOff } from "./no-record";
74
+ import { chooseLedgerRemote, type LedgerRemoteChoice } from "./ledger-remote";
74
75
  import {
75
76
  INDEX_SCOPE_FILE,
76
77
  indexVersionName,
@@ -199,13 +200,15 @@ async function git(args: string[], opts: { cwd?: string; stdin?: string; env?: R
199
200
  return getRuntime().spawn(["git", ...args], { ...(opts.cwd ? { cwd: opts.cwd } : {}), ...(opts.stdin !== undefined ? { stdin: opts.stdin } : {}), env: { ...C_LOCALE, ...(opts.env ?? {}) } });
200
201
  }
201
202
 
202
- /** The remote a ref is pushed to: `origin` when it exists, else the first. */
203
- async function remoteOf(cwd?: string): Promise<string | null> {
203
+ /**
204
+ * The remote a ref is pushed to: the ledger's ({@link chooseLedgerRemote}),
205
+ * or null when there is none. A `CHANT_LIFECYCLE_REMOTE` that names no remote
206
+ * comes back as `failed`.
207
+ */
208
+ async function remoteOf(cwd?: string): Promise<LedgerRemoteChoice> {
204
209
  const result = await git(["remote"], { cwd });
205
210
  if (result.exitCode !== 0) return null;
206
- const names = result.stdout.trim().split("\n").map((n) => n.trim()).filter(Boolean);
207
- if (names.length === 0) return null;
208
- return names.includes("origin") ? "origin" : names[0];
211
+ return chooseLedgerRemote(result.stdout.trim().split("\n").map((n) => n.trim()).filter(Boolean));
209
212
  }
210
213
 
211
214
  /** `user.name`/`user.email` for a checkout that has none, as the ledger's own writes do (#2301). */
@@ -319,8 +322,10 @@ function trackingRefOf(ref: string): string {
319
322
  */
320
323
  export async function fetchRefFastForward(ref: string, opts?: { cwd?: string }): Promise<"fetched" | "no-remote" | "missing" | "kept" | "failed"> {
321
324
  const cwd = opts?.cwd;
322
- const remote = await remoteOf(cwd);
323
- if (!remote) return "no-remote";
325
+ const found = await remoteOf(cwd);
326
+ if (found === null) return "no-remote";
327
+ if ("failed" in found) return "failed";
328
+ const { remote } = found;
324
329
  const tracking = trackingRefOf(ref);
325
330
  const f = await git(["fetch", "--no-tags", remote, `+${ref}:${tracking}`], { cwd });
326
331
  if (f.exitCode !== 0) return /couldn't find remote ref|no such ref was fetched/i.test(f.stderr ?? "") ? "missing" : "failed";
@@ -355,8 +360,10 @@ export async function publishRef(
355
360
  if (ledgerRecordingOff()) return { status: "nothing", detail: "recording is off for this run" };
356
361
  const local = await readRefSha(ref, { cwd });
357
362
  if (!local) return { status: "nothing" };
358
- const remote = await remoteOf(cwd);
359
- if (!remote) return { status: "local", detail: "no remote configured" };
363
+ const found = await remoteOf(cwd);
364
+ if (found === null) return { status: "local", detail: "no remote configured" };
365
+ if ("failed" in found) return { status: "failed", detail: found.stderr };
366
+ const { remote } = found;
360
367
  const tracking = trackingRefOf(ref);
361
368
  for (let attempt = 1; attempt <= 3; attempt++) {
362
369
  const expected = await readRefSha(tracking, { cwd });
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Passkeys for tests (#4646): a key pair listed as `.chant/trust.json` lists
3
+ * one, and assertions built by hand the way an authenticator builds them.
4
+ */
5
+
6
+ import { createHash, generateKeyPairSync, sign, type KeyObject } from "node:crypto";
7
+ import { webAuthnChallenge, type PasskeySigner, type WebAuthnAssertion } from "./gate-webauthn";
8
+
9
+ export const RP = "example.com";
10
+ export const ORIGIN = "https://control.example.com";
11
+
12
+ export interface Passkey {
13
+ signer: PasskeySigner;
14
+ privateKey: KeyObject;
15
+ alg: "EdDSA" | "ES256";
16
+ }
17
+
18
+ /** A passkey for `principal`: a fresh key pair, listed as trust.json lists one. */
19
+ export function passkey(principal: string, id: string, alg: "EdDSA" | "ES256" = "EdDSA"): Passkey {
20
+ const { publicKey, privateKey } = alg === "EdDSA" ? generateKeyPairSync("ed25519") : generateKeyPairSync("ec", { namedCurve: "P-256" });
21
+ return {
22
+ signer: { principal, id, publicKey: publicKey.export({ format: "der", type: "spki" }).toString("base64url"), rpId: RP, origins: [ORIGIN] },
23
+ privateKey,
24
+ alg,
25
+ };
26
+ }
27
+
28
+ /** What an authenticator would return for `statement`, with each part open to change for a refusal. */
29
+ export function assert(
30
+ pk: Passkey,
31
+ statement: Buffer,
32
+ over: { type?: string; challenge?: string; origin?: string; rpId?: string; flags?: number; crossOrigin?: boolean } = {},
33
+ ): WebAuthnAssertion {
34
+ const clientData = Buffer.from(
35
+ JSON.stringify({
36
+ type: over.type ?? "webauthn.get",
37
+ challenge: over.challenge ?? webAuthnChallenge(statement),
38
+ origin: over.origin ?? ORIGIN,
39
+ ...(over.crossOrigin !== undefined ? { crossOrigin: over.crossOrigin } : {}),
40
+ }),
41
+ );
42
+ const authData = Buffer.concat([
43
+ createHash("sha256").update(over.rpId ?? RP).digest(),
44
+ Buffer.from([over.flags ?? 0x05]),
45
+ Buffer.from([0, 0, 0, 7]),
46
+ ]);
47
+ const signed = Buffer.concat([authData, createHash("sha256").update(clientData).digest()]);
48
+ const signature = sign(pk.alg === "EdDSA" ? null : "sha256", signed, pk.privateKey);
49
+ return {
50
+ id: pk.signer.id,
51
+ clientDataJSON: clientData.toString("base64url"),
52
+ authenticatorData: authData.toString("base64url"),
53
+ signature: signature.toString("base64url"),
54
+ };
55
+ }
@@ -39,7 +39,9 @@ describe("the notify bundle", () => {
39
39
  const { inputs, bytes, imports } = await bundle("notify.ts");
40
40
  expect(inputs).toEqual(["packages/core/src/notify-verify.ts", "packages/core/src/notify.ts"]);
41
41
  expect(imports).toEqual(["node:crypto"]);
42
- expect(bytes).toBeLessThan(16 * 1024);
42
+ // 17 KiB since ci.stale (#4678): the ci. events' names and headlines took it to 16.0 KiB, and the cap
43
+ // is there to catch a dependency pulled in, which would add far more than an event name.
44
+ expect(bytes).toBeLessThan(17 * 1024);
43
45
  });
44
46
 
45
47
  test("the verifier holds itself alone, and imports only node:crypto", async () => {
@@ -8,7 +8,7 @@
8
8
  "properties": {
9
9
  "schema": { "const": "chant.notify/v1" },
10
10
  "id": { "type": "string", "minLength": 1, "description": "The same for every send of one event about one digest (else drift fingerprint, else commit), so a receiver can drop a repeat; random when there is none. The delivery header carries it too." },
11
- "event": { "enum": ["waiting", "refused", "failed", "drift", "ci.red", "ci.culprit", "ci.green"], "description": "The ci. events come from chant ci tick (#4645) and carry ci." },
11
+ "event": { "enum": ["waiting", "refused", "failed", "drift", "ci.red", "ci.culprit", "ci.green", "ci.quarantine-passed", "ci.stale"], "description": "The ci. events come from chant ci tick (#4645, ci.stale #4678), and ci.quarantine-passed from chant ci quarantine report (#4677), and carry ci." },
12
12
  "at": { "type": "string", "description": "When it was sent, ISO 8601 UTC." },
13
13
  "source": { "type": "string", "minLength": 1, "description": "The product that sent it: chant, terragucci, sql-yodeler." },
14
14
  "project": { "type": "string", "description": "What the run belongs to: the repository, or a name the product gives." },
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "ci": {
67
67
  "type": "object",
68
- "description": "On ci.red, ci.culprit and ci.green (#4645): the branch and commit. ci.red: the newest decided commit, red after its one retry, with phase and failedRun. ci.culprit: culprit, the first red commit a bisect found for the red commit. ci.green: red, the commit whose ci.red this answers.",
68
+ "description": "On ci.red, ci.culprit and ci.green (#4645): the branch and commit. ci.red: the newest decided commit, red after its one retry, with phase and failedRun. ci.culprit: culprit, the first red commit a bisect found for the red commit. ci.green: red, the commit whose ci.red this answers, and since when it ends a stretch told ci.stale. ci.stale (#4678): commit is the branch's tip, since the oldest commit above the newest green one, lastGreen that green commit (absent when the tick found none), and hours the whole hours since since was committed.",
69
69
  "required": ["branch", "commit"],
70
70
  "properties": {
71
71
  "branch": { "type": "string" },
@@ -76,7 +76,16 @@
76
76
  "properties": { "name": { "type": "string" }, "id": { "type": ["integer", "null"] }, "conclusion": { "type": ["string", "null"] }, "url": { "type": ["string", "null"] } }
77
77
  },
78
78
  "culprit": { "type": "string" },
79
- "red": { "type": "string" }
79
+ "red": { "type": "string" },
80
+ "since": { "type": "string" },
81
+ "lastGreen": { "type": "string" },
82
+ "hours": { "type": "integer", "minimum": 0 },
83
+ "quarantine": {
84
+ "type": "object",
85
+ "description": "On ci.quarantine-passed (#4677): the quarantined test that passed in the scheduled run at commit, as ci.green.quarantine lists it, with phase. Sent by chant 0.124.63 and newer.",
86
+ "required": ["test", "issue", "until"],
87
+ "properties": { "test": { "type": "string" }, "file": { "type": "string" }, "issue": { "type": "string" }, "until": { "type": "string" } }
88
+ }
80
89
  }
81
90
  },
82
91
  "reportUrl": { "type": "string" },
package/src/notify.ts CHANGED
@@ -39,8 +39,12 @@ export const NOTIFY_SCHEMA = "chant.notify/v1";
39
39
  /** The JSON Schema's `$id`. */
40
40
  export const NOTIFY_SCHEMA_ID = "https://intentius.io/chant/schemas/notify/v1/notify.schema.json";
41
41
 
42
- /** What happened. The `ci.` events come from `chant ci tick` (#4645): a branch red after its retry, a bisect's culprit, the branch green again. */
43
- export const NOTIFY_EVENTS = ["waiting", "refused", "failed", "drift", "ci.red", "ci.culprit", "ci.green"] as const;
42
+ /**
43
+ * What happened. The `ci.` events come from `chant ci tick` (#4645): a branch red after its retry, a bisect's culprit, the branch green again,
44
+ * and a branch with no green commit for `staleAfter` hours (#4678);
45
+ * and from `chant ci quarantine report` (#4677): a quarantined test passed in the scheduled run.
46
+ */
47
+ export const NOTIFY_EVENTS = ["waiting", "refused", "failed", "drift", "ci.red", "ci.culprit", "ci.green", "ci.quarantine-passed", "ci.stale"] as const;
44
48
  export type NotifyEventKind = (typeof NOTIFY_EVENTS)[number];
45
49
 
46
50
  /** Where the run is: the CI run's page, the forge, the repository and commit. */
@@ -107,7 +111,13 @@ export interface NotifyEvent {
107
111
  * branch's newest decided commit, red after its one retry, with the phase and
108
112
  * run that failed. `ci.culprit`: `culprit` is the first red commit a bisect
109
113
  * found, for the red `commit`. `ci.green`: `commit` is green, and `red` the
110
- * commit whose `ci.red` this answers.
114
+ * commit whose `ci.red` this answers. `ci.quarantine-passed` (#4677):
115
+ * `commit` is the one the scheduled run tested, with the phase and the
116
+ * quarantined test that passed there. `ci.stale` (#4678): `commit` is the
117
+ * branch's tip, `since` the oldest commit above the newest green one,
118
+ * `lastGreen` that green commit, and `hours` how long since `since` was
119
+ * committed. A `ci.green` that ends a stretch told `ci.stale` names its
120
+ * `since` too.
111
121
  */
112
122
  export interface NotifyCi {
113
123
  branch: string;
@@ -116,6 +126,11 @@ export interface NotifyCi {
116
126
  failedRun?: { name: string; id: number | null; conclusion: string | null; url: string | null };
117
127
  culprit?: string;
118
128
  red?: string;
129
+ /** On `ci.quarantine-passed` (#4677): the quarantined test that passed, as `ci.green.quarantine` lists it. */
130
+ quarantine?: { test: string; file?: string; issue: string; until: string };
131
+ since?: string;
132
+ lastGreen?: string;
133
+ hours?: number;
119
134
  }
120
135
 
121
136
  /** What a product fills in; {@link makeNotifyEvent} adds the rest. */
@@ -179,6 +194,8 @@ const HEADLINE: Record<NotifyEventKind, string> = {
179
194
  "ci.red": "is red",
180
195
  "ci.culprit": "has a culprit",
181
196
  "ci.green": "is green again",
197
+ "ci.quarantine-passed": "passed a quarantined test",
198
+ "ci.stale": "has no green commit",
182
199
  };
183
200
 
184
201
  /** The first line of every chat message: `<source>: <summary>`, or what happened to what when there is no summary. */
@@ -37,6 +37,8 @@ describe("the override-gate bundle", () => {
37
37
  "packages/core/src/intrinsic.ts",
38
38
  "packages/core/src/lifecycle/gate-ledger-select.ts",
39
39
  "packages/core/src/lifecycle/gate-seal.ts",
40
+ // A passkey's seal (#4646), checked with node:crypto.
41
+ "packages/core/src/lifecycle/gate-webauthn.ts",
40
42
  "packages/core/src/lifecycle/plan-digest.ts",
41
43
  "packages/core/src/op/gate-name.ts",
42
44
  "packages/core/src/override-gate.ts",
@@ -34,7 +34,7 @@ describe("the pr-forge bundle", () => {
34
34
  expect(inputs.filter((i) => pattern.test(i)), String(pattern)).toEqual([]);
35
35
  }
36
36
  expect(inputs.map((i) => i.replace(/^.*?packages\//, "packages/")).sort()).toEqual(["packages/core/src/pr-forge.ts"]);
37
- // About 55.9 KB today, after the pull request authors (#4000), pullRequestOpen for target locks (#4293), the four requires checks of an apply before merge (#4301) the approver filter (#4337) the approved fields (#4287) the plan job's GitLab note (#4328) and GitLab's open merge requests for stale notes (#4628).
38
- expect(result.outputFiles.reduce((n, f) => n + f.contents.byteLength, 0)).toBeLessThan(56 * 1024);
37
+ // About 58.5 KB today, after the pull request authors (#4000), pullRequestOpen for target locks (#4293), the four requires checks of an apply before merge (#4301) the approver filter (#4337) the approved fields (#4287) the plan job's GitLab note (#4328), GitLab's open merge requests for stale notes (#4628) and the issues a pull request closes (#4649).
38
+ expect(result.outputFiles.reduce((n, f) => n + f.contents.byteLength, 0)).toBeLessThan(60 * 1024);
39
39
  });
40
40
  });
@@ -17,6 +17,7 @@ import {
17
17
  FORGE_STATUS_STATES,
18
18
  githubForge,
19
19
  gitlabForge,
20
+ closingIssueRefs,
20
21
  statusStateFor,
21
22
  type ForgeFetch,
22
23
  type ForgeStatusState,
@@ -1063,3 +1064,40 @@ describe("setCommitStatus, a runner job's status (#4097)", () => {
1063
1064
  expect(gitlabForge({ apiBase: "https://gl/api/v4", project: "42", token: "t", fetch }).setCommitStatus).toBeUndefined();
1064
1065
  });
1065
1066
  });
1067
+
1068
+ describe("closingIssues, what a pull request closes (#4649)", () => {
1069
+ test("GitHub asks GraphQL once, keeping this repository's issues", async () => {
1070
+ const { fetch, calls } = fakeFetch({
1071
+ "POST /graphql": {
1072
+ data: { repository: { pullRequest: { closingIssuesReferences: { nodes: [{ number: 9, repository: { nameWithOwner: "acme/infra" } }, { number: 3, repository: { nameWithOwner: "Acme/Infra" } }, { number: 4, repository: { nameWithOwner: "acme/other" } }] } } } },
1073
+ },
1074
+ });
1075
+ expect(await githubForge({ apiBase: "https://api.github.com", repo: "acme/infra", token: "t0k", fetch }).closingIssues!(12)).toEqual([3, 9]);
1076
+ expect(calls).toHaveLength(1);
1077
+ expect(calls[0]).toMatchObject({ method: "POST", url: "https://api.github.com/graphql", body: { variables: { owner: "acme", name: "infra", pr: 12 } } });
1078
+ expect(calls[0].headers.Authorization).toBe("Bearer t0k");
1079
+ });
1080
+
1081
+ test("GitHub Enterprise Server's GraphQL is at /api/graphql, and a GraphQL error throws", async () => {
1082
+ const { fetch, calls } = fakeFetch({ "POST /api/graphql": { data: { repository: { pullRequest: null } }, errors: [{ message: "Could not resolve to a PullRequest with the number of 5." }] } });
1083
+ await expect(githubForge({ apiBase: "https://ghe.acme.io/api/v3", repo: "acme/infra", token: "t", fetch }).closingIssues!(5)).rejects.toThrow(/Could not resolve to a PullRequest/);
1084
+ expect(calls[0].url).toBe("https://ghe.acme.io/api/graphql");
1085
+ });
1086
+
1087
+ test("Forgejo reads the closing keywords in the pull request's body", async () => {
1088
+ const { fetch, calls } = fakeFetch({ "GET /api/v1/repos/acme/infra/pulls/7": { number: 7, body: "Closes #12.\nfixes: #3, Resolved #12, see #40, other/repo#5" } });
1089
+ expect(await forgejoForge({ apiBase: "https://code.acme.io/api/v1", repo: "acme/infra", host: "code.acme.io", token: "t", fetch }).closingIssues!(7)).toEqual([3, 12]);
1090
+ expect(calls).toHaveLength(1);
1091
+ });
1092
+
1093
+ test("GitLab asks closes_issues, leaving out another project's issue when the project is an id", async () => {
1094
+ const { fetch, calls } = fakeFetch({ "GET /api/v4/projects/42/merge_requests/5/closes_issues": [{ iid: 8, project_id: 42 }, { iid: 2, project_id: 42 }, { iid: 1, project_id: 7 }] });
1095
+ expect(await gitlabForge({ apiBase: "https://gitlab.com/api/v4", project: "42", token: "t", fetch }).closingIssues!(5)).toEqual([2, 8]);
1096
+ expect(calls).toHaveLength(1);
1097
+ });
1098
+
1099
+ test("closingIssueRefs reads the keywords GitHub and Forgejo honour", () => {
1100
+ expect(closingIssueRefs("close #1 closes #2 closed #3 fix #4 fixes #5 fixed #6 resolve #7 resolves #8 resolved #9")).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
1101
+ expect(closingIssueRefs("prefix #1, addresses #2, a/b#3 fixes a/b#4, unclosed #5")).toEqual([]);
1102
+ });
1103
+ });
package/src/pr-forge.ts CHANGED
@@ -426,6 +426,18 @@ export interface PrForge {
426
426
  labels?(pr: number): Promise<string[]>;
427
427
  /** Whether pull request `pr` is open, closed unmerged, or merged (#4298), for `pr-env sweep`. */
428
428
  pullRequestState?(pr: number): Promise<"open" | "closed" | "merged">;
429
+ /**
430
+ * The issues of this repository that pull request `pr` (merge request `pr`
431
+ * on GitLab) closes when it merges (#4649), ascending, without repeats. One
432
+ * call per pull request. GitHub answers from GraphQL's
433
+ * `closingIssuesReferences`, which holds both the closing keywords in the
434
+ * body and the issues linked by hand, so it needs a token. GitLab answers
435
+ * from `closes_issues`. Forgejo has no such call, so its pull request's body
436
+ * is read for the closing keywords it honours ({@link closingIssueRefs}).
437
+ * An issue in another repository is left out (on GitLab, when the client
438
+ * names its project by id).
439
+ */
440
+ closingIssues?(pr: number): Promise<number[]>;
429
441
  /**
430
442
  * Merge pull request `pr` only if its head is still `opts.sha`. A moved
431
443
  * head, a conflict or a branch rule the forge enforces comes back as
@@ -675,6 +687,19 @@ export class ForgeApiError extends Error {
675
687
  }
676
688
  }
677
689
 
690
+ /**
691
+ * The issues a pull request body closes by keyword, as Forgejo and GitHub
692
+ * read them: `close`, `closes`, `closed`, `fix`, `fixes`, `fixed`,
693
+ * `resolve`, `resolves` or `resolved`, any case, an optional colon, then
694
+ * `#<n>`. A reference to another repository (`owner/name#<n>`) is left out.
695
+ * Ascending, without repeats.
696
+ */
697
+ export function closingIssueRefs(body: string): number[] {
698
+ const out = new Set<number>();
699
+ for (const m of body.matchAll(/(?:^|[^\w/])(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?):?\s+#(\d+)\b/gi)) out.add(Number(m[1]));
700
+ return [...out].sort((a, b) => a - b);
701
+ }
702
+
678
703
  /** The forge answered 404. */
679
704
  const notFound = (err: unknown): boolean => err instanceof ForgeApiError && err.status === 404;
680
705
 
@@ -875,13 +900,12 @@ const GITLAB_DESCRIPTION = 255;
875
900
  /** Which of the two GitHub-shaped forges a client is talking to. */
876
901
  function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): GithubShapedForge {
877
902
  const host = (opts.host ?? "github.com").toLowerCase();
878
- const api = transport(
879
- opts.apiBase,
903
+ const headers =
880
904
  kind === "github"
881
905
  ? { ...(opts.token ? { Authorization: `Bearer ${opts.token}` } : {}), Accept: "application/vnd.github+json" }
882
- : { ...(opts.token ? { Authorization: `token ${opts.token}` } : {}), Accept: "application/json" },
883
- opts.fetch ?? (globalThis.fetch as unknown as ForgeFetch),
884
- );
906
+ : { ...(opts.token ? { Authorization: `token ${opts.token}` } : {}), Accept: "application/json" };
907
+ const fetchImpl = opts.fetch ?? (globalThis.fetch as unknown as ForgeFetch);
908
+ const api = transport(opts.apiBase, headers, fetchImpl);
885
909
  const repo = `/repos/${opts.repo}`;
886
910
  // GitHub pages with per_page (up to 100); Forgejo with limit (capped at 50 by default).
887
911
  const pageSize = kind === "github" ? 100 : 50;
@@ -1230,6 +1254,34 @@ function githubShaped(kind: "github" | "forgejo", opts: GithubForgeOptions): Git
1230
1254
  const listed = await api.list(`${repo}/issues/${pr}/labels`, pageParams, pageSize);
1231
1255
  return listed.map((l) => (isObject(l) ? str(l.name) : undefined)).filter((n): n is string => n !== undefined);
1232
1256
  },
1257
+ async closingIssues(pr) {
1258
+ if (kind === "forgejo") {
1259
+ const p = await api.call("GET", `${repo}/pulls/${pr}`);
1260
+ return closingIssueRefs(isObject(p) ? (str(p.body) ?? "") : "");
1261
+ }
1262
+ // GitHub's REST API has no closing issues; GraphQL does, at /graphql on
1263
+ // github.com and /api/graphql on GitHub Enterprise Server.
1264
+ const root = opts.apiBase.replace(/\/+$/, "");
1265
+ const url = /\/api\/v3$/.test(root) ? `${root.slice(0, -"/v3".length)}/graphql` : `${root}/graphql`;
1266
+ const [owner, name] = opts.repo.split("/");
1267
+ const query =
1268
+ "query($owner:String!,$name:String!,$pr:Int!){repository(owner:$owner,name:$name){pullRequest(number:$pr){closingIssuesReferences(first:100){nodes{number repository{nameWithOwner}}}}}}";
1269
+ const res = await fetchImpl(url, { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify({ query, variables: { owner, name, pr } }) });
1270
+ const text = await res.text();
1271
+ if (!res.ok) throw new ForgeApiError("POST", url, res.status, text);
1272
+ const body: unknown = text ? JSON.parse(text) : null;
1273
+ const errors = isObject(body) && Array.isArray(body.errors) ? body.errors : [];
1274
+ if (errors.length > 0) throw new ForgeApiError("POST", url, res.status, errors.map((e) => (isObject(e) ? (str(e.message) ?? "") : "")).join("; "));
1275
+ const data = isObject(body) && isObject(body.data) && isObject(body.data.repository) ? body.data.repository : undefined;
1276
+ const refs = data && isObject(data.pullRequest) && isObject(data.pullRequest.closingIssuesReferences) ? data.pullRequest.closingIssuesReferences.nodes : undefined;
1277
+ const out = new Set<number>();
1278
+ for (const n of Array.isArray(refs) ? refs : []) {
1279
+ if (!isObject(n) || typeof n.number !== "number") continue;
1280
+ const there = isObject(n.repository) ? str(n.repository.nameWithOwner) : undefined;
1281
+ if (there === undefined || there.toLowerCase() === opts.repo.toLowerCase()) out.add(n.number);
1282
+ }
1283
+ return [...out].sort((a, b) => a - b);
1284
+ },
1233
1285
  async pullRequestState(pr) {
1234
1286
  const p = await api.call("GET", `${repo}/pulls/${pr}`);
1235
1287
  if (!isObject(p)) return "open";
@@ -1635,6 +1687,17 @@ export function gitlabForge(opts: GitlabForgeOptions): PrForge {
1635
1687
  const m = await api.call("GET", `${notes}/${mr}`);
1636
1688
  return isObject(m) && Array.isArray(m.labels) ? m.labels.filter((l): l is string => typeof l === "string") : [];
1637
1689
  },
1690
+ async closingIssues(mr) {
1691
+ const listed = await api.list(`${notes}/${mr}/closes_issues`, pageParams, 100);
1692
+ // An issue of another project is left out when the project is named by id; by path, every one is kept, to spend no second call.
1693
+ const own = /^\d+$/.test(opts.project) ? Number(opts.project) : undefined;
1694
+ const out = new Set<number>();
1695
+ for (const i of listed) {
1696
+ if (!isObject(i) || typeof i.iid !== "number") continue;
1697
+ if (own === undefined || i.project_id === undefined || i.project_id === own) out.add(i.iid);
1698
+ }
1699
+ return [...out].sort((a, b) => a - b);
1700
+ },
1638
1701
  async pullRequestState(mr) {
1639
1702
  const m = await api.call("GET", `${notes}/${mr}`);
1640
1703
  if (!isObject(m)) return "open";
@@ -19,4 +19,4 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.61";
22
+ export const NEXT_RELEASE = "0.124.63";
@@ -29,6 +29,8 @@ describe("the stage-hooks bundle", () => {
29
29
  // The control repo's settings check (#4568, #4617), which the spec checks.
30
30
  "packages/core/src/control/dispatch.ts",
31
31
  "packages/core/src/lifecycle/gate-seal.ts",
32
+ // A passkey's seal (#4646), checked with node:crypto.
33
+ "packages/core/src/lifecycle/gate-webauthn.ts",
32
34
  "packages/core/src/notify-verify.ts",
33
35
  "packages/core/src/notify.ts",
34
36
  "packages/core/src/op/gate-point.ts",