@rightkit/ci 0.3.0 → 0.3.1
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 +41 -1
- package/cli/right-git.mjs +22 -4
- package/install.mjs +1 -1
- package/manifest.mjs +190 -6
- package/manifest.schema.json +9 -1
- package/package.json +4 -2
- package/sync.mjs +47 -3
- package/templates/ci.yml +2 -2
- package/templates/package-smoke.yml +2 -2
- package/templates/profiles/rust-hybrid/ci.yml +7 -7
- package/templates/profiles/rust-hybrid/release-candidate.yml +2 -2
- package/templates/publish-npm.yml +2 -2
- package/templates/qualification.yml +2 -2
- package/templates/release-candidate.yml +2 -2
- package/templates/swift-check.yml +2 -2
- package/artifacts.test.mjs +0 -168
- package/checkout.test.mjs +0 -92
- package/cli.test.mjs +0 -68
- package/drift.test.mjs +0 -203
- package/guard-coverage.test.mjs +0 -237
- package/manifest.test.mjs +0 -535
- package/orkflows.test.mjs +0 -0
- package/ownership-registration.test.mjs +0 -20
- package/pack-smoke.test.mjs +0 -55
- package/pnpm-lock-patch.test.mjs +0 -161
- package/render.test.mjs +0 -2077
- package/supersede.test.mjs +0 -84
- package/swift-check.test.mjs +0 -95
- package/sync.test.mjs +0 -147
- package/test-support.mjs +0 -34
- package/uninstall.test.mjs +0 -89
- package/visibility-gate.test.mjs +0 -141
- package/workflows.test.mjs +0 -213
package/supersede.test.mjs
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import test from "node:test";
|
|
4
|
-
|
|
5
|
-
import { decideSupersede, median, olderRuns, parseSettings, runDurationMs } from "./supersede.mjs";
|
|
6
|
-
|
|
7
|
-
const NOW = Date.parse("2026-10-17T12:00:00Z");
|
|
8
|
-
const MIN = 60_000;
|
|
9
|
-
const startedAgo = (ms) => new Date(NOW - ms).toISOString();
|
|
10
|
-
|
|
11
|
-
test("median handles odd, even, empty and unusable values", () => {
|
|
12
|
-
assert.equal(median([3, 1, 2]), 2);
|
|
13
|
-
assert.equal(median([4, 1, 2, 3]), 2.5);
|
|
14
|
-
assert.equal(median([]), null);
|
|
15
|
-
assert.equal(median([Number.NaN, -1]), null);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("runDurationMs reads start and update times", () => {
|
|
19
|
-
assert.equal(runDurationMs({ run_started_at: "2026-10-17T10:00:00Z", updated_at: "2026-10-17T10:10:00Z" }), 10 * MIN);
|
|
20
|
-
assert.equal(runDurationMs({ run_started_at: "2026-10-17T10:10:00Z", updated_at: "2026-10-17T10:00:00Z" }), null);
|
|
21
|
-
assert.equal(runDurationMs({}), null);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("a run that has only just started is cancelled", () => {
|
|
25
|
-
const decision = decideSupersede({ run: { status: "in_progress", run_started_at: startedAgo(2 * MIN) }, medianMs: 20 * MIN, nowMs: NOW });
|
|
26
|
-
assert.equal(decision.cancel, true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("a run past the grace fraction of the median is left alone", () => {
|
|
30
|
-
const decision = decideSupersede({ run: { status: "in_progress", run_started_at: startedAgo(15 * MIN) }, medianMs: 20 * MIN, nowMs: NOW });
|
|
31
|
-
assert.equal(decision.cancel, false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("the grace boundary is exact: 0.7 of 20 minutes is 14 minutes", () => {
|
|
35
|
-
const at = (ms) => decideSupersede({ run: { status: "in_progress", run_started_at: startedAgo(ms) }, medianMs: 20 * MIN, nowMs: NOW }).cancel;
|
|
36
|
-
assert.equal(at(14 * MIN - 1), true);
|
|
37
|
-
assert.equal(at(14 * MIN), false);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("graceFraction changes the boundary", () => {
|
|
41
|
-
const run = { status: "in_progress", run_started_at: startedAgo(10 * MIN) };
|
|
42
|
-
assert.equal(decideSupersede({ run, medianMs: 20 * MIN, nowMs: NOW, graceFraction: 0.7 }).cancel, true);
|
|
43
|
-
assert.equal(decideSupersede({ run, medianMs: 20 * MIN, nowMs: NOW, graceFraction: 0.4 }).cancel, false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("a run with a failed job is cancelled even when nearly done", () => {
|
|
47
|
-
const run = { status: "in_progress", run_started_at: startedAgo(19 * MIN) };
|
|
48
|
-
for (const conclusion of ["failure", "timed_out"]) {
|
|
49
|
-
assert.equal(decideSupersede({ run, jobs: [{ conclusion: "success" }, { conclusion }], medianMs: 20 * MIN, nowMs: NOW }).cancel, true, conclusion);
|
|
50
|
-
}
|
|
51
|
-
assert.equal(decideSupersede({ run, jobs: [{ conclusion: "success" }, { conclusion: null }], medianMs: 20 * MIN, nowMs: NOW }).cancel, false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("a queued run that never started is cancelled", () => {
|
|
55
|
-
assert.equal(decideSupersede({ run: { status: "queued", created_at: startedAgo(MIN) }, medianMs: null, nowMs: NOW }).cancel, true);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("without a median nothing is cancelled for being young", () => {
|
|
59
|
-
const run = { status: "in_progress", run_started_at: startedAgo(MIN) };
|
|
60
|
-
assert.equal(decideSupersede({ run, medianMs: null, nowMs: NOW }).cancel, false);
|
|
61
|
-
assert.equal(decideSupersede({ run, medianMs: 0, nowMs: NOW }).cancel, false);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("olderRuns keeps only lower run numbers and never the current run", () => {
|
|
65
|
-
const current = { id: 30, run_number: 12 };
|
|
66
|
-
const runs = [{ id: 31, run_number: 13 }, { id: 30, run_number: 12 }, { id: 29, run_number: 11 }, { id: 27, run_number: 9 }];
|
|
67
|
-
assert.deepEqual(olderRuns(runs, current).map((run) => run.id), [27, 29]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("parseSettings defaults and validates", () => {
|
|
71
|
-
assert.deepEqual(parseSettings({}), { graceFraction: 0.7, medianWindow: 10 });
|
|
72
|
-
assert.deepEqual(parseSettings({ RIGHT_GIT_GRACE_FRACTION: "0.5", RIGHT_GIT_MEDIAN_WINDOW: "5" }), { graceFraction: 0.5, medianWindow: 5 });
|
|
73
|
-
assert.throws(() => parseSettings({ RIGHT_GIT_GRACE_FRACTION: "0" }));
|
|
74
|
-
assert.throws(() => parseSettings({ RIGHT_GIT_GRACE_FRACTION: "1.5" }));
|
|
75
|
-
assert.throws(() => parseSettings({ RIGHT_GIT_MEDIAN_WINDOW: "0" }));
|
|
76
|
-
assert.throws(() => parseSettings({ RIGHT_GIT_MEDIAN_WINDOW: "2.5" }));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("the script is safe to embed verbatim in a workflow heredoc", () => {
|
|
80
|
-
const source = fs.readFileSync(new URL("./supersede.mjs", import.meta.url), "utf8");
|
|
81
|
-
assert.doesNotMatch(source, /\$\{/, "no template placeholder or expression syntax");
|
|
82
|
-
assert.doesNotMatch(source, /^RIGHT_GIT_SUPERSEDE_EOF$/m);
|
|
83
|
-
assert.doesNotMatch(source, /\r/);
|
|
84
|
-
});
|
package/swift-check.test.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { spawnSync } from "node:child_process";
|
|
7
|
-
import { buildRenderContext, validateManifest } from "./manifest.mjs";
|
|
8
|
-
import { renderLanes } from "./sync.mjs";
|
|
9
|
-
import { renderTemplate } from "./render.mjs";
|
|
10
|
-
|
|
11
|
-
const CHECK = { runner: "macos-15", xcodeVersion: "16.4", projectDirectory: "ios", spec: "project.yml", project: "Widgets.xcodeproj", scheme: "Widgets", xcodegenVersion: "2.44.1" };
|
|
12
|
-
const BASE = { schemaVersion: 1, compile: "github-actions-only", lanes: ["swift-check"], matrix: { os: ["macos-15"], node: ["26.8.1"] }, packageManager: "pnpm@11.24.0", templateVersion: "1.8.0", swift: { check: CHECK } };
|
|
13
|
-
const render = (manifest = BASE) => renderLanes(manifest, "/repos/widgets")[0].content;
|
|
14
|
-
|
|
15
|
-
test("swift-check supports a standalone default-profile manifest with or without private packages", () => {
|
|
16
|
-
assert.deepEqual(validateManifest(BASE).errors, []);
|
|
17
|
-
assert.deepEqual(validateManifest({ ...BASE, swift: { check: CHECK, privatePackages: [{ host: "github.com", secret: "SWIFT_READ_TOKEN" }] } }).errors, []);
|
|
18
|
-
assert.equal(renderLanes(BASE, "/repos/widgets")[0].filename, "swift-check.yml");
|
|
19
|
-
assert.match(render(), /^name: swift-check$/m);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("swift-check rejects missing configuration, unpinned tools, unsafe fields and unknown keys", () => {
|
|
23
|
-
assert.equal(validateManifest({ ...BASE, swift: undefined }).valid, false);
|
|
24
|
-
assert.equal(validateManifest({ ...BASE, swift: { check: null } }).valid, false);
|
|
25
|
-
assert.equal(validateManifest({ ...BASE, lanes: ["ci"] }).valid, false);
|
|
26
|
-
for (const [key, values] of Object.entries({
|
|
27
|
-
runner: ["macos-latest", "self-hosted", "xcode-27", "ubuntu-24.04", "${{ secrets.TOKEN }}"],
|
|
28
|
-
xcodeVersion: ["latest", "16", "16.4;id", "16.4\n"],
|
|
29
|
-
xcodegenVersion: ["latest", "2.44", "2.44.1$(id)"],
|
|
30
|
-
projectDirectory: ["../ios", "/tmp/ios", "ios dir", "ios\\x", "${{ github.ref }}"],
|
|
31
|
-
spec: ["../project.yml", "-x.yml", "project.yml\nrun: id", "project.json"],
|
|
32
|
-
project: ["../App.xcodeproj", "App.xcworkspace", "$(id).xcodeproj"],
|
|
33
|
-
scheme: ["-scheme", "App Name", "App'", "${{ secrets.TOKEN }}"],
|
|
34
|
-
arbitrary: ["value"],
|
|
35
|
-
})) for (const value of values) {
|
|
36
|
-
assert.equal(validateManifest({ ...BASE, swift: { check: { ...CHECK, [key]: value } } }).valid, false, `${key}=${value}`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("swift-check pins actions, tools and read-only permissions; test execution stays unsigned Debug", () => {
|
|
41
|
-
const out = render();
|
|
42
|
-
for (const line of out.split("\n").filter((line) => line.includes("uses:"))) assert.match(line, /uses: [^@]+@[a-f0-9]{40}(?: |$)/);
|
|
43
|
-
assert.match(out, /^permissions:\n contents: read$/m);
|
|
44
|
-
assert.doesNotMatch(out, /: write|write-all|workflow_dispatch|pull_request_target|workflow_run|signing|notary|\bsecrets\./);
|
|
45
|
-
assert.match(out, /runs-on: macos-15/);
|
|
46
|
-
assert.match(out, /DEVELOPER_DIR: \/Applications\/Xcode_16\.4\.app\/Contents\/Developer/);
|
|
47
|
-
assert.match(out, /test "\$\(xcodegen --version\)" = 'Version: 2\.44\.1'/);
|
|
48
|
-
assert.match(out, /persist-credentials: false/);
|
|
49
|
-
assert.match(out, /xcodegen generate --spec 'project.yml'/);
|
|
50
|
-
assert.match(out, /simctl list devices available --json/);
|
|
51
|
-
assert.match(out, /xcodebuild test -project 'Widgets.xcodeproj' -scheme 'Widgets'/);
|
|
52
|
-
assert.match(out, /-configuration Debug -destination "platform=iOS Simulator,id=\$RIGHT_GIT_SIMULATOR_UDID"/);
|
|
53
|
-
assert.match(out, /-scmProvider system[\s\S]*CODE_SIGNING_ALLOWED=NO/);
|
|
54
|
-
assert.match(out, /Upload XCTest results\n if: \$\{\{ always\(\) \}\}/);
|
|
55
|
-
assert.match(out, /right-release ownership --app \./);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("swift-check shares exact private-package steps and keeps cleanup before artifact upload", () => {
|
|
59
|
-
const out = render({ ...BASE, swift: { check: CHECK, privatePackages: [{ host: "github.com", secret: "SWIFT_READ_TOKEN" }] } });
|
|
60
|
-
const configure = out.indexOf("Configure private Swift package access");
|
|
61
|
-
const generation = out.indexOf("Generate Xcode project");
|
|
62
|
-
const execution = out.indexOf("Run Debug XCTest");
|
|
63
|
-
const cleanup = out.indexOf("Remove private Swift package access");
|
|
64
|
-
assert.ok(configure < generation && generation < execution && execution < cleanup && cleanup < out.indexOf("Upload XCTest results"));
|
|
65
|
-
assert.match(out, /test -n "\$RIGHT_GIT_PRIVATE_TOKEN_0"[\s\S]*secret SWIFT_READ_TOKEN is unavailable/);
|
|
66
|
-
assert.match(out, /Remove private Swift package access\n if: \$\{\{ always\(\) \}\}/);
|
|
67
|
-
assert.equal((out.match(/secrets\.SWIFT_READ_TOKEN/g) ?? []).length, 2);
|
|
68
|
-
for (const line of out.split("\n").filter((line) => line.includes("secrets."))) assert.match(line, /^ {10}RIGHT_GIT_PRIVATE_TOKEN_0:/);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("swift-check config does not change existing lane rendering when lane is unset", () => {
|
|
72
|
-
const manifest = { ...BASE, lanes: ["ci", "qualification", "package-smoke"], swift: undefined };
|
|
73
|
-
const before = renderLanes(manifest, "/repos/widgets");
|
|
74
|
-
const after = renderLanes({ ...manifest, swift: { check: CHECK } }, "/repos/widgets");
|
|
75
|
-
assert.deepEqual(after, before);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("swift-check render refuses credential-bearing unsafe triggers", () => {
|
|
79
|
-
const manifest = { ...BASE, swift: { check: CHECK, privatePackages: [{ host: "github.com", secret: "SWIFT_READ_TOKEN" }] } };
|
|
80
|
-
for (const trigger of ["pull_request_target", "workflow_run"]) {
|
|
81
|
-
assert.throws(() => renderTemplate(render(manifest).replace(" pull_request:", ` ${trigger}:`), buildRenderContext(manifest, "/repos/widgets", "swift-check")), /refusing to render/);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("swift-check generated workflow passes actionlint", (t) => {
|
|
86
|
-
const available = spawnSync("actionlint", ["-version"], { encoding: "utf8" });
|
|
87
|
-
if (available.error?.code === "ENOENT") return t.skip("actionlint is unavailable");
|
|
88
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "right-git-swift-check-"));
|
|
89
|
-
try {
|
|
90
|
-
const filename = path.join(dir, "swift-check.yml");
|
|
91
|
-
fs.writeFileSync(filename, render({ ...BASE, swift: { check: CHECK, privatePackages: [{ host: "github.com", secret: "SWIFT_READ_TOKEN" }] } }));
|
|
92
|
-
const result = spawnSync("actionlint", ["-shellcheck=", "-pyflakes=", filename], { encoding: "utf8" });
|
|
93
|
-
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
94
|
-
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
95
|
-
});
|
package/sync.test.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { applyPlan, planSync, syncCommand } from "./sync.mjs";
|
|
6
|
-
import { makeTempRepo, PUBLIC_DEPS, PRIVATE_DEPS, SAMPLE_MANIFEST } from "./test-support.mjs";
|
|
7
|
-
|
|
8
|
-
test("sync refuses a private repo and writes nothing", async () => {
|
|
9
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
10
|
-
const result = await syncCommand(dir, { deps: PRIVATE_DEPS });
|
|
11
|
-
assert.equal(result.ok, false);
|
|
12
|
-
assert.equal(result.stage, "visibility");
|
|
13
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows")), false);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("sync writes one rendered file per lane for a public repo", async () => {
|
|
17
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
18
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
19
|
-
assert.equal(result.ok, true);
|
|
20
|
-
for (const filename of ["ci.yml", "package-smoke.yml"]) {
|
|
21
|
-
assert.ok(fs.existsSync(path.join(dir, ".github", "workflows", filename)), `${filename} was not written`);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("sync --dry-run plans changes without writing files", async () => {
|
|
26
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
27
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS, dryRun: true });
|
|
28
|
-
assert.equal(result.ok, true);
|
|
29
|
-
assert.ok(result.changes.some((c) => c.action === "create"));
|
|
30
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows")), false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("sync is idempotent: a second run reports no changes", async () => {
|
|
34
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
35
|
-
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
36
|
-
const second = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
37
|
-
assert.ok(second.changes.every((c) => c.action === "unchanged"));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("sync removes a workflow file for a lane dropped from the manifest", async () => {
|
|
41
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
42
|
-
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
43
|
-
fs.writeFileSync(path.join(dir, ".rightgit.json"), `${JSON.stringify({ ...SAMPLE_MANIFEST, lanes: ["ci"] }, null, 2)}\n`, "utf8");
|
|
44
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
45
|
-
assert.equal(result.ok, true);
|
|
46
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows", "package-smoke.yml")), false);
|
|
47
|
-
assert.ok(fs.existsSync(path.join(dir, ".github", "workflows", "ci.yml")));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("sync reports manifest errors instead of writing files", async () => {
|
|
51
|
-
const dir = makeTempRepo(null);
|
|
52
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
53
|
-
assert.equal(result.ok, false);
|
|
54
|
-
assert.equal(result.stage, "manifest");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("sync rejects a Membrane-like release chain without root @rightkit/release", async () => {
|
|
58
|
-
const manifest = {
|
|
59
|
-
schemaVersion: 1,
|
|
60
|
-
compile: "github-actions-only",
|
|
61
|
-
lanes: ["ci", "release-candidate"],
|
|
62
|
-
matrix: { os: ["windows-2025", "macos-15"], node: ["22.23.2"] },
|
|
63
|
-
packageManager: "pnpm@11.24.0",
|
|
64
|
-
templateVersion: "1.5.0",
|
|
65
|
-
profile: "rust-hybrid",
|
|
66
|
-
gate: { path: "scripts/ci/run-ci.sh" },
|
|
67
|
-
candidate: {
|
|
68
|
-
buildScript: "release:candidate:build",
|
|
69
|
-
checkScript: "release:candidate:check",
|
|
70
|
-
admissionScript: "release:admit",
|
|
71
|
-
stageSummaryScript: "release:stage-summary",
|
|
72
|
-
artifactRoot: "membrane-release-candidate",
|
|
73
|
-
os: ["windows-2025", "macos-15"],
|
|
74
|
-
signWindows: true,
|
|
75
|
-
signMacos: true,
|
|
76
|
-
releaseChain: {
|
|
77
|
-
evidenceVerificationScript: "release:verify-evidence",
|
|
78
|
-
windowsFinalizeScript: "release:finalize:windows",
|
|
79
|
-
macosFinalizeScript: "release:finalize:macos",
|
|
80
|
-
installedQualificationScript: "release:qualify:installed",
|
|
81
|
-
publishScript: "release:publish:qualified",
|
|
82
|
-
qualificationRunnerVariable: "MEMBRANE_QUALIFICATION_RUNNER_LABEL",
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
const dir = makeTempRepo(manifest, { packageJson: { name: "membrane", devDependencies: { "@rightkit/ci": "0.2.13" } } });
|
|
87
|
-
const missing = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
88
|
-
assert.equal(missing.ok, false);
|
|
89
|
-
assert.equal(missing.stage, "dependency");
|
|
90
|
-
assert.match(missing.errors[0], /direct devDependency @rightkit\/release/);
|
|
91
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows")), false);
|
|
92
|
-
|
|
93
|
-
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({ name: "membrane", devDependencies: { "@rightkit/ci": "0.2.13", "@rightkit/release": "0.2.84" } }), "utf8");
|
|
94
|
-
const present = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
95
|
-
assert.equal(present.ok, true);
|
|
96
|
-
assert.ok(fs.existsSync(path.join(dir, ".github", "workflows", "release-candidate.yml")));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test("sync refuses an unmanaged same-name workflow", async () => {
|
|
100
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
101
|
-
const target = path.join(dir, ".github", "workflows", "ci.yml");
|
|
102
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
103
|
-
fs.writeFileSync(target, "name: handwritten\n", "utf8");
|
|
104
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
105
|
-
assert.equal(result.stage, "managed-conflict");
|
|
106
|
-
assert.equal(fs.readFileSync(target, "utf8"), "name: handwritten\n");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("apply preflights every planned byte before writing", async () => {
|
|
110
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
111
|
-
const plan = await planSync(dir, PUBLIC_DEPS);
|
|
112
|
-
const target = path.join(dir, ".github", "workflows", "ci.yml");
|
|
113
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
114
|
-
fs.writeFileSync(target, "raced\n", "utf8");
|
|
115
|
-
const applied = applyPlan(dir, plan);
|
|
116
|
-
assert.equal(applied.stage, "apply-conflict");
|
|
117
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows", "package-smoke.yml")), false);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// F15 end-to-end: a hostile `.rightgit.json` on disk — the real attack
|
|
121
|
-
// surface, not just the in-memory validateManifest() unit — must be refused
|
|
122
|
-
// at the manifest stage, before renderLanes() (and therefore render.mjs's
|
|
123
|
-
// unescaped `${TOKEN}` substitution) ever sees the payload. This is the
|
|
124
|
-
// concrete proof that "none survive into rendered output": nothing is
|
|
125
|
-
// rendered or written at all when the manifest is hostile. Covers a family
|
|
126
|
-
// of payloads across the fields that flow into the credential-bearing
|
|
127
|
-
// publish-package-managers lane.
|
|
128
|
-
const HOSTILE_MANIFESTS = [
|
|
129
|
-
{ tap: "acme/tap", formulaName: "${{ secrets.APPLE_CERTIFICATE }}" },
|
|
130
|
-
{ tap: "acme/tap", formulaName: "`whoami`" },
|
|
131
|
-
{ tap: "acme/tap", formulaName: "widgets\nrun: exit 1" },
|
|
132
|
-
{ tap: "acme/${{ secrets.X }}", formulaName: "widgets" },
|
|
133
|
-
];
|
|
134
|
-
|
|
135
|
-
for (const [i, homebrew] of HOSTILE_MANIFESTS.entries()) {
|
|
136
|
-
test(`F15: sync refuses a hostile manifest and writes nothing (payload ${i})`, async () => {
|
|
137
|
-
const dir = makeTempRepo({
|
|
138
|
-
...SAMPLE_MANIFEST,
|
|
139
|
-
lanes: ["publish-package-managers"],
|
|
140
|
-
publish: { homebrew, winget: { packageIdentifier: "Acme.Widgets" } },
|
|
141
|
-
});
|
|
142
|
-
const result = await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
143
|
-
assert.equal(result.ok, false);
|
|
144
|
-
assert.equal(result.stage, "manifest");
|
|
145
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows")), false, "no workflow file may be written for a hostile manifest");
|
|
146
|
-
});
|
|
147
|
-
}
|
package/test-support.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Shared fixtures for sync/drift/uninstall tests. Not a *.test.mjs file, so
|
|
2
|
-
// `node --test *.test.mjs` never picks it up as a test suite on its own.
|
|
3
|
-
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import os from "node:os";
|
|
7
|
-
|
|
8
|
-
export function makeTempRepo(manifest, { packageJson } = {}) {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "right-git-test-"));
|
|
10
|
-
if (manifest) fs.writeFileSync(path.join(dir, ".rightgit.json"), `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
11
|
-
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify(packageJson || { name: "widgets" }), "utf8");
|
|
12
|
-
return dir;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function ghDeps(visibility) {
|
|
16
|
-
return {
|
|
17
|
-
execFile: async (cmd) => {
|
|
18
|
-
if (cmd === "gh") return { stdout: JSON.stringify({ visibility }) };
|
|
19
|
-
throw new Error(`unexpected exec: ${cmd}`);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const PUBLIC_DEPS = ghDeps("PUBLIC");
|
|
25
|
-
export const PRIVATE_DEPS = ghDeps("PRIVATE");
|
|
26
|
-
|
|
27
|
-
export const SAMPLE_MANIFEST = {
|
|
28
|
-
schemaVersion: 1,
|
|
29
|
-
compile: "github-actions-only",
|
|
30
|
-
lanes: ["ci", "package-smoke"],
|
|
31
|
-
matrix: { os: ["ubuntu-latest"], node: ["22.13"] },
|
|
32
|
-
packageManager: "pnpm@11.24.0",
|
|
33
|
-
templateVersion: "1.0.0",
|
|
34
|
-
};
|
package/uninstall.test.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { syncCommand } from "./sync.mjs";
|
|
6
|
-
import { DEFAULT_TEMPLATE_VERSION, installCommand } from "./install.mjs";
|
|
7
|
-
import { uninstallCommand } from "./uninstall.mjs";
|
|
8
|
-
import { listManagedFiles } from "./sync.mjs";
|
|
9
|
-
import { MANIFEST_FILENAME } from "./manifest.mjs";
|
|
10
|
-
import { makeTempRepo, PUBLIC_DEPS, SAMPLE_MANIFEST } from "./test-support.mjs";
|
|
11
|
-
|
|
12
|
-
test("uninstall removes every managed file, leaving zero behind — including the manifest (F6/I5)", async () => {
|
|
13
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
14
|
-
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
15
|
-
assert.equal(listManagedFiles(dir).length, 2);
|
|
16
|
-
|
|
17
|
-
const result = uninstallCommand(dir);
|
|
18
|
-
assert.equal(result.ok, true);
|
|
19
|
-
// 2 workflow files + the manifest itself: I5 requires *zero* managed
|
|
20
|
-
// files left behind, and .rightgit.json is a file `install` wrote.
|
|
21
|
-
assert.equal(result.removed.length, 3);
|
|
22
|
-
assert.ok(result.removed.includes(MANIFEST_FILENAME));
|
|
23
|
-
assert.deepEqual(listManagedFiles(dir), []);
|
|
24
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows", "ci.yml")), false);
|
|
25
|
-
assert.equal(fs.existsSync(path.join(dir, ".github", "workflows", "package-smoke.yml")), false);
|
|
26
|
-
assert.equal(fs.existsSync(path.join(dir, MANIFEST_FILENAME)), false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// F6 regression: install writes .rightgit.json *before* running sync (see
|
|
30
|
-
// install.mjs), so a repo whose visibility check flips or errors between
|
|
31
|
-
// that write and sync's own visibility re-check is left with an orphaned
|
|
32
|
-
// manifest and zero (or partial) workflow files. The old uninstallCommand
|
|
33
|
-
// only ever looked at marker-bearing workflow files, so it reported success
|
|
34
|
-
// while leaving the manifest behind. Reproduces the QA report's
|
|
35
|
-
// "interruptedInstall" probe.
|
|
36
|
-
test("install rolls back precisely when visibility changes after preflight", async () => {
|
|
37
|
-
const dir = makeTempRepo(null);
|
|
38
|
-
let calls = 0;
|
|
39
|
-
const flakyDeps = {
|
|
40
|
-
execFile: async (cmd) => {
|
|
41
|
-
calls += 1;
|
|
42
|
-
if (cmd === "gh" && calls === 1) return { stdout: JSON.stringify({ visibility: "PUBLIC" }) };
|
|
43
|
-
if (cmd === "gh") throw new Error("gh: rate limited");
|
|
44
|
-
throw new Error(`unexpected exec: ${cmd}`);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const installResult = await installCommand(dir, { lanes: ["ci"] }, flakyDeps);
|
|
49
|
-
assert.equal(installResult.ok, false);
|
|
50
|
-
assert.equal(installResult.stage, "visibility");
|
|
51
|
-
assert.equal(fs.existsSync(path.join(dir, MANIFEST_FILENAME)), false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("uninstall never touches an unmanaged file in the same directory", async () => {
|
|
55
|
-
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
56
|
-
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
57
|
-
const handWritten = path.join(dir, ".github", "workflows", "hand-written.yml");
|
|
58
|
-
fs.writeFileSync(handWritten, "name: hand-written\n", "utf8");
|
|
59
|
-
|
|
60
|
-
uninstallCommand(dir);
|
|
61
|
-
assert.ok(fs.existsSync(handWritten), "uninstall deleted a file it does not manage");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("uninstall on a repo with no managed files is a no-op, not an error", () => {
|
|
65
|
-
// makeTempRepo(null): no manifest, no workflow files — genuinely zero
|
|
66
|
-
// managed state (makeTempRepo(SAMPLE_MANIFEST) would itself write
|
|
67
|
-
// .rightgit.json, which is now correctly treated as managed per F6).
|
|
68
|
-
const dir = makeTempRepo(null);
|
|
69
|
-
const result = uninstallCommand(dir);
|
|
70
|
-
assert.equal(result.ok, true);
|
|
71
|
-
assert.deepEqual(result.removed, []);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("install validates before it creates a manifest", async () => {
|
|
75
|
-
const dir = makeTempRepo(null);
|
|
76
|
-
const result = await installCommand(dir, { lanes: ["not-a-lane"] }, PUBLIC_DEPS);
|
|
77
|
-
assert.equal(result.stage, "manifest-invalid");
|
|
78
|
-
assert.equal(fs.existsSync(path.join(dir, MANIFEST_FILENAME)), false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("install emits GitHub-Actions-only policy at template 1.8.0", async () => {
|
|
82
|
-
const dir = makeTempRepo(null);
|
|
83
|
-
const result = await installCommand(dir, { lanes: ["ci"] }, PUBLIC_DEPS);
|
|
84
|
-
assert.equal(result.ok, true);
|
|
85
|
-
const manifest = JSON.parse(fs.readFileSync(path.join(dir, MANIFEST_FILENAME), "utf8"));
|
|
86
|
-
assert.equal(manifest.compile, "github-actions-only");
|
|
87
|
-
assert.equal(DEFAULT_TEMPLATE_VERSION, "1.8.0");
|
|
88
|
-
assert.equal(manifest.templateVersion, DEFAULT_TEMPLATE_VERSION);
|
|
89
|
-
});
|
package/visibility-gate.test.mjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { assertPublic, resolveVisibility, parseOwnerRepo } from "./policy/visibility-gate.mjs";
|
|
4
|
-
|
|
5
|
-
function ghExecFile(visibility) {
|
|
6
|
-
return async (cmd, cmdArgs) => {
|
|
7
|
-
if (cmd === "gh") return { stdout: JSON.stringify({ visibility }) };
|
|
8
|
-
throw new Error(`unexpected exec: ${cmd} ${cmdArgs.join(" ")}`);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function failingGhExecFile(remoteUrl) {
|
|
13
|
-
return async (cmd, cmdArgs) => {
|
|
14
|
-
if (cmd === "gh") throw new Error("gh: command not found");
|
|
15
|
-
if (cmd === "git" && cmdArgs[0] === "remote") return { stdout: `${remoteUrl}\n` };
|
|
16
|
-
throw new Error(`unexpected exec: ${cmd} ${cmdArgs.join(" ")}`);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
test("assertPublic allows a repo gh reports as public", async () => {
|
|
21
|
-
const result = await assertPublic("/repo", { execFile: ghExecFile("PUBLIC") });
|
|
22
|
-
assert.equal(result.allowed, true);
|
|
23
|
-
assert.equal(result.visibility, "public");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("assertPublic refuses a repo gh reports as private — no override", async () => {
|
|
27
|
-
const result = await assertPublic("/repo", { execFile: ghExecFile("PRIVATE") });
|
|
28
|
-
assert.equal(result.allowed, false);
|
|
29
|
-
assert.equal(result.visibility, "private");
|
|
30
|
-
assert.match(result.reason, /public repos only/);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("assertPublic refuses a repo gh reports as internal", async () => {
|
|
34
|
-
const result = await assertPublic("/repo", { execFile: ghExecFile("INTERNAL") });
|
|
35
|
-
assert.equal(result.allowed, false);
|
|
36
|
-
assert.equal(result.visibility, "internal");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("assertPublic falls back to git-remote + API when gh is unavailable, and allows a confirmed-public repo", async () => {
|
|
40
|
-
const execFile = failingGhExecFile("https://github.com/acme/widgets.git");
|
|
41
|
-
const fetchFn = async () => ({ ok: true, json: async () => ({ private: false }) });
|
|
42
|
-
const result = await assertPublic("/repo", { execFile, fetch: fetchFn });
|
|
43
|
-
assert.equal(result.allowed, true);
|
|
44
|
-
assert.equal(result.source, "git-remote-api");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("assertPublic fails closed to 'unknown' when neither gh nor the API can confirm public", async () => {
|
|
48
|
-
const execFile = failingGhExecFile("https://github.com/acme/widgets.git");
|
|
49
|
-
const fetchFn = async () => ({ ok: false, status: 404 });
|
|
50
|
-
const result = await assertPublic("/repo", { execFile, fetch: fetchFn });
|
|
51
|
-
assert.equal(result.allowed, false);
|
|
52
|
-
assert.equal(result.visibility, "unknown");
|
|
53
|
-
assert.match(result.reason, /fail closed/);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("assertPublic never throws even when every network path errors", async () => {
|
|
57
|
-
const execFile = async () => {
|
|
58
|
-
throw new Error("no network");
|
|
59
|
-
};
|
|
60
|
-
const result = await assertPublic("/repo", { execFile, fetch: async () => { throw new Error("no network"); } });
|
|
61
|
-
assert.equal(result.allowed, false);
|
|
62
|
-
assert.equal(result.visibility, "unknown");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("resolveVisibility never throws and returns a typed result on total failure", async () => {
|
|
66
|
-
const execFile = async () => {
|
|
67
|
-
throw new Error("boom");
|
|
68
|
-
};
|
|
69
|
-
const result = await resolveVisibility("/repo", { execFile });
|
|
70
|
-
assert.equal(result.source, "error");
|
|
71
|
-
assert.equal(result.visibility, "unknown");
|
|
72
|
-
assert.ok(typeof result.error === "string");
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("parseOwnerRepo handles https and ssh remote forms", () => {
|
|
76
|
-
assert.deepEqual(parseOwnerRepo("https://github.com/acme/widgets.git"), { owner: "acme", repo: "widgets" });
|
|
77
|
-
assert.deepEqual(parseOwnerRepo("git@github.com:acme/widgets.git"), { owner: "acme", repo: "widgets" });
|
|
78
|
-
assert.equal(parseOwnerRepo("not-a-github-url"), null);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// F16 regression: the old repo-name group excluded '.' from its character
|
|
82
|
-
// class, so it could never reach the end-of-string anchor for a dotted repo
|
|
83
|
-
// name — the whole match failed and a legitimate public repo could not be
|
|
84
|
-
// identified through the gh-unavailable fallback. Reproduces the QA report's
|
|
85
|
-
// exact probe input.
|
|
86
|
-
test("F16: parseOwnerRepo identifies a valid GitHub repo whose name contains dots", () => {
|
|
87
|
-
assert.deepEqual(parseOwnerRepo("https://github.com/owner/repo.with.dot.git"), {
|
|
88
|
-
owner: "owner",
|
|
89
|
-
repo: "repo.with.dot",
|
|
90
|
-
});
|
|
91
|
-
assert.deepEqual(parseOwnerRepo("git@github.com:owner/repo.with.dot.git"), {
|
|
92
|
-
owner: "owner",
|
|
93
|
-
repo: "repo.with.dot",
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// F16 non-regression: an unconfigured enterprise GitHub host must still fail
|
|
98
|
-
// closed to null (the unauthenticated-API fallback only ever targets
|
|
99
|
-
// api.github.com, so this parse never reaches an enterprise instance).
|
|
100
|
-
test("F16: parseOwnerRepo still fails closed for an unconfigured enterprise GitHub host", () => {
|
|
101
|
-
assert.equal(parseOwnerRepo("https://github.example.com/owner/repo.git"), null);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// Canonicalization hygiene regression: uppercase host, embedded userinfo
|
|
105
|
-
// (credentials), and a non-standard port are all *genuinely* github.com —
|
|
106
|
-
// DNS is case-insensitive, userinfo is just embedded credentials, and the
|
|
107
|
-
// API query ignores the port. These are not lookalike hosts, so they must
|
|
108
|
-
// still resolve to the real owner/repo rather than fail closed. The WHATWG
|
|
109
|
-
// URL parser already lowercases hostnames and separates userinfo/port from
|
|
110
|
-
// host — parseOwnerRepo's `url.hostname` comparison relies on exactly that,
|
|
111
|
-
// so this locks the behavior in against any future regression that starts
|
|
112
|
-
// comparing against the raw authority string instead of `url.hostname`.
|
|
113
|
-
test("canonicalization: parseOwnerRepo accepts uppercase github.com host", () => {
|
|
114
|
-
assert.deepEqual(parseOwnerRepo("https://GITHUB.COM/owner/repo"), { owner: "owner", repo: "repo" });
|
|
115
|
-
assert.deepEqual(parseOwnerRepo("https://GitHub.com/owner/repo.git"), { owner: "owner", repo: "repo" });
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("canonicalization: parseOwnerRepo accepts a github.com remote with embedded userinfo", () => {
|
|
119
|
-
assert.deepEqual(parseOwnerRepo("https://attacker@github.com/victim/repo"), {
|
|
120
|
-
owner: "victim",
|
|
121
|
-
repo: "repo",
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test("canonicalization: parseOwnerRepo accepts a github.com remote on a non-standard port", () => {
|
|
126
|
-
assert.deepEqual(parseOwnerRepo("https://github.com:8443/owner/repo"), { owner: "owner", repo: "repo" });
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Lookalike-family non-regression (N1): every one of these has a host that
|
|
130
|
-
// is NOT github.com — they must keep failing closed to null. Re-asserted
|
|
131
|
-
// here alongside the canonicalization-hygiene cases above so the two
|
|
132
|
-
// concerns (accept real github.com in any authority shape, reject anything
|
|
133
|
-
// that merely contains the substring "github.com") are tested side by side.
|
|
134
|
-
test("N1 lookalikes: parseOwnerRepo still rejects every non-github.com host", () => {
|
|
135
|
-
assert.equal(parseOwnerRepo("https://notgithub.com/owner/repo"), null);
|
|
136
|
-
assert.equal(parseOwnerRepo("https://github.com.evil.io/owner/repo"), null);
|
|
137
|
-
assert.equal(parseOwnerRepo("https://mygithub.com/owner/repo"), null);
|
|
138
|
-
assert.equal(parseOwnerRepo("https://github.com@evil.io/owner/repo"), null);
|
|
139
|
-
assert.equal(parseOwnerRepo("https://github.como/owner/repo"), null);
|
|
140
|
-
assert.equal(parseOwnerRepo("https://github.example.com/owner/repo"), null);
|
|
141
|
-
});
|