@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.
- 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 +177 -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 +167 -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 -7
- 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 +568 -491
- 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 +58 -0
- package/snapshot-request.mjs +25 -2
- package/stage-commands.mjs +33 -4
- package/stage-ledger.mjs +6 -1
- 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
package/r2-verified-upload.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
1
|
import path from "node:path";
|
|
4
2
|
import { spawnSync } from "./background-process.mjs";
|
|
5
3
|
import { assertArtifactUnchanged, PublicationError, verifyArtifactFile } from "./publication-artifacts.mjs";
|
|
4
|
+
import { deriveR2S3Credentials, R2_ACCOUNT_ID, R2_MULTIPART_THRESHOLD_BYTES, streamObjectDigest, uploadMultipart } from "./r2-s3-multipart.mjs";
|
|
6
5
|
|
|
7
6
|
// Wrangler's pipe input transports the verified buffer, with no path lookup by its child.
|
|
8
7
|
export function uploadVerifiedR2Artifact(artifact, key, bucket, { run = spawnSync, env = process.env, cwd } = {}) {
|
|
@@ -16,26 +15,39 @@ export function uploadVerifiedR2Artifact(artifact, key, bucket, { run = spawnSyn
|
|
|
16
15
|
if (result.error || result.status !== 0) throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 upload failed: ${key}`);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
// Path-only large-file transport: success requires remote bytes matching captured evidence.
|
|
20
|
-
|
|
18
|
+
// Path-only large-file transport: success requires remote bytes matching captured evidence. Objects below R2_MULTIPART_THRESHOLD_BYTES go up in
|
|
19
|
+
// one wrangler request; larger ones (wrangler stops at 300 MiB) go through the S3-compatible endpoint as a multipart upload (r2-s3-multipart.mjs,
|
|
20
|
+
// #902). Either way the readback streams GetObject through a sha256 and a byte counter, because `wrangler r2 object get` aborts mid-stream on
|
|
21
|
+
// large objects (docs/rules/cloudflare-access.md Rule 6). The S3 credentials are derived in memory from CLOUDFLARE_API_TOKEN and never printed.
|
|
22
|
+
// The order the callers keep is immutable object -> signed envelope -> pointer, and a readback that differs from the evidence is
|
|
23
|
+
// PUBLICATION_REMOTE_MISMATCH.
|
|
24
|
+
export async function uploadVerifiedR2File(file, evidence, key, bucket, { run = spawnSync, env = process.env, cwd, dryRun = false, fetchImpl, sleep } = {}) {
|
|
21
25
|
if (!["public", "private"].includes(bucket) || !/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(key ?? "") || key.includes("..")) throw new PublicationError("PUBLICATION_ROUTE_INVALID", "invalid R2 publication route");
|
|
22
26
|
const artifact = verifyArtifactFile(file, evidence);
|
|
23
27
|
if (dryRun) return artifact;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
28
|
+
const bucketName = bucket === "public" ? "rightapps-downloads" : "rightapps-updates";
|
|
29
|
+
const target = `${bucketName}/${key}`;
|
|
30
|
+
const cleanEnv = { ...env, CLOUDFLARE_ACCOUNT_ID: env.CLOUDFLARE_ACCOUNT_ID || R2_ACCOUNT_ID };
|
|
26
31
|
for (const name of ["CLOUDFLARE_API_KEY", "CLOUDFLARE_EMAIL", "CF_API_KEY", "CF_EMAIL"]) delete cleanEnv[name];
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const credentials = await deriveR2S3Credentials(cleanEnv.CLOUDFLARE_API_TOKEN, { account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl });
|
|
33
|
+
const transport = { bucket: bucketName, key, credentials, account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl, sleep };
|
|
34
|
+
if (artifact.sizeBytes >= R2_MULTIPART_THRESHOLD_BYTES) {
|
|
35
|
+
try { await uploadMultipart({ file: path.resolve(file), evidence: artifact, ...transport }); }
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error instanceof PublicationError && error.code !== "PUBLICATION_UPLOAD_FAILED") throw error;
|
|
38
|
+
throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 multipart upload failed (${error.message}); inspect remote key ${target}`);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
const options = { cwd, env: cleanEnv, windowsHide: true, shell: process.platform === "win32", encoding: "utf8" };
|
|
42
|
+
const result = run("pnpm", ["dlx", "wrangler@4", "r2", "object", "put", target, "--file", path.resolve(file), "--remote"], { ...options, stdio: "inherit" });
|
|
43
|
+
if (result.error || result.status !== 0) throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 upload failed; inspect remote key ${target}`);
|
|
44
|
+
}
|
|
32
45
|
try {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
verifyArtifactFile(downloaded, artifact);
|
|
46
|
+
const remote = await streamObjectDigest(transport);
|
|
47
|
+
if (remote.sha256 !== artifact.sha256) throw new Error("remote sha256 differs from the evidence");
|
|
48
|
+
if (remote.sizeBytes !== artifact.sizeBytes) throw new Error(`remote size ${remote.sizeBytes} differs from ${artifact.sizeBytes}`);
|
|
37
49
|
} catch (error) {
|
|
38
50
|
throw new PublicationError("PUBLICATION_REMOTE_MISMATCH", `R2 verification failed (${error.message}); remove remote key ${target}`);
|
|
39
|
-
}
|
|
51
|
+
}
|
|
40
52
|
return artifact;
|
|
41
53
|
}
|
package/recipe-build.mjs
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// `pre` never creates the broker-side parent directory. `verify: [{ app, real }]` requires the real file to equal the
|
|
29
29
|
// signed app file before and after the build step; `resolve: { manifest, expected }` re-runs cargo metadata and
|
|
30
30
|
// requires the planned target directory before and after it (a temporary bridge until the broker exposes artifacts).
|
|
31
|
-
import { existsSync as nodeExistsSync, readFileSync, readdirSync as nodeReaddirSync, rmSync as nodeRmSync, statSync as nodeStatSync } from "node:fs";
|
|
31
|
+
import { existsSync as nodeExistsSync, readFileSync, readdirSync as nodeReaddirSync, readlinkSync as nodeReadlinkSync, rmSync as nodeRmSync, statSync as nodeStatSync } from "node:fs";
|
|
32
32
|
import path from "node:path";
|
|
33
33
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
34
34
|
import { spawnSync as nodeSpawnSync } from "./background-process.mjs";
|
|
@@ -59,7 +59,7 @@ const NATIVE_HELPERS_KEYS = new Set(["app", "helpers", "version", "forceArch", "
|
|
|
59
59
|
const UNIVERSAL_TRIPLE = "universal-apple-darwin";
|
|
60
60
|
const STAGE_KEYS = new Set(["pre", "post", "verify", "resolve"]);
|
|
61
61
|
const STAGE_ENTRY_KEYS = new Set(["from", "to", "fresh"]);
|
|
62
|
-
const CLEANUP_KEYS = new Set(["remove", "apps", "dmgVolumes"]);
|
|
62
|
+
const CLEANUP_KEYS = new Set(["remove", "apps", "dmgVolumes", "killProcesses"]);
|
|
63
63
|
const APPS_KEYS = new Set(["dir", "remove", "unregister"]);
|
|
64
64
|
const STABILITY_KEYS = new Set(["files", "intervalMs", "checks", "timeoutMs"]);
|
|
65
65
|
const LSREGISTER = "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister";
|
|
@@ -118,6 +118,12 @@ function validateCleanup(value, errors, bound = []) {
|
|
|
118
118
|
if (dir) out.apps = { dir, remove: value.apps.remove === true, unregister: value.apps.unregister === true };
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
if (value.killProcesses !== undefined) {
|
|
122
|
+
// Directories (app-relative, strictly inside the app) whose running executables are stopped before the build: a previous build's app or
|
|
123
|
+
// helper still running from its output folder locks the very files the build rewrites (rightkit#753). Never a name match.
|
|
124
|
+
if (!Array.isArray(value.killProcesses) || !value.killProcesses.length) errors.push("cleanup.killProcesses must be a non-empty list of relative directories");
|
|
125
|
+
else out.killProcesses = value.killProcesses.map((item, index) => insideApp(item, `cleanup.killProcesses[${index}]`, errors, { strict: true, bound })).filter(Boolean);
|
|
126
|
+
}
|
|
121
127
|
if (value.dmgVolumes !== undefined) {
|
|
122
128
|
if (!Array.isArray(value.dmgVolumes) || value.dmgVolumes.some(badVolumePrefix)) errors.push("cleanup.dmgVolumes must be a list of non-empty volume name prefixes (no path separators)");
|
|
123
129
|
else out.dmgVolumes = [...value.dmgVolumes];
|
|
@@ -282,14 +288,58 @@ export function diskImageMountPoints(plistText) {
|
|
|
282
288
|
return mounts;
|
|
283
289
|
}
|
|
284
290
|
|
|
291
|
+
/** Running processes as `[{ pid, image }]` (the full path of the executable): `ps` on macOS, /proc on Linux, CIM on Windows. Unreadable rows are dropped. */
|
|
292
|
+
export function listProcessImages({ platform = process.platform, spawnSync = nodeSpawnSync, fs = {} } = {}) {
|
|
293
|
+
if (platform === "darwin") {
|
|
294
|
+
const out = spawnSync("ps", ["-axo", "pid=,comm="], { encoding: "utf8", windowsHide: true });
|
|
295
|
+
if (out?.error || out?.status !== 0) return null;
|
|
296
|
+
return String(out.stdout ?? "").split("\n").flatMap((line) => { const match = /^\s*(\d+)\s+(\/.*)$/.exec(line); return match ? [{ pid: Number(match[1]), image: match[2].trim() }] : []; });
|
|
297
|
+
}
|
|
298
|
+
if (platform === "linux") {
|
|
299
|
+
const readdir = fs.readdirSync ?? nodeReaddirSync;
|
|
300
|
+
const readlink = fs.readlinkSync ?? nodeReadlinkSync;
|
|
301
|
+
let names;
|
|
302
|
+
try { names = readdir("/proc"); } catch { return null; }
|
|
303
|
+
return names.filter((name) => /^\d+$/.test(name)).flatMap((name) => { try { return [{ pid: Number(name), image: readlink(`/proc/${name}/exe`) }]; } catch { return []; } });
|
|
304
|
+
}
|
|
305
|
+
if (platform === "win32") {
|
|
306
|
+
const script = 'Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath } | ForEach-Object { "$($_.ProcessId)`t$($_.ExecutablePath)" }';
|
|
307
|
+
const out = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], { encoding: "utf8", windowsHide: true });
|
|
308
|
+
if (out?.error || out?.status !== 0) return null;
|
|
309
|
+
return String(out.stdout ?? "").split(/\r?\n/).flatMap((line) => { const match = /^(\d+)\t(.+)$/.exec(line.trim()); return match ? [{ pid: Number(match[1]), image: match[2] }] : []; });
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Stop every running process whose executable lies strictly inside one of `dirs` (absolute). Returns the pids stopped. Never the current process. */
|
|
315
|
+
export function killProcessesUnder(dirs, { platform = process.platform, log = () => {}, spawnSync = nodeSpawnSync, fs, kill = (pid, signal) => process.kill(pid, signal), sleep = defaultSleep, selfPid = process.pid } = {}) {
|
|
316
|
+
const fold = (value) => (platform === "win32" ? path.win32.resolve(value).toLowerCase() : path.resolve(value));
|
|
317
|
+
const inside = (image) => dirs.some((dir) => { const rel = path.relative(fold(dir), fold(image)); return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel); });
|
|
318
|
+
const images = listProcessImages({ platform, spawnSync, fs });
|
|
319
|
+
if (!images) { log("recipe-build: cleanup killProcesses skipped (the process list could not be read)"); return []; }
|
|
320
|
+
const hits = images.filter((item) => item.pid !== selfPid && item.pid !== process.ppid && inside(item.image));
|
|
321
|
+
for (const { pid, image } of hits) {
|
|
322
|
+
log(`recipe-build: cleanup stops pid ${pid} (${image})`);
|
|
323
|
+
try { if (platform === "win32") spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], { windowsHide: true }); else kill(pid, "SIGTERM"); } catch (error) { if (error?.code !== "ESRCH") log(`recipe-build: cleanup could not stop pid ${pid} (${error?.message})`); }
|
|
324
|
+
}
|
|
325
|
+
if (hits.length && platform !== "win32") {
|
|
326
|
+
sleep(2000);
|
|
327
|
+
const alive = new Set((listProcessImages({ platform, spawnSync, fs }) ?? []).map((item) => item.pid));
|
|
328
|
+
for (const { pid } of hits) if (alive.has(pid)) { try { kill(pid, "SIGKILL"); } catch { /* gone */ } }
|
|
329
|
+
}
|
|
330
|
+
return hits.map((item) => item.pid);
|
|
331
|
+
}
|
|
332
|
+
|
|
285
333
|
/**
|
|
286
334
|
* Stale-artifact cleanup, run before the build. Returns what it did: { removed, unregistered, detached }.
|
|
287
335
|
* A failing detach or unregister is logged and skipped: the build's own gates decide pass or fail.
|
|
288
336
|
* Options: appRoot, platform, log, spawnSync, fs ({ existsSync, readdirSync, rmSync }), volumesDir.
|
|
289
337
|
*/
|
|
290
338
|
export function runRecipeCleanup(cleanup, { appRoot, platform = process.platform, log = () => {}, spawnSync = nodeSpawnSync, fs = defaultFs, volumesDir = "/Volumes" } = {}) {
|
|
291
|
-
const result = { removed: [], unregistered: [], detached: [] };
|
|
339
|
+
const result = { removed: [], unregistered: [], detached: [], killed: [] };
|
|
292
340
|
if (!cleanup) return result;
|
|
341
|
+
// First: a process still running from an output folder holds its files open, so nothing below (remove, unregister) can finish while it lives.
|
|
342
|
+
if (cleanup.killProcesses?.length) result.killed = killProcessesUnder(cleanup.killProcesses.map((relative) => path.resolve(appRoot, relative)), { platform, log, spawnSync });
|
|
293
343
|
const tool = (cmd, args) => {
|
|
294
344
|
const run = spawnSync(cmd, args, { stdio: "inherit", windowsHide: true });
|
|
295
345
|
const ok = !(run?.error || run?.status !== 0);
|
package/release-checks.mjs
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Run only app-configured pre-build checks; release safeguards never route here.
|
|
3
|
+
*
|
|
4
|
+
* A `checks` entry is a package script name (it passes when the script exits 0) or an object
|
|
5
|
+
* `{ script, expectOutput?, forbidOutput? }` (rightkit#753): the script must exit 0 AND its standard output must contain every
|
|
6
|
+
* `expectOutput` string and none of the `forbidOutput` strings (plain, case-sensitive substrings; a string or a list of strings).
|
|
7
|
+
* The output is captured, echoed, and judged here; a dry run captures nothing, so it asserts nothing.
|
|
8
|
+
*/
|
|
9
|
+
export class ReleaseCheckError extends Error {
|
|
10
|
+
constructor(message) { super(message); this.name = "ReleaseCheckError"; this.code = "RK_RELEASE_CHECK"; }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const SCRIPT = /^[^\s\0]+$/;
|
|
14
|
+
const ENTRY_KEYS = new Set(["script", "expectOutput", "forbidOutput"]);
|
|
15
|
+
|
|
16
|
+
const stringList = (value, label) => {
|
|
17
|
+
if (value === undefined) return [];
|
|
18
|
+
const list = Array.isArray(value) ? value : [value];
|
|
19
|
+
if (!list.length || list.some((item) => typeof item !== "string" || item === "")) throw new ReleaseCheckError(`${label} must be a non-empty string or a list of non-empty strings`);
|
|
20
|
+
return list;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Validate one `checks` entry and return `{ script, expect, forbid }`. */
|
|
24
|
+
export function releaseCheckEntry(entry, index = 0) {
|
|
25
|
+
const label = `checks[${index}]`;
|
|
26
|
+
if (typeof entry === "string" || entry === false) return { script: entry, expect: [], forbid: [] }; // exit status only, exactly as before (false is a no-op)
|
|
27
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) throw new ReleaseCheckError(`${label} must be a script name or { script, expectOutput?, forbidOutput? }`);
|
|
28
|
+
const unknown = Object.keys(entry).filter((key) => !ENTRY_KEYS.has(key));
|
|
29
|
+
if (unknown.length) throw new ReleaseCheckError(`${label} has unknown key(s): ${unknown.join(", ")} (allowed: ${[...ENTRY_KEYS].join(", ")})`);
|
|
30
|
+
if (typeof entry.script !== "string" || !SCRIPT.test(entry.script)) throw new ReleaseCheckError(`${label}.script must be a package script name`);
|
|
31
|
+
const expect = stringList(entry.expectOutput, `${label}.expectOutput`);
|
|
32
|
+
const forbid = stringList(entry.forbidOutput, `${label}.forbidOutput`);
|
|
33
|
+
if (!expect.length && !forbid.length) throw new ReleaseCheckError(`${label} names no expectOutput or forbidOutput; use the script name alone for an exit-status check`);
|
|
34
|
+
return { script: entry.script, expect, forbid };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The assertion problems of a captured output (empty when it passes). `null` output (a dry run) asserts nothing. */
|
|
38
|
+
export function releaseCheckOutputProblems({ script, expect, forbid }, output) {
|
|
39
|
+
if (output === null || output === undefined) return [];
|
|
40
|
+
const text = String(output);
|
|
41
|
+
return [
|
|
42
|
+
...expect.filter((needle) => !text.includes(needle)).map((needle) => `check ${JSON.stringify(script)} output does not contain ${JSON.stringify(needle)}`),
|
|
43
|
+
...forbid.filter((needle) => text.includes(needle)).map((needle) => `check ${JSON.stringify(script)} output contains the forbidden ${JSON.stringify(needle)}`),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
2
47
|
export async function runConfiguredChecks({ packageManager, checks = [], workdir, skipChecks = false, run }) {
|
|
3
48
|
if (skipChecks) return;
|
|
4
|
-
|
|
49
|
+
const entries = checks.map((entry, index) => releaseCheckEntry(entry, index));
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (!entry.expect.length && !entry.forbid.length) { await run(packageManager, entry.script, workdir); continue; }
|
|
52
|
+
const output = await run(packageManager, entry.script, workdir, { captureStdout: true });
|
|
53
|
+
const problems = releaseCheckOutputProblems(entry, output);
|
|
54
|
+
if (problems.length) throw new ReleaseCheckError(problems.join("; "));
|
|
55
|
+
}
|
|
5
56
|
}
|
package/release-config.mjs
CHANGED
|
@@ -37,11 +37,16 @@ export const RELEASE_CONFIG_SCHEMA = 1;
|
|
|
37
37
|
export const MAX_CONFIG_BYTES = 1024 * 1024;
|
|
38
38
|
export const LEGACY_EXECUTABLE_EXTENSIONS = Object.freeze([".mjs", ".js", ".cjs", ".ts", ".mts", ".cts", ".jsx", ".tsx"]);
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* The complete set of top-level keys. A key outside it is refused: a new capability is a RightKit change, not an app extension.
|
|
42
|
+
* `runtimeArtifacts` was removed from the set (rightkit#753): no code read it, so an app that declared it got a silent no-op. It is now
|
|
43
|
+
* refused with RELEASE_CONFIG_KEY. Runtime artifacts are staged by `sidecars` (kind native-library, onnxruntime, remote, resource) and
|
|
44
|
+
* delivered by the runtime-artifact manifests (runtime-artifact-manifest.mjs, docs/RUNTIME-ARTIFACT-DELIVERY.md).
|
|
45
|
+
*/
|
|
41
46
|
export const TOP_LEVEL_KEYS = Object.freeze([
|
|
42
47
|
"$schema", "$comment", "schema", "app", "version", "channel", "distribution", "packageManager", "workdir", "targets", "development",
|
|
43
|
-
"deps", "checks", "buildInputs", "hostedWorkflows", "devtools", "releaseSwitches", "qa", "nativeAssembly", "legal", "web", "tests",
|
|
44
|
-
"sidecars", "assembly", "releaseDependencies", "appStoreConnect", "storage", "cargoProfileExempt", "
|
|
48
|
+
"deps", "checks", "buildInputs", "hostedWorkflows", "devtools", "releaseSwitches", "qa", "nativeAssembly", "legal", "security", "web", "tests",
|
|
49
|
+
"sidecars", "directRelease", "modelBundles", "assembly", "releaseDependencies", "appStoreConnect", "storage", "cargoProfileExempt", "windows",
|
|
45
50
|
]);
|
|
46
51
|
export const TEMPLATE_TOKENS = Object.freeze(["app", "version", "home", "localAppData"]);
|
|
47
52
|
|
package/release-invocation.mjs
CHANGED
|
@@ -219,6 +219,14 @@ export function iosTrustPackageResolved(iosSpec) {
|
|
|
219
219
|
|
|
220
220
|
const outside = (root, file) => { const relative = path.relative(root, file); return relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative); };
|
|
221
221
|
|
|
222
|
+
/** The Package.swift a SwiftPM target requires: the one in the app root or the config workdir, else the app root's unless the target is an Xcode-built bundle (`notarize.appBeforePackage`). */
|
|
223
|
+
function swiftPackageManifestInputs({ appRoot, config, target }) {
|
|
224
|
+
const roots = [appRoot, path.resolve(appRoot, config?.workdir ?? ".")];
|
|
225
|
+
const found = roots.map((root) => path.join(root, "Package.swift")).find((file) => existsSync(file));
|
|
226
|
+
if (found) return [found];
|
|
227
|
+
return target?.notarize?.appBeforePackage ? [] : [path.join(appRoot, "Package.swift")];
|
|
228
|
+
}
|
|
229
|
+
|
|
222
230
|
export function resolveReleaseBuildInputs({ repoRoot, appRoot, configPath, config, target, env = process.env }) {
|
|
223
231
|
const swift = resolveProjectType({ appRoot, config, target }) === "swiftpm";
|
|
224
232
|
const iosSpec = iosPackageSpecOf(target);
|
|
@@ -250,8 +258,10 @@ export function resolveReleaseBuildInputs({ repoRoot, appRoot, configPath, confi
|
|
|
250
258
|
const requiredInputs = [
|
|
251
259
|
configPath,
|
|
252
260
|
...(swift
|
|
253
|
-
// SwiftPM: Package.swift is required
|
|
254
|
-
|
|
261
|
+
// SwiftPM: the Package.swift is required where the target's layout puts it (the app root or the config's workdir); an Xcode-built
|
|
262
|
+
// mac bundle that notarizes before it packages (Pulse's mac/ notch, #920) has no root SwiftPM package, so none is demanded.
|
|
263
|
+
// Package.resolved and the Node manifests only when they exist.
|
|
264
|
+
? [...swiftPackageManifestInputs({ appRoot, config, target }), ...optionalIfPresent(["Package.resolved", "package.json", "pnpm-lock.yaml"])]
|
|
255
265
|
: nativeIos
|
|
256
266
|
// Native iOS: package.json and pnpm-lock.yaml only when the app has them, plus the declared Cargo manifest and its lock.
|
|
257
267
|
? [...optionalIfPresent(["package.json", "pnpm-lock.yaml"]), ...(pinnedLayout ? [pinnedLayout.manifestPath, pinnedLayout.lockPath] : [])]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// An app's own @rightkit/release child (stage-sidecar, web-build, package) is the code that makes its non-compiling cargo calls. One older
|
|
2
|
+
// than the direct route (DIRECT_ROUTE_RELEASE_FLOOR, cargo-target-shim.mjs, GATE-CONTRACT GC-A11) carries them to the broker, which refuses
|
|
3
|
+
// them, and the compile stage fails after Class A passed (rightkit#1491). This judges the app's pin and the version installed in the
|
|
4
|
+
// snapshot BEFORE any compile, naming both and the fix. Pure over what it is given; nothing is read or run here.
|
|
5
|
+
import { DIRECT_ROUTE_RELEASE_FLOOR } from "./cargo-target-shim.mjs";
|
|
6
|
+
|
|
7
|
+
export const RELEASE_PIN_BELOW_FLOOR = "RK_RELEASE_PIN_BELOW_FLOOR";
|
|
8
|
+
const PACKAGE = "@rightkit/release";
|
|
9
|
+
const DEPENDENCY_TABLES = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
10
|
+
|
|
11
|
+
const triple = (text) => { const m = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(String(text ?? "").trim()); return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null; };
|
|
12
|
+
|
|
13
|
+
/** -1, 0 or 1 comparing two X.Y.Z versions (a prerelease or build suffix is ignored); null when either is not one. */
|
|
14
|
+
export function compareVersions(a, b) {
|
|
15
|
+
const x = triple(a), y = triple(b);
|
|
16
|
+
if (!x || !y) return null;
|
|
17
|
+
for (let i = 0; i < 3; i += 1) if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The exact version a dependency spec pins (`0.6.30`, `=0.6.30`), or null for a range, tag, alias or workspace spec (those are judged by the installed version). */
|
|
22
|
+
export function exactPinOf(spec) {
|
|
23
|
+
const m = /^=?\s*(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(String(spec ?? "").trim());
|
|
24
|
+
return m ? m[1] : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The refusal for an app whose @rightkit/release is below `floor`, or null. `packageJsonText` is the app's committed package.json and
|
|
29
|
+
* `installedVersion` the version found in its snapshot's node_modules (null when none is installed). An app that does not depend on
|
|
30
|
+
* @rightkit/release is not judged; a pin that is a range is judged by the installed version only.
|
|
31
|
+
*/
|
|
32
|
+
export function releasePinFloorProblem({ packageJsonText, installedVersion = null, floor = DIRECT_ROUTE_RELEASE_FLOOR, where = "package.json" }) {
|
|
33
|
+
let manifest;
|
|
34
|
+
try { manifest = JSON.parse(packageJsonText); } catch { return null; }
|
|
35
|
+
const specs = DEPENDENCY_TABLES.map((t) => manifest?.[t]?.[PACKAGE]).filter((v) => typeof v === "string");
|
|
36
|
+
if (!specs.length) return null;
|
|
37
|
+
const fix = `set ${PACKAGE} to =${floor} or newer in ${where} (every app moves to the same pinned version), reinstall, and run again`;
|
|
38
|
+
for (const spec of specs) {
|
|
39
|
+
const pin = exactPinOf(spec);
|
|
40
|
+
if (pin !== null && compareVersions(pin, floor) === -1) return { code: RELEASE_PIN_BELOW_FLOOR, message: `${RELEASE_PIN_BELOW_FLOOR}: ${where} pins ${PACKAGE}@${pin}, below the host gate's floor ${floor} for compile stages: its own right-release child would carry non-compiling cargo calls to the broker, which refuses them (GC-A11); ${fix}` };
|
|
41
|
+
}
|
|
42
|
+
if (installedVersion !== null && compareVersions(installedVersion, floor) === -1) return { code: RELEASE_PIN_BELOW_FLOOR, message: `${RELEASE_PIN_BELOW_FLOOR}: the installed ${PACKAGE} is ${installedVersion} (${where} asks ${specs.join(", ")}), below the host gate's floor ${floor} for compile stages: its own right-release child would carry non-compiling cargo calls to the broker, which refuses them (GC-A11); ${fix}` };
|
|
43
|
+
return null;
|
|
44
|
+
}
|
package/release-qa-audit.mjs
CHANGED
|
@@ -16,6 +16,8 @@ import { assertInstalledQaAdmission, loadQaFloor, QaAdmissionError, qaReceiptPat
|
|
|
16
16
|
import { platformDirOf, platformOfDir } from "./platform-dir.mjs";
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
const MOBILE_PLATFORMS = new Set(["ios", "android"]);
|
|
20
|
+
|
|
19
21
|
/** "missing" when no receipt exists; "rejected" for anything else the gate refused (bad receipt, no key, wrong commit). */
|
|
20
22
|
function refusalStatus(error) {
|
|
21
23
|
return /^no installed QA receipt/.test(error.message) ? "missing" : "rejected";
|
|
@@ -61,6 +63,19 @@ export const installedQaRecordPath = ({ repoRoot, releaseId, platform }) =>
|
|
|
61
63
|
|
|
62
64
|
/** Publication stage (upload, publish-update, github). Records the outcome durably; throws in `refuse` mode. */
|
|
63
65
|
export function admitInstalledQa(opts, { provider, now = () => new Date(), ...hooks } = {}) {
|
|
66
|
+
// iOS and Android have no installed-QA lane: the qa command takes mac|win only, and qualification is the store's test track
|
|
67
|
+
// (the CHANGELOG door-platforms entry). Nothing can produce a receipt for them, so no warning names a command that cannot run (#976).
|
|
68
|
+
if (MOBILE_PLATFORMS.has(opts.platform)) {
|
|
69
|
+
const record = { status: "not-applicable", reason: `${opts.platform} has no installed QA lane; qualification is the store test track`, checkedAt: now().toISOString(), provider };
|
|
70
|
+
const file = installedQaRecordPath({ repoRoot: opts.repoRoot, releaseId: opts.manifest.releaseId, platform: opts.platform });
|
|
71
|
+
try {
|
|
72
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
73
|
+
writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
(hooks.warn ?? ((line) => console.error(line)))(`[right-release] could not record the ${opts.platform} QA status at ${file} (${error.message}); release continues.`);
|
|
76
|
+
}
|
|
77
|
+
return record;
|
|
78
|
+
}
|
|
64
79
|
const { loaded, app, mode } = policyContext(opts, hooks, "installed");
|
|
65
80
|
const outcome = admit(() => assertInstalledQaAdmission({ ...opts, afterVerify: hardening("installed", opts, loaded, { ...hooks, now }) }), { ...hooks, mode, app });
|
|
66
81
|
const record = {
|
|
@@ -88,6 +103,7 @@ function installedStatus({ repoRoot, releaseId, platformDir }) {
|
|
|
88
103
|
const published = existsSync(stateDir) && readdirSync(stateDir).some((name) => /^verified-.*\.json$/.test(name));
|
|
89
104
|
if (record) return { uploaded: true, status: record.status, ...(record.reason ? { reason: record.reason } : {}), ...(record.checkedAt ? { checkedAt: record.checkedAt } : {}) };
|
|
90
105
|
if (!published) return { uploaded: false, status: "not-uploaded" };
|
|
106
|
+
if (MOBILE_PLATFORMS.has(platformDir)) return { uploaded: true, status: "not-applicable", reason: `${platformDir} has no installed QA lane; qualification is the store test track` };
|
|
91
107
|
// Uploaded before outcomes were recorded: fall back to the receipt file the old gate required.
|
|
92
108
|
const receipt = readQaReceipt(qaReceiptPath({ repoRoot, releaseId, platform: platformOfDir(platformDir), stage: "installed" }));
|
|
93
109
|
if (receipt?.status === "passed") return { uploaded: true, status: "passed", reason: "legacy upload; receipt file present, not re-verified" };
|
|
@@ -108,7 +124,7 @@ export function auditQa({ repoRoot, since } = {}) {
|
|
|
108
124
|
rows.push({
|
|
109
125
|
releaseId, platform: platformDir, version: manifest.version ?? null, sealedAt: manifest.sealedAt ?? null, uploaded,
|
|
110
126
|
installed: installedRest,
|
|
111
|
-
ok: !uploaded || installedRest.status === "passed",
|
|
127
|
+
ok: !uploaded || installedRest.status === "passed" || installedRest.status === "not-applicable",
|
|
112
128
|
});
|
|
113
129
|
}
|
|
114
130
|
}
|
|
@@ -126,7 +142,7 @@ export function formatAuditTable(report) {
|
|
|
126
142
|
line(header), ...body.map(line),
|
|
127
143
|
"",
|
|
128
144
|
flagged.length
|
|
129
|
-
? `${flagged.length} uploaded build(s) lack passing QA:\n${flagged.map((row) => ` ${row.releaseId} ${row.platform}: ${[row.installed.status !== "passed" && `installed ${row.installed.status}${row.installed.reason ? ` (${row.installed.reason})` : ""}`].filter(Boolean).join("; ")}`).join("\n")}`
|
|
145
|
+
? `${flagged.length} uploaded build(s) lack passing QA:\n${flagged.map((row) => ` ${row.releaseId} ${row.platform}: ${[row.installed.status !== "passed" && row.installed.status !== "not-applicable" && `installed ${row.installed.status}${row.installed.reason ? ` (${row.installed.reason})` : ""}`].filter(Boolean).join("; ")}`).join("\n")}`
|
|
130
146
|
: "all uploaded builds have passing QA",
|
|
131
147
|
].join("\n");
|
|
132
148
|
}
|
package/release-qa-command.mjs
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// There is no source stage (GATE-CONTRACT GC-A07): QA journeys run after the build against the installed dev copy.
|
|
23
23
|
// This command refuses to seal from inside a QA run (RIGHT_RELEASE_QA_STAGE set): sealing is never test execution.
|
|
24
24
|
import { createHash } from "node:crypto";
|
|
25
|
+
import { createRequire } from "node:module";
|
|
25
26
|
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
26
27
|
import os from "node:os";
|
|
27
28
|
import path from "node:path";
|
|
@@ -102,6 +103,18 @@ export function evidencePathFromOutput(stdout) {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
/** Run the QA plan through the runner, then seal a receipt. `deps` are test seams; production uses the defaults. */
|
|
106
|
+
/** GC-A10: the QA config of an app with journeys declares `[snapshot]` (the real data and credential items rightkit-qa snapshots and restores). */
|
|
107
|
+
export function assertSnapshotConfigured(qaConfigFile) {
|
|
108
|
+
let table;
|
|
109
|
+
try { table = createRequire(import.meta.url)("smol-toml").parse(readFileSync(qaConfigFile, "utf8")); } catch (error) {
|
|
110
|
+
throw new Error(`qa.config ${qaConfigFile} is not readable TOML: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
const snapshot = table?.snapshot;
|
|
113
|
+
const named = snapshot && typeof snapshot === "object" && (
|
|
114
|
+
(typeof snapshot.app_name === "string" && snapshot.app_name.trim()) || (Array.isArray(snapshot.extra_paths) && snapshot.extra_paths.length) || snapshot.suite_shared === true || snapshot.android);
|
|
115
|
+
if (!named) throw new Error(`QA journeys run on the real app data under a snapshot and restore (GATE-CONTRACT GC-A10, rightkit#1437): ${qaConfigFile} has no usable [snapshot] table (app_name, extra_paths, suite_shared or android, plus process_names and the [[snapshot.credentials]] items a journey changes). Declare it; no memory backend, test-mode or dummy data stands in for it`);
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
export const SOURCE_QA_REMOVED = "source QA is removed (GATE-CONTRACT GC-A07): QA journeys run after the build against the installed dev copy";
|
|
106
119
|
|
|
107
120
|
export async function runQa({ stage, platform, releaseIdArg, configPath, deps = {} }) {
|
|
@@ -164,6 +177,9 @@ export async function runQa({ stage, platform, releaseIdArg, configPath, deps =
|
|
|
164
177
|
const journeysConfig = config.qa.journeys ?? null;
|
|
165
178
|
const qaConfig = path.resolve(appRoot, config.qa.config);
|
|
166
179
|
if (!existsSync(qaConfig)) throw new Error(`qa.config does not exist: ${qaConfig}`);
|
|
180
|
+
// GC-A10 (rightkit#1437): journeys run on the real data, so the QA config must declare the `[snapshot]` the runner
|
|
181
|
+
// snapshots and restores around them. No fake backend, no dummy data: a journeys lane without it is refused.
|
|
182
|
+
if (journeysConfig) assertSnapshotConfigured(qaConfig);
|
|
167
183
|
// #184: opt in with `qa.installed: { installDir? }`. Mounts the sealed DMG (mac) or runs the sealed NSIS installer into a
|
|
168
184
|
// throwaway directory (win) and hands the runner the opened app; always cleaned up, even when the runner throws.
|
|
169
185
|
let installedQa = null;
|
|
@@ -241,7 +257,7 @@ export async function runQa({ stage, platform, releaseIdArg, configPath, deps =
|
|
|
241
257
|
}
|
|
242
258
|
|
|
243
259
|
function usage(code) {
|
|
244
|
-
console.log("usage: right-release qa --stage installed --platform mac|win [--release <sealed-id>] [--config right-release.config.json]\n (seals the QA receipt; admission is warn or refuse per app in qa-admission-policy.json; refused inside a QA run)\n right-release qa audit [--app <dir>] [--json] [--since <YYYY-MM-DD>]\n right-release qa policy show | set --app <app> --mode warn|refuse --set-by <name> [--stage installed]\n | approve-runner --runner <file> --version <v> --platform mac|win --set-by <name> [--note <text>]");
|
|
260
|
+
console.log("usage: right-release qa --stage installed --platform mac|win [--release <sealed-id>] [--config right-release.config.json]\n (seals the QA receipt; admission is warn or refuse per app in qa-admission-policy.json; refused inside a QA run)\n right-release qa audit [--app <dir>] [--json] [--since <YYYY-MM-DD>]\n right-release qa policy show | set --repo <rightkit checkout> --app <app> --mode warn|refuse --set-by <name> [--stage installed]\n | approve-runner --repo <rightkit checkout> --runner <file> --version <v> --platform mac|win --set-by <name> [--note <text>]\n (policy writes name their checkout with --repo or --dir and are refused inside node_modules or a trusted-gates root)");
|
|
245
261
|
process.exit(code);
|
|
246
262
|
}
|
|
247
263
|
|
package/release-qa-policy.mjs
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
// see ownership-policy-bundle.mjs). CI should set RIGHT_RELEASE_QA_POLICY_BASELINE_REF=origin/main so the baseline
|
|
37
37
|
// is the protected branch rather than the local HEAD.
|
|
38
38
|
import { createHash } from "node:crypto";
|
|
39
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
39
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
40
40
|
import path from "node:path";
|
|
41
41
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
42
42
|
import { spawnSync } from "./background-process.mjs";
|
|
@@ -214,6 +214,21 @@ export function admissionModeFor(policy, app, stage) {
|
|
|
214
214
|
|
|
215
215
|
export const approvedRunnerDigests = (policy) => (policy?.approvedRunners ?? []).map((runner) => runner.sha256);
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* A policy write targets a RightKit checkout, never a package that is installed or pinned: a write inside `node_modules` would mutate an
|
|
219
|
+
* install, and one inside a trusted-gates root (the managed `.rightkit-managed/trusted-gates/...` pin) would modify the pinned gate's own
|
|
220
|
+
* files (#1235). The path is resolved through symlinks first, so a link cannot hide the location.
|
|
221
|
+
*/
|
|
222
|
+
export function assertWritablePolicyDir(dir) {
|
|
223
|
+
let resolved = path.resolve(dir);
|
|
224
|
+
try { resolved = realpathSync(resolved); } catch { /* a missing directory is refused when the policy file is read */ }
|
|
225
|
+
const segments = resolved.split(/[\\/]+/).map((segment) => segment.toLowerCase());
|
|
226
|
+
const refuse = (where) => { throw new QaPolicyError(`QA admission policy writes target a RightKit checkout, not ${where}: ${resolved}; pass --repo <rightkit checkout> or --dir <checkout>/packages/release`); };
|
|
227
|
+
if (segments.includes("node_modules")) refuse("an installed package (node_modules)");
|
|
228
|
+
if (segments.includes("trusted-gates") || segments.includes(".rightkit-managed")) refuse("a trusted-gates root");
|
|
229
|
+
return resolved;
|
|
230
|
+
}
|
|
231
|
+
|
|
217
232
|
/** Write the policy atomically, apps and runners in a deterministic order. */
|
|
218
233
|
function writePolicy(file, policy) {
|
|
219
234
|
const sorted = {
|
|
@@ -245,6 +260,7 @@ export function setAdmissionMode({ app, mode, setBy, stage, dir = here, now = ()
|
|
|
245
260
|
if (!ADMISSION_MODES.includes(mode)) throw new QaPolicyError("mode must be warn or refuse");
|
|
246
261
|
if (!setBy || !String(setBy).trim()) throw new QaPolicyError("set_by is required");
|
|
247
262
|
if (stage !== undefined && !ADMISSION_STAGES.includes(stage)) throw new QaPolicyError(`stage must be ${ADMISSION_STAGES.join(" or ")}`);
|
|
263
|
+
assertWritablePolicyDir(dir);
|
|
248
264
|
const file = path.join(dir, QA_ADMISSION_POLICY_FILE);
|
|
249
265
|
const current = parsePolicyText(readFileSync(file, "utf8"), QA_ADMISSION_POLICY_FILE);
|
|
250
266
|
const entry = { mode, since: now().toISOString().slice(0, 10), set_by: String(setBy) };
|
|
@@ -292,6 +308,7 @@ export function approveRunner({
|
|
|
292
308
|
throw new QaPolicyError(`${file} --version reported ${JSON.stringify(output.slice(0, 80))} (exit ${run?.status ?? run?.error?.message ?? "none"}), expected "rightkit-qa ${version}"`);
|
|
293
309
|
}
|
|
294
310
|
if (sha256Of(readRunnerBytes(file)) !== sha256) throw new QaPolicyError(`${file} changed while its version was being checked; nothing was approved`);
|
|
311
|
+
assertWritablePolicyDir(dir);
|
|
295
312
|
const policyFile = path.join(dir, QA_ADMISSION_POLICY_FILE);
|
|
296
313
|
const current = parsePolicyText(readFileSync(policyFile, "utf8"), QA_ADMISSION_POLICY_FILE);
|
|
297
314
|
const present = current.approvedRunners.find((item) => item.sha256 === sha256 && (item.platform ?? null) === platform);
|
|
@@ -308,10 +325,20 @@ export function approveRunner({
|
|
|
308
325
|
* are test seams: `dir` (the policy directory), `env`, `now`, `spawn`, `versionsFile`, and `program` (the usage name).
|
|
309
326
|
*/
|
|
310
327
|
export function main(args, {
|
|
311
|
-
stdout = (text) => console.log(text), stderr = (text) => console.error(text), dir, env, now, spawn, versionsFile, program = "release-qa-policy.mjs",
|
|
328
|
+
stdout = (text) => console.log(text), stderr = (text) => console.error(text), dir: injectedDir, env, now, spawn, versionsFile: injectedVersionsFile, program = "release-qa-policy.mjs",
|
|
312
329
|
} = {}) {
|
|
313
330
|
const value = (flag) => { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; };
|
|
314
331
|
try {
|
|
332
|
+
// The policy directory: --dir <dir holding qa-admission-policy.json>, or --repo <RightKit checkout> (its packages/release). `show` may read the
|
|
333
|
+
// package's own copy; `set` and `approve-runner` write, so they name their checkout explicitly (#1235).
|
|
334
|
+
if (args.includes("--dir") && args.includes("--repo")) throw new QaPolicyError("give --dir or --repo, not both");
|
|
335
|
+
for (const flag of ["--dir", "--repo"]) if (args.includes(flag) && !nonEmpty(value(flag))) throw new QaPolicyError(`${flag} needs a value`);
|
|
336
|
+
const named = args.includes("--dir") ? path.resolve(value("--dir")) : args.includes("--repo") ? path.join(path.resolve(value("--repo")), "packages", "release") : undefined;
|
|
337
|
+
const dir = named ?? injectedDir;
|
|
338
|
+
if (named === undefined && injectedDir === undefined && (args[0] === "set" || args[0] === "approve-runner")) {
|
|
339
|
+
throw new QaPolicyError(`${args[0]} writes the policy: name the RightKit checkout with --repo <checkout> (or --dir <checkout>/packages/release); it never writes the installed package`);
|
|
340
|
+
}
|
|
341
|
+
const versionsFile = injectedVersionsFile ?? (named ? path.join(named, "rightkit-versions.json") : undefined);
|
|
315
342
|
if (args[0] === "show") { stdout(JSON.stringify(loadAdmissionPolicy({ dir, env }).policy, null, 2)); return 0; }
|
|
316
343
|
if (args[0] === "set") {
|
|
317
344
|
// A `--stage` with no value must not fall through to the app-level write, which removes the stages.
|
|
@@ -325,7 +352,7 @@ export function main(args, {
|
|
|
325
352
|
stdout(`qa runner approved: ${entry.sha256} rightkit-qa ${entry.version} (${entry.platform ?? "any platform"}, since ${entry.since}, set_by ${entry.set_by})`);
|
|
326
353
|
return 0;
|
|
327
354
|
}
|
|
328
|
-
stderr(`usage: ${program} show\n ${program} set --app <app> --mode warn|refuse --set-by <name> [--stage installed]\n ${program} approve-runner --runner <file> --version <v> --platform mac|win --set-by <name> [--note <text>]`);
|
|
355
|
+
stderr(`usage: ${program} show [--repo <checkout> | --dir <dir>]\n ${program} set --repo <checkout> --app <app> --mode warn|refuse --set-by <name> [--stage installed]\n ${program} approve-runner --repo <checkout> --runner <file> --version <v> --platform mac|win --set-by <name> [--note <text>]\n (--dir <dir> names the directory holding ${QA_ADMISSION_POLICY_FILE} instead; a write inside node_modules or a trusted-gates root is refused)`);
|
|
329
356
|
return 2;
|
|
330
357
|
} catch (error) {
|
|
331
358
|
stderr(`release-qa-policy: ${error.message}`);
|