@rightkit/release 0.6.39 → 0.6.42

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 (86) hide show
  1. package/README.md +110 -11
  2. package/admission-files.mjs +40 -0
  3. package/admission-host.mjs +2 -1
  4. package/app-check.mjs +303 -16
  5. package/app-closure.mjs +6 -4
  6. package/bin/rightkit-gate.mjs +177 -32
  7. package/cargo-contract.mjs +17 -31
  8. package/cargo-license-notices.mjs +129 -19
  9. package/cargo-target-shim.mjs +14 -0
  10. package/carried-cargo.mjs +2 -4
  11. package/cli/right-release.mjs +24 -2
  12. package/cross-targets.mjs +24 -0
  13. package/deterministic-scans.mjs +167 -58
  14. package/development-signing.mjs +25 -2
  15. package/development.mjs +34 -1
  16. package/direct-release-command.mjs +154 -0
  17. package/disk-policy.mjs +16 -0
  18. package/feature-coverage.mjs +134 -0
  19. package/gate-coverage.mjs +38 -0
  20. package/gate-stages.mjs +1 -0
  21. package/ghsa-audit.mjs +95 -0
  22. package/install-app.mjs +33 -5
  23. package/install-channels.mjs +301 -0
  24. package/interactive-session-run.mjs +105 -0
  25. package/legal-contract.mjs +10 -1
  26. package/legion-freeze-consumer.mjs +241 -0
  27. package/linux-publish.mjs +136 -0
  28. package/local-publish.mjs +31 -7
  29. package/nsis-pack.mjs +95 -0
  30. package/nsis-upgrade-template.mjs +93 -0
  31. package/outdated-command.mjs +19 -0
  32. package/ownership-class-rules.mjs +32 -10
  33. package/ownership-mandatory-set.json +23 -0
  34. package/ownership-mandatory-set.mjs +66 -8
  35. package/package-recipe-targets.mjs +54 -19
  36. package/package.json +1 -1
  37. package/payload-root-install.mjs +123 -0
  38. package/plugin-delivery.mjs +141 -0
  39. package/prebuild-gates.mjs +8 -4
  40. package/preflight.mjs +6 -1
  41. package/provision-model-bundle.mjs +172 -0
  42. package/pub-upload.mjs +1 -1
  43. package/publish-local-npm.mjs +34 -9
  44. package/publish-retention.mjs +106 -0
  45. package/publish-update.mjs +15 -8
  46. package/qa-build-features.mjs +24 -15
  47. package/qa-contract.mjs +5 -6
  48. package/qa-control-scan.mjs +14 -0
  49. package/qa-web-pairing.mjs +76 -0
  50. package/r2-s3-multipart.mjs +190 -0
  51. package/r2-verified-upload.mjs +28 -16
  52. package/recipe-build.mjs +53 -3
  53. package/release-checks.mjs +53 -2
  54. package/release-config.mjs +8 -3
  55. package/release-invocation.mjs +12 -2
  56. package/release-pin-floor.mjs +44 -0
  57. package/release-qa-audit.mjs +18 -2
  58. package/release-qa-command.mjs +17 -1
  59. package/release-qa-policy.mjs +30 -3
  60. package/release-switch-cfg.mjs +271 -0
  61. package/release-switch-registry.json +60 -1
  62. package/release-switch-scan.mjs +398 -23
  63. package/release.mjs +97 -6
  64. package/render-views.mjs +141 -0
  65. package/rightkit-registry-resolver.mjs +1 -1
  66. package/rightkit-versions.json +568 -491
  67. package/runtime-artifact-manifest.mjs +9 -0
  68. package/runtime-manifest-refresh.mjs +88 -0
  69. package/rustright-stage.mjs +197 -0
  70. package/scan-digest.mjs +15 -9
  71. package/scan-tool-enrolment.mjs +1 -1
  72. package/security-policy.mjs +196 -0
  73. package/shell-contract.mjs +32 -0
  74. package/snapshot-broker.mjs +8 -1
  75. package/snapshot-check.mjs +58 -0
  76. package/snapshot-request.mjs +25 -2
  77. package/stage-commands.mjs +33 -4
  78. package/stage-ledger.mjs +6 -1
  79. package/stage-receipt.mjs +115 -0
  80. package/stage-sidecar.mjs +188 -17
  81. package/stage-xcframework.mjs +118 -0
  82. package/suite-api.generated.mjs +16 -1
  83. package/unit-gate.mjs +14 -2
  84. package/upload-large.mjs +4 -4
  85. package/upload-release.mjs +6 -0
  86. package/win-package-recipe.mjs +26 -4
@@ -18,6 +18,7 @@
18
18
  // devtools-declaration SC-R7 the five sites of the content-only DevTools declaration disagree
19
19
  // shell-lifecycle-external SC-R8 lifecycle_only next to an external-URL window (no hardening, no navigation policy)
20
20
  // legal-receipt-native SC-R9 legal acceptance stamped with the webview clock instead of the native receipt service
21
+ // autostart-owner SC-R10 an app registering login launch itself (the Run key, auto-launch, tauri-plugin-autostart) instead of through the shell's autostart service
21
22
  //
22
23
  // An app is every tracked tauri.conf.json outside node_modules/, vendor/ and target/. Targets are `base` plus each tauri.<platform>.conf.json:
23
24
  // Tauri merges a platform file into the base by JSON Merge Patch (RFC 7396: objects merge, arrays replace, null deletes), and a platform
@@ -1056,6 +1057,36 @@ const legalReceiptNative = perApp(({ app, root }) => {
1056
1057
  return out;
1057
1058
  });
1058
1059
 
1060
+ // ---- R10 autostart-owner -----------------------------------------------------------------------------------------------------
1061
+ // Login launch has ONE owner, rightkit-tauri-shell's autostart service (rightkit#1227): it registers the declared install path only and refuses a
1062
+ // current_exe under a build target directory, the managed root or any other non-install location. An app that writes the Windows Run key itself,
1063
+ // or drives the auto-launch / tauri-plugin-autostart crates directly, registers whatever path it happens to run from, so a dev or test run from the
1064
+ // broker's target directory leaves a login entry that the next build or clean deletes or replaces. Detected from the app's committed Rust only.
1065
+ const AUTOSTART_PATTERNS = [
1066
+ { subject: "run-key-write", pattern: /CurrentVersion(?:\\\\|\\|\/)Run(?:Once)?\b/, what: "writes the HKCU ...\\CurrentVersion\\Run key itself" },
1067
+ { subject: "auto-launch-crate", pattern: /\bauto_launch\s*::|\bAutoLaunch(?:Builder)?\b/, what: "drives the auto-launch crate directly" },
1068
+ { subject: "autostart-plugin", pattern: /\btauri_plugin_autostart\b/, what: "installs tauri-plugin-autostart directly" },
1069
+ ];
1070
+ const autostartOwner = perApp(({ app, root }) => {
1071
+ const out = [];
1072
+ for (const file of app.rustFiles) {
1073
+ const text = readText(root, file);
1074
+ if (text === null) continue;
1075
+ const lines = text.split("\n");
1076
+ for (const { subject, pattern, what } of AUTOSTART_PATTERNS) {
1077
+ const index = lines.findIndex((line) => !/^\s*\/\//.test(line) && pattern.test(line));
1078
+ if (index < 0) continue;
1079
+ out.push({
1080
+ file,
1081
+ subject,
1082
+ problem: `${file}:${index + 1} ${what}: it registers the path it is running from, so a run from a build target directory leaves a login entry that points at a file the next build or clean replaces`,
1083
+ fix: "register login launch through rightkit-tauri-shell's autostart service (it registers the declared install path only and refuses a build-target, managed-root or other non-install executable); delete this registration",
1084
+ });
1085
+ }
1086
+ }
1087
+ return out;
1088
+ });
1089
+
1059
1090
  export const SHELL_CONTRACT_RULES = Object.freeze([
1060
1091
  { id: "shell-window-hidden", gap: "SC-R1", run: shellWindowHidden },
1061
1092
  { id: "shell-plugin-order", gap: "SC-R2", run: shellPluginOrder },
@@ -1066,4 +1097,5 @@ export const SHELL_CONTRACT_RULES = Object.freeze([
1066
1097
  { id: "devtools-declaration", gap: "SC-R7", run: devtoolsDeclaration },
1067
1098
  { id: "shell-lifecycle-external", gap: "SC-R8", run: shellLifecycleExternal },
1068
1099
  { id: "legal-receipt-native", gap: "SC-R9", run: legalReceiptNative },
1100
+ { id: "autostart-owner", gap: "SC-R10", run: autostartOwner },
1069
1101
  ]);
@@ -27,7 +27,7 @@ import { removeCarrier, sweepSnapshotRequests } from "./carrier-census.mjs";
27
27
  import { DEFAULT_RETRY_WINDOW_MS, RETRYABLE_OUTCOME_CODES, clientGuardMs, diagnoseControlReply, drainFrames, operationDeadlineEnv, operationOutcomeInOutput, overCapProblem, refusalInCapturedOutput, retryPauseMs, sleepSync } from "./broker-wire.mjs";
28
28
  import { OWNERSHIP_ENV, OWNERSHIP_FILE_ENV, markCarriedSend, markCarriedUnsent } from "./ownership-mark.mjs";
29
29
  import {
30
- MANAGED_RUST_ENVIRONMENT_KEYS, SNAPSHOT_REQUEST_SCHEMA, SnapshotRequestError, argvSha256, declaredInputDigestsOf, isCallHandleOf, lockedArgv, observedEnvOf, readDeclaredInputs, readRequestRef, verifySnapshotReceipt, writeSnapshotRequest,
30
+ MANAGED_RUST_ENVIRONMENT_KEYS, SNAPSHOT_REQUEST_SCHEMA, SnapshotRequestError, argvSha256, declaredInputDigestProblems, declaredInputDigestsOf, isCallHandleOf, lockedArgv, observedEnvOf, readDeclaredInputs, readRequestRef, verifySnapshotReceipt, writeSnapshotRequest,
31
31
  } from "./snapshot-request.mjs";
32
32
 
33
33
  /**
@@ -790,6 +790,13 @@ export async function verifyBrokerLedger(entries, sb, { seen = { nonces: new Set
790
790
  for (const child of verified.nestedChildren) {
791
791
  if (seen.ids.has(child.requestId)) throw new SnapshotRequestError("replay", `nested child ${child.requestId} was reported twice in this stage`);
792
792
  seen.ids.add(child.requestId);
793
+ // rightkit#1418: a nested compile child that signs its own declared-input digests is compared strictly, like a top-level compile: an input swapped
794
+ // for the child and restored before the stage ends is refused. (A child with none is not yet signed by the broker; that half is the broker's.)
795
+ if (child.declaredInputDigests !== undefined) {
796
+ if (!inputPolicy) throw new SnapshotRequestError("evidence", `nested child ${child.requestId} signs declared-input digests but the gate holds no end-of-stage digest of the declared inputs to compare them with`);
797
+ const bad = declaredInputDigestProblems(child.declaredInputDigests, { gateInputs: readDeclaredInputs(sb.snapshot.path), policy: inputPolicy });
798
+ if (bad.length) throw new SnapshotRequestError("evidence", `nested child ${child.requestId} (${child.argv.join(" ")}): ${bad[0]}`);
799
+ }
793
800
  }
794
801
  }
795
802
  } catch (error) { problems.push(`${call} (from ${e.cwd}): the gate's own verification of the broker's receipt failed (${error.code ?? "error"}: ${error.message})`); }
@@ -322,6 +322,64 @@ export function installSnapshotDependencies({ checkout, snapshot, commit, tree,
322
322
  return records;
323
323
  }
324
324
 
325
+ /**
326
+ * Content check's store proof (rightkit#1488): every pnpm root the commit has (a lockfile in the snapshot) must find each package its lockfile
327
+ * names in the offline store, so a missing tarball (workerd in ViewRight's workers/waitlist) fails the check and is never first seen by the
328
+ * compile stage's install. `pnpm fetch --offline` reads the lockfile alone and installs nothing: its virtual store is a directory under
329
+ * `tmpRoot` (the gate's scratch root, removed afterwards), never the snapshot, and the snapshot is verified unchanged after the last root.
330
+ * Returns one record per root ({ root, storeDir, storeSource, pnpm, pinned, lockfileSha256, ms } or { root, skipped }); throws CheckError on a
331
+ * store miss, a pnpm that is not the pinned one, or any failure.
332
+ */
333
+ export function verifySnapshotStore({ checkout, snapshot, commit, tree, ledger, roots, tmpRoot, env = process.env, spawn = defaultSpawn, now = () => Date.now(), readFile, exists }) {
334
+ const records = [];
335
+ if (!commit || !tree) throw new CheckError("the snapshot store check needs the selected commit and tree");
336
+ if (typeof tmpRoot !== "string" || !path.isAbsolute(tmpRoot)) throw new CheckError("the snapshot store check needs the gate's scratch root (an absolute path)");
337
+ const base = path.resolve(snapshot);
338
+ try {
339
+ const st = fs.lstatSync(base);
340
+ if (!st.isDirectory() || fs.realpathSync.native(base) !== base) throw new Error("not a real directory");
341
+ } catch (error) { throw new CheckError(`the snapshot store check needs a real snapshot directory: ${snapshot}: ${error.message}`); }
342
+ if (inside(base, checkout) || inside(checkout, base)) throw new CheckError(`snapshot ${base} and checkout ${checkout} overlap`);
343
+ verifySnapshotDir({ checkout, dir: base, commit, tree, when: "before the offline store check", ...(ledger !== undefined ? { ledger } : {}) });
344
+ const versionOf = (cwd) => { const r = spawn("pnpm", ["--version"], { cwd, env: { ...env, COREPACK_ENABLE_AUTO_PIN: "0" } }); return failed(r) ? null : text(r).trim().split(/\r?\n/).pop(); };
345
+ for (const root of roots) {
346
+ const dir = path.resolve(base, root);
347
+ if (!inside(dir, base)) throw new CheckError(`root ${root}: the store check is outside the snapshot`);
348
+ if (!fs.existsSync(path.join(dir, "pnpm-lock.yaml"))) { records.push({ root, skipped: "no pnpm-lock.yaml in the commit: nothing to check against the store (the pnpm-lockfile scan judges it)" }); continue; }
349
+ const { storeDir, source } = resolvePrimaryStore({ checkout, root, env, spawn, ...(readFile ? { readFile } : {}), ...(exists ? { exists } : {}) });
350
+ const pin = pinnedPnpm(dir) ?? pinnedPnpm(snapshot);
351
+ const version = versionOf(dir);
352
+ if (!version) throw new CheckError("pnpm is not runnable on this host; the snapshot's dependencies cannot be checked against the store");
353
+ if (pin && version !== pin) throw new CheckError(`pnpm ${version} is on PATH, but root ${root} of the commit pins pnpm@${pin} (packageManager); install the pinned pnpm`);
354
+ fs.mkdirSync(tmpRoot, { recursive: true });
355
+ const virtualStore = fs.mkdtempSync(path.join(tmpRoot, "rightkit-store-check-"));
356
+ const started = now();
357
+ let r;
358
+ try {
359
+ r = spawn("pnpm", ["fetch", "--offline", "--ignore-scripts", "--ignore-pnpmfile", "--store-dir", storeDir, "--virtual-store-dir", path.join(virtualStore, ".pnpm"), "--config.enable-global-virtual-store=false", "--reporter", "append-only"], {
360
+ cwd: dir, env: { ...env, COREPACK_ENABLE_AUTO_PIN: "0", CI: "true" }, maxBuffer: 1 << 28,
361
+ });
362
+ } catch (error) { r = { error }; } finally { fs.rmSync(virtualStore, { recursive: true, force: true }); }
363
+ const ms = now() - started;
364
+ if (failed(r)) {
365
+ const joined = `${r?.stdout ?? ""}\n${r?.stderr ?? ""}`.replace(/(https?:\/\/)\s+/g, "$1");
366
+ const miss = /ERR_PNPM_NO_OFFLINE_TARBALL[\s\S]{0,600}?(https?:\/\/\S+?\/-\/(\S+?)\.tgz)/.exec(joined);
367
+ throw new CheckError(miss
368
+ ? `root ${root}: ${miss[2]} is missing from the store ${storeDir} (offline, no network fallback); install the checkout's dependencies so the store holds it, then run the check again`
369
+ : `root ${root}: the offline store check failed (store ${storeDir}): ${tail(r) || r?.error?.message || `exit ${r?.status}`}`);
370
+ }
371
+ records.push({ root, storeDir, storeSource: source, pnpm: version, pinned: pin, lockfileSha256: crypto.createHash("sha256").update(fs.readFileSync(path.join(dir, "pnpm-lock.yaml"))).digest("hex"), ms });
372
+ }
373
+ verifySnapshotDir({ checkout, dir: base, commit, tree, when: "after the offline store check", ...(ledger !== undefined ? { ledger } : {}) });
374
+ return records;
375
+ }
376
+
377
+ /** One line per root of the offline store check, for the check's output. */
378
+ export function describeStoreCheck(record) {
379
+ if (record.skipped) return `snapshot store root=${record.root} not checked: ${record.skipped}`;
380
+ return `snapshot store root=${record.root} pnpm=${record.pnpm}${record.pinned ? ` (pinned ${record.pinned})` : ""} store=${record.storeDir} (from ${record.storeSource}) holds every package of lockfile=sha256:${record.lockfileSha256} ms=${record.ms}`;
381
+ }
382
+
325
383
  /** One line per installed root, for the check's output and evidence. */
326
384
  export function describeInstall(record) {
327
385
  if (record.skipped) return `snapshot dependencies root=${record.root} not installed: ${record.skipped}`;
@@ -474,6 +474,28 @@ export function verifySnapshotEvidenceIdentity(evidence, { commit, tree = commit
474
474
  }
475
475
 
476
476
  export const NESTED_CHILD_FIELDS = Object.freeze(["requestId", "parentRequestId", "shim", "argv", "cwd", "exitCode", "status", "outputDir"]);
477
+ /**
478
+ * Fields a nested child may also carry (rightkit#1418): `declaredInputDigests`, the digests of the snapshot's declared inputs the BROKER signs from
479
+ * the child's own admission and binds at its exit, as it does for a top-level compile. Optional until the broker signs them (rustright, nested compile
480
+ * children); when present it is well formed here and compared strictly by the gate (declaredInputDigestProblems, verifyBrokerLedger).
481
+ */
482
+ export const NESTED_CHILD_OPTIONAL_FIELDS = Object.freeze(["declaredInputDigests"]);
483
+ const DIGEST_ENTRY_KEYS = (d) => { const k = Object.keys(d).sort().join(); return (k === "path,sha256" && typeof d.sha256 === "string" && /^[0-9a-f]{64}$/.test(d.sha256)) || (k === "absent,path" && d.absent === true); };
484
+
485
+ /**
486
+ * The problems of a nested child's signed `declaredInputDigests` against the gate's own truth, `[]` when they hold: `gateInputs` are the snapshot's
487
+ * declared input paths in declaration order, `policy` is `{ produced: Set, current: one digest per declared input }` as verifySnapshotReceipt takes it.
488
+ * Each entry must be the gate's digest of that input at the end of the stage unless the stage itself produced the input: an input swapped for the
489
+ * child and restored before the stage ended is seen as the child's differing digest (a child that read B while the stage ends with A).
490
+ */
491
+ export function declaredInputDigestProblems(signed, { gateInputs, policy }) {
492
+ if (!Array.isArray(signed) || signed.length !== gateInputs.length || !signed.every((d, i) => isObject(d) && d.path === gateInputs[i] && DIGEST_ENTRY_KEYS(d))) return ["its signed declaredInputDigests are not the snapshot's declared inputs in declaration order, each exactly { path, sha256 } or { path, absent: true }"];
493
+ const { produced, current } = policy ?? {};
494
+ if (!(produced instanceof Set) || !Array.isArray(current) || current.length !== gateInputs.length) return ["the gate has no end-of-stage digest of the declared inputs to compare it with"];
495
+ const problems = [];
496
+ signed.forEach((d, i) => { if (!produced.has(gateInputs[i]) && !same(d, current[i])) problems.push(`its signed declaredInputDigests entry for ${gateInputs[i]} is not the gate's own digest of that input at the end of the stage, and the stage did not change it`); });
497
+ return problems;
498
+ }
477
499
  /** The most children a root job's list may carry (rustright#190: the broker's cap; a refused child is never listed). */
478
500
  export const NESTED_CHILDREN_CAP = 8192;
479
501
 
@@ -497,7 +519,8 @@ export function verifyNestedChildren(evidence, receipt, { snapshotPath, checkout
497
519
  const ids = new Set();
498
520
  return list.map((child, index) => {
499
521
  const where = `nestedChildren[${index}]`;
500
- if (!isObject(child) || Object.keys(child).sort().join() !== [...NESTED_CHILD_FIELDS].sort().join()) fail("nested", `${where} is not exactly { ${NESTED_CHILD_FIELDS.join(", ")} }`);
522
+ if (!isObject(child) || !NESTED_CHILD_FIELDS.every((k) => Object.hasOwn(child, k)) || !Object.keys(child).every((k) => NESTED_CHILD_FIELDS.includes(k) || NESTED_CHILD_OPTIONAL_FIELDS.includes(k))) fail("nested", `${where} is not exactly { ${NESTED_CHILD_FIELDS.join(", ")} } (plus optionally ${NESTED_CHILD_OPTIONAL_FIELDS.join(", ")})`);
523
+ if (child.declaredInputDigests !== undefined && (!Array.isArray(child.declaredInputDigests) || !child.declaredInputDigests.every((d) => isObject(d) && typeof d.path === "string" && DIGEST_ENTRY_KEYS(d)))) fail("nested", `${where} declaredInputDigests is not a list of { path, sha256 } or { path, absent: true }`);
501
524
  if (typeof child.requestId !== "string" || !child.requestId || child.requestId === jobId || ids.has(child.requestId)) fail("nested", `${where} has no request id of its own`);
502
525
  const name = `${where} (${child.requestId})`;
503
526
  // The parent is the job the request named: this job, or a child listed before it (admission order; depth >= 2, rustright#190 ad9ecb37).
@@ -517,7 +540,7 @@ export function verifyNestedChildren(evidence, receipt, { snapshotPath, checkout
517
540
  if (inside(out, checkout, platform) || inside(out, canon(checkout), platform)) fail("nested", `${name} output directory ${out} is inside the checkout`);
518
541
  if (!isInsideGenerationTarget(out, outputRoots, platform)) fail("nested", `${name} output directory ${out} is not inside a managed generation target under ${outputRoots.join(", ")}`);
519
542
  }
520
- return { requestId: child.requestId, parentRequestId: child.parentRequestId, shim: child.shim, argv: [...child.argv], cwd: child.cwd, exitCode: 0, status: child.status, outputDir: out };
543
+ return { requestId: child.requestId, parentRequestId: child.parentRequestId, shim: child.shim, argv: [...child.argv], cwd: child.cwd, exitCode: 0, status: child.status, outputDir: out, ...(child.declaredInputDigests !== undefined ? { declaredInputDigests: child.declaredInputDigests.map((d) => ({ ...d })) } : {}) };
521
544
  });
522
545
  }
523
546
 
@@ -6,7 +6,8 @@ import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { CARGO_METADATA_ARGS, cargoPackageArgs, localTestPlan, npmPackArgs, qualifyFmtArgs } from "./local-publish.mjs";
8
8
  import { SWAP_HELPER_CARGO_ARGS, SWAP_HELPER_METADATA_ARGS, SWAP_HELPER_PACKAGE } from "./swap-helper-bundle.mjs";
9
- import { carriedRequestOf } from "./snapshot-request.mjs";
9
+ import { carriedRequestOf, lockedArgv, splitCarriedArgs } from "./snapshot-request.mjs";
10
+ import { directCargoShape } from "./cargo-target-shim.mjs";
10
11
 
11
12
  /** Stands for the one argument that is a fresh absolute scratch path (`pnpm pack --pack-destination <mkdtemp>`). */
12
13
  export const ANY_ABSOLUTE_PATH = Object.freeze({ anyAbsolutePath: true });
@@ -20,7 +21,10 @@ const PNPM = (...argvs) => ({ kind: "adapter", adapter: "rightkit-pnpm", argvs }
20
21
  const CARGO = (cwd, ...argvs) => {
21
22
  const carried = argvs.map((argv) => carriedRequestOf(argv, cwd) ?? { argv, cwd });
22
23
  if (new Set(carried.map((c) => c.cwd)).size !== 1) throw new Error(`the spellings of one cargo command run in different directories: ${argvs.map((a) => a.join(" ")).join(" | ")}`);
23
- return { kind: "cargo", argvs: carried.map((c) => c.argv), cwd: carried[0].cwd };
24
+ // GC-A11: a command of the direct shape (directCargoShape, the one list carried-cargo.mjs runs by) compiles nothing and runs directly,
25
+ // so it makes no broker job and no signed receipt: the row is `direct`, the stage owes its recorded direct ledger entry instead.
26
+ const direct = carried.every((c) => directCargoShape(c.argv));
27
+ return { kind: "cargo", argvs: carried.map((c) => c.argv), cwd: carried[0].cwd, ...(direct ? { direct: true } : {}) };
24
28
  };
25
29
 
26
30
  /** Readable name of an expected command (scratch paths shown as <scratch>). */
@@ -90,11 +94,12 @@ export function requestIs(payload, row, { checkout = null } = {}) {
90
94
  }
91
95
 
92
96
  /**
93
- * Assigns each job (`{ id, payload }`) to a distinct command of the stage. Returns { assigned: Map(id -> row), unmatched: [id...],
97
+ * Assigns each job (`{ id, payload }`) to a distinct command of the stage that runs in the broker (a `direct` row has none). Returns { assigned: Map(id -> row), unmatched: [id...],
94
98
  * missing: [row...] }: a job that is none of the commands is unmatched; a command no job covers is missing.
95
99
  */
96
100
  export function assignJobs(rows, jobs, options = {}) {
97
- const free = rows.map((row) => ({ row, taken: false }));
101
+ // A direct row (GC-A11) is never a broker job: it is neither matched to a receipt nor reported missing; directRowsNotRun checks it.
102
+ const free = rows.filter((row) => row.direct !== true).map((row) => ({ row, taken: false }));
98
103
  const assigned = new Map(), unmatched = [];
99
104
  for (const job of jobs) {
100
105
  const slot = free.find((s) => !s.taken && requestIs(job.payload, s.row, options));
@@ -102,3 +107,27 @@ export function assignJobs(rows, jobs, options = {}) {
102
107
  }
103
108
  return { assigned, unmatched, missing: free.filter((s) => !s.taken).map((s) => s.row) };
104
109
  }
110
+
111
+ /**
112
+ * The direct rows (GC-A11) of a stage that the carrier's ledger does not show as run, each with why. `entries` are the stage's ledger
113
+ * records (cargo-ledger.mjs readLedger). A direct row is satisfied by a record of a direct call (`direct: true`, status `ran`) with exit 0
114
+ * whose cargo words, locked as the stage's are, are one of the row's spellings and whose directory (the process cwd, or the
115
+ * `--manifest-path` directory) is the row's `cwd` of the checkout the stage ran in. One record satisfies one row.
116
+ */
117
+ export function directRowsNotRun(rows, entries) {
118
+ const pool = (entries ?? []).filter((e) => e?.direct === true && e.status === "ran");
119
+ const problems = [];
120
+ for (const row of rows.filter((r) => r.direct === true)) {
121
+ const matching = pool.filter((e) => {
122
+ const split = splitCarriedArgs(Array.isArray(e.argv) ? e.argv : []);
123
+ if (split.refusal) return false;
124
+ const dir = posixOf(split.manifestPath === null ? e.cwd : path.resolve(String(e.cwd), path.dirname(split.manifestPath)));
125
+ const words = lockedArgv(split.words);
126
+ return row.argvs.some((argv) => argv.length === words.length && argv.every((w, i) => w === words[i])) && (row.cwd === "." ? dir !== "" : dir.endsWith(`/${row.cwd}`) || dir === row.cwd);
127
+ });
128
+ const ran = matching.find((e) => e.exit === 0);
129
+ if (ran) { pool.splice(pool.indexOf(ran), 1); continue; }
130
+ problems.push({ row, why: matching.length ? `ran with exit ${matching[0].exit}` : "has no recorded direct run" });
131
+ }
132
+ return problems;
133
+ }
package/stage-ledger.mjs CHANGED
@@ -121,6 +121,9 @@ export function walkSnapshot({ dir, tracked, dependencyRoots = new Set(), run =
121
121
  return { entries, problems };
122
122
  }
123
123
 
124
+ /** tauri-build's generated schema files, `<app crate>/gen/schemas/<name>.json`. */
125
+ export const TAURI_GEN_SCHEMA = /(?:^|\/)gen\/schemas\/[^/]+\.json$/;
126
+
124
127
  /** What changed between two entry lists: `{ added, changed, removed }` as paths. */
125
128
  export function diffEntries(before, after) {
126
129
  const b = new Map(before.map((e) => [e.path, e])); const a = new Map(after.map((e) => [e.path, e]));
@@ -144,7 +147,9 @@ export function attributionProblems({ before, after, reported, receipt, removabl
144
147
  // the staged sidecar outputs of the step's own earlier staging, which a `wipeStageDir` re-stage deletes); nothing else may be removed.
145
148
  const removableSet = new Set(removable);
146
149
  const problems = [];
147
- for (const p of [...d.added, ...d.changed]) if (!allowed.has(p)) problems.push(`${p} was written by the staging step but it did not report it`);
150
+ // tauri-build writes its capability and ACL schemas to `<app crate>/gen/schemas/*.json` on every build of a Tauri crate; the folder is
151
+ // ignored by the app's own rules (checked in the walk) and is that build script's fixed output, not an unattributed write (Pulse, 2026-11-03).
152
+ for (const p of [...d.added, ...d.changed]) if (!allowed.has(p) && !TAURI_GEN_SCHEMA.test(p)) problems.push(`${p} was written by the staging step but it did not report it`);
148
153
  for (const p of d.removed) if (!removableSet.has(p)) problems.push(`${p} was removed by the staging step`);
149
154
  const present = new Set(after.map((e) => e.path));
150
155
  for (const p of allowed) if (!present.has(p)) problems.push(`${p} was reported by the staging step but is not in the snapshot as a ledger entry`);
@@ -0,0 +1,115 @@
1
+ // Read the stage receipt back and prove it (rightkit#1039, #428).
2
+ //
3
+ // `stage-sidecar` writes `stage-sidecar.json` (receipt) with one row per staged file: name, path, sha256, and for a cargo-bin row the Cargo profile.
4
+ // An app that assembles a payload by hand (copies those files into an .app or a payload folder) must not trust the receipt's word: this module
5
+ // reads it back and compares it with the bytes on disk.
6
+ //
7
+ // readVerifiedStageReceipt({ root, receiptPath?, target, profile?, mode?, names, kind? }) -> { [name]: { path (absolute), sha256 } }
8
+ // throws StageReceiptError when the receipt is not a valid receipt for `target`, a name has no row (or more than one), a row was staged with another
9
+ // Cargo `profile`, the receipt was written by another build `mode` (a release asks for mode "release"; a receipt that records none is refused),
10
+ // or the file on disk is missing, is not a regular file, or has other bytes than the row.
11
+ //
12
+ // assertStageReceiptGuard({ root, config, mode }) the release-time guard, enabled by `targets.<platform>.sign.stageReceipt`:
13
+ // { receipt: "<app-relative receipt>", bind?: { "<app-relative payload file>": "<row name>" } }
14
+ // Immediately before signing: the receipt must be a release receipt (every profiled row `release`), every row's staged file must still have
15
+ // its recorded sha256, and every bound payload file must be byte-identical to its row (a hand-assembled copy that drifted refuses).
16
+ import { createHash } from "node:crypto";
17
+ import nodeFs from "node:fs";
18
+ import path from "node:path";
19
+ import { validateStageSidecarReceipt } from "./stage-sidecar.mjs";
20
+
21
+ export const DEFAULT_STAGE_RECEIPT = "src-tauri/binaries/stage-sidecar.json";
22
+
23
+ export class StageReceiptError extends Error {
24
+ constructor(message, details = {}) { super(message); this.name = "StageReceiptError"; this.code = "RK_STAGE_RECEIPT"; Object.assign(this, details); }
25
+ }
26
+ const fail = (message, details) => { throw new StageReceiptError(message, details); };
27
+ const sha256Of = (fs, file) => createHash("sha256").update(fs.readFileSync(file)).digest("hex");
28
+
29
+ function contained(root, relative, label) {
30
+ if (typeof relative !== "string" || !relative || path.isAbsolute(relative) || path.win32.isAbsolute(relative) || /^[A-Za-z]:/.test(relative) || relative.split(/[\\/]/).includes("..")) fail(`${label} must be a relative path inside the app: ${JSON.stringify(relative)}`);
31
+ return path.resolve(root, relative);
32
+ }
33
+
34
+ function loadReceipt({ root, receiptPath, target, fs }) {
35
+ const file = contained(root, receiptPath, "receiptPath");
36
+ let raw;
37
+ try { raw = JSON.parse(String(fs.readFileSync(file, "utf8"))); } catch (error) { fail(`cannot read the stage receipt ${file}: ${error.message}`); }
38
+ try { validateStageSidecarReceipt(raw, target ? { target } : {}); } catch (error) { fail(error.message); }
39
+ return { receipt: raw, file };
40
+ }
41
+
42
+ /** Rows that are staged files themselves (not the per-arch thin slices of a universal row). */
43
+ const mainRows = (receipt) => receipt.files.filter((row) => row.sliceOf === undefined);
44
+
45
+ function verifyRow(root, row, fs) {
46
+ const file = path.resolve(root, row.path);
47
+ const info = fs.lstatSync(file, { throwIfNoEntry: false });
48
+ if (!info) fail(`${row.name}: the staged file ${row.path} is missing`, { name: row.name });
49
+ if (info.isSymbolicLink() || !info.isFile()) fail(`${row.name}: ${row.path} is not a regular file`, { name: row.name });
50
+ const actual = sha256Of(fs, file);
51
+ if (actual !== row.sha256) fail(`${row.name}: ${row.path} has sha256 ${actual}, the receipt row says ${row.sha256}; the staged file changed after it was staged`, { name: row.name, expected: row.sha256, actual });
52
+ return file;
53
+ }
54
+
55
+ export function readVerifiedStageReceipt({ root, receiptPath = DEFAULT_STAGE_RECEIPT, target, profile, mode, names, kind, fs = nodeFs } = {}) {
56
+ if (typeof root !== "string" || !path.isAbsolute(root)) fail("root must be the absolute app root");
57
+ if (!Array.isArray(names) || !names.length || names.some((name) => typeof name !== "string" || !name)) fail("names must be a non-empty list of receipt row names");
58
+ const { receipt } = loadReceipt({ root, receiptPath, target, fs });
59
+ if (mode !== undefined) {
60
+ if (receipt.mode === undefined) fail(`the receipt records no build mode, so it cannot be accepted for a ${mode} build; stage again`);
61
+ if (receipt.mode !== mode) fail(`the receipt was staged in ${receipt.mode} mode, not ${mode}`, { expected: mode, actual: receipt.mode });
62
+ }
63
+ const out = {};
64
+ for (const name of names) {
65
+ const rows = mainRows(receipt).filter((row) => row.name === name && (kind === undefined || row.kind === kind));
66
+ if (rows.length !== 1) fail(`the receipt has ${rows.length} row(s) named ${name}${kind ? ` of kind ${kind}` : ""}, expected exactly one`, { name });
67
+ const [row] = rows;
68
+ if (profile !== undefined && row.profile !== profile) fail(`${name} was staged with Cargo profile ${row.profile === undefined ? "(none recorded)" : row.profile}, not ${profile}`, { name, expected: profile, actual: row.profile });
69
+ out[name] = { path: verifyRow(root, row, fs), sha256: row.sha256 };
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** Validate `sign.stageReceipt`; returns { receipt, bind } (bind: array of [file, rowName]). */
75
+ export function validateStageReceiptConfig(value, label = "sign.stageReceipt") {
76
+ if (value === null || typeof value !== "object" || Array.isArray(value)) fail(`${label} must be { receipt, bind? }`);
77
+ const unknown = Object.keys(value).filter((key) => !["receipt", "bind"].includes(key));
78
+ if (unknown.length) fail(`${label} has unknown key(s): ${unknown.join(", ")} (allowed: receipt, bind)`);
79
+ const receipt = value.receipt === undefined ? DEFAULT_STAGE_RECEIPT : value.receipt;
80
+ contained(path.sep === "\\" ? "C:\\app" : "/app", receipt, `${label}.receipt`);
81
+ const bind = value.bind === undefined ? {} : value.bind;
82
+ if (bind === null || typeof bind !== "object" || Array.isArray(bind)) fail(`${label}.bind must map payload file paths to receipt row names`);
83
+ const pairs = Object.entries(bind).map(([file, name]) => {
84
+ contained(path.sep === "\\" ? "C:\\app" : "/app", file, `${label}.bind key`);
85
+ if (typeof name !== "string" || !name) fail(`${label}.bind[${JSON.stringify(file)}] must be a receipt row name`);
86
+ return [file, name];
87
+ });
88
+ return { receipt, bind: pairs };
89
+ }
90
+
91
+ /** The release-time guard. Throws StageReceiptError naming every problem; returns { rows, bound } when it passes. */
92
+ export function assertStageReceiptGuard({ root, config, mode = "release", target, fs = nodeFs } = {}) {
93
+ const { receipt: receiptPath, bind } = validateStageReceiptConfig(config);
94
+ const { receipt } = loadReceipt({ root, receiptPath, target, fs });
95
+ const problems = [];
96
+ if (mode === "release") {
97
+ if (receipt.mode !== "release") problems.push(receipt.mode === undefined ? "the receipt records no build mode (a release needs a receipt staged in release mode)" : `the receipt was staged in ${receipt.mode} mode; a release build refuses a ${receipt.mode} receipt`);
98
+ for (const row of mainRows(receipt)) if (row.profile !== undefined && row.profile !== "release") problems.push(`${row.name} was staged with Cargo profile ${row.profile}; a release build needs release`);
99
+ }
100
+ const rows = mainRows(receipt);
101
+ for (const row of rows) { try { verifyRow(root, row, fs); } catch (error) { problems.push(error.message); } }
102
+ const bound = [];
103
+ for (const [file, name] of bind) {
104
+ const row = rows.find((item) => item.name === name);
105
+ if (!row) { problems.push(`${file} is bound to ${name}, which has no row in the receipt`); continue; }
106
+ const full = contained(root, file, "bound file");
107
+ const info = fs.lstatSync(full, { throwIfNoEntry: false });
108
+ if (!info || info.isSymbolicLink() || !info.isFile()) { problems.push(`${file} (bound to ${name}) is missing or not a regular file`); continue; }
109
+ const actual = sha256Of(fs, full);
110
+ if (actual !== row.sha256) problems.push(`${file} (bound to ${name}) has sha256 ${actual}, the receipt says ${row.sha256}: the hand-assembled copy is not the staged file`);
111
+ else bound.push({ file, name, sha256: actual });
112
+ }
113
+ if (problems.length) fail(`the stage receipt guard refused signing:\n${problems.map((line) => `- ${line}`).join("\n")}`, { problems });
114
+ return { rows: rows.length, bound };
115
+ }