@adea-ai/app-framework 0.30.0 → 0.32.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 (148) hide show
  1. package/README.md +26 -11
  2. package/dist/app/application.js +4 -2
  3. package/dist/app/create-application.js +4 -3
  4. package/dist/app/serial-queue.d.ts +5 -0
  5. package/dist/app/serial-queue.js +14 -0
  6. package/dist/app/value-guards.d.ts +15 -0
  7. package/dist/app/value-guards.js +29 -0
  8. package/dist/appearance/appearance-host.js +6 -0
  9. package/dist/appearance/appearance-preferences.js +6 -2
  10. package/dist/appearance/composition.d.ts +1 -1
  11. package/dist/appearance/custom-theme-import.js +12 -19
  12. package/dist/appearance/custom-theme-library.d.ts +5 -4
  13. package/dist/appearance/custom-theme-library.js +20 -2
  14. package/dist/appearance/editor.js +4 -1
  15. package/dist/appearance/legacy-imported-theme-token-projection.d.ts +84 -0
  16. package/dist/appearance/legacy-imported-theme-token-projection.js +142 -0
  17. package/dist/appearance/theme-record-adapter.js +37 -9
  18. package/dist/ci/toolchain-identity.js +1 -1
  19. package/dist/desktop/channel-proof.js +2 -1
  20. package/dist/desktop/client-asset-stream.js +6 -12
  21. package/dist/desktop/desktop-host.d.ts +25 -5
  22. package/dist/desktop/desktop-host.js +75 -20
  23. package/dist/framework-source.json +1 -1
  24. package/dist/installer/command-artifact.js +4 -3
  25. package/dist/installer/command-qualification-command.js +6 -5
  26. package/dist/installer/hosted-runner.d.ts +9 -2
  27. package/dist/installer/hosted-runner.js +18 -5
  28. package/dist/installer/installed-payload.js +20 -46
  29. package/dist/installer/installer-archive.d.ts +33 -0
  30. package/dist/installer/installer-archive.js +116 -0
  31. package/dist/installer/installer-ci-bootstrap.js +10 -6
  32. package/dist/installer/installer-extraction.js +54 -120
  33. package/dist/installer/installer-identity.js +33 -111
  34. package/dist/installer/installer-observation.js +3 -2
  35. package/dist/installer/installer-process-cleanup.js +7 -46
  36. package/dist/installer/installer-qualification-command.js +6 -5
  37. package/dist/installer/installer-upgrade-command.js +5 -5
  38. package/dist/installer/installer-worker-guard.js +2 -1
  39. package/dist/native/canonical-path.d.ts +5 -0
  40. package/dist/native/canonical-path.js +10 -0
  41. package/dist/native/cef-helper.js +5 -4
  42. package/dist/native/electrobun-source-patch.js +3 -2
  43. package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
  44. package/dist/native/native-rename.js +126 -0
  45. package/dist/native/native-secret-store.js +2 -6
  46. package/dist/native/native-utilities.js +4 -4
  47. package/dist/native/posix-launcher-build.js +1 -1
  48. package/dist/native/posix-tree-removal.js +2 -2
  49. package/dist/native/windows-process.d.ts +9 -0
  50. package/dist/native/windows-process.js +60 -0
  51. package/dist/release/feed-release-cut.js +2 -1
  52. package/dist/release/framework-package-publish.js +1 -1
  53. package/dist/release/framework-update-lock.js +2 -1
  54. package/dist/release/github-cli.d.ts +18 -0
  55. package/dist/release/github-cli.js +13 -1
  56. package/dist/release/github-release-cut.js +3 -2
  57. package/dist/release/github-release-provenance.js +2 -1
  58. package/dist/release/github-release-publisher.js +2 -1
  59. package/dist/release/local-provenance.js +3 -2
  60. package/dist/release/local-release.js +6 -6
  61. package/dist/release/qualification-run.d.ts +25 -0
  62. package/dist/release/qualification-run.js +43 -0
  63. package/dist/release/release-artifact.js +3 -11
  64. package/dist/release/release-assets-plan.js +16 -6
  65. package/dist/release/release-config.js +14 -14
  66. package/dist/release/release-cut-command.js +14 -4
  67. package/dist/release/release-cut.js +3 -2
  68. package/dist/release/release-descriptor-staging.js +13 -27
  69. package/dist/release/release-finalize.js +2 -1
  70. package/dist/release/release-publication.js +3 -11
  71. package/dist/release/release-publish-command.js +15 -6
  72. package/dist/release/release-qualification.js +3 -2
  73. package/dist/release/retained-release-build.js +12 -12
  74. package/dist/shell/app-shell.js +76 -48
  75. package/dist/shell/app-utilities.d.ts +5 -3
  76. package/dist/shell/app-utilities.js +15 -7
  77. package/dist/shell/help-shortcuts.d.ts +4 -0
  78. package/dist/shell/help-shortcuts.js +38 -7
  79. package/dist/shell/keyboard-target.d.ts +2 -0
  80. package/dist/shell/keyboard-target.js +54 -0
  81. package/dist/shell/settings-sections.d.ts +5 -0
  82. package/dist/shell/settings-shortcuts.d.ts +10 -0
  83. package/dist/shell/settings-shortcuts.js +67 -0
  84. package/dist/update-helper.bundle.js +250 -190
  85. package/dist/updates/desktop-updater.js +53 -58
  86. package/dist/updates/packaged-launch-admission.js +3 -2
  87. package/dist/updates/packaged-release-config.js +6 -5
  88. package/dist/updates/release-feed.js +9 -9
  89. package/dist/updates/signed-release.js +5 -5
  90. package/dist/updates/stable-file.d.ts +18 -0
  91. package/dist/updates/stable-file.js +54 -1
  92. package/dist/updates/update-adapter.d.ts +2 -13
  93. package/dist/updates/update-arm.js +7 -5
  94. package/dist/updates/update-channel-store.js +7 -9
  95. package/dist/updates/update-discovery.js +30 -34
  96. package/dist/updates/update-download-cleanup.js +2 -1
  97. package/dist/updates/update-download.js +2 -4
  98. package/dist/updates/update-extraction.js +1 -1
  99. package/dist/updates/update-generation-lease.js +4 -3
  100. package/dist/updates/update-handoff-plan.js +3 -2
  101. package/dist/updates/update-helper.js +8 -6
  102. package/dist/updates/update-instance-lease.js +3 -2
  103. package/dist/updates/update-launch-gate.js +12 -25
  104. package/dist/updates/update-launch.js +3 -2
  105. package/dist/updates/update-lock.js +3 -2
  106. package/dist/updates/update-marker.js +3 -2
  107. package/dist/updates/update-process-fence.js +10 -39
  108. package/dist/updates/update-process-liveness.js +2 -1
  109. package/dist/updates/update-resume.js +26 -22
  110. package/dist/updates/update-retention-marker.js +7 -5
  111. package/dist/updates/update-retention-plan.js +2 -2
  112. package/dist/updates/update-retirement.js +40 -39
  113. package/dist/updates/update-state-store.js +29 -37
  114. package/dist/updates/update-state.d.ts +8 -3
  115. package/dist/updates/update-swap-stage.js +6 -5
  116. package/dist/updates/update-swap.d.ts +1 -1
  117. package/dist/updates/update-swap.js +8 -6
  118. package/dist/views/app-help.js +2 -1
  119. package/dist/views/app-settings.js +5 -2
  120. package/dist/views/appearance-surface.js +33 -19
  121. package/package.json +7 -13
  122. package/src/app/application.tsx +3 -1
  123. package/src/appearance/appearance-host.tsx +6 -0
  124. package/src/appearance/appearance-preferences.ts +7 -1
  125. package/src/appearance/composition.ts +3 -1
  126. package/src/appearance/custom-theme-import.ts +21 -37
  127. package/src/appearance/custom-theme-library.ts +21 -5
  128. package/src/appearance/editor.ts +7 -6
  129. package/src/appearance/legacy-imported-theme-token-projection.ts +51 -0
  130. package/src/appearance/theme-record-adapter.ts +58 -11
  131. package/src/desktop/client-asset-stream.ts +6 -12
  132. package/src/shell/app-shell.tsx +88 -58
  133. package/src/shell/app-utilities.tsx +29 -17
  134. package/src/shell/help-shortcuts.ts +77 -6
  135. package/src/shell/keyboard-target.ts +74 -0
  136. package/src/shell/settings-sections.ts +5 -0
  137. package/src/shell/settings-shortcuts.ts +116 -0
  138. package/src/updates/update-adapter.ts +2 -14
  139. package/src/updates/update-state.ts +11 -2
  140. package/src/views/app-settings.tsx +5 -3
  141. package/src/views/appearance-surface.tsx +63 -27
  142. package/dist/native/directory-exchange.js +0 -90
  143. package/dist/native/exclusive-rename.d.ts +0 -2
  144. package/dist/native/exclusive-rename.js +0 -52
  145. package/dist/release/retention-dry-run.d.ts +0 -46
  146. package/dist/release/retention-dry-run.js +0 -94
  147. package/dist/updates/update-exclusive-rename.d.ts +0 -3
  148. package/dist/updates/update-exclusive-rename.js +0 -5
@@ -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,
@@ -1,38 +1,24 @@
1
+ import { errorCode, isRecord } from "../app/value-guards.js";
1
2
  import { validateCommandReceipts, validateInstallerReceipt } from "./release-qualification.js";
2
3
  import { signReleaseDescriptor, verifyReleaseDescriptor } from "../updates/signed-release.js";
3
4
  import { feedUrl } from "../updates/release-feed.js";
4
5
  import { discoveryPolicies, parseReleaseConfig, platformPayloads, platformTargets } from "./release-config.js";
5
6
  import { planReleaseAssets } from "./release-assets-plan.js";
7
+ import { hashFileAt } from "../updates/stable-file.js";
6
8
  import { commandReceiptName } from "../installer/command-qualification-command.js";
7
- import { lstat, open, readFile, writeFile } from "node:fs/promises";
9
+ import { lstat, readFile, writeFile } from "node:fs/promises";
8
10
  import { join, resolve } from "node:path";
9
- import { createHash, createPublicKey } from "node:crypto";
11
+ import { createPublicKey } from "node:crypto";
10
12
  // src/release/release-descriptor-staging.ts
11
- var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
12
13
  async function staged(path, name) {
13
14
  const info = await lstat(path);
14
15
  if (!info.isFile() || info.isSymbolicLink() || !Number.isSafeInteger(info.size) || info.size < 1) throw new Error("Invalid staged payload");
15
- const file = await open(path, "r");
16
- try {
17
- const before = await file.stat();
18
- if (before.dev !== info.dev || before.ino !== info.ino || before.size !== info.size) throw new Error("Staged payload changed");
19
- const hash = createHash("sha256");
20
- let size = 0;
21
- for await (const chunk of file.createReadStream({ autoClose: false })) {
22
- size += chunk.length;
23
- if (size > before.size) throw new Error("Staged payload changed");
24
- hash.update(chunk);
25
- }
26
- const after = await file.stat();
27
- if (size !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.dev !== before.dev || after.ino !== before.ino) throw new Error("Staged payload changed");
28
- return {
29
- name,
30
- size,
31
- digest: "sha256:" + hash.digest("hex")
32
- };
33
- } finally {
34
- await file.close();
35
- }
16
+ const { size, sha256 } = await hashFileAt(path, info, "Staged payload changed");
17
+ return {
18
+ name,
19
+ size,
20
+ digest: "sha256:" + sha256
21
+ };
36
22
  }
37
23
  /** Sign and self-verify one descriptor per discovery policy, each naming its staged payload. */
38
24
  function signDiscoveryDescriptors(options) {
@@ -79,7 +65,7 @@ async function writeDescriptors(directory, signed) {
79
65
  await lstat(join(directory, value.name));
80
66
  throw new Error("Descriptor already exists");
81
67
  } catch (error) {
82
- if (error.code !== "ENOENT") throw error;
68
+ if (errorCode(error) !== "ENOENT") throw error;
83
69
  }
84
70
  for (const value of signed) await writeFile(join(directory, value.name), value.bytes, {
85
71
  flag: "wx",
@@ -88,7 +74,7 @@ async function writeDescriptors(directory, signed) {
88
74
  }
89
75
  /** The configured public key for `keyId`, which must be the signing key's own. */
90
76
  function configuredSigningKey(config, keyId, privateKey) {
91
- if (!object(config.releaseSigningKeys) || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(keyId) || privateKey.type !== "private" || privateKey.asymmetricKeyType !== "ed25519") throw new Error("Invalid descriptor signing context");
77
+ if (!isRecord(config.releaseSigningKeys) || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(keyId) || privateKey.type !== "private" || privateKey.asymmetricKeyType !== "ed25519") throw new Error("Invalid descriptor signing context");
92
78
  const encoded = config.releaseSigningKeys[keyId];
93
79
  const publicKey = createPublicKey(privateKey).export({
94
80
  type: "spki",
@@ -113,7 +99,7 @@ async function stageReleaseDescriptors(options) {
113
99
  tag,
114
100
  run: options.run
115
101
  });
116
- if (env.SOURCE_SHA !== plan.sourceSha || !object(config) || typeof config.appId !== "string" || !object(config.descriptors)) throw new Error("Invalid descriptor signing context");
102
+ if (env.SOURCE_SHA !== plan.sourceSha || !isRecord(config) || typeof config.appId !== "string" || !isRecord(config.descriptors)) throw new Error("Invalid descriptor signing context");
117
103
  const encoded = configuredSigningKey(config, keyId, privateKey);
118
104
  const parsed = parseReleaseConfig(config), requirements = parsed.requirements(tag), feed = feedUrl(parsed.feed);
119
105
  const policies = discoveryPolicies(config, tag);
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { githubCli } from "./github-cli.js";
2
3
  import { lookupRelease } from "./github-release-lookup.js";
3
4
  import { isRepositorySlug } from "../updates/signed-release.js";
@@ -34,7 +35,7 @@ function parseFinalizationEvent(event, repository, eventName = "workflow_run") {
34
35
  async function finalizeReleasePleaseDraft(options) {
35
36
  const { env, config, tag, runId, runAttempt } = options;
36
37
  const repository = env.GITHUB_REPOSITORY ?? "";
37
- if (env.GITHUB_ACTIONS !== "true" || !["workflow_run", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") || env.GITHUB_REF !== "refs/heads/main" || !isRepositorySlug(repository) || !/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? "") || !/^[1-9]\d{0,19}$/.test(runId) || !Number.isSafeInteger(runAttempt) || runAttempt < 1 || !/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) || tag.length > 65) throw new Error("Invalid release finalization context");
38
+ if (env.GITHUB_ACTIONS !== "true" || !["workflow_run", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") || env.GITHUB_REF !== "refs/heads/main" || !isRepositorySlug(repository) || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(runId) || !Number.isSafeInteger(runAttempt) || runAttempt < 1 || !/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) || tag.length > 65) throw new Error("Invalid release finalization context");
38
39
  const parsed = parseReleaseConfig(config);
39
40
  if (!parsed.releasePleaseManifestPath || typeof config !== "object" || config === null || typeof config.appName !== "string") throw new Error("Release Please finalization is not configured");
40
41
  const run = options.run ?? githubCli();
@@ -1,7 +1,7 @@
1
1
  import { validateReleaseQualification } from "./release-qualification.js";
2
2
  import { verifyReleaseDescriptor } from "../updates/signed-release.js";
3
3
  import { releaseAssetNames } from "./release-config.js";
4
- import { openUnchangedFile, sameFile } from "../updates/stable-file.js";
4
+ import { hashUnchangedFile, openUnchangedFile } from "../updates/stable-file.js";
5
5
  import { lstat, mkdtemp, open, rm, writeFile } from "node:fs/promises";
6
6
  import { join, resolve } from "node:path";
7
7
  import { createHash } from "node:crypto";
@@ -17,19 +17,11 @@ async function fileIdentity(path, name) {
17
17
  const { file, before } = await openUnchangedFile(path, info, "Invalid staged artifact");
18
18
  try {
19
19
  if (!Number.isSafeInteger(before.size) || before.size < 1) throw new Error("Invalid staged artifact");
20
- const hash = createHash("sha256");
21
- let size = 0;
22
- for await (const chunk of file.createReadStream({ autoClose: false })) {
23
- size += chunk.length;
24
- if (size > before.size) throw new Error("Staged artifact changed");
25
- hash.update(chunk);
26
- }
27
- const after = await file.stat();
28
- if (size !== before.size || !sameFile(before, after)) throw new Error("Staged artifact changed");
20
+ const { size, sha256 } = await hashUnchangedFile(file, before, "Staged artifact changed");
29
21
  return {
30
22
  name,
31
23
  size,
32
- digest: "sha256:" + hash.digest("hex")
24
+ digest: "sha256:" + sha256
33
25
  };
34
26
  } finally {
35
27
  await file.close();
@@ -1,4 +1,5 @@
1
- import { githubCli } from "./github-cli.js";
1
+ import { isGitSha, isRecord } from "../app/value-guards.js";
2
+ import { githubCli, verifyWorkflowAttempt } from "./github-cli.js";
2
3
  import { assertRepositorySlug } from "../updates/signed-release.js";
3
4
  import { feedUrl } from "../updates/release-feed.js";
4
5
  import { discoveryPolicies, parseReleaseConfig } from "./release-config.js";
@@ -8,7 +9,6 @@ import { createGitHubReleasePublisher } from "./github-release-publisher.js";
8
9
  import { open } from "node:fs/promises";
9
10
  import { join, resolve } from "node:path";
10
11
  // src/release/release-publish-command.ts
11
- var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
12
12
  async function boundedJson(path) {
13
13
  const handle = await open(path, "r");
14
14
  try {
@@ -30,10 +30,10 @@ async function boundedJson(path) {
30
30
  /** Publish only the current trusted release-assets attempt and its staged receipts. */
31
31
  async function runReleasePublishCommand(options) {
32
32
  const { env, config } = options;
33
- if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY || !/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? "") || !/^[a-f0-9]{40}$/.test(env.SOURCE_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(env.RELEASE_TAG ?? "")) throw new Error("Publication requires a trusted release-assets workflow");
33
+ if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !isGitSha(env.SOURCE_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(env.RELEASE_TAG ?? "")) throw new Error("Publication requires a trusted release-assets workflow");
34
34
  assertRepositorySlug(env.GITHUB_REPOSITORY);
35
35
  const { requirements, releasePleaseManifestPath, releaseWorkflows, feed } = parseReleaseConfig(config);
36
- if (!record(config) || typeof config.appId !== "string" || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(config.appId) || config.appId.length > 255 || !record(config.releaseSigningKeys) || !record(config.descriptors)) throw new Error("Invalid release signing configuration");
36
+ if (!isRecord(config) || typeof config.appId !== "string" || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(config.appId) || config.appId.length > 255 || !isRecord(config.releaseSigningKeys) || !isRecord(config.descriptors)) throw new Error("Invalid release signing configuration");
37
37
  const keyEntries = Object.entries(config.releaseSigningKeys);
38
38
  if (!keyEntries.length || keyEntries.length > 16) throw new Error("Missing release verification keys");
39
39
  const keys = /* @__PURE__ */ new Map();
@@ -59,8 +59,17 @@ async function runReleasePublishCommand(options) {
59
59
  allowedPayloads: [policy.payload]
60
60
  };
61
61
  const run = options.run ?? githubCli();
62
- const workflow = JSON.parse(await run(["api", `repos/${repository}/actions/runs/${env.GITHUB_RUN_ID}/attempts/${env.GITHUB_RUN_ATTEMPT}`]));
63
- if (String(workflow?.id) !== env.GITHUB_RUN_ID || String(workflow?.run_attempt) !== env.GITHUB_RUN_ATTEMPT || workflow?.head_sha !== env.GITHUB_SHA || workflow?.event !== "workflow_dispatch" || workflow?.path !== releaseWorkflows.assets || workflow?.repository?.full_name !== repository) throw new Error("Release-assets workflow provenance mismatch");
62
+ await verifyWorkflowAttempt({
63
+ run,
64
+ repository,
65
+ env,
66
+ expected: {
67
+ headSha: env.GITHUB_SHA,
68
+ event: "workflow_dispatch",
69
+ path: releaseWorkflows.assets
70
+ },
71
+ mismatch: "Release-assets workflow provenance mismatch"
72
+ });
64
73
  const directory = resolve(options.directory);
65
74
  const installerReceipts = await Promise.all(Object.keys(releaseRequirements.platforms).map(async (platform) => await boundedJson(join(directory, `installer-test-${platform}.json`))));
66
75
  const commandReceipts = releaseRequirements.commandArtifacts ? await Promise.all(Object.entries(releaseRequirements.commandArtifacts).flatMap(([kind, byPlatform]) => Object.keys(byPlatform).map(async (platform) => await boundedJson(join(directory, commandReceiptName(kind, platform)))))) : void 0;
@@ -1,3 +1,4 @@
1
+ import { isGitSha } from "../app/value-guards.js";
1
2
  import { containsAsciiControl } from "../desktop/string-policy.js";
2
3
  // src/release/release-qualification.ts
3
4
  function assert(condition, message) {
@@ -75,7 +76,7 @@ function validateInstallerReceipt(identity, entry, platform, names, assets, offl
75
76
  return true;
76
77
  }
77
78
  function assertIdentity(identity, platform) {
78
- assert(/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) && /^[a-f0-9]{40}$/.test(identity.sourceSha) && /^[a-f0-9]{40}$/.test(identity.workflowSha) && /^[1-9]\d{0,19}$/.test(identity.runId) && Number.isSafeInteger(identity.runAttempt) && identity.runAttempt > 0 && /^[a-z0-9-]+$/.test(platform), "Invalid receipt context");
79
+ assert(/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) && isGitSha(identity.sourceSha) && isGitSha(identity.workflowSha) && /^[1-9]\d{0,19}$/.test(identity.runId) && Number.isSafeInteger(identity.runAttempt) && identity.runAttempt > 0 && /^[a-z0-9-]+$/.test(platform), "Invalid receipt context");
79
80
  }
80
81
  /** Validate one command artifact receipt against the exact attempt and payload bytes. */
81
82
  function validateCommandReceipt(identity, entry, kind, platform, name, assets) {
@@ -111,7 +112,7 @@ function validateCommandReceipts(identity, receipts, requirements, assets) {
111
112
  function validateReleaseQualification(release, receipt, sourceSha, requirements) {
112
113
  const required = expectedAssets(requirements);
113
114
  const platforms = Object.keys(requirements.platforms);
114
- assert(release.draft === false && receipt.schema === 2 && receipt.tag === release.tag_name && receipt.sourceSha === sourceSha && /^[a-f0-9]{40}$/.test(sourceSha) && /^[a-f0-9]{40}$/.test(receipt.workflowSha) && /^[1-9]\d*$/.test(receipt.runId) && Number.isSafeInteger(receipt.runAttempt) && receipt.runAttempt > 0, "Qualification identity mismatch");
115
+ assert(release.draft === false && receipt.schema === 2 && receipt.tag === release.tag_name && receipt.sourceSha === sourceSha && isGitSha(sourceSha) && isGitSha(receipt.workflowSha) && /^[1-9]\d*$/.test(receipt.runId) && Number.isSafeInteger(receipt.runAttempt) && receipt.runAttempt > 0, "Qualification identity mismatch");
115
116
  assert(receipt.platforms.length === platforms.length && receipt.installerTests.length === platforms.length && receipt.installerReceipts.length === platforms.length && platforms.every((platform) => receipt.platforms.filter((x) => x === platform).length === 1 && receipt.installerTests.filter((x) => x === platform).length === 1), "Missing or duplicate platform tests");
116
117
  for (const platform of platforms) {
117
118
  const entries = receipt.installerReceipts.filter((entry) => entry.platform === platform);