@adea-ai/app-framework 0.31.0 → 0.33.0

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 (111) hide show
  1. package/README.md +33 -15
  2. package/dist/app/create-application.js +4 -3
  3. package/dist/app/serial-queue.d.ts +5 -0
  4. package/dist/app/serial-queue.js +14 -0
  5. package/dist/app/value-guards.d.ts +15 -0
  6. package/dist/app/value-guards.js +29 -0
  7. package/dist/ci/toolchain-identity.js +1 -1
  8. package/dist/desktop/channel-proof.js +2 -1
  9. package/dist/desktop/client-asset-stream.js +6 -12
  10. package/dist/desktop/desktop-host.d.ts +25 -5
  11. package/dist/desktop/desktop-host.js +75 -20
  12. package/dist/framework-source.json +1 -1
  13. package/dist/installer/command-artifact.js +4 -3
  14. package/dist/installer/command-qualification-command.js +6 -5
  15. package/dist/installer/hosted-runner.d.ts +9 -2
  16. package/dist/installer/hosted-runner.js +18 -5
  17. package/dist/installer/installed-payload.js +20 -46
  18. package/dist/installer/installer-archive.d.ts +33 -0
  19. package/dist/installer/installer-archive.js +116 -0
  20. package/dist/installer/installer-ci-bootstrap.js +10 -6
  21. package/dist/installer/installer-extraction.js +54 -120
  22. package/dist/installer/installer-identity.js +33 -111
  23. package/dist/installer/installer-observation.js +3 -2
  24. package/dist/installer/installer-process-cleanup.js +7 -46
  25. package/dist/installer/installer-qualification-command.js +6 -5
  26. package/dist/installer/installer-upgrade-command.js +5 -5
  27. package/dist/installer/installer-worker-guard.js +2 -1
  28. package/dist/native/canonical-path.d.ts +5 -0
  29. package/dist/native/canonical-path.js +10 -0
  30. package/dist/native/cef-helper.js +5 -4
  31. package/dist/native/electrobun-source-patch.js +3 -2
  32. package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
  33. package/dist/native/native-rename.js +126 -0
  34. package/dist/native/native-secret-store.js +2 -6
  35. package/dist/native/native-utilities.js +4 -4
  36. package/dist/native/posix-launcher-build.js +1 -1
  37. package/dist/native/posix-tree-removal.js +2 -2
  38. package/dist/native/windows-process.d.ts +9 -0
  39. package/dist/native/windows-process.js +60 -0
  40. package/dist/release/feed-release-cut.js +2 -1
  41. package/dist/release/framework-package-publish.js +1 -1
  42. package/dist/release/framework-update-lock.js +2 -1
  43. package/dist/release/github-cli.d.ts +18 -0
  44. package/dist/release/github-cli.js +13 -1
  45. package/dist/release/github-release-cut.js +3 -2
  46. package/dist/release/github-release-provenance.js +2 -1
  47. package/dist/release/github-release-publisher.js +2 -1
  48. package/dist/release/local-provenance.js +3 -2
  49. package/dist/release/local-release.js +6 -6
  50. package/dist/release/qualification-run.d.ts +25 -0
  51. package/dist/release/qualification-run.js +43 -0
  52. package/dist/release/release-artifact.js +3 -11
  53. package/dist/release/release-assets-plan.js +16 -6
  54. package/dist/release/release-config.js +14 -14
  55. package/dist/release/release-cut-command.js +14 -4
  56. package/dist/release/release-cut.js +3 -2
  57. package/dist/release/release-descriptor-staging.js +13 -27
  58. package/dist/release/release-finalize.js +2 -1
  59. package/dist/release/release-publication.js +3 -11
  60. package/dist/release/release-publish-command.js +15 -6
  61. package/dist/release/release-qualification.js +3 -2
  62. package/dist/release/retained-release-build.js +12 -12
  63. package/dist/update-helper.bundle.js +250 -178
  64. package/dist/updates/desktop-updater.js +53 -58
  65. package/dist/updates/packaged-launch-admission.js +3 -2
  66. package/dist/updates/packaged-release-config.js +6 -5
  67. package/dist/updates/packaged-update-startup.d.ts +25 -5
  68. package/dist/updates/packaged-update-startup.js +30 -5
  69. package/dist/updates/release-feed.js +9 -9
  70. package/dist/updates/signed-release.js +5 -5
  71. package/dist/updates/stable-file.d.ts +18 -0
  72. package/dist/updates/stable-file.js +65 -2
  73. package/dist/updates/update-adapter.d.ts +2 -13
  74. package/dist/updates/update-arm.js +13 -13
  75. package/dist/updates/update-channel-store.js +7 -9
  76. package/dist/updates/update-discovery.js +30 -34
  77. package/dist/updates/update-download-cleanup.js +2 -1
  78. package/dist/updates/update-download.js +2 -4
  79. package/dist/updates/update-extraction.js +1 -1
  80. package/dist/updates/update-generation-lease.js +4 -3
  81. package/dist/updates/update-handoff-plan.js +3 -2
  82. package/dist/updates/update-helper.js +8 -6
  83. package/dist/updates/update-instance-lease.js +3 -2
  84. package/dist/updates/update-launch-gate.js +12 -25
  85. package/dist/updates/update-launch.js +3 -2
  86. package/dist/updates/update-lock.js +3 -2
  87. package/dist/updates/update-marker.js +3 -2
  88. package/dist/updates/update-process-fence.js +10 -39
  89. package/dist/updates/update-process-liveness.js +2 -1
  90. package/dist/updates/update-resume.js +30 -27
  91. package/dist/updates/update-retention-marker.js +7 -5
  92. package/dist/updates/update-retention-plan.js +2 -2
  93. package/dist/updates/update-retirement.js +52 -52
  94. package/dist/updates/update-state-store.d.ts +2 -0
  95. package/dist/updates/update-state-store.js +34 -38
  96. package/dist/updates/update-state.d.ts +8 -3
  97. package/dist/updates/update-swap-stage.js +6 -5
  98. package/dist/updates/update-swap.d.ts +1 -1
  99. package/dist/updates/update-swap.js +8 -6
  100. package/package.json +4 -12
  101. package/src/desktop/client-asset-stream.ts +6 -12
  102. package/src/updates/update-adapter.ts +2 -14
  103. package/src/updates/update-state.ts +11 -2
  104. package/templates/application/src/bun/index.ts +13 -9
  105. package/dist/native/directory-exchange.js +0 -90
  106. package/dist/native/exclusive-rename.d.ts +0 -2
  107. package/dist/native/exclusive-rename.js +0 -52
  108. package/dist/release/retention-dry-run.d.ts +0 -46
  109. package/dist/release/retention-dry-run.js +0 -94
  110. package/dist/updates/update-exclusive-rename.d.ts +0 -3
  111. package/dist/updates/update-exclusive-rename.js +0 -5
@@ -1,5 +1,5 @@
1
+ import { isCanonicalPath } from "./canonical-path.js";
1
2
  import { lstat, open } from "node:fs/promises";
2
- import { isAbsolute, resolve } from "node:path";
3
3
  import { FFIType, dlopen, ptr, read } from "bun:ffi";
4
4
  import { constants as constants$1 } from "node:fs";
5
5
  // src/native/posix-tree-removal.ts
@@ -371,7 +371,7 @@ async function removeDirectoryContentsChunk(options) {
371
371
  const { root, expectedRootIdentity, maxOperations, prioritizeVersionMarker, testOnlyFailBarrierAtCall } = options;
372
372
  const darwin = process.platform === "darwin";
373
373
  if (!darwin || process.arch !== "arm64") throw new Error("Safe directory-relative removal is unsupported on this platform");
374
- if (typeof root !== "string" || !isAbsolute(root) || resolve(root) !== root || root.includes("\0") || !expectedRootIdentity || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.device) || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.inode) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096 || testOnlyFailBarrierAtCall !== void 0 && (!Number.isSafeInteger(testOnlyFailBarrierAtCall) || testOnlyFailBarrierAtCall < 1)) throw new Error("Invalid bounded tree removal request");
374
+ if (!isCanonicalPath(root) || !expectedRootIdentity || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.device) || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.inode) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096 || testOnlyFailBarrierAtCall !== void 0 && (!Number.isSafeInteger(testOnlyFailBarrierAtCall) || testOnlyFailBarrierAtCall < 1)) throw new Error("Invalid bounded tree removal request");
375
375
  const rootInfo = await lstat(root, { bigint: true });
376
376
  if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new Error("Tree removal root is not a directory");
377
377
  if (rootInfo.dev.toString() !== expectedRootIdentity.device || rootInfo.ino.toString() !== expectedRootIdentity.inode) throw new Error("Tree removal root identity changed");
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ask the Windows kernel for a process's executable image path. `missing` means
3
+ * the process id could not be opened. With `requireRunning`, a process that has
4
+ * already exited reports `missing` too: an exited process keeps no STILL_ACTIVE
5
+ * exit code even while another process holds a handle to it.
6
+ */
7
+ export declare function windowsProcessImage(pid: number, options: {
8
+ requireRunning: boolean;
9
+ }): string | 'missing';
@@ -0,0 +1,60 @@
1
+ import { FFIType, dlopen, ptr } from "bun:ffi";
2
+ // src/native/windows-process.ts
3
+ var PROCESS_QUERY_LIMITED_INFORMATION = 4096;
4
+ var STILL_ACTIVE = 259;
5
+ var MAX_PATH_CHARS = 32768;
6
+ function kernel32() {
7
+ return dlopen("kernel32.dll", {
8
+ OpenProcess: {
9
+ args: [
10
+ FFIType.u32,
11
+ FFIType.i32,
12
+ FFIType.u32
13
+ ],
14
+ returns: FFIType.ptr
15
+ },
16
+ GetExitCodeProcess: {
17
+ args: [FFIType.ptr, FFIType.ptr],
18
+ returns: FFIType.i32
19
+ },
20
+ QueryFullProcessImageNameW: {
21
+ args: [
22
+ FFIType.ptr,
23
+ FFIType.u32,
24
+ FFIType.ptr,
25
+ FFIType.ptr
26
+ ],
27
+ returns: FFIType.i32
28
+ },
29
+ CloseHandle: {
30
+ args: [FFIType.ptr],
31
+ returns: FFIType.i32
32
+ }
33
+ }).symbols;
34
+ }
35
+ var symbols;
36
+ /**
37
+ * Ask the Windows kernel for a process's executable image path. `missing` means
38
+ * the process id could not be opened. With `requireRunning`, a process that has
39
+ * already exited reports `missing` too: an exited process keeps no STILL_ACTIVE
40
+ * exit code even while another process holds a handle to it.
41
+ */
42
+ function windowsProcessImage(pid, options) {
43
+ symbols ??= kernel32();
44
+ const handle = symbols.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);
45
+ if (!handle) return "missing";
46
+ try {
47
+ if (options.requireRunning) {
48
+ const code = /* @__PURE__ */ new Uint32Array(1);
49
+ if (!symbols.GetExitCodeProcess(handle, ptr(code))) throw new Error("Unable to query process state");
50
+ if (code[0] !== STILL_ACTIVE) return "missing";
51
+ }
52
+ const name = new Uint16Array(MAX_PATH_CHARS), length = new Uint32Array([MAX_PATH_CHARS]);
53
+ if (!symbols.QueryFullProcessImageNameW(handle, 0, ptr(name), ptr(length))) throw new Error("Unable to query process executable");
54
+ if (!length[0] || length[0] >= MAX_PATH_CHARS) throw new Error("Invalid process executable path");
55
+ return Buffer.from(name.buffer, 0, length[0] * 2).toString("utf16le");
56
+ } finally {
57
+ symbols.CloseHandle(handle);
58
+ }
59
+ }
60
+ export { windowsProcessImage };
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { gitIsAncestor } from "./local-provenance.js";
2
3
  // src/release/feed-release-cut.ts
3
4
  function checkVersion(version) {
@@ -26,7 +27,7 @@ async function commitTree(git, sha) {
26
27
  "--verify",
27
28
  `${sha}^{tree}`
28
29
  ]);
29
- if (!/^[a-f0-9]{40}$/.test(tree)) throw new Error("Invalid commit tree");
30
+ if (!isGitSha(tree)) throw new Error("Invalid commit tree");
30
31
  return tree;
31
32
  }
32
33
  async function hasCommit(git, sha) {
@@ -2,8 +2,8 @@ import { readPackageFile } from "./framework-update.js";
2
2
  import { gitCli, resolveLocalProvenance } from "./local-provenance.js";
3
3
  import { lstat, mkdtemp, open, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { basename, join, resolve } from "node:path";
5
- import { execFile } from "node:child_process";
6
5
  import { createHash } from "node:crypto";
6
+ import { execFile } from "node:child_process";
7
7
  import { tmpdir } from "node:os";
8
8
  // src/release/framework-package-publish.ts
9
9
  var packageName = "@adea-ai/app-framework";
@@ -1,3 +1,4 @@
1
+ import { errorCode } from "../app/value-guards.js";
1
2
  import { lstat, mkdir, rmdir } from "node:fs/promises";
2
3
  // src/release/framework-update-lock.ts
3
4
  /** Serialize cooperating framework updates in one Git worktree. */
@@ -5,7 +6,7 @@ async function withFrameworkUpdateLock(path, run) {
5
6
  try {
6
7
  await mkdir(path);
7
8
  } catch (error) {
8
- if (error.code === "EEXIST") throw new Error("A framework update is running or its lock remains; inspect the worktree lock", { cause: error });
9
+ if (errorCode(error) === "EEXIST") throw new Error("A framework update is running or its lock remains; inspect the worktree lock", { cause: error });
9
10
  throw error;
10
11
  }
11
12
  let owner;
@@ -3,4 +3,22 @@ type GitHubRun = (args: string[], input?: string) => Promise<string>;
3
3
  /** The `gh` CLI runner every release command shares. A failure rejects with
4
4
  * 'GitHub request failed', carrying stderr and whether GitHub answered 404. */
5
5
  export declare function githubCli(env?: NodeJS.ProcessEnv): GitHubRun;
6
+ /**
7
+ * Fetch this exact workflow attempt from GitHub and require it to match the
8
+ * runner's environment and the expected workflow identity. Release commands use
9
+ * it so a forged or re-pointed environment cannot borrow another run's rights.
10
+ */
11
+ export declare function verifyWorkflowAttempt(options: {
12
+ run: GitHubRun;
13
+ repository: string;
14
+ env: Record<string, string | undefined>;
15
+ expected: {
16
+ headSha: string;
17
+ event: string;
18
+ path: string;
19
+ headBranch?: string;
20
+ displayTitle?: string;
21
+ };
22
+ mismatch: string;
23
+ }): Promise<void>;
6
24
  export {};
@@ -13,4 +13,16 @@ function githubCli(env) {
13
13
  })) : resolve(stdout)).stdin?.end(input);
14
14
  });
15
15
  }
16
- export { githubCli };
16
+ /**
17
+ * Fetch this exact workflow attempt from GitHub and require it to match the
18
+ * runner's environment and the expected workflow identity. Release commands use
19
+ * it so a forged or re-pointed environment cannot borrow another run's rights.
20
+ */
21
+ async function verifyWorkflowAttempt(options) {
22
+ const { run, repository, env, expected } = options;
23
+ const response = JSON.parse(await run(["api", `repos/${repository}/actions/runs/${env.GITHUB_RUN_ID}/attempts/${env.GITHUB_RUN_ATTEMPT}`]));
24
+ if (typeof response !== "object" || response === null || Array.isArray(response)) throw new Error(options.mismatch);
25
+ const workflow = response;
26
+ if (String(workflow.id) !== env.GITHUB_RUN_ID || String(workflow.run_attempt) !== env.GITHUB_RUN_ATTEMPT || workflow.head_sha !== expected.headSha || workflow.event !== expected.event || workflow.path !== expected.path || expected.headBranch !== void 0 && workflow.head_branch !== expected.headBranch || expected.displayTitle !== void 0 && workflow.display_title !== expected.displayTitle || workflow.repository?.full_name !== repository) throw new Error(options.mismatch);
27
+ }
28
+ export { githubCli, verifyWorkflowAttempt };
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { containsAsciiControl } from "../desktop/string-policy.js";
2
3
  import { githubCli } from "./github-cli.js";
3
4
  import { verifyReleaseProvenance } from "./github-release-provenance.js";
@@ -20,12 +21,12 @@ function createGitHubReleaseCutProvider(options) {
20
21
  includeDraft: true
21
22
  });
22
23
  const isMainAncestor = async (sha) => {
23
- if (!/^[a-f0-9]{40}$/.test(sha)) return false;
24
+ if (!isGitSha(sha)) return false;
24
25
  const result = await read(`${base}/compare/${sha}...main`);
25
26
  return ["ahead", "identical"].includes(String(result?.status));
26
27
  };
27
28
  const isAncestor = async (older, newer) => {
28
- if (!/^[a-f0-9]{40}$/.test(older) || !/^[a-f0-9]{40}$/.test(newer)) return false;
29
+ if (!isGitSha(older) || !isGitSha(newer)) return false;
29
30
  return (await read(`${base}/compare/${older}...${newer}`))?.status === "ahead";
30
31
  };
31
32
  async function tagExists(tag) {
@@ -1,8 +1,9 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  // src/release/github-release-provenance.ts
2
3
  /** Check the tag and source independently; legacy release notes are never rewritten. */
3
4
  async function verifyReleaseProvenance(options) {
4
5
  const { tag, sourceSha, body, releasePleaseManifestPath, read, base } = options;
5
- if (!/^[a-f0-9]{40}$/.test(sourceSha)) return false;
6
+ if (!isGitSha(sourceSha)) return false;
6
7
  const lines = body.split(/\r?\n/);
7
8
  const markers = lines.filter((line) => line.startsWith("adea-channel:"));
8
9
  const sources = lines.filter((line) => line.startsWith("Source: "));
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { githubCli } from "./github-cli.js";
2
3
  import { listGitHubReleaseAssets } from "./github-release-assets.js";
3
4
  import { verifyReleaseProvenance } from "./github-release-provenance.js";
@@ -7,7 +8,7 @@ import { isRepositorySlug } from "../updates/signed-release.js";
7
8
  /** GitHub adapter; callers must run it in a trusted release job with GH_TOKEN. */
8
9
  function createGitHubReleasePublisher(options) {
9
10
  const { repository, identity } = options;
10
- if (!isRepositorySlug(repository) || identity.tag.length > 65 || !/^v[0-9]+\.[0-9]+\.[0-9]+(?:-dev\.[0-9]+)?$/.test(identity.tag) || !/^[a-f0-9]{40}$/.test(identity.sourceSha) || !/^[a-f0-9]{40}$/.test(identity.workflowSha)) throw new Error("Invalid GitHub release identity");
11
+ if (!isRepositorySlug(repository) || identity.tag.length > 65 || !/^v[0-9]+\.[0-9]+\.[0-9]+(?:-dev\.[0-9]+)?$/.test(identity.tag) || !isGitSha(identity.sourceSha) || !isGitSha(identity.workflowSha)) throw new Error("Invalid GitHub release identity");
11
12
  const run = options.run ?? githubCli();
12
13
  const base = `repos/${repository}`;
13
14
  const read = async (path) => JSON.parse(await run(["api", path]));
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { execFile } from "node:child_process";
2
3
  // src/release/local-provenance.ts
3
4
  function gitCli() {
@@ -5,7 +6,7 @@ function gitCli() {
5
6
  }
6
7
  /** Whether `older` is `newer` or one of its ancestors; any other failure propagates. */
7
8
  async function gitIsAncestor(git, older, newer) {
8
- if (!/^[a-f0-9]{40}$/.test(older) || !/^(?:[a-f0-9]{40}|refs\/remotes\/origin\/main)$/.test(newer)) return false;
9
+ if (!isGitSha(older) || !/^(?:[a-f0-9]{40}|refs\/remotes\/origin\/main)$/.test(newer)) return false;
9
10
  try {
10
11
  await git([
11
12
  "merge-base",
@@ -57,7 +58,7 @@ async function originRepository(git) {
57
58
  */
58
59
  async function resolveLocalProvenance(options) {
59
60
  const { git, sourceSha } = options;
60
- if (!/^[a-f0-9]{40}$/.test(sourceSha)) throw new Error("Invalid source commit");
61
+ if (!isGitSha(sourceSha)) throw new Error("Invalid source commit");
61
62
  if (await git([
62
63
  "rev-parse",
63
64
  "--verify",
@@ -1,4 +1,5 @@
1
- import { renameExclusive } from "../native/exclusive-rename.js";
1
+ import { errorCode, isGitSha, isRecord } from "../app/value-guards.js";
2
+ import { renameExclusive } from "../native/native-rename.js";
2
3
  import { verifyReleaseDescriptor } from "../updates/signed-release.js";
3
4
  import { feedAssetKey, feedChannelKey, feedIndexKey, feedReleaseKey, feedUrl, parseReleaseLedger } from "../updates/release-feed.js";
4
5
  import { discoveryPolicies, parseReleaseConfig, platformPayloads, platformTargets } from "./release-config.js";
@@ -21,7 +22,6 @@ import { createHash } from "node:crypto";
21
22
  * object keys and an ordered upload plan; the caller uploads it with its own credentials.
22
23
  */
23
24
  var UPLOAD_PLAN = "upload-plan.json";
24
- var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
25
25
  var channelOf = (tag) => tag.includes("-dev.") ? "dev" : "daily";
26
26
  var IMMUTABLE = "public, max-age=31536000, immutable";
27
27
  var MUTABLE = "no-cache";
@@ -33,7 +33,7 @@ function hostReleasePlatform(platform = process.platform, arch = process.arch) {
33
33
  }
34
34
  function localConfig(config) {
35
35
  const parsed = parseReleaseConfig(config);
36
- if (!object(config) || typeof config.appId !== "string" || !object(config.releaseSigningKeys) || !object(config.descriptors)) throw new Error("Invalid release signing configuration");
36
+ if (!isRecord(config) || typeof config.appId !== "string" || !isRecord(config.releaseSigningKeys) || !isRecord(config.descriptors)) throw new Error("Invalid release signing configuration");
37
37
  const entries = Object.entries(config.releaseSigningKeys);
38
38
  if (!entries.length || entries.length > 16) throw new Error("Missing release verification keys");
39
39
  const keys = /* @__PURE__ */ new Map();
@@ -111,7 +111,7 @@ async function localTagProvenance(options) {
111
111
  async function stageLocalDescriptors(options) {
112
112
  const { tag, platform } = options;
113
113
  const local = localConfig(options.config);
114
- if (!/^[1-9]\d{0,19}$/.test(options.runId) || !/^[a-f0-9]{40}$/.test(options.sourceSha)) throw new Error("Invalid local release identity");
114
+ if (!/^[1-9]\d{0,19}$/.test(options.runId) || !isGitSha(options.sourceSha)) throw new Error("Invalid local release identity");
115
115
  const publicKey = configuredSigningKey(local.config, options.keyId, options.privateKey);
116
116
  const payloads = platformPayloads(local.requirements(tag), platform);
117
117
  const directory = resolve(options.directory);
@@ -160,7 +160,7 @@ async function writeStagedTree(out, feed, assets, documents) {
160
160
  await lstat(root);
161
161
  throw new Error("Release output directory already exists");
162
162
  } catch (error) {
163
- if (error.code !== "ENOENT") throw error;
163
+ if (errorCode(error) !== "ENOENT") throw error;
164
164
  }
165
165
  await mkdir(dirname(root), {
166
166
  recursive: true,
@@ -337,7 +337,7 @@ async function stageLocalRelease(options) {
337
337
  * require them; a stable promoted without a supported platform records it as `missingPlatforms`.
338
338
  */
339
339
  function stablePlatforms(config) {
340
- const value = object(config) ? config.stablePlatforms : void 0;
340
+ const value = isRecord(config) ? config.stablePlatforms : void 0;
341
341
  if (value === void 0) return ["macos-arm64"];
342
342
  if (!Array.isArray(value) || !value.length || new Set(value).size !== value.length || !value.every((name) => typeof name === "string" && Object.hasOwn(platformTargets, name))) throw new Error("Invalid stablePlatforms in the release configuration");
343
343
  return value;
@@ -0,0 +1,25 @@
1
+ import { type GitRun } from './local-provenance';
2
+ /** The release and CI run a qualification receipt is bound to. */
3
+ export type QualificationRun = {
4
+ tag: string;
5
+ sourceSha: string;
6
+ workflowSha: string;
7
+ version: string;
8
+ runId: string;
9
+ runAttempt: number;
10
+ };
11
+ /**
12
+ * Resolve the run a platform qualification job belongs to.
13
+ *
14
+ * On GitHub Actions this is the trusted release-assets workflow ({@link planReleaseAssets}).
15
+ * On GitLab CI it is a tag pipeline for `tag`: the tagged commit is both the source and the
16
+ * commit whose pipeline definition ran, as in a local release, and its provenance is checked
17
+ * from the job's checkout (a clean, full-history checkout with `origin/main` fetched). The
18
+ * pipeline id names the run; GitLab retries a job, not a pipeline, so the attempt is 1.
19
+ */
20
+ export declare function planQualificationRun(options: {
21
+ env: Record<string, string | undefined>;
22
+ config: unknown;
23
+ tag: string;
24
+ git?: GitRun;
25
+ }): Promise<QualificationRun>;
@@ -0,0 +1,43 @@
1
+ import { isGitSha } from "../app/value-guards.js";
2
+ import { planReleaseAssets } from "./release-assets-plan.js";
3
+ import { gitCli } from "./local-provenance.js";
4
+ import { localTagProvenance } from "./local-release.js";
5
+ // src/release/qualification-run.ts
6
+ /**
7
+ * Resolve the run a platform qualification job belongs to.
8
+ *
9
+ * On GitHub Actions this is the trusted release-assets workflow ({@link planReleaseAssets}).
10
+ * On GitLab CI it is a tag pipeline for `tag`: the tagged commit is both the source and the
11
+ * commit whose pipeline definition ran, as in a local release, and its provenance is checked
12
+ * from the job's checkout (a clean, full-history checkout with `origin/main` fetched). The
13
+ * pipeline id names the run; GitLab retries a job, not a pipeline, so the attempt is 1.
14
+ */
15
+ async function planQualificationRun(options) {
16
+ const { env, config, tag } = options;
17
+ if (env.GITHUB_ACTIONS === "true") return {
18
+ ...await planReleaseAssets({
19
+ env,
20
+ config,
21
+ tag
22
+ }),
23
+ runId: env.GITHUB_RUN_ID,
24
+ runAttempt: Number(env.GITHUB_RUN_ATTEMPT)
25
+ };
26
+ if (env.GITLAB_CI !== "true" || env.CI_COMMIT_TAG !== tag || !isGitSha(env.CI_COMMIT_SHA) || !/^[1-9]\d{0,19}$/.test(env.CI_PIPELINE_ID ?? "") || !/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Qualification requires a GitHub release-assets run or a GitLab tag pipeline");
27
+ const sourceSha = env.CI_COMMIT_SHA;
28
+ await localTagProvenance({
29
+ config,
30
+ tag,
31
+ sourceSha,
32
+ git: options.git ?? gitCli()
33
+ });
34
+ return {
35
+ tag,
36
+ sourceSha,
37
+ workflowSha: sourceSha,
38
+ version: tag.slice(1),
39
+ runId: env.CI_PIPELINE_ID,
40
+ runAttempt: 1
41
+ };
42
+ }
43
+ export { planQualificationRun };
@@ -1,7 +1,7 @@
1
1
  import { signReleaseDescriptor } from "../updates/signed-release.js";
2
+ import { hashUnchangedFile } from "../updates/stable-file.js";
2
3
  import { open } from "node:fs/promises";
3
4
  import { basename } from "node:path";
4
- import { createHash } from "node:crypto";
5
5
  // src/release/release-artifact.ts
6
6
  /** Hash the actual staged archive without buffering it, then sign its provenance and its
7
7
  * URL in the app's release feed (`feed` ends in `/`). */
@@ -10,21 +10,13 @@ async function signReleaseArtifact(path, identity, key, feed) {
10
10
  try {
11
11
  const before = await file.stat();
12
12
  if (!before.isFile() || !Number.isSafeInteger(before.size) || before.size < 1) throw new Error("Invalid release artifact");
13
- const hash = createHash("sha256");
14
- let size = 0;
15
- for await (const chunk of file.createReadStream({ autoClose: false })) {
16
- size += chunk.length;
17
- if (!Number.isSafeInteger(size) || size > before.size) throw new Error("Release artifact changed during hashing");
18
- hash.update(chunk);
19
- }
20
- const after = await file.stat();
21
- if (size !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.ino !== before.ino || after.dev !== before.dev) throw new Error("Release artifact changed during hashing");
13
+ const { size, sha256 } = await hashUnchangedFile(file, before, "Release artifact changed during hashing");
22
14
  const name = basename(path);
23
15
  const asset = {
24
16
  name,
25
17
  url: `${feed}${identity.tag}/${name}`,
26
18
  size,
27
- sha256: hash.digest("hex")
19
+ sha256
28
20
  };
29
21
  return signReleaseDescriptor({
30
22
  ...identity,
@@ -1,4 +1,5 @@
1
- import { githubCli } from "./github-cli.js";
1
+ import { isGitSha } from "../app/value-guards.js";
2
+ import { githubCli, verifyWorkflowAttempt } from "./github-cli.js";
2
3
  import { isRepositorySlug } from "../updates/signed-release.js";
3
4
  import { parseReleaseConfig } from "./release-config.js";
4
5
  import { createGitHubReleaseCutProvider } from "./github-release-cut.js";
@@ -34,7 +35,7 @@ function releasePlanGitHubEnvironment(env) {
34
35
  /** Resolve the immutable release source before building anything in a trusted assets workflow. */
35
36
  async function planReleaseAssets(options) {
36
37
  const { env, config, tag } = options;
37
- if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !isRepositorySlug(env.GITHUB_REPOSITORY ?? "") || !/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? "") || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || !/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Asset planning requires a trusted main workflow and valid tag");
38
+ if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !isRepositorySlug(env.GITHUB_REPOSITORY ?? "") || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || !/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Asset planning requires a trusted main workflow and valid tag");
38
39
  if (typeof config !== "object" || config === null || Array.isArray(config) || typeof config.appName !== "string") throw new Error("Invalid release configuration");
39
40
  const { requirements, releasePleaseManifestPath, releaseWorkflows } = parseReleaseConfig(config);
40
41
  requirements(tag);
@@ -49,10 +50,19 @@ async function planReleaseAssets(options) {
49
50
  hiddenDrafts: true,
50
51
  run
51
52
  });
52
- const response = JSON.parse(await run(["api", `repos/${repository}/actions/runs/${env.GITHUB_RUN_ID}/attempts/${env.GITHUB_RUN_ATTEMPT}`]));
53
- if (typeof response !== "object" || response === null || Array.isArray(response)) throw new Error("Invalid asset workflow response");
54
- const workflow = response;
55
- if (String(workflow.id) !== env.GITHUB_RUN_ID || String(workflow.run_attempt) !== env.GITHUB_RUN_ATTEMPT || workflow.head_sha !== workflowSha || workflow.head_branch !== "main" || workflow.event !== "workflow_dispatch" || workflow.path !== releaseWorkflows.assets || workflow.display_title !== `framework-release-assets:${tag}` || workflow.repository?.full_name !== repository) throw new Error("Release-assets workflow provenance mismatch");
53
+ await verifyWorkflowAttempt({
54
+ run,
55
+ repository,
56
+ env,
57
+ expected: {
58
+ headSha: workflowSha,
59
+ headBranch: "main",
60
+ event: "workflow_dispatch",
61
+ path: releaseWorkflows.assets,
62
+ displayTitle: `framework-release-assets:${tag}`
63
+ },
64
+ mismatch: "Release-assets workflow provenance mismatch"
65
+ });
56
66
  const release = await provider.find(tag);
57
67
  if (!release || (release.draft ? release.stageableDraft !== true : !release.prerelease) || !await provider.isMainAncestor(release.sourceSha) || !await provider.isMainAncestor(workflowSha)) throw new Error("Release source or workflow is not an eligible main ancestor");
58
68
  return {
@@ -1,9 +1,9 @@
1
+ import { isGitSha, isRecord } from "../app/value-guards.js";
1
2
  import { containsAsciiControl } from "../desktop/string-policy.js";
2
3
  import { assertSidecarNames } from "../native/app-bundle.js";
3
4
  import { parseOfflinePolicy } from "./release-qualification.js";
4
5
  import { parseReleaseFeed } from "../updates/release-feed.js";
5
6
  // src/release/release-config.ts
6
- var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
7
7
  var strings = (value) => Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string" && item.length <= 200 && /^[A-Za-z0-9][A-Za-z0-9._{}-]*$/.test(item) && !item.replaceAll("{tag}", "").includes("{") && !item.replaceAll("{tag}", "").includes("}")) && new Set(value).size === value.length;
8
8
  var appIdPattern = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/;
9
9
  var token = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._=-]{0,63}$/.test(value);
@@ -18,11 +18,11 @@ var platformTargets = {
18
18
  var releasePlatforms = Object.keys(platformTargets);
19
19
  function parseCommandArtifacts(value, platforms) {
20
20
  if (value === void 0) return [];
21
- if (!object(value) || Object.keys(value).length > 4) throw new Error("Invalid command artifacts");
21
+ if (!isRecord(value) || Object.keys(value).length > 4) throw new Error("Invalid command artifacts");
22
22
  return Object.entries(value).map(([kind, policy]) => {
23
- const qualification = object(policy) ? policy.qualification : void 0;
24
- const env = object(qualification) ? qualification.env : void 0;
25
- if (!/^[a-z][a-z0-9-]{0,31}$/.test(kind) || !object(policy) || Object.keys(policy).length !== 5 || typeof policy.appId !== "string" || policy.appId.length > 255 || !appIdPattern.test(policy.appId) || typeof policy.executable !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(policy.executable) || !relativePath(policy.build) || !object(policy.platforms) || Object.keys(policy.platforms).length !== platforms.length || platforms.some((platform) => typeof policy.platforms[platform] !== "string" || !strings([policy.platforms[platform]]) || !policy.platforms[platform].endsWith(".tar.gz")) || !object(qualification) || Object.keys(qualification).length !== 3 || !object(env) || Object.keys(env).length > 16 || Object.entries(env).some(([name, item]) => !/^[A-Z][A-Z0-9_]{0,63}$/.test(name) || /^(?:PATH|HOME|USERPROFILE|TMP|TEMP|TMPDIR|SYSTEMROOT|WINDIR|COMSPEC|PATHEXT|LOCALAPPDATA|APPDATA|XDG_[A-Z_]+)$/.test(name) || typeof item !== "string" || item.length > 256 || containsAsciiControl(item)) || !Array.isArray(qualification.probes) || qualification.probes.length > 8 || !qualification.probes.every((probe) => tokens(probe, 1)) || !tokens(qualification.service, 1)) throw new Error("Invalid command artifact");
23
+ const qualification = isRecord(policy) ? policy.qualification : void 0;
24
+ const env = isRecord(qualification) ? qualification.env : void 0;
25
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(kind) || !isRecord(policy) || Object.keys(policy).length !== 5 || typeof policy.appId !== "string" || policy.appId.length > 255 || !appIdPattern.test(policy.appId) || typeof policy.executable !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(policy.executable) || !relativePath(policy.build) || !isRecord(policy.platforms) || Object.keys(policy.platforms).length !== platforms.length || platforms.some((platform) => typeof policy.platforms[platform] !== "string" || !strings([policy.platforms[platform]]) || !policy.platforms[platform].endsWith(".tar.gz")) || !isRecord(qualification) || Object.keys(qualification).length !== 3 || !isRecord(env) || Object.keys(env).length > 16 || Object.entries(env).some(([name, item]) => !/^[A-Z][A-Z0-9_]{0,63}$/.test(name) || /^(?:PATH|HOME|USERPROFILE|TMP|TEMP|TMPDIR|SYSTEMROOT|WINDIR|COMSPEC|PATHEXT|LOCALAPPDATA|APPDATA|XDG_[A-Z_]+)$/.test(name) || typeof item !== "string" || item.length > 256 || containsAsciiControl(item)) || !Array.isArray(qualification.probes) || qualification.probes.length > 8 || !qualification.probes.every((probe) => tokens(probe, 1)) || !tokens(qualification.service, 1)) throw new Error("Invalid command artifact");
26
26
  return {
27
27
  kind,
28
28
  appId: policy.appId,
@@ -43,9 +43,9 @@ var workflowFile = (path) => path.slice(18);
43
43
  var workflowPath = (value) => typeof value === "string" && value.length <= 200 && value.startsWith(workflowDirectory) && /^[A-Za-z0-9][A-Za-z0-9._-]*\.ya?ml$/.test(workflowFile(value));
44
44
  /** Validate shared daily, dev and stable asset requirements. */
45
45
  function parseReleaseConfig(config) {
46
- if (!object(config) || !object(config.platforms) || !strings(config.releaseAssets) || !strings(config.dailyDiscoveryAssets) || !strings(config.stableDiscoveryAssets) || !strings(config.devDiscoveryAssets) || !Number.isSafeInteger(config.soakHours) || Number(config.soakHours) < 0 || Number(config.soakHours) > 8760) throw new Error("Invalid release configuration");
46
+ if (!isRecord(config) || !isRecord(config.platforms) || !strings(config.releaseAssets) || !strings(config.dailyDiscoveryAssets) || !strings(config.stableDiscoveryAssets) || !strings(config.devDiscoveryAssets) || !Number.isSafeInteger(config.soakHours) || Number(config.soakHours) < 0 || Number(config.soakHours) > 8760) throw new Error("Invalid release configuration");
47
47
  const workflows = config.releaseWorkflows;
48
- if (!object(workflows) || Object.keys(workflows).length !== 2 || !workflowPath(workflows.control) || !workflowPath(workflows.assets) || workflows.control === workflows.assets) throw new Error("Invalid release workflows");
48
+ if (!isRecord(workflows) || Object.keys(workflows).length !== 2 || !workflowPath(workflows.control) || !workflowPath(workflows.assets) || workflows.control === workflows.assets) throw new Error("Invalid release workflows");
49
49
  const releaseWorkflows = {
50
50
  control: workflows.control,
51
51
  assets: workflows.assets
@@ -59,7 +59,7 @@ function parseReleaseConfig(config) {
59
59
  }
60
60
  const offlinePolicy = config.offlinePolicy === void 0 ? void 0 : parseOfflinePolicy(config.offlinePolicy);
61
61
  const source = config.versionSource;
62
- if (!object(source) || Object.keys(source).length !== 2 || source.kind !== "source-manifest" || typeof source.path !== "string" || source.path.length > 200 || !/^[A-Za-z0-9._/-]+\.json$/.test(source.path) || source.path.startsWith("/") || !source.path.split("/").every((part) => part !== "" && part !== "." && part !== "..")) throw new Error("Invalid release version source");
62
+ if (!isRecord(source) || Object.keys(source).length !== 2 || source.kind !== "source-manifest" || typeof source.path !== "string" || source.path.length > 200 || !/^[A-Za-z0-9._/-]+\.json$/.test(source.path) || source.path.startsWith("/") || !source.path.split("/").every((part) => part !== "" && part !== "." && part !== "..")) throw new Error("Invalid release version source");
63
63
  const versionSource = {
64
64
  kind: "source-manifest",
65
65
  path: source.path
@@ -118,14 +118,14 @@ function parseReleaseConfig(config) {
118
118
  requirements
119
119
  };
120
120
  }
121
- var sha = (value) => typeof value === "string" && /^[a-f0-9]{40}$/.test(value);
121
+ var sha = (value) => typeof value === "string" && isGitSha(value);
122
122
  /** Parse the optional `historyRewrite` list: at most 256 entries of exactly `from`, `to` and
123
123
  * `tree`, each a full lowercase SHA-1, with `from` distinct from `to` and never listed twice. */
124
124
  function parseHistoryRewrite(value) {
125
125
  if (value === void 0) return [];
126
126
  if (!Array.isArray(value) || value.length > 256) throw new Error("Invalid history rewrite");
127
127
  const entries = value.map((entry) => {
128
- if (!object(entry) || Object.keys(entry).length !== 3 || !sha(entry.from) || !sha(entry.to) || !sha(entry.tree) || entry.from === entry.to) throw new Error("Invalid history rewrite");
128
+ if (!isRecord(entry) || Object.keys(entry).length !== 3 || !sha(entry.from) || !sha(entry.to) || !sha(entry.tree) || entry.from === entry.to) throw new Error("Invalid history rewrite");
129
129
  return {
130
130
  from: entry.from,
131
131
  to: entry.to,
@@ -158,7 +158,7 @@ function platformPayloads(requirements, platform) {
158
158
  function discoveryPolicies(config, tag) {
159
159
  const parsed = parseReleaseConfig(config);
160
160
  const requirements = parsed.requirements(tag);
161
- if (!object(config) || typeof config.appId !== "string" || config.appId.length > 255 || !appIdPattern.test(config.appId) || !object(config.descriptors)) throw new Error("Invalid discovery policy");
161
+ if (!isRecord(config) || typeof config.appId !== "string" || config.appId.length > 255 || !appIdPattern.test(config.appId) || !isRecord(config.descriptors)) throw new Error("Invalid discovery policy");
162
162
  const descriptors = config.descriptors;
163
163
  const kinds = [{
164
164
  appId: config.appId,
@@ -174,11 +174,11 @@ function discoveryPolicies(config, tag) {
174
174
  if (!Array.isArray(configured)) throw new Error("Invalid discovery policy");
175
175
  for (const template of configured) {
176
176
  const policy = typeof template === "string" ? descriptors[template] : void 0;
177
- const platform = object(policy) ? releasePlatforms.find((value) => policy.platform === platformTargets[value][0] && policy.arch === platformTargets[value][1]) : void 0;
178
- const payload = object(policy) && Array.isArray(policy.allowedPayloads) && policy.allowedPayloads.length === 1 && typeof policy.allowedPayloads[0] === "string" ? policy.allowedPayloads[0].replaceAll("{tag}", tag) : void 0;
177
+ const platform = isRecord(policy) ? releasePlatforms.find((value) => policy.platform === platformTargets[value][0] && policy.arch === platformTargets[value][1]) : void 0;
178
+ const payload = isRecord(policy) && Array.isArray(policy.allowedPayloads) && policy.allowedPayloads.length === 1 && typeof policy.allowedPayloads[0] === "string" ? policy.allowedPayloads[0].replaceAll("{tag}", tag) : void 0;
179
179
  const kind = platform && kinds.find((value) => value.payloads(platform) === payload);
180
180
  const name = template.replaceAll("{tag}", tag);
181
- if (!object(policy) || policy.channel !== channel || !platform || !kind || !payload || !requirements.releaseAssets.includes(name)) throw new Error("Invalid discovery policy");
181
+ if (!isRecord(policy) || policy.channel !== channel || !platform || !kind || !payload || !requirements.releaseAssets.includes(name)) throw new Error("Invalid discovery policy");
182
182
  if (result.some((value) => value.name === name || value.channel === channel && value.appId === kind.appId && value.platform === platform)) throw new Error("Duplicate discovery policy");
183
183
  const [os, arch] = platformTargets[platform];
184
184
  result.push({
@@ -1,4 +1,5 @@
1
- import { githubCli } from "./github-cli.js";
1
+ import { isGitSha } from "../app/value-guards.js";
2
+ import { githubCli, verifyWorkflowAttempt } from "./github-cli.js";
2
3
  import { parseReleaseConfig, workflowFile } from "./release-config.js";
3
4
  import { createGitHubReleaseCutProvider } from "./github-release-cut.js";
4
5
  import { cutRelease } from "./release-cut.js";
@@ -10,7 +11,7 @@ var execute = promisify(execFile);
10
11
  /** Execute release cuts only from the recorded main-branch GitHub workflow. */
11
12
  async function runReleaseCutCommand(options) {
12
13
  const { env, kind } = options;
13
- if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || !env.GITHUB_REPOSITORY || !/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? "") || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || (kind === "daily" ? !["schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : kind === "dev" ? !["push", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : true)) throw new Error("Release cut requires a trusted main workflow");
14
+ if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || (kind === "daily" ? !["schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : kind === "dev" ? !["push", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : true)) throw new Error("Release cut requires a trusted main workflow");
14
15
  const { requirements, versionSource, releasePleaseManifestPath, releaseWorkflows } = parseReleaseConfig(options.config);
15
16
  const run = options.run ?? githubCli();
16
17
  const git = options.git ?? (async (args) => (await execute("git", args, { maxBuffer: 1048576 })).stdout.trim());
@@ -24,8 +25,17 @@ async function runReleaseCutCommand(options) {
24
25
  releasePleaseManifestPath,
25
26
  run
26
27
  });
27
- const workflow = JSON.parse(await run(["api", `repos/${repository}/actions/runs/${env.GITHUB_RUN_ID}`]));
28
- if (String(workflow?.id) !== env.GITHUB_RUN_ID || String(workflow?.run_attempt) !== env.GITHUB_RUN_ATTEMPT || workflow?.head_sha !== sourceSha || workflow?.event !== env.GITHUB_EVENT_NAME || workflow?.path !== releaseWorkflows.control || workflow?.repository?.full_name !== repository) throw new Error("Release workflow provenance mismatch");
28
+ await verifyWorkflowAttempt({
29
+ run,
30
+ repository,
31
+ env,
32
+ expected: {
33
+ headSha: sourceSha,
34
+ event: env.GITHUB_EVENT_NAME,
35
+ path: releaseWorkflows.control
36
+ },
37
+ mismatch: "Release workflow provenance mismatch"
38
+ });
29
39
  const assetsWorkflow = JSON.parse(await run(["api", `repos/${repository}/actions/workflows/${workflowFile(releaseWorkflows.assets)}`]));
30
40
  if (assetsWorkflow?.path !== releaseWorkflows.assets || assetsWorkflow?.state !== "active") throw new Error("Release-assets workflow is unavailable");
31
41
  const releasedVersion = await readSourceVersion(git, sourceSha, versionSource.path);
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  // src/release/release-cut.ts
2
3
  /**
3
4
  * The version dev builds after `released` are numbered for: the next minor version.
@@ -25,7 +26,7 @@ function nextDevVersion(released) {
25
26
  */
26
27
  async function cutRelease(options) {
27
28
  const { kind, sourceSha, releasedVersion, provider } = options;
28
- if (!["daily", "dev"].includes(kind) || !/^[a-f0-9]{40}$/.test(sourceSha) || typeof releasedVersion !== "string" || releasedVersion.length > 48 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(releasedVersion)) throw new Error("Invalid release identity");
29
+ if (!["daily", "dev"].includes(kind) || !isGitSha(sourceSha) || typeof releasedVersion !== "string" || releasedVersion.length > 48 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(releasedVersion)) throw new Error("Invalid release identity");
29
30
  const version = kind === "dev" ? nextDevVersion(releasedVersion) : releasedVersion;
30
31
  if (!await provider.isMainAncestor(sourceSha)) throw new Error("Requested source is not on main");
31
32
  let count = 0;
@@ -53,7 +54,7 @@ async function cutRelease(options) {
53
54
  });
54
55
  release = await provider.find(tag);
55
56
  }
56
- if (!release || release.tag !== tag || release.kind !== kind || release.draft && !(kind === "daily" && release.stageableDraft === true) || !/^[a-f0-9]{40}$/.test(release.sourceSha) || kind === "dev" && release.sourceSha !== sourceSha || !await provider.isMainAncestor(release.sourceSha)) throw new Error("Existing release identity mismatch");
57
+ if (!release || release.tag !== tag || release.kind !== kind || release.draft && !(kind === "daily" && release.stageableDraft === true) || !isGitSha(release.sourceSha) || kind === "dev" && release.sourceSha !== sourceSha || !await provider.isMainAncestor(release.sourceSha)) throw new Error("Existing release identity mismatch");
57
58
  const qualification = await provider.qualification(release);
58
59
  if (qualification === "qualified") return {
59
60
  tag,