@rightkit/release 0.2.69 → 0.2.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +4 -2
  2. package/rightkit-versions.json +3 -2
  3. package/addon-command.test.mjs +0 -54
  4. package/addon-contract.test.mjs +0 -48
  5. package/asr-artifact-adoption.test.mjs +0 -122
  6. package/build-invocation-contract.test.mjs +0 -124
  7. package/build-release.test.mjs +0 -242
  8. package/cache-command.test.mjs +0 -118
  9. package/cache-policy.test.mjs +0 -346
  10. package/cargo-guard.test.mjs +0 -195
  11. package/cargo-target.test.mjs +0 -82
  12. package/create-mac-updater.test.mjs +0 -14
  13. package/github-release.test.mjs +0 -103
  14. package/heavy-command.test.mjs +0 -221
  15. package/legal-contract.test.mjs +0 -151
  16. package/mirror-root-artifact.test.mjs +0 -58
  17. package/model-promote.test.mjs +0 -284
  18. package/notary-auth.test.mjs +0 -31
  19. package/nsis-payload.test.mjs +0 -139
  20. package/nsis-upgrade-contract.test.mjs +0 -57
  21. package/pipeline-normalization-contract.test.mjs +0 -140
  22. package/preflight.test.mjs +0 -123
  23. package/progress-control.test.mjs +0 -56
  24. package/prune-r2.test.mjs +0 -12
  25. package/publish-cargo.test.mjs +0 -43
  26. package/publish-swift.test.mjs +0 -44
  27. package/publish-update.test.mjs +0 -207
  28. package/qa-contract.test.mjs +0 -47
  29. package/registry-parity.test.mjs +0 -30
  30. package/release-cli-contract.test.mjs +0 -119
  31. package/release-invocation.test.mjs +0 -22
  32. package/release-state.test.mjs +0 -395
  33. package/release-token.test.mjs +0 -21
  34. package/release.test.mjs +0 -533
  35. package/right-suite-contract.test.mjs +0 -1011
  36. package/rightapps-register.test.mjs +0 -28
  37. package/runtime-artifact-manifest.test.mjs +0 -128
  38. package/sign-updater.test.mjs +0 -12
  39. package/source-gate.test.mjs +0 -25
  40. package/standalone-clone-evidence.json +0 -32
  41. package/standalone-clone-verify.test.mjs +0 -76
  42. package/suite-doctor.test.mjs +0 -19
  43. package/target-bridge.test.mjs +0 -269
  44. package/tauri-bundle-marker.test.mjs +0 -81
  45. package/upload-large.test.mjs +0 -70
@@ -1,195 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import path from "node:path";
3
- import test from "node:test";
4
-
5
- import { assertComputePolicyAllowsCargo, cargoCacheEnvironment, cargoProjectRoot, cargoSubcommand, checkHookInput, computePolicyPath, resolveRealCargo, resolveRealRustc, runCargoGuard, shellRunsCargoTest, shouldGuardCargo } from "./cargo-guard.mjs";
6
-
7
- test("compute policy path ignores XDG_CONFIG_HOME regardless of value", () => {
8
- assert.equal(
9
- computePolicyPath({ platform: "linux", env: { XDG_CONFIG_HOME: "/one/path" }, home: "/home/u" }),
10
- computePolicyPath({ platform: "linux", env: {}, home: "/home/u" }),
11
- );
12
- assert.equal(computePolicyPath({ platform: "linux", env: {}, home: "/home/u" }), path.join("/home/u/.config/rightsuite", "compute-policy.json"));
13
- });
14
-
15
- test("Cargo guard serializes compiling commands but bypasses inspection and formatting", () => {
16
- for (const args of [["build"], ["test"], ["check"], ["clippy"], ["nextest", "run"], ["clean"], ["+stable", "bench"]]) {
17
- assert.equal(shouldGuardCargo(args), true, args.join(" "));
18
- }
19
- for (const args of [["fmt", "--check"], ["metadata"], ["tree"], ["fetch"], ["--version"], []]) {
20
- assert.equal(shouldGuardCargo(args), false, args.join(" "));
21
- }
22
- assert.equal(cargoSubcommand(["+stable", "test"]), "test");
23
- assert.equal(shouldGuardCargo(["--color", "always", "fmt"]), false);
24
- assert.equal(shouldGuardCargo(["--config", "net.git-fetch-with-cli=true", "check"]), true);
25
- assert.equal(shouldGuardCargo(["-Z", "unstable-options", "fmt"]), false);
26
- });
27
-
28
- test("global policy denies Cargo test before Cargo resolution", async () => {
29
- const policy = { exists: () => true, read: () => '{"schemaVersion":1,"cargoTest":"deny"}', env: {} };
30
- assert.throws(() => assertComputePolicyAllowsCargo(["test", "-p", "app"], policy), /denied by global/);
31
- assert.doesNotThrow(() => assertComputePolicyAllowsCargo(["check"], policy));
32
- let resolved = false;
33
- await assert.rejects(runCargoGuard(["test"], {
34
- env: { RIGHTSUITE_COMPUTE_POLICY: "/policy.json" },
35
- policyOptions: { exists: () => true, read: () => '{"schemaVersion":1,"cargoTest":"deny"}' },
36
- resolveCargo: () => { resolved = true; return "/real/cargo"; },
37
- }), /denied by global/);
38
- assert.equal(resolved, false);
39
- });
40
-
41
- test("Bash policy detects direct, absolute, rustup and nested Cargo tests only", () => {
42
- for (const command of ["cargo test -p app", "cd app && /toolchain/bin/cargo +stable test", "rustup run stable cargo test", "bash -c 'cargo test'"]) {
43
- assert.equal(shellRunsCargoTest(command), true, command);
44
- }
45
- for (const command of ["cargo check", "rg 'cargo test' docs", "echo cargo test", "cargo fmt --check"]) {
46
- assert.equal(shellRunsCargoTest(command), false, command);
47
- }
48
- assert.throws(() => checkHookInput(JSON.stringify({ tool_input: { command: "cargo test" } }), {
49
- exists: () => true, read: () => '{"schemaVersion":1,"cargoTest":"deny"}', env: {},
50
- }), /denied by global/);
51
- });
52
-
53
- test("Cargo guard resolves real Cargo through rustup or explicit override", () => {
54
- assert.equal(resolveRealCargo({ env: { RIGHTSUITE_REAL_CARGO: "/opt/toolchain/cargo" } }), path.resolve("/opt/toolchain/cargo"));
55
- const calls = [];
56
- const cargo = resolveRealCargo({ env: {}, run: (command, args) => { calls.push([command, args]); return { status: 0, stdout: "/real/cargo\n" }; } });
57
- assert.equal(cargo, path.resolve("/real/cargo"));
58
- assert.deepEqual(calls[0][1], ["which", "cargo"]);
59
- assert.equal(resolveRealRustc({ env: { RIGHTSUITE_REAL_RUSTC: "/opt/toolchain/rustc" } }), path.resolve("/opt/toolchain/rustc"));
60
- assert.equal(resolveRealRustc({ env: {}, run: () => ({ status: 0, stdout: "/real/rustc\n" }) }), path.resolve("/real/rustc"));
61
- });
62
-
63
- function cacheEnv(overrides = {}) {
64
- return { ...(process.platform === "win32" ? { LOCALAPPDATA: "C:\\Users\\test\\AppData\\Local" } : { RIGHT_RELEASE_CACHE_ROOT: "/tmp/rightkit-release-cache" }), ...overrides };
65
- }
66
-
67
- test("Cargo guard injects project-keyed target and sccache directories", async () => {
68
- let guarded;
69
- await runCargoGuard(["build"], {
70
- env: cacheEnv(), resolveCargo: () => "/real/cargo", resolveRustc: () => "/real/rustc",
71
- runHeavy: async (_args, config) => { guarded = config.env; return 0; },
72
- });
73
- assert.match(guarded.CARGO_TARGET_DIR, /dev-targets[/\\][^/\\]+-[a-f0-9]{12}$/);
74
- assert.match(guarded.SCCACHE_DIR, /[/\\]sccache$/);
75
- assert.equal(guarded.RUSTC_WRAPPER, "sccache");
76
- });
77
-
78
- test("Cargo guard rejects cache escapes and alternate compiler wrappers", async () => {
79
- const run = (args, overrides) => runCargoGuard(args, {
80
- env: cacheEnv(overrides), resolveCargo: () => "/real/cargo", resolveRustc: () => "/real/rustc",
81
- runHeavy: async () => 0,
82
- });
83
- await assert.rejects(run(["build"], { CARGO_TARGET_DIR: path.resolve("outside-target") }), /CARGO_TARGET_DIR/);
84
- await assert.rejects(run(["build"], { SCCACHE_DIR: path.resolve("outside-sccache") }), /SCCACHE_DIR/);
85
- await assert.rejects(run(["build", `--target-dir=${path.resolve("outside-flag")}`]), /--target-dir/);
86
- await assert.rejects(run(["build"], { RUSTC_WRAPPER: "rustc-wrapper" }), /RUSTC_WRAPPER/);
87
- });
88
-
89
- test("Cargo guard hands the whole invocation to the broker on a managed host", async () => {
90
- const calls = [];
91
- let resolvedReal = false;
92
- const options = {
93
- env: { TEST: "1" },
94
- policyOptions: { exists: () => false },
95
- isBrokerHost: () => true,
96
- resolveShim: () => "/managed/agent-bin/cargo",
97
- resolveCargo: () => { resolvedReal = true; return "/real/cargo"; },
98
- resolveRustc: () => { resolvedReal = true; return "/real/rustc"; },
99
- runHeavy: async () => { throw new Error("must not run heavy on a broker host"); },
100
- runLight: async (command, args) => { calls.push([command, args]); return 0; },
101
- };
102
- // A guarded command (build) and a light command (--version) both delegate to
103
- // the broker shim verbatim, and the real-toolchain resolver is never touched.
104
- assert.equal(await runCargoGuard(["build", "--release"], options), 0);
105
- assert.equal(await runCargoGuard(["--version"], options), 0);
106
- assert.deepEqual(calls, [["/managed/agent-bin/cargo", ["build", "--release"]], ["/managed/agent-bin/cargo", ["--version"]]]);
107
- assert.equal(resolvedReal, false);
108
- });
109
-
110
- test("Cargo guard falls back to real resolution when a broker signal has no shim", async () => {
111
- const calls = [];
112
- await runCargoGuard(["build"], {
113
- env: cacheEnv(), isBrokerHost: () => true, resolveShim: () => null,
114
- resolveCargo: () => "/real/cargo", resolveRustc: () => "/real/rustc",
115
- runHeavy: async (args) => { calls.push(args); return 0; },
116
- });
117
- assert.deepEqual(calls[0].slice(0, 2), ["--", "/real/cargo"]);
118
- });
119
-
120
- test("Cargo guard routes heavy and light commands without recursion", async () => {
121
- const calls = [];
122
- const options = {
123
- env: { TEST: "1", ...cacheEnv() },
124
- policyOptions: { exists: () => false },
125
- resolveCargo: () => "/real/cargo",
126
- resolveRustc: () => "/real/rustc",
127
- runHeavy: async (args, config) => { calls.push(["heavy", args, config.env]); return 0; },
128
- runLight: async (command, args, env) => { calls.push(["light", command, args, env]); return 0; },
129
- };
130
- assert.equal(await runCargoGuard(["test"], options), 0);
131
- assert.equal(await runCargoGuard(["fmt", "--check"], options), 0);
132
- assert.deepEqual(calls[0].slice(0, 2), ["heavy", ["--", "/real/cargo", "test"]]);
133
- const cacheRoot = cacheEnv().RIGHT_RELEASE_CACHE_ROOT ?? path.join(cacheEnv().LOCALAPPDATA, "RightSuite", "Cache", "release");
134
- assert.equal(calls[0][2].CARGO_TARGET_DIR.startsWith(path.join(path.resolve(cacheRoot), "dev-targets") + path.sep), true);
135
- assert.equal(calls[0][2].RUSTC_WRAPPER, "sccache");
136
- assert.deepEqual(calls[1], ["light", "/real/cargo", ["fmt", "--check"], options.env]);
137
- });
138
-
139
- test("Cargo guard forces target and compiler caches for each project", () => {
140
- const existing = new Set(["/repo/Cargo.toml", "/repo/crate/Cargo.toml"]);
141
- assert.equal(cargoProjectRoot(["test"], { cwd: "/repo/crate", platform: "mac", exists: (file) => existing.has(file) }), "/repo");
142
- const env = cargoCacheEnvironment(["test"], {
143
- cwd: "/repo/crate", platform: "mac", exists: (file) => existing.has(file),
144
- env: { RIGHT_RELEASE_CACHE_ROOT: "/cache" },
145
- });
146
- assert.match(env.CARGO_TARGET_DIR, /^\/cache\/dev-targets\/repo-[a-f0-9]{12}$/);
147
- assert.equal(env.RUSTC_WRAPPER, "sccache");
148
- assert.equal(env.SCCACHE_DIR, "/cache/sccache");
149
- assert.equal(env.RIGHTSUITE_CARGO_CACHE_GUARD, "1");
150
- });
151
-
152
- test("Cargo guard rejects cache bypasses and permits RightKit-owned cache paths", () => {
153
- const base = { cwd: "/repo", platform: "mac", exists: () => false };
154
- assert.throws(() => cargoCacheEnvironment(["test"], { ...base, env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", CARGO_TARGET_DIR: "/tmp/target" } }), /CARGO_TARGET_DIR must stay inside/);
155
- assert.throws(() => cargoCacheEnvironment(["test", "--target-dir", "/tmp/target"], { ...base, env: { RIGHT_RELEASE_CACHE_ROOT: "/cache" } }), /--target-dir must stay inside/);
156
- assert.throws(() => cargoCacheEnvironment(["test"], { ...base, env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", RUSTC_WRAPPER: "rustc-wrapper" } }), /must be sccache/);
157
- const env = cargoCacheEnvironment(["test", "--target-dir=/cache/test-targets/app"], {
158
- ...base,
159
- env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", CARGO_TARGET_DIR: "/cache/test-targets/app", SCCACHE_DIR: "/cache/sccache", RUSTC_WRAPPER: "/usr/bin/sccache" },
160
- });
161
- assert.equal(env.CARGO_TARGET_DIR, "/cache/test-targets/app");
162
- });
163
-
164
- test("Cargo guard passes a broker-owned CARGO_TARGET_DIR through instead of rejecting it", () => {
165
- const base = { cwd: "/repo", platform: "mac", exists: () => false };
166
- // Outside the shared cache root, which would be rejected on a non-broker host
167
- // (see the previous test) — but the broker owns this value, not Cache V2.
168
- const env = cargoCacheEnvironment(["test"], {
169
- ...base,
170
- env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", RIGHTKIT_BUILD_BROKER_SOCKET: "/managed/broker.sock", CARGO_TARGET_DIR: "/broker/workspace/target" },
171
- });
172
- assert.equal(env.CARGO_TARGET_DIR, "/broker/workspace/target");
173
-
174
- // Same for an explicit --target-dir outside the cache root.
175
- const explicit = cargoCacheEnvironment(["test", "--target-dir", "/broker/workspace/target"], {
176
- ...base,
177
- env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", RIGHTKIT_BUILD_BROKER_SOCKET: "/managed/broker.sock" },
178
- });
179
- assert.doesNotThrow(() => explicit);
180
-
181
- // Non-broker host: unchanged, still rejects the cache bypass.
182
- assert.throws(
183
- () => cargoCacheEnvironment(["test"], { ...base, env: { RIGHT_RELEASE_CACHE_ROOT: "/cache", CARGO_TARGET_DIR: "/tmp/target" } }),
184
- /CARGO_TARGET_DIR must stay inside/,
185
- );
186
- });
187
-
188
- test("Cargo guard derives native Windows cache paths", () => {
189
- const env = cargoCacheEnvironment(["build"], {
190
- cwd: "D:\\Claude\\citadel", platform: "win", exists: (file) => file === "D:\\Claude\\citadel\\Cargo.toml",
191
- env: { LOCALAPPDATA: "C:\\Users\\test\\AppData\\Local" },
192
- });
193
- assert.match(env.CARGO_TARGET_DIR, /^C:\\Users\\test\\AppData\\Local\\RightSuite\\Cache\\release\\dev-targets\\citadel-[a-f0-9]{12}$/);
194
- assert.equal(env.SCCACHE_DIR, "C:\\Users\\test\\AppData\\Local\\RightSuite\\Cache\\release\\sccache");
195
- });
@@ -1,82 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import { spawnSync } from "node:child_process";
6
- import test from "node:test";
7
- import { fileURLToPath } from "node:url";
8
-
9
- import { resolveTargetRoot } from "./cargo-target.mjs";
10
-
11
- const here = path.dirname(fileURLToPath(import.meta.url));
12
- const cli = path.join(here, "cargo-target.mjs");
13
-
14
- function fakeCargo() {
15
- const bin = mkdtempSync(path.join(os.tmpdir(), "rightkit-fake-cargo-"));
16
- return {
17
- bin,
18
- execFileSync(_command, args) {
19
- const manifest = args.at(-1);
20
- if (manifest.includes("fail-manifest")) throw new Error("boom");
21
- if (manifest.includes("bad-target-manifest")) return '{"target_directory":"relative/target"}';
22
- return JSON.stringify({ target_directory: path.join(bin, "target") });
23
- },
24
- };
25
- }
26
-
27
- test("resolveTargetRoot returns the absolute target_directory Cargo metadata reports", () => {
28
- const { bin, execFileSync } = fakeCargo();
29
- const manifest = path.join(mkdtempSync(path.join(os.tmpdir(), "rightkit-cargo-target-fixture-")), "Cargo.toml");
30
- const result = resolveTargetRoot(manifest, { execFileSync });
31
- assert.equal(result, path.resolve(path.join(bin, "target")));
32
- });
33
-
34
- test("resolveTargetRoot fails closed, naming the manifest, when target_directory is not absolute", () => {
35
- const { execFileSync } = fakeCargo();
36
- const manifest = path.join(mkdtempSync(path.join(os.tmpdir(), "rightkit-cargo-target-fixture-")), "bad-target-manifest-Cargo.toml");
37
- assert.throws(
38
- () => resolveTargetRoot(manifest, { execFileSync }),
39
- new RegExp(`metadata for .*bad-target-manifest-Cargo\\.toml did not report an absolute target_directory`),
40
- );
41
- });
42
-
43
- test("resolveTargetRoot fails closed, naming the manifest, when the metadata command exits non-zero", () => {
44
- const { execFileSync } = fakeCargo();
45
- const manifest = path.join(mkdtempSync(path.join(os.tmpdir(), "rightkit-cargo-target-fixture-")), "fail-manifest-Cargo.toml");
46
- assert.throws(
47
- () => resolveTargetRoot(manifest, { execFileSync }),
48
- new RegExp(`metadata failed for .*fail-manifest-Cargo\\.toml`),
49
- );
50
- });
51
-
52
- test("resolveTargetRoot throws when no manifest path is given", () => {
53
- assert.throws(() => resolveTargetRoot(), /resolveTargetRoot requires a Cargo.toml manifest path/);
54
- assert.throws(() => resolveTargetRoot(""), /resolveTargetRoot requires a Cargo.toml manifest path/);
55
- });
56
-
57
- test("CLI mode writes only the resolved path to stdout on success", () => {
58
- const manifestDir = mkdtempSync(path.join(os.tmpdir(), "rightkit-cargo-target-fixture-"));
59
- const manifest = path.join(manifestDir, "Cargo.toml");
60
- mkdirSync(path.join(manifestDir, "src"));
61
- writeFileSync(path.join(manifestDir, "src", "lib.rs"), "");
62
- writeFileSync(manifest, "[package]\nname = \"fixture\"\nversion = \"0.0.0\"\n");
63
- const result = spawnSync(process.execPath, [cli, manifest], { encoding: "utf8" });
64
- assert.equal(result.status, 0, result.stderr);
65
- assert.equal(path.isAbsolute(result.stdout.trim()), true);
66
- });
67
-
68
- test("CLI mode writes a message to stderr and exits 1 on failure", () => {
69
- const manifestDir = mkdtempSync(path.join(os.tmpdir(), "rightkit-cargo-target-fixture-"));
70
- const manifest = path.join(manifestDir, "fail-manifest-Cargo.toml");
71
- writeFileSync(manifest, "not valid toml");
72
- const result = spawnSync(process.execPath, [cli, manifest], { encoding: "utf8" });
73
- assert.equal(result.status, 1);
74
- assert.equal(result.stdout, "");
75
- assert.match(result.stderr, /metadata failed for .*fail-manifest-Cargo\.toml/);
76
- });
77
-
78
- test("CLI mode requires a manifest argument", () => {
79
- const result = spawnSync(process.execPath, [cli], { encoding: "utf8" });
80
- assert.equal(result.status, 1);
81
- assert.match(result.stderr, /usage: cargo-target\.mjs/);
82
- });
@@ -1,14 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { spawnSync } from "node:child_process";
3
- import { fileURLToPath } from "node:url";
4
- import test from "node:test";
5
-
6
- const helper = fileURLToPath(new URL("./create-mac-updater.mjs", import.meta.url));
7
-
8
- test("documents the final signed-app to signed-updater sequence in dry-run mode", () => {
9
- const result = spawnSync(process.execPath, [helper, "--app", "bundle/Test.app", "--output", "bundle/Test.app.tar.gz", "--dry-run"], { encoding: "utf8" });
10
- assert.equal(result.status, 0, result.stderr);
11
- assert.match(result.stdout, /COPYFILE_DISABLE=1 tar .*Test\.app\.tar\.gz.*Test\.app[\\/]Contents/);
12
- assert.doesNotMatch(result.stdout, / Test\.app$/m);
13
- assert.match(result.stdout, /tauri signer sign .*Test\.app\.tar\.gz/);
14
- });
@@ -1,103 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { createHash } from "node:crypto";
3
- import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import test from "node:test";
7
- import { execFileSync } from "node:child_process";
8
- import { canonicalAddonManifest, createAddonManifest } from "./addon-contract.mjs";
9
- import { prepareGitHubAddonRelease, prepareGitHubRelease, publishGitHubRelease } from "./github-release.mjs";
10
-
11
- const sha256 = (value) => createHash("sha256").update(value).digest("hex");
12
-
13
- function fixture() {
14
- const root = mkdtempSync(path.join(os.tmpdir(), "right-release-github-"));
15
- const releaseId = "cutright-1.2.3-abcdef12";
16
- const sealedDir = path.join(root, ".right-release", "sealed", releaseId, "windows");
17
- mkdirSync(sealedDir, { recursive: true });
18
- writeFileSync(path.join(sealedDir, "CutRight.exe"), "signed-installer");
19
- writeFileSync(path.join(sealedDir, "release-manifest.json"), `${JSON.stringify({
20
- schema: 1, releaseId, app: "cutright", version: "1.2.3", commit: "abcdef1234567890", platform: "win",
21
- files: [{ role: "installer", name: "CutRight.exe", sha256: sha256("signed-installer"), sizeBytes: 16 }],
22
- checkpoints: ["sealed"],
23
- })}\n`);
24
- return { root, releaseId };
25
- }
26
-
27
- function addonFixture() {
28
- const root = mkdtempSync(path.join(os.tmpdir(), "right-release-github-addon-"));
29
- mkdirSync(path.join(root, "out"));
30
- for (const [name, bytes] of [["membrane", "command"], ["membrane-service", "service"], ["icon.png", "icon"], ["LICENSE", "license"], ["EULA.txt", "eula"], ["PRIVACY.md", "privacy"], ["THIRD-PARTY-NOTICES.txt", "notices"]]) writeFileSync(path.join(root, "out", name), bytes);
31
- execFileSync("git", ["init", "--initial-branch", "main"], { cwd: root });
32
- execFileSync("git", ["config", "user.email", "test@example.com"], { cwd: root });
33
- execFileSync("git", ["config", "user.name", "Test"], { cwd: root });
34
- writeFileSync(path.join(root, "tracked"), "source"); execFileSync("git", ["add", "."], { cwd: root }); execFileSync("git", ["commit", "-m", "source"], { cwd: root });
35
- const files = [["command", "membrane", true], ["service", "membrane-service", true], ["icon", "icon.png", false], ["license", "LICENSE", false], ["eula", "EULA.txt", false], ["privacy", "PRIVACY.md", false], ["third-party-notices", "THIRD-PARTY-NOTICES.txt", false]].map(([role, name, executable]) => ({ role, name, source: `out/${name}`, executable }));
36
- const config = { schema: 1, kind: "headless-addon", addon: "membrane", version: "0.1.0", packageManager: "pnpm", distribution: { provider: "github-releases", repository: "Orthic-Labs/Membrane" }, checks: [], buildInputs: { include: ["tracked"] }, consumer: { contract: "membrane-product-v1" }, targets: { win: { targetTriple: "x86_64-pc-windows-msvc", build: { cmd: "false", args: [] }, signing: { contract: "azure-artifact-signing-v1" }, files } } };
37
- const commit = execFileSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }).trim();
38
- const manifest = createAddonManifest({ config, root, platform: "win", commit, signing: { command: { contract: "test-fixture-v1", status: "verified" }, service: { contract: "test-fixture-v1", status: "verified" } } });
39
- const sealed = path.join(root, ".right-release", "addons", "membrane", "0.1.0", commit.slice(0, 8), "win"); mkdirSync(sealed, { recursive: true });
40
- for (const file of manifest.files) writeFileSync(path.join(sealed, file.name), readFileSync(path.join(root, "out", file.name)));
41
- writeFileSync(path.join(sealed, "addon-manifest.json"), canonicalAddonManifest(manifest));
42
- return { root, config };
43
- }
44
-
45
- test("GitHub plan derives tag, notes, installer, manifest & checksums only from sealed bytes", () => {
46
- const fx = fixture();
47
- const plan = prepareGitHubRelease({ repoRoot: fx.root, releaseId: fx.releaseId, platform: "win", repo: "Orthic-Labs/CutRight" });
48
- assert.equal(plan.tag, "v1.2.3");
49
- assert.equal(plan.assets.length, 3);
50
- assert.match(plan.notes, /abcdef1234567890/);
51
- assert.equal(readFileSync(plan.assets[2], "utf8"), `${sha256("signed-installer")} CutRight.exe\n`);
52
- });
53
-
54
- test("dry-run checks public visibility without creating or uploading a release", () => {
55
- const fx = fixture();
56
- const plan = prepareGitHubRelease({ repoRoot: fx.root, releaseId: fx.releaseId, platform: "win", repo: "Orthic-Labs/CutRight" });
57
- const calls = [];
58
- const run = (_command, args, options = {}) => {
59
- calls.push(args);
60
- if (args[0] === "repo") return JSON.stringify({ visibility: "PUBLIC" });
61
- if (args[0] === "release" && args[1] === "view") return options.allowFailure ? { ok: false } : "";
62
- throw new Error(`unexpected mutation: ${args.join(" ")}`);
63
- };
64
- assert.equal(publishGitHubRelease(plan, { repo: "Orthic-Labs/CutRight", dryRun: true, run }).status, "would-create");
65
- assert.equal(calls.length, 2);
66
- });
67
-
68
- test("GitHub add-on plan uses a content-addressed platform tag and manifest URL", () => {
69
- const fx = addonFixture();
70
- const plan = prepareGitHubAddonRelease({ repoRoot: fx.root, config: fx.config, platform: "win", repo: "Orthic-Labs/Membrane" });
71
- assert.match(plan.tag, /^addon-membrane-v0\.1\.0-win-sha256-[0-9a-f]{64}$/);
72
- assert.equal(plan.assets.at(-1), plan.manifestPath);
73
- assert.equal(plan.manifestUrl, `https://github.com/Orthic-Labs/Membrane/releases/download/${plan.tag}/addon-manifest.json`);
74
- });
75
-
76
- test("existing GitHub add-on release is verified without upload mutation", () => {
77
- const asset = path.join(mkdtempSync(path.join(os.tmpdir(), "right-release-existing-")), "addon-manifest.json"); writeFileSync(asset, "sealed");
78
- const calls = [];
79
- const run = (_command, args, options = {}) => {
80
- calls.push(args);
81
- if (args[0] === "repo") return JSON.stringify({ visibility: "PUBLIC" });
82
- if (args[0] === "release" && args[1] === "view") return options.allowFailure ? { ok: true } : "";
83
- if (args[0] === "release" && args[1] === "download") { mkdirSync(args[args.indexOf("--dir") + 1], { recursive: true }); writeFileSync(path.join(args[args.indexOf("--dir") + 1], path.basename(asset)), "sealed"); return options.allowFailure ? { ok: true, output: "" } : ""; }
84
- throw new Error(`unexpected mutation: ${args.join(" ")}`);
85
- };
86
- const result = publishGitHubRelease({ kind: "addon", manifest: { files: [] }, sealedDir: path.dirname(asset), tag: "immutable", assets: [asset], manifestUrl: "https://example.test/manifest" }, { repo: "Orthic-Labs/Membrane", run });
87
- assert.equal(result.status, "already-verified");
88
- assert.equal(calls.some((args) => args[0] === "release" && args[1] === "upload"), false);
89
- });
90
-
91
- test("partial GitHub add-on release uploads only missing assets then verifies all", () => {
92
- const root = mkdtempSync(path.join(os.tmpdir(), "right-release-resume-")); const first = path.join(root, "first"); const second = path.join(root, "second"); writeFileSync(first, "one"); writeFileSync(second, "two");
93
- const remote = new Map([["first", "one"]]); const uploads = [];
94
- const run = (_command, args, options = {}) => {
95
- if (args[0] === "repo") return JSON.stringify({ visibility: "PUBLIC" });
96
- if (args[0] === "release" && args[1] === "view") return { ok: true };
97
- if (args[0] === "release" && args[1] === "download") { const name = args[args.indexOf("--pattern") + 1]; if (!remote.has(name)) return { ok: false, error: "no assets match" }; const dir = args[args.indexOf("--dir") + 1]; mkdirSync(dir, { recursive: true }); writeFileSync(path.join(dir, name), remote.get(name)); return { ok: true, output: "" }; }
98
- if (args[0] === "release" && args[1] === "upload") { for (const value of args.slice(3, args.indexOf("--repo"))) { uploads.push(path.basename(value)); remote.set(path.basename(value), readFileSync(value, "utf8")); } return ""; }
99
- throw new Error(`unexpected call: ${args.join(" ")}`);
100
- };
101
- const result = publishGitHubRelease({ kind: "addon", manifest: { files: [] }, sealedDir: root, tag: "immutable", assets: [first, second], manifestUrl: "https://example.test/manifest" }, { repo: "Orthic-Labs/Membrane", run });
102
- assert.equal(result.status, "resumed-verified"); assert.deepEqual(uploads, ["second"]);
103
- });
@@ -1,221 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { mkdtempSync } from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import test from "node:test";
7
-
8
- import {
9
- acquireHeavyWorkSlot,
10
- formatResourceSnapshot,
11
- heavyChildDetached,
12
- heavyCommandEnvironment,
13
- heavyWorkRoot,
14
- parseMacResourceSnapshot,
15
- parseWindowsResourceSnapshot,
16
- resourceBlockers,
17
- runHeavyCommand,
18
- sweepTrackedHeavyWorkOrphan,
19
- systemResourceSnapshot,
20
- terminateProcessTree,
21
- watchOwnedProcessTree,
22
- } from "./heavy-command.mjs";
23
-
24
- test("heavy-work root is machine-wide rather than repository-local", () => {
25
- assert.equal(heavyWorkRoot({ platform: "mac", home: "/Users/test", env: {} }), "/Users/test/Library/Caches/RightSuite/heavy-work");
26
- assert.equal(heavyWorkRoot({ platform: "win", env: { LOCALAPPDATA: "C:\\Users\\test\\AppData\\Local" } }), "C:\\Users\\test\\AppData\\Local\\RightSuite\\heavy-work");
27
- });
28
-
29
- test("heavy-work root ignores XDG_CACHE_HOME regardless of value", () => {
30
- assert.equal(
31
- heavyWorkRoot({ platform: "linux", env: { XDG_CACHE_HOME: "/one/path" }, home: "/home/u" }),
32
- heavyWorkRoot({ platform: "linux", env: {}, home: "/home/u" }),
33
- );
34
- assert.equal(heavyWorkRoot({ platform: "linux", env: {}, home: "/home/u" }), "/home/u/.cache/rightsuite/heavy-work");
35
- });
36
-
37
- test("heavy commands default compiler and test concurrency to two", () => {
38
- const env = heavyCommandEnvironment({});
39
- assert.equal(env.CARGO_BUILD_JOBS, "2");
40
- assert.equal(env.RUST_TEST_THREADS, "2");
41
- assert.equal(env.RIGHTSUITE_HEAVY_WORK_OWNER, "1");
42
- assert.equal(heavyCommandEnvironment({ CARGO_BUILD_JOBS: "3", RUST_TEST_THREADS: "1" }).CARGO_BUILD_JOBS, "3");
43
- });
44
-
45
- test("only the slot owner creates a new POSIX process group", () => {
46
- assert.equal(heavyChildDetached({ slot: {}, platform: "mac" }), true);
47
- assert.equal(heavyChildDetached({ slot: null, platform: "mac" }), false);
48
- assert.equal(heavyChildDetached({ slot: {}, platform: "win" }), false);
49
- });
50
-
51
- test("mac resource parser reports memory, swap and thermal limiting", () => {
52
- const snapshot = parseMacResourceSnapshot({
53
- memory: "System-wide memory free percentage: 9%",
54
- swap: "vm.swapusage: total = 8192.00M used = 7750.62M free = 441.38M",
55
- thermal: "CPU_Speed_Limit = 70",
56
- });
57
- assert.equal(snapshot.freePercent, 9);
58
- assert.equal(Math.round(snapshot.swapUsedBytes / 1024 ** 2), 7751);
59
- assert.equal(snapshot.thermalLimited, true);
60
- assert.deepEqual(resourceBlockers(snapshot), ["memory free 9% < 15%", "macOS reports thermal/performance limiting"]);
61
- });
62
-
63
- test("Windows admission uses physical memory and CPU load with a Node memory fallback", () => {
64
- const snapshot = parseWindowsResourceSnapshot({
65
- system: JSON.stringify({ TotalBytes: 16 * 1024 ** 3, FreeBytes: 4 * 1024 ** 3, CpuLoadPercent: 94 }),
66
- });
67
- assert.equal(snapshot.freePercent, 25);
68
- assert.equal(snapshot.cpuLoadPercent, 94);
69
- assert.deepEqual(resourceBlockers(snapshot), ["CPU load 94% > 90%"]);
70
-
71
- const fallback = parseWindowsResourceSnapshot({ system: "not-json", fallbackTotalBytes: 8 * 1024 ** 3, fallbackFreeBytes: 2 * 1024 ** 3 });
72
- assert.equal(fallback.freePercent, 25);
73
- assert.equal(fallback.cpuLoadPercent, null);
74
- });
75
-
76
- test("Windows resource snapshot queries PowerShell without requiring optional modules", () => {
77
- const calls = [];
78
- const snapshot = systemResourceSnapshot({
79
- platform: "win",
80
- run: (command, args) => { calls.push({ command, args }); return { status: 0, stdout: '{"TotalBytes":8589934592,"FreeBytes":1073741824,"CpuLoadPercent":42}' }; },
81
- totalmem: () => 1,
82
- freemem: () => 1,
83
- });
84
- assert.equal(calls[0].command, "powershell.exe");
85
- assert.deepEqual(calls[0].args.slice(0, 3), ["-NoLogo", "-NoProfile", "-NonInteractive"]);
86
- assert.equal(snapshot.freePercent, 12.5);
87
- assert.equal(snapshot.cpuLoadPercent, 42);
88
- assert.equal(snapshot.thermalLimited, false);
89
- assert.equal(formatResourceSnapshot(snapshot), "memory-free=12.5% cpu-load=42%");
90
- });
91
-
92
- test("nested heavy command preserves ownership without another slot", async () => {
93
- const code = await runHeavyCommand(["--", process.execPath, "-e", "process.exit(0)"], { env: { ...process.env, RIGHTSUITE_HEAVY_WORK_OWNER: "1" } });
94
- assert.equal(code, 0);
95
- });
96
-
97
- test("owned process-tree termination targets a POSIX group or Windows task tree", () => {
98
- const signals = [];
99
- terminateProcessTree(202, { platform: "mac", kill: (pid, signal) => signals.push([pid, signal]), treeAlive: () => true, pause: () => {} });
100
- assert.deepEqual(signals, [[-202, "SIGTERM"], [-202, "SIGKILL"]]);
101
- const calls = [];
102
- terminateProcessTree(303, { platform: "win", run: (command, args) => calls.push([command, args]) });
103
- assert.deepEqual(calls, [["taskkill", ["/PID", "303", "/T", "/F"]]]);
104
- });
105
-
106
- test("slot serializes contenders and removes stale owners", () => {
107
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-"));
108
- const quiet = () => {};
109
- const snapshot = () => ({ freePercent: 50, swapUsedBytes: 0, swapTotalBytes: 0, thermalLimited: false });
110
- const first = acquireHeavyWorkSlot({ root, pid: 101, alive: (pid) => pid === 101, snapshot, log: quiet });
111
- assert.throws(
112
- () => acquireHeavyWorkSlot({ root, pid: 202, waitMs: 1, pollMs: 1, alive: (pid) => pid === 101, pause: () => {}, snapshot, log: quiet }),
113
- /holder pid 101/,
114
- );
115
- first.release();
116
-
117
- const lockDir = path.join(root, "slot");
118
- mkdirSync(lockDir);
119
- writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify({ pid: 303, token: "stale" }));
120
- const replacement = acquireHeavyWorkSlot({ root, pid: 404, alive: () => false, snapshot, log: quiet });
121
- replacement.release();
122
- });
123
-
124
- test("dead slot owner reaps its recorded matching child tree", () => {
125
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-owned-"));
126
- const killed = [];
127
- const options = {
128
- root, snapshot: () => ({ freePercent: 50, thermalLimited: false }), log: () => {},
129
- alive: (pid) => pid === 202,
130
- processStartedAt: (pid) => pid === 202 ? 1234 : null,
131
- terminate: (pid) => killed.push(pid),
132
- startWatcher: () => {},
133
- };
134
- const first = acquireHeavyWorkSlot({ ...options, pid: 101 });
135
- first.trackChild(202, "cargo");
136
- assert.equal(JSON.parse(readFileSync(path.join(root, "slot", "child.json"), "utf8")).childPid, 202);
137
- const replacement = acquireHeavyWorkSlot({ ...options, pid: 404 });
138
- assert.deepEqual(killed, [202]);
139
- replacement.release();
140
- });
141
-
142
- test("dead slot owner refuses to kill a reused child PID", () => {
143
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-reused-"));
144
- let observedStart = 1234;
145
- const options = {
146
- root, snapshot: () => ({ freePercent: 50, thermalLimited: false }), log: () => {},
147
- alive: (pid) => pid === 202,
148
- processStartedAt: (pid) => pid === 202 ? observedStart : null,
149
- terminate: () => assert.fail("reused PID must not be terminated"),
150
- startWatcher: () => {},
151
- };
152
- const first = acquireHeavyWorkSlot({ ...options, pid: 101 });
153
- first.trackChild(202, "cargo");
154
- observedStart = 5678;
155
- assert.throws(() => acquireHeavyWorkSlot({ ...options, pid: 404 }), /identity changed/);
156
- first.release();
157
- });
158
-
159
- test("preflight sweep reaps only a tracked child after an owner PID is reused", () => {
160
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-preflight-"));
161
- const lockDir = path.join(root, "slot");
162
- mkdirSync(lockDir);
163
- writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify({ pid: 101, ownerStartedAtMs: 100, token: "stale" }));
164
- writeFileSync(path.join(lockDir, "child.json"), JSON.stringify({ childPid: 202, childStartedAtMs: 200 }));
165
- const killed = [];
166
- assert.equal(sweepTrackedHeavyWorkOrphan({
167
- root,
168
- alive: (pid) => pid === 101 || pid === 202,
169
- startedAt: (pid) => pid === 101 ? 5_000 : pid === 202 ? 200 : null,
170
- terminate: (pid) => killed.push(pid),
171
- log: () => {},
172
- }), true);
173
- assert.deepEqual(killed, [202]);
174
- assert.equal(existsSync(lockDir), false);
175
- });
176
-
177
- test("preflight sweep refuses a reused tracked child PID instead of killing broadly", () => {
178
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-preflight-reused-"));
179
- const lockDir = path.join(root, "slot");
180
- mkdirSync(lockDir);
181
- writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify({ pid: 101, ownerStartedAtMs: 100, token: "stale" }));
182
- writeFileSync(path.join(lockDir, "child.json"), JSON.stringify({ childPid: 202, childStartedAtMs: 200 }));
183
- assert.throws(() => sweepTrackedHeavyWorkOrphan({
184
- root,
185
- alive: (pid) => pid === 101 || pid === 202,
186
- startedAt: (pid) => pid === 101 ? 5_000 : pid === 202 ? 4_000 : null,
187
- terminate: () => assert.fail("reused child PID must not be terminated"),
188
- log: () => {},
189
- }), /identity changed/);
190
- });
191
-
192
- test("preflight sweep refuses a tracked child without a verifiable start identity", () => {
193
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-preflight-unverified-"));
194
- const lockDir = path.join(root, "slot");
195
- mkdirSync(lockDir);
196
- writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify({ pid: 101, ownerStartedAtMs: 100, token: "stale" }));
197
- writeFileSync(path.join(lockDir, "child.json"), JSON.stringify({ childPid: 202, childStartedAtMs: 200 }));
198
- assert.throws(() => sweepTrackedHeavyWorkOrphan({
199
- root,
200
- alive: (pid) => pid === 101 || pid === 202,
201
- startedAt: (pid) => pid === 101 ? 5_000 : null,
202
- terminate: () => assert.fail("unverified child PID must not be terminated"),
203
- log: () => {},
204
- }), /identity changed/);
205
- });
206
-
207
- test("detached watcher reaps an owned child as soon as its owner disappears", async () => {
208
- const root = mkdtempSync(path.join(os.tmpdir(), "rightsuite-heavy-watch-"));
209
- const lockDir = path.join(root, "slot");
210
- mkdirSync(lockDir);
211
- writeFileSync(path.join(lockDir, "owner.json"), JSON.stringify({ pid: 101, token: "owned" }));
212
- writeFileSync(path.join(lockDir, "child.json"), JSON.stringify({ childPid: 202, childStartedAtMs: 1234 }));
213
- const killed = [];
214
- const result = await watchOwnedProcessTree(
215
- { root, token: "owned", ownerPid: 101, childPid: 202, childStartedAtMs: 1234 },
216
- { alive: (pid) => pid === 202, startedAt: () => 1234, terminate: (pid) => killed.push(pid), pause: async () => {} },
217
- );
218
- assert.equal(result, true);
219
- assert.deepEqual(killed, [202]);
220
- assert.equal(existsSync(lockDir), false);
221
- });