@rightkit/release 0.6.40 → 0.6.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -11
- package/admission-files.mjs +40 -0
- package/admission-host.mjs +2 -1
- package/app-check.mjs +303 -16
- package/app-closure.mjs +6 -4
- package/bin/rightkit-gate.mjs +180 -32
- package/cargo-contract.mjs +17 -31
- package/cargo-license-notices.mjs +129 -19
- package/cargo-target-shim.mjs +14 -0
- package/carried-cargo.mjs +2 -4
- package/cli/right-release.mjs +24 -2
- package/cross-targets.mjs +24 -0
- package/deterministic-scans.mjs +150 -58
- package/development-signing.mjs +25 -2
- package/development.mjs +34 -1
- package/direct-release-command.mjs +154 -0
- package/disk-policy.mjs +16 -0
- package/feature-coverage.mjs +134 -0
- package/gate-coverage.mjs +38 -0
- package/gate-stages.mjs +1 -0
- package/ghsa-audit.mjs +95 -0
- package/install-app.mjs +33 -5
- package/install-channels.mjs +301 -0
- package/interactive-session-run.mjs +105 -0
- package/legal-contract.mjs +10 -1
- package/legion-freeze-consumer.mjs +241 -0
- package/linux-publish.mjs +136 -0
- package/local-publish.mjs +31 -8
- package/nsis-pack.mjs +95 -0
- package/nsis-upgrade-template.mjs +93 -0
- package/outdated-command.mjs +19 -0
- package/ownership-class-rules.mjs +32 -10
- package/ownership-mandatory-set.json +23 -0
- package/ownership-mandatory-set.mjs +66 -8
- package/package-recipe-targets.mjs +54 -19
- package/package.json +1 -1
- package/payload-root-install.mjs +123 -0
- package/plugin-delivery.mjs +141 -0
- package/prebuild-gates.mjs +8 -4
- package/preflight.mjs +6 -1
- package/provision-model-bundle.mjs +172 -0
- package/pub-upload.mjs +1 -1
- package/publish-local-npm.mjs +34 -9
- package/publish-retention.mjs +106 -0
- package/publish-update.mjs +15 -8
- package/qa-build-features.mjs +24 -15
- package/qa-contract.mjs +5 -6
- package/qa-control-scan.mjs +14 -0
- package/qa-web-pairing.mjs +76 -0
- package/r2-s3-multipart.mjs +190 -0
- package/r2-verified-upload.mjs +28 -16
- package/recipe-build.mjs +53 -3
- package/release-checks.mjs +53 -2
- package/release-config.mjs +8 -3
- package/release-invocation.mjs +12 -2
- package/release-pin-floor.mjs +44 -0
- package/release-qa-audit.mjs +18 -2
- package/release-qa-command.mjs +17 -1
- package/release-qa-policy.mjs +30 -3
- package/release-switch-cfg.mjs +271 -0
- package/release-switch-registry.json +60 -1
- package/release-switch-scan.mjs +398 -23
- package/release.mjs +97 -6
- package/render-views.mjs +141 -0
- package/rightkit-registry-resolver.mjs +1 -1
- package/rightkit-versions.json +140 -103
- package/runtime-artifact-manifest.mjs +9 -0
- package/runtime-manifest-refresh.mjs +88 -0
- package/rustright-stage.mjs +197 -0
- package/scan-digest.mjs +15 -9
- package/scan-tool-enrolment.mjs +1 -1
- package/security-policy.mjs +196 -0
- package/shell-contract.mjs +32 -0
- package/snapshot-broker.mjs +8 -1
- package/snapshot-check.mjs +59 -1
- package/snapshot-identity.mjs +48 -0
- package/snapshot-request.mjs +25 -2
- package/snapshot.mjs +69 -9
- package/stage-commands.mjs +33 -4
- package/stage-ledger.mjs +5 -0
- package/stage-receipt.mjs +115 -0
- package/stage-sidecar.mjs +188 -17
- package/stage-xcframework.mjs +118 -0
- package/suite-api.generated.mjs +16 -1
- package/unit-gate.mjs +14 -2
- package/upload-large.mjs +4 -4
- package/upload-release.mjs +6 -0
- package/win-package-recipe.mjs +26 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The source-identity file of a gate snapshot (docs/GATE-CONTRACT.md GC-A23; rightkit#1504, rustright#176).
|
|
2
|
+
//
|
|
3
|
+
// A gate snapshot has no `.git`, so a build script that wants the commit it is built from (Pulse's membrane-runtime and this repository's
|
|
4
|
+
// rightkit-context-runtime read it) finds nothing and reports "unknown". The gate therefore writes `.rightkit-source-identity.json`
|
|
5
|
+
// into the snapshot root for the commit it syncs:
|
|
6
|
+
// { "schema": "rightkit.source-identity.v1", "commit": "<40 hex>", "trees": { "": "<root tree id>", "<dir>": "<tree id>", ... } }
|
|
7
|
+
// with one `trees` entry for the root and one for every directory of the commit that holds a Cargo.toml, Package.swift or
|
|
8
|
+
// package.json, each the git tree id `git rev-parse <commit>:<dir>` prints, read from the checkout's object database through the sealed
|
|
9
|
+
// runner. The bytes are a pure function of the commit (keys sorted, fixed spacing, one trailing newline), so every sync of one commit
|
|
10
|
+
// writes the same file and a verify can recompute it.
|
|
11
|
+
//
|
|
12
|
+
// It is a generated file, never a commit byte: snapshot.mjs admits it as its fourth named allowance (beside the pnpm dependency
|
|
13
|
+
// directories and the config-only `.git/config`) only when ALL hold: it sits at the snapshot root; the commit does not track a file
|
|
14
|
+
// of that name; it is a regular file with one hard link; its bytes equal sourceIdentityBytes() for the snapshot's commit; and the
|
|
15
|
+
// commit's own ignore rules ignore it (so the seeded tree id, which the broker computes the same way, still equals `<sha>^{tree}`).
|
|
16
|
+
// Any other byte, a link, a second name or a missing ignore rule is an extra path and fails the snapshot as before.
|
|
17
|
+
import { sealedRun } from "./snapshot-git.mjs";
|
|
18
|
+
|
|
19
|
+
export const SOURCE_IDENTITY_FILE = ".rightkit-source-identity.json";
|
|
20
|
+
export const SOURCE_IDENTITY_SCHEMA = "rightkit.source-identity.v1";
|
|
21
|
+
const MARKERS = new Set(["Cargo.toml", "Package.swift", "package.json"]);
|
|
22
|
+
const CHUNK = 200;
|
|
23
|
+
|
|
24
|
+
/** The directories of the commit (posix, "" for the root) that hold a Cargo.toml, Package.swift or package.json, sorted. */
|
|
25
|
+
export function identityDirectories(entries) {
|
|
26
|
+
const dirs = new Set([""]);
|
|
27
|
+
for (const e of entries) {
|
|
28
|
+
const i = e.path.lastIndexOf("/");
|
|
29
|
+
if (MARKERS.has(i < 0 ? e.path : e.path.slice(i + 1))) dirs.add(i < 0 ? "" : e.path.slice(0, i));
|
|
30
|
+
}
|
|
31
|
+
return [...dirs].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The exact bytes (a Buffer) of the identity file for `commit`: `entries` are the commit's `treeEntries`, `run` is injectable (tests). */
|
|
35
|
+
export function sourceIdentityBytes({ checkout, commit, entries, run = sealedRun }) {
|
|
36
|
+
if (!/^[0-9a-f]{40}$/.test(String(commit))) throw new Error(`the source identity needs a 40-hex SHA-1 commit id, not ${JSON.stringify(commit)}`);
|
|
37
|
+
const dirs = identityDirectories(entries);
|
|
38
|
+
const trees = {};
|
|
39
|
+
for (let i = 0; i < dirs.length; i += CHUNK) {
|
|
40
|
+
const chunk = dirs.slice(i, i + CHUNK);
|
|
41
|
+
const r = run(checkout, ["rev-parse", ...chunk.map((d) => (d === "" ? `${commit}^{tree}` : `${commit}:${d}`))]);
|
|
42
|
+
if (r.error || r.status !== 0) throw new Error(`git rev-parse of the commit's trees failed: ${r.error ? r.error.message : String(r.stderr ?? "").trim() || `exit ${r.status}`}`);
|
|
43
|
+
const ids = String(r.stdout ?? "").split("\n").filter(Boolean);
|
|
44
|
+
if (ids.length !== chunk.length || !ids.every((id) => /^[0-9a-f]{40}$/.test(id))) throw new Error(`git rev-parse answered ${ids.length} tree ids for ${chunk.length} directories`);
|
|
45
|
+
chunk.forEach((d, k) => { trees[d] = ids[k]; });
|
|
46
|
+
}
|
|
47
|
+
return Buffer.from(`${JSON.stringify({ schema: SOURCE_IDENTITY_SCHEMA, commit, trees }, null, 2)}\n`, "utf8");
|
|
48
|
+
}
|
package/snapshot-request.mjs
CHANGED
|
@@ -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.
|
|
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
|
|
package/snapshot.mjs
CHANGED
|
@@ -39,6 +39,7 @@ import { readDiskPolicy, scratchRoots } from "./disk-policy.mjs";
|
|
|
39
39
|
import { resolveManagedRoots } from "./managed-roots.mjs";
|
|
40
40
|
import { HostConfigError, hostConfigFile, readSnapshotRootConfig } from "./snapshot-root-config.mjs";
|
|
41
41
|
import { discoveryGit, discoveryRun, sealedRepoInfo, sealedRun, withSealedGit } from "./snapshot-git.mjs";
|
|
42
|
+
import { SOURCE_IDENTITY_FILE, sourceIdentityBytes } from "./snapshot-identity.mjs";
|
|
42
43
|
import { acquireBuildOwnership, migrateBirthlessRoot, OwnershipBusy, ownershipFile, recordRootBirth } from "./build-ownership.mjs";
|
|
43
44
|
// The error class and the managed-root guard live in managed-root-guard.mjs, which build-ownership.mjs imports too (decision D4 rule 1).
|
|
44
45
|
import { SnapshotError, requireManagedRoot } from "./managed-root-guard.mjs";
|
|
@@ -257,7 +258,7 @@ export function snapshotTree({ checkout, dir, baseTree, repo = repositoryOf(chec
|
|
|
257
258
|
* input even though the seeded tree id cannot see it. Never follows a link (only real directories are entered); names compare
|
|
258
259
|
* case-insensitively where the host filesystem does (Mac, Windows; colliding names were refused before this runs).
|
|
259
260
|
*/
|
|
260
|
-
function pruneToTree(dir, entries, platform = process.platform) {
|
|
261
|
+
function pruneToTree(dir, entries, platform = process.platform, keepRoot = new Set()) {
|
|
261
262
|
const fold = platform === "darwin" || platform === "win32" ? (n) => n.toLowerCase() : (n) => n;
|
|
262
263
|
const files = new Set(entries.map((e) => fold(e.path)));
|
|
263
264
|
const dirs = new Set();
|
|
@@ -268,7 +269,7 @@ function pruneToTree(dir, entries, platform = process.platform) {
|
|
|
268
269
|
const r = rel ? `${rel}/${e.name}` : e.name;
|
|
269
270
|
const p = path.join(d, e.name);
|
|
270
271
|
if (e.isDirectory()) { if (dirs.has(fold(r))) walk(p, r); else { fs.rmSync(p, { recursive: true, force: true }); removed++; } }
|
|
271
|
-
else if (!files.has(fold(r))) { fs.unlinkSync(p); removed++; }
|
|
272
|
+
else if (!files.has(fold(r)) && !(rel === "" && keepRoot.has(fold(r)))) { fs.unlinkSync(p); removed++; }
|
|
272
273
|
}
|
|
273
274
|
};
|
|
274
275
|
walk(dir, "");
|
|
@@ -324,6 +325,11 @@ function refuseCaseCollisions(entries, commit, platform = process.platform) {
|
|
|
324
325
|
* byte-equal to what the gate writes for THIS checkout's origin (gateGitConfigBody over `git config --get remote.origin.url`).
|
|
325
326
|
* Any other URL (`ext::sh -c id` was the r2#5 probe), any other section, any other byte is an extra. A checkout with no origin
|
|
326
327
|
* gets no `.git` at all.
|
|
328
|
+
* 3. the generated source-identity file `.rightkit-source-identity.json` at the snapshot root (snapshot-identity.mjs, GATE-CONTRACT
|
|
329
|
+
* GC-A23; rightkit#1504): admitted only when the caller names the snapshot's `commit`, the commit tracks no file of that name, it
|
|
330
|
+
* is a regular, non-executable file with one hard link, its bytes equal sourceIdentityBytes() for that commit exactly, and the
|
|
331
|
+
* commit's own ignore rules ignore it (so the seeded tree id, the broker's included, still equals `<sha>^{tree}`). Without
|
|
332
|
+
* `commit`, with other bytes, or unignored, it is an extra like any other file.
|
|
327
333
|
* Nothing else is an extra the gate may leave, and the dependency bytes of allowance 1 are bound by the environment digest
|
|
328
334
|
* (`rightkit-gate env-digest --snapshot`, which `verifySnapshot` takes as `environment`), so a changed or planted byte under a
|
|
329
335
|
* `node_modules` is refused at the end verify even though this walk lets the directory be.
|
|
@@ -413,7 +419,7 @@ function sha256File(file) {
|
|
|
413
419
|
return h.digest("hex");
|
|
414
420
|
}
|
|
415
421
|
|
|
416
|
-
function inspectSnapshot({ dir, entries, checkout, platform = process.platform, originUrl, ledger, admitNew = false }) {
|
|
422
|
+
function inspectSnapshot({ dir, entries, checkout, commit, platform = process.platform, originUrl, ledger, admitNew = false }) {
|
|
417
423
|
const problem = (message) => ({ problem: message, admitted: [] });
|
|
418
424
|
const ledgerMode = ledger !== undefined || admitNew === true;
|
|
419
425
|
const fold = foldFor(platform);
|
|
@@ -454,6 +460,22 @@ function inspectSnapshot({ dir, entries, checkout, platform = process.platform,
|
|
|
454
460
|
if (!s?.isFile() || fs.readFileSync(config, "utf8") !== gateGitConfigBody(origin)) return `${rel}/config is not in the commit's tree (it is not byte-equal to the gate's config-only file for this checkout's origin)`;
|
|
455
461
|
return null;
|
|
456
462
|
};
|
|
463
|
+
// Allowance 3: the generated source-identity file (see the allowances above). Judged here, never as a ledger candidate, so the ledger
|
|
464
|
+
// and the tree id stay exactly what they were.
|
|
465
|
+
const identityName = fold(SOURCE_IDENTITY_FILE);
|
|
466
|
+
const identityProblem = (r, p) => {
|
|
467
|
+
if (!commit) return `${r} is not in the commit's tree (the source-identity file is admitted only when the snapshot's commit is named)`;
|
|
468
|
+
const s = lstat(p);
|
|
469
|
+
if (!s?.isFile()) return `${r} is not in the commit's tree (it is not a regular file)`;
|
|
470
|
+
if (s.nlink > 1n) return `${r} is not in the commit's tree and has ${s.nlink} hard links (the gate's source-identity file has one)`;
|
|
471
|
+
if (platform !== "win32" && (Number(s.mode) & 0o111) !== 0) return `${r} is not in the commit's tree and is executable (the gate writes the source-identity file without an exec bit)`;
|
|
472
|
+
let want;
|
|
473
|
+
try { want = sourceIdentityBytes({ checkout, commit, entries }); }
|
|
474
|
+
catch (e) { return `${r} is not in the commit's tree and the source identity of commit ${commit} cannot be recomputed to judge it: ${e.message}`; }
|
|
475
|
+
if (!fs.readFileSync(p).equals(want)) return `${r} is not in the commit's tree and is not the gate's source identity for commit ${commit} (its bytes differ from the deterministic file)`;
|
|
476
|
+
if (!neutralIgnored(dir, [r]).has(r)) return `${r} is the gate's source identity but the commit's own ignore rules do not ignore it, so it would change the tree id (add /${SOURCE_IDENTITY_FILE} to the commit's .gitignore)`;
|
|
477
|
+
return null;
|
|
478
|
+
};
|
|
457
479
|
const fileProblem = (r, p, entry) => {
|
|
458
480
|
const s = lstat(p);
|
|
459
481
|
if (!s) return `${r} vanished while it was checked`;
|
|
@@ -519,7 +541,7 @@ function inspectSnapshot({ dir, entries, checkout, platform = process.platform,
|
|
|
519
541
|
else if (dirs.has(key)) found = walk(p, r, false);
|
|
520
542
|
else if (key === ".git") found = gitConfigProblem(r, p);
|
|
521
543
|
else found = ledgerMode ? candidateDir(p, r) : `${r} is not in the commit's tree (a directory the commit does not have)`;
|
|
522
|
-
} else if (!inDeps) found = !byKey.has(key) ? (ledgerMode ? candidate(p, r) : `${r} is not in the commit's tree`) : fileProblem(r, p, byKey.get(key));
|
|
544
|
+
} else if (!inDeps) found = !byKey.has(key) ? (rel === "" && key === identityName ? identityProblem(r, p) : ledgerMode ? candidate(p, r) : `${r} is not in the commit's tree`) : fileProblem(r, p, byKey.get(key));
|
|
523
545
|
if (found) return found;
|
|
524
546
|
}
|
|
525
547
|
return null;
|
|
@@ -889,17 +911,55 @@ export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), ma
|
|
|
889
911
|
try { fs.rmdirSync(stagingRoot); } catch { /* another sync's staging, or not empty */ }
|
|
890
912
|
}
|
|
891
913
|
|
|
892
|
-
// 4. Everything the commit does not hold is removed: the snapshot is exactly the commit (§1).
|
|
914
|
+
// 4. Everything the commit does not hold is removed: the snapshot is exactly the commit (§1). The one exception is the gate's own
|
|
915
|
+
// source-identity file when it already holds this commit's exact bytes (kept, so its mtime and Cargo's fingerprints stay warm).
|
|
893
916
|
assertLockHeld();
|
|
894
|
-
|
|
917
|
+
let identityBytes = null;
|
|
918
|
+
const identity = { file: SOURCE_IDENTITY_FILE, written: false, kept: false, reason: null };
|
|
919
|
+
if (repo.objectFormat !== "sha1") identity.reason = `the repository's object format is ${repo.objectFormat}, and the source identity records SHA-1 ids`;
|
|
920
|
+
else if (wanted.has(SOURCE_IDENTITY_FILE)) identity.reason = `the commit itself tracks ${SOURCE_IDENTITY_FILE}`;
|
|
921
|
+
else {
|
|
922
|
+
try { identityBytes = sourceIdentityBytes({ checkout: repo.checkout, commit, entries }); }
|
|
923
|
+
catch (e) { throw new SnapshotError("error", `the source identity of commit ${commit} cannot be computed: ${e.message}`); }
|
|
924
|
+
}
|
|
925
|
+
const identityPath = path.join(dir, SOURCE_IDENTITY_FILE);
|
|
926
|
+
const keepIdentity = (() => {
|
|
927
|
+
if (!identityBytes) return false;
|
|
928
|
+
const s = lstat(identityPath);
|
|
929
|
+
return !!s?.isFile() && s.nlink === 1n && (process.platform === "win32" || (Number(s.mode) & 0o111) === 0) && fs.readFileSync(identityPath).equals(identityBytes);
|
|
930
|
+
})();
|
|
931
|
+
removed += pruneToTree(dir, entries, process.platform, keepIdentity ? new Set([foldFor(process.platform)(SOURCE_IDENTITY_FILE)]) : new Set());
|
|
932
|
+
if (identityBytes) {
|
|
933
|
+
// Written only when the commit's own ignore rules ignore the name (they are in the snapshot now): an unignored file would change the
|
|
934
|
+
// tree id the broker computes too, so the gate would break every build of that repository. Then nothing is written and the reason is reported.
|
|
935
|
+
if (!neutralIgnored(dir, [SOURCE_IDENTITY_FILE]).has(SOURCE_IDENTITY_FILE)) {
|
|
936
|
+
identity.reason = `the commit's own ignore rules do not ignore /${SOURCE_IDENTITY_FILE}; add it to the commit's .gitignore and no source identity is written to this snapshot until then`;
|
|
937
|
+
if (keepIdentity) fs.unlinkSync(identityPath); // a copy kept from an earlier sync would now be an unignored extra
|
|
938
|
+
} else if (keepIdentity) identity.kept = true;
|
|
939
|
+
else {
|
|
940
|
+
assertLockHeld();
|
|
941
|
+
const stagingRoot2 = `${dir}.staging`;
|
|
942
|
+
const tmp = path.join(stagingRoot2, `identity-${crypto.randomUUID()}`);
|
|
943
|
+
fs.mkdirSync(stagingRoot2, { recursive: true, mode: 0o700 });
|
|
944
|
+
try {
|
|
945
|
+
fs.writeFileSync(tmp, identityBytes, { mode: 0o644, flag: "wx" });
|
|
946
|
+
if (process.platform !== "win32") fs.chmodSync(tmp, 0o644);
|
|
947
|
+
fs.renameSync(tmp, identityPath);
|
|
948
|
+
identity.written = true;
|
|
949
|
+
} finally {
|
|
950
|
+
fs.rmSync(tmp, { force: true });
|
|
951
|
+
try { fs.rmdirSync(stagingRoot2); } catch { /* another sync's staging, or not empty */ }
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
895
955
|
|
|
896
956
|
assertLockHeld();
|
|
897
|
-
const extra = snapshotProblem({ dir, entries, checkout: repo.checkout });
|
|
957
|
+
const extra = snapshotProblem({ dir, entries, checkout: repo.checkout, commit });
|
|
898
958
|
if (extra) throw new SnapshotError("mismatch", `snapshot ${dir} is not exactly commit ${commit} after sync: ${extra}`);
|
|
899
959
|
const actual = snapshotTree({ checkout: repo.checkout, dir, baseTree: tree, repo });
|
|
900
960
|
if (actual !== tree) throw new SnapshotError("mismatch", `snapshot ${dir} is tree ${actual} after sync, not tree ${tree} of commit ${commit}`);
|
|
901
961
|
writeState(stateFile, { schema: STATE_SCHEMA, repo: repo.checkout, repoKey: repo.key, commit, tree, paths: [...wanted.keys()], stat: nextStat, syncedAt: new Date(now()).toISOString() });
|
|
902
|
-
return { schema: SNAPSHOT_SCHEMA, path: dir, repoKey: repo.key, commit, tree, written, removed, modesFixed, unchanged, linksRemoved, hardLinksReplaced, casesFixed, ms: now() - started };
|
|
962
|
+
return { schema: SNAPSHOT_SCHEMA, path: dir, repoKey: repo.key, commit, tree, written, removed, modesFixed, unchanged, linksRemoved, hardLinksReplaced, casesFixed, identity, ms: now() - started };
|
|
903
963
|
} finally {
|
|
904
964
|
release();
|
|
905
965
|
}
|
|
@@ -930,7 +990,7 @@ export function verifySnapshot({ checkout, rev = "HEAD", root = snapshotRoot(),
|
|
|
930
990
|
if (path.resolve(path.dirname(at)) === path.resolve(root)) requirePrivateRoot(root, lstat(root));
|
|
931
991
|
if (!lstat(at)?.isDirectory()) throw new SnapshotError("mismatch", `no snapshot directory at ${at}`);
|
|
932
992
|
// The seeded tree id cannot see an ignored file or follow a link, so the directory itself is walked first (E6, §1 exact snapshot).
|
|
933
|
-
const inspected = snapshotProblem({ dir: at, entries: treeEntries(repo.checkout, commit), checkout: repo.checkout, ledger, admitNew });
|
|
993
|
+
const inspected = snapshotProblem({ dir: at, entries: treeEntries(repo.checkout, commit), checkout: repo.checkout, commit, ledger, admitNew });
|
|
934
994
|
const extra = ledger !== undefined || admitNew ? inspected.problem : inspected;
|
|
935
995
|
if (extra) throw new SnapshotError("mismatch", `the snapshot at ${at} is not exactly commit ${commit}${ledger !== undefined || admitNew ? " plus its stage-output ledger" : ""}: ${extra}`);
|
|
936
996
|
const actual = snapshotTree({ checkout: repo.checkout, dir: at, baseTree: tree, repo });
|
package/stage-commands.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
@@ -15,6 +15,7 @@ import fs from "node:fs";
|
|
|
15
15
|
import os from "node:os";
|
|
16
16
|
import path from "node:path";
|
|
17
17
|
import { spawnSync } from "./background-process.mjs";
|
|
18
|
+
import { SOURCE_IDENTITY_FILE } from "./snapshot-identity.mjs";
|
|
18
19
|
|
|
19
20
|
export const LEDGER_RESERVED_SEGMENTS = Object.freeze(["target", ".right-release", ".git", "node_modules"]);
|
|
20
21
|
export const NULL_DEVICE = process.platform === "win32" ? "NUL" : "/dev/null";
|
|
@@ -99,6 +100,10 @@ export function walkSnapshot({ dir, tracked, dependencyRoots = new Set(), run =
|
|
|
99
100
|
const bad = reserved(r);
|
|
100
101
|
if (bad) { problems.push(`${r} is under the reserved path segment ${JSON.stringify(bad)} (a stage output is never written there)`); continue; }
|
|
101
102
|
if (st.nlink > 1) { problems.push(`${r} has ${st.nlink} hard links (a stage output has exactly one)`); continue; }
|
|
103
|
+
// The gate's own generated source-identity file (snapshot-identity.mjs, GC-A23) is neither a stage output nor a ledger entry. Its bytes,
|
|
104
|
+
// type, mode, link count and ignore status are judged against the commit by snapshot.mjs (inspectSnapshot), which every stage-open
|
|
105
|
+
// and stage-close verify runs right after this walk; this walk only keeps it out of the ledger.
|
|
106
|
+
if (rel === "" && key === f(SOURCE_IDENTITY_FILE)) continue;
|
|
102
107
|
candidates.push({ rel: r, abs: p, size: st.size, execBit: platform !== "win32" && (st.mode & 0o111) !== 0 });
|
|
103
108
|
}
|
|
104
109
|
return any;
|
|
@@ -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
|
+
}
|