@rightkit/release 0.6.51 → 0.6.54
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 +1 -1
- package/adapter-env.mjs +16 -105
- package/admission-host.mjs +14 -1
- package/bin/darwin/rightkit-swap +0 -0
- package/bin/rightkit-gate.mjs +609 -404
- package/broker-admission.mjs +122 -2
- package/build-launch.mjs +52 -58
- package/build-release.mjs +2 -2
- package/cargo-ledger.mjs +24 -5
- package/cargo-target-shim.mjs +54 -23
- package/cargo-target.mjs +2 -2
- package/carried-adapter-run.mjs +7 -8
- package/carried-cargo-run.mjs +1 -1
- package/ci-compile-admission.mjs +1 -1
- package/clippy-route.mjs +65 -18
- package/compile-inputs.mjs +91 -15
- package/cross-targets.mjs +5 -3
- package/deps-cargo-lock.mjs +1 -1
- package/deterministic-scans.mjs +789 -259
- package/development.mjs +33 -7
- package/direct-receipt.mjs +3 -5
- package/feature-coverage.mjs +45 -9
- package/feature-partition.mjs +204 -0
- package/feature-sets.mjs +113 -0
- package/gate-acceptance.mjs +187 -115
- package/gate-seam.mjs +352 -0
- package/gate-serve.mjs +34 -2
- package/gate-stages.mjs +6 -2
- package/ghsa-audit.mjs +19 -4
- package/heavy-command.mjs +5 -4
- package/install-tauri-authenticode.mjs +73 -4
- package/ios-dev.mjs +3 -3
- package/ios-package-recipe.mjs +6 -6
- package/linux-setup.mjs +3 -2
- package/local-publish.mjs +113 -17
- package/lock-identity.mjs +24 -100
- package/managed-cargo.mjs +3 -3
- package/managed-root-guard.mjs +2 -2
- package/managed-roots.mjs +3 -3
- package/native-adapters.mjs +41 -244
- package/native-helpers.mjs +1 -1
- package/pack-digest.mjs +1 -1
- package/package-recipe-targets.mjs +3 -3
- package/package.json +2 -2
- package/publication-gate.mjs +29 -6
- package/publish-cargo.mjs +4 -5
- package/publish-local-cargo.mjs +77 -1
- package/qualification-verify.mjs +76 -49
- package/receipt-signature.mjs +104 -0
- package/release-switch-registry.json +4 -0
- package/release-switch-scan.mjs +13 -10
- package/rightkit-versions.json +126 -113
- package/scan-digest.mjs +43 -14
- package/seam-broker.mjs +168 -0
- package/snapshot-check.mjs +4 -1
- package/snapshot-dependency-reuse.mjs +1 -1
- package/snapshot-metadata.mjs +24 -35
- package/snapshot.mjs +328 -49
- package/stage-commands.mjs +59 -5
- package/stage-ledger.mjs +2 -2
- package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
- package/stage-sidecar.mjs +3 -3
- package/tauri-bundle-marker.mjs +5 -2
- package/tauri-locked.mjs +1 -1
- package/tool-build.mjs +8 -6
- package/unit-gate.mjs +40 -10
- package/web-build.mjs +6 -0
- package/broker-handshake.mjs +0 -160
- package/broker-wire.mjs +0 -278
- package/build-ownership.mjs +0 -1578
- package/cargo-shapes.mjs +0 -332
- package/cargo-width.mjs +0 -49
- package/carrier-census.mjs +0 -124
- package/clippy-equivalence.mjs +0 -202
- package/freshness-census.mjs +0 -405
- package/handle-revocation.mjs +0 -100
- package/handle-revocation.rust-vector.json +0 -1
- package/handle-revocation.vectors.json +0 -53
- package/legion-freeze-consumer.mjs +0 -241
- package/linux-qualifier.mjs +0 -83
- package/native-tool-planning.mjs +0 -94
- package/owner-process-proof.mjs +0 -14
- package/ownership-mark.mjs +0 -191
- package/ownership-recover.mjs +0 -78
- package/pnpm-adapter-grammar.mjs +0 -226
- package/provenance-verify.mjs +0 -413
- package/snapshot-broker.mjs +0 -808
- package/snapshot-request.mjs +0 -722
- package/unit-list-compile.mjs +0 -356
package/broker-admission.mjs
CHANGED
|
@@ -15,8 +15,16 @@
|
|
|
15
15
|
// an unreadable broker never makes a scan immortal.
|
|
16
16
|
import fs from "node:fs";
|
|
17
17
|
import { spawnBrokerClient } from "./broker-client.mjs";
|
|
18
|
-
import
|
|
19
|
-
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
|
|
20
|
+
const REQUEST_REF_SCHEMA = "rustright.request-ref.v1";
|
|
21
|
+
/** The request reference the client writes at submit (RUSTRIGHT_REQUEST_ID_FILE: `{ schema, requestId, workspace }`), or a throw (moved here from snapshot-request.mjs, deleted at plan step 5). */
|
|
22
|
+
function readRequestRef(file) {
|
|
23
|
+
let ref;
|
|
24
|
+
try { ref = JSON.parse(fs.readFileSync(file, "utf8")); } catch (e) { throw new Error(`no request reference at ${file} (${e.message})`); }
|
|
25
|
+
if (ref?.schema !== REQUEST_REF_SCHEMA || typeof ref.requestId !== "string" || !ref.requestId || typeof ref.workspace !== "string" || !path.isAbsolute(ref.workspace)) throw new Error(`${file} is not a ${REQUEST_REF_SCHEMA}`);
|
|
26
|
+
return ref;
|
|
27
|
+
}
|
|
20
28
|
|
|
21
29
|
/** How long a cancelled carried scan may take to end by itself before its process tree is stopped. */
|
|
22
30
|
export const CARRIED_CANCEL_GRACE_MS = 15_000;
|
|
@@ -182,3 +190,115 @@ export function watchBrokerAdmission({ clock, refFiles, live, poller = null, int
|
|
|
182
190
|
},
|
|
183
191
|
};
|
|
184
192
|
}
|
|
193
|
+
|
|
194
|
+
// ---- moved from broker-wire.mjs (deleted at reset step 5): the parts the seam's run clock still uses ----
|
|
195
|
+
const TERMINAL_STATES = new Set(["SUCCEEDED", "FAILED", "CANCELLED", "TIMED_OUT", "REJECTED"]);
|
|
196
|
+
const REFUSAL_CLASSES = Object.freeze({ RK_ADMISSION_PAUSED: "paused", RK_JOB_SUSPENDED: "suspended", RK_JOB_NOT_FOUND: "not-found", RK_ACTIVATION_PENDING: "activation-pending", RK_CUTOVER_DRAIN_PENDING: "cutover-drain" });
|
|
197
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
198
|
+
|
|
199
|
+
// ---- the typed refusals of BROKER-CONTRACT section 16: each its own diagnosis, and whether waiting clears it ----
|
|
200
|
+
// RK_BROKER_BUSY GB-52 every pipe instance stayed busy: the connection never opened, no byte was sent (a wait, not an outage) retryable
|
|
201
|
+
// RK_RECOVERY_PENDING GB-78 restart recovery of the workspace is still running after the bounded wait: nothing was admitted retryable
|
|
202
|
+
// RK_STORAGE_BUDGET_UNAVAILABLE GB-39 the storage budget could not be settled within bounds.budgetAdmissionWaitMs: the root was not admitted retryable
|
|
203
|
+
// RK_ADAPTER_PIN_REQUIRED GB-51 a Gradle wrapper without a pinned distributionSha256Sum: START failed before any spawn not retryable (the commit must pin it)
|
|
204
|
+
// RK_OPERATION_DEADLINE GB-52 the client's operation deadline passed: it cancelled by id and watched for the terminal state not retryable (never resubmitted)
|
|
205
|
+
// A retryable refusal is a wait the gate makes within its own deadline (each retry a new carrier and sub-handle, a refused submission being a settled, spawned:false member); it is never
|
|
206
|
+
// success and never a generic failure. `refusal` is the class name a diagnosis carries.
|
|
207
|
+
export const TYPED_REFUSALS = Object.freeze({
|
|
208
|
+
RK_BROKER_BUSY: Object.freeze({ refusal: "broker-busy", retryable: true }),
|
|
209
|
+
RK_RECOVERY_PENDING: Object.freeze({ refusal: "recovery-pending", retryable: true }),
|
|
210
|
+
RK_STORAGE_BUDGET_UNAVAILABLE: Object.freeze({ refusal: "storage-budget-unavailable", retryable: true }),
|
|
211
|
+
RK_ADAPTER_PIN_REQUIRED: Object.freeze({ refusal: "adapter-pin-required", retryable: false }),
|
|
212
|
+
RK_OPERATION_DEADLINE: Object.freeze({ refusal: "operation-deadline", retryable: false }),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The typed refusal one reply names, or null: the event's (or its receipt's) `code`, else a message that STARTS with the code (`RK_RECOVERY_PENDING: restart recovery ...`, which is how the
|
|
217
|
+
* broker words them). A code merely mentioned inside other text is not a refusal. `{ code, refusal, retryable }`.
|
|
218
|
+
*/
|
|
219
|
+
export function typedRefusalOf(...sources) {
|
|
220
|
+
for (const source of sources) {
|
|
221
|
+
if (!isObject(source)) continue;
|
|
222
|
+
const named = typeof source.code === "string" && Object.hasOwn(TYPED_REFUSALS, source.code) ? source.code : null;
|
|
223
|
+
const prefixed = named === null ? ["error", "message"].map((key) => (typeof source[key] === "string" ? /^\s*(?:error:\s*)?(RK_[A-Z0-9_]+)\b/.exec(source[key])?.[1] : null)).find((code) => code && Object.hasOwn(TYPED_REFUSALS, code)) ?? null : null;
|
|
224
|
+
const code = named ?? prefixed;
|
|
225
|
+
if (code !== null) return { code, ...TYPED_REFUSALS[code] };
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* What a client concludes from one STATUS or RESULT line about a request it knows by id. Only `terminal` is a build outcome, and only after the receipt's own signed
|
|
232
|
+
* validation; every other kind keeps the broker's code, state and identity instead of collapsing into a generic receipt failure, and a known request is reconciled by
|
|
233
|
+
* its durable id, never resubmitted because a diagnosis improved:
|
|
234
|
+
* { kind: "live", id, state } non-terminal with an absent or null receipt (pending; never a result, never green)
|
|
235
|
+
* { kind: "terminal", id, state, receipt } a terminal state with a receipt object whose id is the request's
|
|
236
|
+
* { kind: "unavailable", id, reason } the front gate's STATUS with state UNAVAILABLE and its diagnostic code
|
|
237
|
+
* { kind: "refused", code, refusal, message } a RESULT with status REJECTED: paused, suspended, not-found, activation-pending, cutover-drain, other
|
|
238
|
+
* { kind: "malformed", message } not a typed object, another request's id or receipt, no state, a terminal state without a receipt, a receipt that is not an object
|
|
239
|
+
*/
|
|
240
|
+
export function diagnoseControlReply(event, expectedId = null) {
|
|
241
|
+
const malformed = (message) => ({ kind: "malformed", message });
|
|
242
|
+
if (!isObject(event) || typeof event.type !== "string") return malformed("the reply is not a typed object");
|
|
243
|
+
const id = typeof event.id === "string" ? event.id : null;
|
|
244
|
+
if (expectedId !== null && id !== null && expectedId !== id) return malformed("the reply names another request");
|
|
245
|
+
const receiptOf = (state) => {
|
|
246
|
+
const receipt = event.receipt;
|
|
247
|
+
if (isObject(receipt)) {
|
|
248
|
+
const receiptId = typeof receipt.id === "string" ? receipt.id : null;
|
|
249
|
+
const want = expectedId ?? id;
|
|
250
|
+
if (want !== null && receiptId !== null && want !== receiptId) return malformed("the receipt is for another request");
|
|
251
|
+
if (want !== null && receiptId === null) return malformed("the receipt names no request");
|
|
252
|
+
// A root the broker refused before it ran (a storage budget that could not be settled, a recovery still running, a wrapper without a pinned distribution) ends FAILED with its code:
|
|
253
|
+
// it is the typed refusal, never a receipt to validate and never a build outcome. Only a failed or rejected state is read so; a SUCCEEDED receipt is never turned into a refusal.
|
|
254
|
+
const typed = state === "FAILED" || state === "REJECTED" ? typedRefusalOf(receipt, { error: event.error }) : null;
|
|
255
|
+
if (typed) return { kind: "refused", id, state, code: typed.code, refusal: typed.refusal, retryable: typed.retryable, message: typeof receipt.error === "string" ? receipt.error : typeof event.error === "string" ? event.error : "" };
|
|
256
|
+
return { kind: "terminal", id, state, receipt };
|
|
257
|
+
}
|
|
258
|
+
if (receipt === undefined || receipt === null) return TERMINAL_STATES.has(state) ? malformed("a finished job's reply carries no receipt") : { kind: "live", id, state };
|
|
259
|
+
return malformed("the receipt is not an object");
|
|
260
|
+
};
|
|
261
|
+
if (event.type === "STATUS") {
|
|
262
|
+
if (typeof event.state !== "string" || event.state === "") return malformed("the status carries no state");
|
|
263
|
+
if (event.state === "UNAVAILABLE") {
|
|
264
|
+
const reason = (isObject(event.diagnostic) && typeof event.diagnostic.code === "string" ? event.diagnostic.code : null) ?? (typeof event.code === "string" ? event.code : null) ?? "unavailable";
|
|
265
|
+
return { kind: "unavailable", id, reason };
|
|
266
|
+
}
|
|
267
|
+
return receiptOf(event.state);
|
|
268
|
+
}
|
|
269
|
+
if (event.type === "RESULT") {
|
|
270
|
+
if (event.status === "REJECTED") {
|
|
271
|
+
const code = typeof event.code === "string" ? event.code : null;
|
|
272
|
+
const typed = typedRefusalOf(event);
|
|
273
|
+
if (typed) return { kind: "refused", code: typed.code, refusal: typed.refusal, retryable: typed.retryable, message: typeof event.error === "string" ? event.error : "" };
|
|
274
|
+
return { kind: "refused", code, refusal: (code !== null && Object.hasOwn(REFUSAL_CLASSES, code) ? REFUSAL_CLASSES[code] : "other"), retryable: false, message: typeof event.error === "string" ? event.error : "" };
|
|
275
|
+
}
|
|
276
|
+
return typeof event.status === "string" && TERMINAL_STATES.has(event.status) ? receiptOf(event.status) : malformed("the result carries no terminal status");
|
|
277
|
+
}
|
|
278
|
+
return malformed("the reply is not a STATUS or RESULT");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// ---- GB-52: an end-to-end operation deadline and explicit cancellation for carried calls (BROKER-CONTRACT section 16) ----
|
|
283
|
+
// RustRight's client bounds one submit-and-watch operation with RUSTRIGHT_OPERATION_DEADLINE_MS (absent or 0: none; a user-set test cap or stall limit is never replaced
|
|
284
|
+
// by a universal duration). Past it the client does not abandon or resubmit the job: it sends CANCEL by id and polls STATUS for the terminal state within
|
|
285
|
+
// RUSTRIGHT_CANCEL_WAIT_MS (default 30000), failing with `operation deadline of N ms passed; request <id>: cancelConfirmed: <bool>, terminal state: <state | not observed>`.
|
|
286
|
+
// An unobserved state keeps ownership unknown. `RK_BROKER_BUSY` (every pipe instance busy: a wait) is distinct from `RK_BROKER_UNAVAILABLE`.
|
|
287
|
+
export const OPERATION_DEADLINE_ENV = "RUSTRIGHT_OPERATION_DEADLINE_MS";
|
|
288
|
+
export const CANCEL_WAIT_ENV = "RUSTRIGHT_CANCEL_WAIT_MS";
|
|
289
|
+
export const DEFAULT_CANCEL_WAIT_MS = 30_000;
|
|
290
|
+
/** The gate's remaining stage budget, as an absolute epoch-ms instant a stage sets for its children (unset: no budget). */
|
|
291
|
+
export const STAGE_DEADLINE_AT_ENV = "RK_GATE_STAGE_DEADLINE_AT";
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The environment delta that gives one carried call its operation deadline: the caller's own RUSTRIGHT_OPERATION_DEADLINE_MS is never replaced (a user-set cap wins);
|
|
295
|
+
* otherwise `deadlineMs` (a scan's or stage's own limit) or the time left to `deadlineAt` (STAGE_DEADLINE_AT_ENV in `env`), at least 1 ms. `{}` when there is no budget.
|
|
296
|
+
*/
|
|
297
|
+
export function operationDeadlineEnv({ env = {}, deadlineMs = null, deadlineAt = null, now = Date.now() } = {}) {
|
|
298
|
+
const set = Object.entries(env).find(([key]) => key.toUpperCase() === OPERATION_DEADLINE_ENV);
|
|
299
|
+
if (set && String(set[1]).trim() !== "") return {};
|
|
300
|
+
const at = deadlineAt ?? (Number.isFinite(Number(env[STAGE_DEADLINE_AT_ENV])) && Number(env[STAGE_DEADLINE_AT_ENV]) > 0 ? Number(env[STAGE_DEADLINE_AT_ENV]) : null);
|
|
301
|
+
const budget = deadlineMs ?? (at !== null ? at - now : null);
|
|
302
|
+
if (!Number.isFinite(budget) || budget === null) return {};
|
|
303
|
+
return { [OPERATION_DEADLINE_ENV]: String(Math.max(1, Math.trunc(budget))) };
|
|
304
|
+
}
|
package/build-launch.mjs
CHANGED
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
// - swift <args> -> <rustright> run rightkit-swift -- <args> (a native helper's SwiftPM build; carried like the others on a snapshot stage)
|
|
19
19
|
// A carried adapter step's own environment (the `env` the step declares, passed as `host.stepEnv`) is forwarded as the adapter request's
|
|
20
20
|
// environment: the door sets RUSTRIGHT_ADAPTER_ENV to exactly those names (adapter-env.mjs), the broker accepts the names the adapter's
|
|
21
|
-
// registration lists in `env
|
|
22
|
-
// RUSTRIGHT_ADAPTER_ENV.
|
|
21
|
+
// registration lists in `env` (RK_ADAPTER_ENV_DENIED, adapter.rs check_environment; the client refuses a reserved name first, shims.rs adapter_environment), and the
|
|
22
|
+
// values are bound into the signed request. A step with no env gets no RUSTRIGHT_ADAPTER_ENV.
|
|
23
23
|
// - rustright run <adapter> -- <args> on a snapshot stage -> the same step as the adapter's own program (pnpm, node, swift), so
|
|
24
24
|
// the door's rules apply to it; any other `rustright <command>` there is refused (RK_BUILD_LAUNCH_REFUSED)
|
|
25
|
-
// - pnpm exec <target> -> only a target in EXEC_TARGETS (tauri
|
|
26
|
-
//
|
|
25
|
+
// - pnpm exec <target> -> only a target in EXEC_TARGETS (tauri) on a broker host; pnpm exec right-release runs the gate's own right-release: the door keeps this one list because the
|
|
26
|
+
// broker enforces a target list only when the operator's pnpm registration carries `opaqueTargets.exec`, so `pnpm exec node -e ...` would otherwise pass the node flag ban
|
|
27
27
|
// - anything else -> refused on a managed host: no broker adapter runs it yet, and running it directly would bypass the
|
|
28
28
|
// broker (fail closed; the per-app impact is mapped in rightkit#1241)
|
|
29
|
-
// - xcodegen | xcodebuild | gradle (./gradlew) | cmake -> the tool's own
|
|
30
|
-
//
|
|
29
|
+
// - xcodegen | xcodebuild | gradle (./gradlew) | cmake -> the tool's own adapter (native-adapters.mjs maps the tool to `rightkit-<tool>` and makes its paths relative to the step's directory); the broker
|
|
30
|
+
// judges the argv, the call's shape and its files at admission (RK_ADAPTER_UNKNOWN, RK_ADAPTER_ARGV_DENIED, RK_ADAPTER_PIN_REQUIRED); never an environment; a
|
|
31
31
|
// signing-properties file is a typed path handoff that a broker route refuses before launch (RK_NATIVE_SIGNING_FILE_UNSUPPORTED). The client of an uncarried one is the resolved
|
|
32
32
|
// executor's (the declared Linux broker's, else the managed runtime client), never a PATH lookup. `createNativeRunner` is the production runner the iOS and Android lanes inject.
|
|
33
33
|
// A launch from inside a broker job is routed the same way: the broker attributes it to its parent job by the parent's own
|
|
@@ -38,14 +38,13 @@ import { fileURLToPath } from "node:url";
|
|
|
38
38
|
import { resolveExecutor } from "./gate-executor.mjs";
|
|
39
39
|
import { gateNoBroker } from "./managed-cargo.mjs";
|
|
40
40
|
import { resolveExecutable } from "./admission-host.mjs";
|
|
41
|
-
import { CARRIED_CARGO_MAP_ENV as CARRIED_MAP_ENV, carriedCargoMapOf,
|
|
41
|
+
import { CARRIED_CARGO_MAP_ENV as CARRIED_MAP_ENV, carriedCargoMapOf, runStageAdapter } from "./stage-seam.mjs";
|
|
42
42
|
import { spawnSync } from "./background-process.mjs";
|
|
43
43
|
import { managedRuntimeClient } from "./managed-roots.mjs";
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
44
|
+
import { QA_HANDOFF_ENV, adapterEnvLaunch } from "./adapter-env.mjs";
|
|
45
|
+
import { cargoCommandIndex, expandCargoAliases } from "./cargo-target-shim.mjs";
|
|
46
46
|
import { swiftScratchRefusal } from "./swift-scratch.mjs";
|
|
47
|
-
import { NATIVE_ADAPTERS, NATIVE_SIGNING_FILE_ENV,
|
|
48
|
-
import { PNPM_ADAPTER_GRAMMAR, adapterArgvRefusal, liveAdapterGrammar, scanAdapterArgv } from "./pnpm-adapter-grammar.mjs";
|
|
47
|
+
import { NATIVE_ADAPTERS, NATIVE_SIGNING_FILE_ENV, nativeManagedOutputs, nativeOutputsFromReceipt, nativeSigningFileRefusal, nativeStateDir, nativeToolLaunch, nativeToolOf } from "./native-adapters.mjs";
|
|
49
48
|
|
|
50
49
|
/** The environment variable the door sets for a stage that runs from a commit snapshot (gate-stages.mjs CHECKOUT_ENV). */
|
|
51
50
|
const SNAPSHOT_STAGE_ENV = "RK_GATE_CHECKOUT";
|
|
@@ -66,8 +65,9 @@ const CARRIED_ADAPTER_RUN = fileURLToPath(new URL("./carried-adapter-run.mjs", i
|
|
|
66
65
|
const PNPM_VALUE_OPTIONS = new Set(["--dir", "-C", "--filter", "-F", "--prefix", "--config", "--reporter", "--workspace-concurrency"]);
|
|
67
66
|
// Node flags that change no code path; everything else before the script (-e, --eval, -p, --import, -r, --require, --loader, …) refuses.
|
|
68
67
|
const NODE_FLAGS = /^--(?:disable-warning=[A-Za-z0-9_-]+|no-experimental-webstorage|no-warnings|enable-source-maps|max-old-space-size=\d+|stack-size=\d+)$/;
|
|
69
|
-
/** The pnpm `exec` targets the door
|
|
70
|
-
|
|
68
|
+
/** The pnpm `exec` targets the door sends to the broker: exactly the reference registration's `opaqueTargets.exec` (GB-03; rightkit#1528). `pnpm exec right-release`
|
|
69
|
+
* runs this package's own right-release in the gate's Node (GB-06, below); vite runs through a committed package script (`pnpm run <script>`). */
|
|
70
|
+
export const EXEC_TARGETS = Object.freeze(["tauri"]);
|
|
71
71
|
/** The broker adapter a `rustright run <adapter> -- ...` names, and the program whose door rules judge the step. */
|
|
72
72
|
const ADAPTER_PROGRAMS = Object.freeze({ "rightkit-pnpm": "pnpm", "rightkit-node": "node", "rightkit-swift": "swift", "rightkit-xcodegen": "xcodegen", "rightkit-xcodebuild": "xcodebuild", "rightkit-gradle": "gradle", "rightkit-cmake": "cmake" });
|
|
73
73
|
const name = (program) => path.basename(String(program ?? "").replaceAll("\\", "/")).replace(/\.(exe|cmd|bat)$/i, "").toLowerCase();
|
|
@@ -109,7 +109,7 @@ function pnpmCommandAt(words) {
|
|
|
109
109
|
/**
|
|
110
110
|
* The pnpm command of an argv read LENIENTLY (the first word that is not an option or an option's value), or null. Only the install-skip of a snapshot
|
|
111
111
|
* stage uses it (a stage that skips `install` runs nothing, so a lenient reading can only skip more); everything the door SENDS is judged by the
|
|
112
|
-
*
|
|
112
|
+
* broker's own adapter parser at admission (RK_ADAPTER_ARGV_DENIED, rustright admission_impl.rs `admit_adapter`).
|
|
113
113
|
*/
|
|
114
114
|
export function pnpmCommandOf(args) {
|
|
115
115
|
const words = args.map(String);
|
|
@@ -170,14 +170,16 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
170
170
|
// `.rustright/broker.json`, or the host lists them in `buildRules.forwardTestEnv`). Nothing here carries a signing key or credential.
|
|
171
171
|
const cargoHandoffEnv = (cargoArgs) => {
|
|
172
172
|
const present = Object.keys(handoffEnv());
|
|
173
|
-
|
|
173
|
+
const cargoWords = expandCargoAliases(cargoArgs.map(String));
|
|
174
|
+
const cargoAt = cargoCommandIndex(cargoWords);
|
|
175
|
+
if (!present.length || cargoAt === null || !["test", "bench", "run", "nextest"].includes(cargoWords[cargoAt])) return {};
|
|
174
176
|
for (const key of present) {
|
|
175
177
|
if (!(path.isAbsolute(env[key]) || path.win32.isAbsolute(env[key])) || env[key].split(/[\\/]/).includes("..")) refuse(`${name(command)} ${args.join(" ")}: ${key} must be an absolute path with no '..' (the signed artifact's exact path); it is not forwarded`);
|
|
176
178
|
}
|
|
177
179
|
const existing = String(env.RUSTRIGHT_FORWARD_ENV ?? "").split(",").map((n) => n.trim()).filter(Boolean);
|
|
178
180
|
return { env: { RUSTRIGHT_FORWARD_ENV: [...new Set([...existing, ...present])].join(",") } };
|
|
179
181
|
};
|
|
180
|
-
// A snapshot stage's `cargo` and `rustright cargo` steps are carried (
|
|
182
|
+
// A snapshot stage's `cargo` and `rustright cargo` steps are carried (stage-seam.mjs), never sent to the client: one signed, ledgered
|
|
181
183
|
// request per call, from the step's working directory, on every platform (rightkit#1301 F3).
|
|
182
184
|
const carriedArgs = program === "cargo" ? args : program === "rustright" && String(args[0]) === "cargo" ? args.slice(1) : null;
|
|
183
185
|
// R3-X02: the broker's cargo-ndk output rule (rustright-policy ndk.rs `check_output_dir`): the libraries go to a directory strictly inside the workspace, never `.git`. The lexical half is judged here, before the send.
|
|
@@ -193,12 +195,12 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
193
195
|
const adapterMap = ["pnpm", "node", "swift"].includes(program) || nativeToolOf(command) !== null ? carriedCargoMapOf(env) : null;
|
|
194
196
|
if (adapterMap?.error) refuse(`${name(command)} ${args.join(" ")}: ${adapterMap.error}; a snapshot stage's step is never sent to the client around its carrier`);
|
|
195
197
|
// The step's own environment rides the adapter request (adapter-env.mjs): RUSTRIGHT_ADAPTER_ENV names exactly what the step declares, plus the
|
|
196
|
-
// signed-artifact handoff (GB-05) when a sign step set it in this environment.
|
|
197
|
-
//
|
|
198
|
-
|
|
198
|
+
// signed-artifact handoff (GB-05) when a sign step set it in this environment. The gate judges only what it alone can (signing material, a name or value that
|
|
199
|
+
// cannot ride the list); a reserved or unregistered key is refused by the client (shims.rs adapter_environment) and by the broker's admission
|
|
200
|
+
// (RK_ADAPTER_ENV_DENIED, admission_impl.rs `admit_adapter`, adapter.rs check_environment), naming the key and the registered set.
|
|
201
|
+
const stepEnvLaunch = () => {
|
|
199
202
|
try {
|
|
200
|
-
|
|
201
|
-
return adapterEnvLaunch({ ...(host.stepEnv ?? {}), ...handoffEnv() }, { registered });
|
|
203
|
+
return adapterEnvLaunch({ ...(host.stepEnv ?? {}), ...handoffEnv() });
|
|
202
204
|
} catch (error) {
|
|
203
205
|
const refusal = new Error(`${name(command)} ${args.join(" ")}: ${error.message}`);
|
|
204
206
|
refusal.code = BUILD_LAUNCH_REFUSED;
|
|
@@ -211,7 +213,7 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
211
213
|
// identity: nothing is launched until the exact client is found, and none is found by searching PATH.
|
|
212
214
|
const executorClient = () => executor.client ?? managedRuntimeClient(env, platform, exists) ?? refuse(`${name(command)} ${args.join(" ")}: no installed RustRight client for this broker-managed ${platform} host (the declared Linux broker client, or the managed runtime client); a native build tool is never launched through a PATH lookup`, "RK_NATIVE_CLIENT_UNRESOLVED");
|
|
213
215
|
const adapterLaunch = (adapter, adapterArgs, resolveClient = client) => {
|
|
214
|
-
const stepLaunchEnv = stepEnvLaunch(
|
|
216
|
+
const stepLaunchEnv = stepEnvLaunch();
|
|
215
217
|
const launchEnv = { ...(Object.keys(stepLaunchEnv).length ? { env: stepLaunchEnv } : {}), ...(stepLaunchEnv.signingEnvDropped?.length ? { signingEnvDropped: stepLaunchEnv.signingEnvDropped } : {}) };
|
|
216
218
|
return adapterMap?.map ? { command: process.execPath, args: [CARRIED_ADAPTER_RUN, adapter, "--", ...adapterArgs], ...launchEnv } : { command: resolveClient(), args: ["run", adapter, "--", ...adapterArgs], ...launchEnv };
|
|
217
219
|
};
|
|
@@ -231,22 +233,15 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
231
233
|
return buildLaunch(adapterProgram, args.slice(3), host);
|
|
232
234
|
}
|
|
233
235
|
// GB-51 / RA-07..RA-09: a declared native build tool (xcodegen, xcodebuild, Gradle and its wrapper, CMake) is a snapshot-bound adapter job of its own constrained adapter (native-adapters.mjs): its argv is
|
|
234
|
-
// judged by the
|
|
235
|
-
//
|
|
236
|
+
// judged by the broker at admission (an output override, an unregistered flag or a shape it has no managed form for is refused there: RK_ADAPTER_ARGV_DENIED, RK_ADAPTER_PIN_REQUIRED), its paths are made
|
|
237
|
+
// relative to the step's directory here, and the step carries no environment of its own: the signing-properties file is a typed handoff, never an environment, and refuses
|
|
236
238
|
// here when no broker can carry it. The client is the resolved executor's. Nothing runs the tool around the broker, and no generic spawn stands in for a compiler-capable phase.
|
|
237
239
|
const nativeTool = nativeToolOf(command);
|
|
238
240
|
if (nativeTool !== null) {
|
|
239
241
|
const entry = NATIVE_ADAPTERS[nativeTool];
|
|
240
242
|
const cwd = host.cwd ?? process.cwd();
|
|
241
|
-
const advertised = host.brokerCapabilities;
|
|
242
|
-
if (advertised !== undefined && advertised !== null && !(advertised instanceof Set ? advertised : new Set(advertised)).has(entry.capability)) refuse(`${name(command)} ${args.join(" ")}: the broker does not advertise ${entry.capability}; nothing was sent`, "RK_NATIVE_CAPABILITY_MISSING");
|
|
243
243
|
const launch = nativeToolLaunch(nativeTool, args, { cwd });
|
|
244
244
|
if (launch.refusal) refuse(`${launch.refusal.code}: ${launch.refusal.message}`, launch.refusal.code);
|
|
245
|
-
const fsProblem = nativeCallFsProblem(nativeTool, launch.args, { cwd, ...(host.nativeFs ? { fsOps: host.nativeFs } : {}) });
|
|
246
|
-
if (fsProblem) {
|
|
247
|
-
const code = fsProblem.pin ? "RK_ADAPTER_PIN_REQUIRED" : "RK_ADAPTER_ARGV_DENIED";
|
|
248
|
-
refuse(`${code}: ${nativeTool} ${launch.args.join(" ")}: ${fsProblem.message}; the broker's ${entry.adapter} adapter (capability ${entry.capability}) would refuse it (rightkit#1241), so it is not sent`, code);
|
|
249
|
-
}
|
|
250
245
|
const signing = nativeSigningFileRefusal(nativeTool, host.signingFile, { signerRoot: host.signerRoot });
|
|
251
246
|
if (signing) refuse(`${signing.code}: ${signing.message}`, signing.code);
|
|
252
247
|
const launchedBare = adapterLaunch(entry.adapter, launch.args, executorClient);
|
|
@@ -256,7 +251,7 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
256
251
|
const snapshotRoot = adapterMap?.map?.broker?.snapshot?.path;
|
|
257
252
|
const real = (dir) => { try { return realpathSync(dir); } catch { return path.resolve(dir); } };
|
|
258
253
|
const relativeCwd = typeof snapshotRoot === "string" && snapshotRoot ? path.relative(real(snapshotRoot), real(cwd)).split(path.sep).join("/") : null;
|
|
259
|
-
return { ...launched, native: { tool: nativeTool, adapter: entry.adapter,
|
|
254
|
+
return { ...launched, native: { tool: nativeTool, adapter: entry.adapter, args: launch.args, relativeCwd, carried: Boolean(adapterMap?.map) } };
|
|
260
255
|
}
|
|
261
256
|
if (program === "swift") {
|
|
262
257
|
// GB-67: the broker owns SwiftPM's scratch and build path; a caller that names one is refused here, typed, before anything is sent.
|
|
@@ -287,15 +282,18 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
287
282
|
}
|
|
288
283
|
if (program === "pnpm") {
|
|
289
284
|
const words = args.map(String);
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
285
|
+
// rightkit#1528: an app config's `pnpm exec right-release <args>` is this package's own right-release (GB-06), run in the gate's Node under the same
|
|
286
|
+
// NODE_OPTIONS rule; the broker's registration admits only `tauri` as an exec target, so it is never sent there.
|
|
287
|
+
if (words[0] === "exec" && words[1] === "right-release") {
|
|
288
|
+
const options = String(env.NODE_OPTIONS ?? "");
|
|
289
|
+
if (options.trim() !== "" && options !== String(process.env.NODE_OPTIONS ?? "")) refuse(`pnpm ${words.join(" ")}: NODE_OPTIONS is neither empty nor exactly this process's own; on a broker-managed host the door runs right-release only with no added startup code`);
|
|
290
|
+
return { command: process.execPath, args: [OWN_RIGHT_RELEASE, ...words.slice(2)] };
|
|
291
|
+
}
|
|
292
|
+
// The pnpm argv grammar (command token, global flags, `--if-present`, the opaque tail, the pack destination, the snapshot subcommands) is judged by the broker at
|
|
293
|
+
// admission (RK_ADAPTER_ARGV_DENIED, admission_impl.rs `admit_adapter` -> adapter.rs check_argv and snapshot_argv_check), not mirrored here; nothing is rewritten.
|
|
294
|
+
// `pnpm exec <target> ...`: the door keeps its own list of the targets the apps' configs run (the broker's target list exists only when the registration has one).
|
|
295
|
+
const execAt = pnpmCommandAt(words);
|
|
296
|
+
if (execAt >= 0 && words[execAt] === "exec" && !EXEC_TARGETS.includes(words[execAt + 1] ?? "")) refuse(`pnpm ${words.join(" ")}: pnpm exec target ${JSON.stringify(words[execAt + 1] ?? null)} is not allowed (allowed: ${EXEC_TARGETS.join(", ")}); on a broker-managed host pnpm exec runs only those, as a broker job (rightkit#1241)`);
|
|
299
297
|
return adapterLaunch("rightkit-pnpm", words);
|
|
300
298
|
}
|
|
301
299
|
return refuse(`${program} ${args.join(" ")}: no broker adapter runs this command yet, and on a broker-managed host a build or test command never runs around the broker (rightkit#1241)`);
|
|
@@ -303,28 +301,27 @@ export function buildLaunch(command, args = [], host = {}) {
|
|
|
303
301
|
|
|
304
302
|
/**
|
|
305
303
|
* The production runner of the native compile phases (RA-07, RA-08, RA-09), for the iOS and Android callers to inject: `createNativeRunner({ cwd, env, ... }).run(command, args, options)`.
|
|
306
|
-
* It is the real route and nothing else: `buildLaunch` decides (the
|
|
307
|
-
* through the carrier in this process (`
|
|
308
|
-
* executor parameter: a test injects a host description (`which`, `exists`, `readFile
|
|
304
|
+
* It is the real route and nothing else: `buildLaunch` decides (the tool-to-adapter mapping, the relative paths, the executor's client, the typed signing-file handoff; the broker judges the call), a carried step goes
|
|
305
|
+
* through the carrier in this process (`runStageAdapter`: one seam call filed in the stage's ledger, its receipt read), an uncarried one through the resolved executor's client (the broker decides). There is NO
|
|
306
|
+
* executor parameter: a test injects a host description (`which`, `exists`, `readFile`) to `plan`, which only maps and spawns nothing. A command that is not a native build tool is
|
|
309
307
|
* refused (`RK_NATIVE_TOOL_REFUSED`): a compiler-capable phase never falls back to a generic spawn, and a non-compiling query (`plutil`, `git`) is the caller's own direct step.
|
|
310
308
|
*
|
|
311
309
|
* `plan(command, args, options)` returns the launch (`{ command, args, env?, native }`) or throws the door's refusal (`code` RK_BUILD_LAUNCH_REFUSED, `reason` the typed code).
|
|
312
310
|
* `run(command, args, options)` is synchronous and returns this fixed shape (spawnSync-compatible: `status`, `signal`, `stdout`, `stderr`, `error`):
|
|
313
311
|
* { ok, status, signal, stdout, stderr, error, refusal: { code, message } | null, // a refusal is before any launch: nothing was sent, status is null
|
|
314
|
-
* tool, adapter,
|
|
312
|
+
* tool, adapter, argv, carried, relativeCwd, // what was sent (argv after relativization); null on a refusal before the plan
|
|
315
313
|
* requestId, outputDir, // the verified job (carried and verified), else null
|
|
316
314
|
* outputs: { ok, source: "receipt" | "grammar", state, outputs: [{ role, path }], byRole, unresolved?: [role] } | { ok: false, problem } | null,
|
|
317
315
|
* nestedChildren }
|
|
318
316
|
* `outputs` maps the call's managed locations by role under the job's verified output directory: "receipt" when the verified signed receipt's `executable.managedOutputs` was read back and equals the grammar's
|
|
319
317
|
* mapping; "grammar" when the carrier surfaced only the output directory (the result bundle of a test action is then `unresolved` unless the request id is known). A caller consumes `byRole`, never a path of its own.
|
|
320
|
-
* options: `cwd`, `env` (the step's own launch environment, none of it forwarded), `stdio`, `timeout`, `signingFile` and `signerRoot` (the signing-properties file handoff, path only)
|
|
318
|
+
* options: `cwd`, `env` (the step's own launch environment, none of it forwarded), `stdio`, `timeout`, `signingFile` and `signerRoot` (the signing-properties file handoff, path only).
|
|
321
319
|
*/
|
|
322
|
-
export function createNativeRunner({ cwd = process.cwd(), env = process.env, platform = process.platform, exists = existsSync, which, readFile,
|
|
320
|
+
export function createNativeRunner({ cwd = process.cwd(), env = process.env, platform = process.platform, exists = existsSync, which, readFile, signerRoot } = {}) {
|
|
323
321
|
const hostOf = (options) => ({
|
|
324
322
|
env: options.env ?? env, platform, exists, cwd: options.cwd ?? cwd,
|
|
325
|
-
...(which ? { which } : {}), ...(readFile ? { readFile } : {}),
|
|
323
|
+
...(which ? { which } : {}), ...(readFile ? { readFile } : {}),
|
|
326
324
|
...(options.signingFile ? { signingFile: options.signingFile } : {}), ...((options.signerRoot ?? signerRoot) ? { signerRoot: options.signerRoot ?? signerRoot } : {}),
|
|
327
|
-
...((options.brokerCapabilities ?? brokerCapabilities) ? { brokerCapabilities: options.brokerCapabilities ?? brokerCapabilities } : {}),
|
|
328
325
|
});
|
|
329
326
|
const plan = (command, args = [], options = {}) => {
|
|
330
327
|
if (nativeToolOf(command) === null) refuse(`RK_NATIVE_TOOL_REFUSED: ${name(command)} ${args.join(" ")}: not a native build tool (xcodegen, xcodebuild, gradle, cmake); a compiler-capable phase has no generic spawn (rightkit#1241), and a non-compiling command is the caller's own direct step`, "RK_NATIVE_TOOL_REFUSED");
|
|
@@ -332,7 +329,7 @@ export function createNativeRunner({ cwd = process.cwd(), env = process.env, pla
|
|
|
332
329
|
};
|
|
333
330
|
const refused = (error, tool) => ({
|
|
334
331
|
ok: false, status: null, signal: null, stdout: "", stderr: `${error.message}\n`, error, refusal: { code: error.reason ?? error.code, message: error.message },
|
|
335
|
-
tool: tool ?? null, adapter: tool ? NATIVE_ADAPTERS[tool].adapter : null,
|
|
332
|
+
tool: tool ?? null, adapter: tool ? NATIVE_ADAPTERS[tool].adapter : null, argv: null, carried: false, relativeCwd: null, requestId: null, outputDir: null, outputs: null, nestedChildren: null,
|
|
336
333
|
});
|
|
337
334
|
const run = (command, args = [], options = {}) => {
|
|
338
335
|
const tool = nativeToolOf(command);
|
|
@@ -345,7 +342,7 @@ export function createNativeRunner({ cwd = process.cwd(), env = process.env, pla
|
|
|
345
342
|
if (native.carried) {
|
|
346
343
|
const carried = carriedCargoMapOf(runEnv);
|
|
347
344
|
if (!carried?.map) return refused(Object.assign(new Error(`${name(command)}: ${carried?.error ?? "no carried map in the environment"}; a snapshot stage's native step is never sent to the client around its carrier`), { code: BUILD_LAUNCH_REFUSED, reason: "RK_ADAPTER_CARRIER_MISSING" }), tool);
|
|
348
|
-
result =
|
|
345
|
+
result = runStageAdapter(native.adapter, native.args, { cwd: stepCwd, env: runEnv, stdio: options.stdio === "inherit" ? "inherit" : "capture" }, { map: carried.map });
|
|
349
346
|
} else {
|
|
350
347
|
result = spawnSync(launch.command, launch.args, { cwd: stepCwd, env: runEnv, encoding: "utf8", windowsHide: true, shell: false, maxBuffer: 512 * 1024 * 1024, ...(options.stdio ? { stdio: options.stdio } : {}), ...(options.timeout ? { timeout: options.timeout } : {}) });
|
|
351
348
|
}
|
|
@@ -359,19 +356,16 @@ export function createNativeRunner({ cwd = process.cwd(), env = process.env, pla
|
|
|
359
356
|
else {
|
|
360
357
|
const state = nativeStateDir(outputDir, native.tool, native.relativeCwd ?? "");
|
|
361
358
|
const grammar = nativeManagedOutputs(native.tool, native.args, { state, jobId: requestId ?? undefined });
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const resolved = grammar.outputs.filter((entry) => !entry.unresolved).map(({ role, path: file }) => ({ role, path: file }));
|
|
366
|
-
outputs = { ok: true, source: "grammar", state, outputs: resolved, byRole: Object.fromEntries(resolved.map(({ role, path: file }) => [role, file])), ...(unresolved.length ? { unresolved } : {}) };
|
|
367
|
-
}
|
|
359
|
+
const unresolved = grammar.outputs.filter((entry) => entry.unresolved).map((entry) => entry.role);
|
|
360
|
+
const resolved = grammar.outputs.filter((entry) => !entry.unresolved).map(({ role, path: file }) => ({ role, path: file }));
|
|
361
|
+
outputs = { ok: true, source: "grammar", state, outputs: resolved, byRole: Object.fromEntries(resolved.map(({ role, path: file }) => [role, file])), ...(unresolved.length ? { unresolved } : {}) };
|
|
368
362
|
}
|
|
369
363
|
}
|
|
370
364
|
const error = result.error ?? (result.refusal ? Object.assign(new Error(result.refusal.message), { code: result.refusal.code }) : null);
|
|
371
365
|
return {
|
|
372
366
|
ok: result.status === 0 && !error && !result.refusal, status: result.status ?? null, signal: result.signal ?? null, stdout: String(result.stdout ?? ""), stderr: String(result.stderr ?? ""), error,
|
|
373
367
|
refusal: result.refusal ? { code: result.refusal.code, message: result.refusal.message } : null,
|
|
374
|
-
tool: native.tool, adapter: native.adapter,
|
|
368
|
+
tool: native.tool, adapter: native.adapter, argv: [...native.args], carried: native.carried, relativeCwd: native.relativeCwd,
|
|
375
369
|
requestId, outputDir, outputs, nestedChildren: Array.isArray(result.nestedChildren) ? result.nestedChildren : null,
|
|
376
370
|
};
|
|
377
371
|
};
|
package/build-release.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { recordLockChild } from "./snapshot.mjs";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
3
4
|
import {
|
|
4
5
|
chmodSync,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
import path from "node:path";
|
|
21
22
|
import { preflightOwnershipScope } from "./ownership-scope.mjs";
|
|
22
23
|
import { spawn, spawnSync } from "./background-process.mjs";
|
|
23
|
-
import { spawnUnderOwnership } from "./build-ownership.mjs";
|
|
24
24
|
import { RightKitRegistryError, SNAPSHOT_ENV, SNAPSHOT_FILE, assertManifestRegistryEvidence, loadAdmittedSnapshot, prepareRightKitResolution, registryManifestFields, rightKitLockInventory, writeAdmissionRecord, writeSnapshot } from "./rightkit-registry-resolver.mjs";
|
|
25
25
|
import { formatAdmission, formatNotRun, runAdmission } from "./admission.mjs";
|
|
26
26
|
import { sccacheRefusal } from "./admission-host.mjs";
|
|
@@ -961,7 +961,7 @@ async function runProgress(cmd, runArgs, cwd, env, watchDir, diagnosticPath = nu
|
|
|
961
961
|
const settleResolve = () => { if (!settled) { settled = true; resolve(); } };
|
|
962
962
|
const settleReject = (error) => { if (!settled) { settled = true; reject(error); } };
|
|
963
963
|
const useShell = process.platform === "win32" && !/\.(?:exe|com)$/i.test(cmd);
|
|
964
|
-
child =
|
|
964
|
+
child = recordLockChild(spawn(cmd, runArgs, { cwd, env, stdio: ["inherit", "pipe", "pipe"], windowsHide: true, shell: useShell, detached: process.platform !== "win32" }), { env });
|
|
965
965
|
try {
|
|
966
966
|
if (child.pid && heavySlot) heavySlot.trackChild(child.pid, cmd);
|
|
967
967
|
} catch (error) {
|
package/cargo-ledger.mjs
CHANGED
|
@@ -12,6 +12,9 @@ import path from "node:path";
|
|
|
12
12
|
export const LEDGER_SCHEMA = "rightkit.cargo-ledger/1";
|
|
13
13
|
export const SCAN_TOKEN_ENV = "RIGHTKIT_CARGO_SCAN";
|
|
14
14
|
export const UNSCOPED = "unscoped";
|
|
15
|
+
/** Exit status of a refused cargo call, everywhere a gate-made refusal stands in for cargo (cargo's own error status, so every caller reads it as a failed cargo). Defined here,
|
|
16
|
+
* in a module that imports none of the gate's, so the wrapper, the stage seam and the carrier share it without an import cycle reading it before it exists. */
|
|
17
|
+
export const CARGO_REFUSAL_STATUS = 101;
|
|
15
18
|
/** Statuses that are a completed success: a direct call that ran, a broker call whose signed receipt verified. */
|
|
16
19
|
export const OK_STATUSES = Object.freeze(["ran", "verified"]);
|
|
17
20
|
|
|
@@ -36,13 +39,13 @@ export function appendLedger(dir, token, entry) {
|
|
|
36
39
|
export function readLedger(dir, token) {
|
|
37
40
|
const file = tokenFile(dir, validToken(token));
|
|
38
41
|
let text = "";
|
|
39
|
-
try { text = fs.readFileSync(file, "utf8"); } catch (e) { if (e.code === "ENOENT") return { entries: [], problems: [] }; throw e; }
|
|
40
|
-
const byId = new Map(); const problems = [];
|
|
42
|
+
try { text = fs.readFileSync(file, "utf8"); } catch (e) { if (e.code === "ENOENT") return { entries: [], problems: [], malformed: 0 }; throw e; }
|
|
43
|
+
const byId = new Map(); const problems = []; let malformed = 0;
|
|
41
44
|
for (const line of text.split("\n")) {
|
|
42
45
|
if (!line.trim()) continue;
|
|
43
46
|
let entry;
|
|
44
|
-
try { entry = JSON.parse(line); } catch { problems.push(`an unreadable ledger record in ${path.basename(file)}`); continue; }
|
|
45
|
-
if (entry?.schema !== LEDGER_SCHEMA || typeof entry.id !== "string") { problems.push(`a malformed ledger record in ${path.basename(file)}`); continue; }
|
|
47
|
+
try { entry = JSON.parse(line); } catch { problems.push(`an unreadable ledger record in ${path.basename(file)}`); malformed += 1; continue; }
|
|
48
|
+
if (entry?.schema !== LEDGER_SCHEMA || typeof entry.id !== "string") { problems.push(`a malformed ledger record in ${path.basename(file)}`); malformed += 1; continue; }
|
|
46
49
|
byId.set(entry.id, { ...(byId.get(entry.id) ?? {}), ...entry });
|
|
47
50
|
}
|
|
48
51
|
const entries = [...byId.values()];
|
|
@@ -51,7 +54,23 @@ export function readLedger(dir, token) {
|
|
|
51
54
|
const call = `${e.adapter ?? "cargo"} ${(e.argv ?? []).join(" ")}`.trim();
|
|
52
55
|
problems.push(e.status === "pending" ? `${call} (from ${e.cwd}) never completed: the wrapper recorded it and no outcome, so it is unverified` : `${call} (from ${e.cwd}) was ${e.status}${e.code ? ` (${e.code})` : ""}${e.message ? `: ${e.message}` : ""}`);
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
// `malformed`: records that could not be read as a call (unreadable JSON, wrong schema, no id). Whose call they were is unknown, so a reader that needs
|
|
58
|
+
// positive evidence (the door's seam lock release) counts each as unsettled.
|
|
59
|
+
return { entries, problems, malformed };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Every file of a ledger directory read as one ledger (`unscoped` and every scan token), in file-name order: `{ entries, problems, malformed }`. */
|
|
63
|
+
export function readLedgerDir(dir) {
|
|
64
|
+
let names = [];
|
|
65
|
+
try { names = fs.readdirSync(dir).filter((n) => n.endsWith(".jsonl")).sort(); } catch (e) { if (e.code === "ENOENT") return { entries: [], problems: [], malformed: 0 }; throw e; }
|
|
66
|
+
const out = { entries: [], problems: [], malformed: 0 };
|
|
67
|
+
for (const name of names) {
|
|
68
|
+
const token = name.slice(0, -".jsonl".length);
|
|
69
|
+
if (token !== UNSCOPED && validToken(token) === UNSCOPED) { out.problems.push(`a ledger file with an invalid name: ${name}`); out.malformed += 1; continue; }
|
|
70
|
+
const r = readLedger(dir, token);
|
|
71
|
+
out.entries.push(...r.entries); out.problems.push(...r.problems); out.malformed += r.malformed;
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
/** Ledger files nobody claimed: the scan token was cleared or invented by the code under test. */
|