@rightkit/ci 0.0.0-stage → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -2
- package/adopt.mjs +96 -0
- package/checkout.mjs +93 -0
- package/checkout.test.mjs +91 -0
- package/cli/right-git.mjs +218 -0
- package/cli.test.mjs +68 -0
- package/drift.mjs +201 -0
- package/drift.test.mjs +203 -0
- package/guard-coverage.test.mjs +236 -0
- package/install.mjs +81 -0
- package/manifest.mjs +1862 -0
- package/manifest.schema.json +286 -0
- package/manifest.test.mjs +487 -0
- package/ownership-registration.mjs +33 -0
- package/ownership-registration.test.mjs +20 -0
- package/pack-smoke.test.mjs +55 -0
- package/package.json +38 -4
- package/pnpm-lock-patch.test.mjs +161 -0
- package/policy/visibility-gate.mjs +168 -0
- package/render.mjs +69 -0
- package/render.test.mjs +1722 -0
- package/rightkit-ownership.json +15 -0
- package/sync.mjs +180 -0
- package/sync.test.mjs +147 -0
- package/templates/ci.yml +50 -0
- package/templates/package-smoke.yml +38 -0
- package/templates/profiles/rust-hybrid/ci.yml +127 -0
- package/templates/profiles/rust-hybrid/regenerate.yml +96 -0
- package/templates/profiles/rust-hybrid/release-candidate.yml +193 -0
- package/templates/publish-npm.yml +72 -0
- package/templates/publish-package-managers.yml +158 -0
- package/templates/qualification.yml +94 -0
- package/templates/regenerate.yml +80 -0
- package/templates/release-candidate.yml +57 -0
- package/test-support.mjs +34 -0
- package/uninstall.mjs +36 -0
- package/uninstall.test.mjs +89 -0
- package/visibility-gate.test.mjs +141 -0
package/drift.test.mjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
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 { syncCommand } from "./sync.mjs";
|
|
7
|
+
import { driftCommand, findManagedRepos } from "./drift.mjs";
|
|
8
|
+
import { makeTempRepo, PUBLIC_DEPS, PRIVATE_DEPS, SAMPLE_MANIFEST } from "./test-support.mjs";
|
|
9
|
+
|
|
10
|
+
test("drift reports no drift right after a clean sync", async () => {
|
|
11
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
12
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
13
|
+
const result = await driftCommand(dir, PUBLIC_DEPS);
|
|
14
|
+
assert.equal(result.ok, true);
|
|
15
|
+
assert.equal(result.driftDetected, false);
|
|
16
|
+
assert.ok(result.findings.every((f) => f.status === "match"));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("drift detects a hand-mutated managed file", async () => {
|
|
20
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
21
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
22
|
+
const ciPath = path.join(dir, ".github", "workflows", "ci.yml");
|
|
23
|
+
fs.appendFileSync(ciPath, "\n# hand edit\n");
|
|
24
|
+
|
|
25
|
+
const result = await driftCommand(dir, PUBLIC_DEPS);
|
|
26
|
+
assert.equal(result.ok, true);
|
|
27
|
+
assert.equal(result.driftDetected, true);
|
|
28
|
+
const ciFinding = result.findings.find((f) => f.filename === "ci.yml");
|
|
29
|
+
assert.equal(ciFinding.status, "mismatch");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("drift flags driftDetected when a lane's file is missing", async () => {
|
|
33
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
34
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
35
|
+
fs.rmSync(path.join(dir, ".github", "workflows", "ci.yml"));
|
|
36
|
+
|
|
37
|
+
const result = await driftCommand(dir, PUBLIC_DEPS);
|
|
38
|
+
assert.equal(result.driftDetected, true);
|
|
39
|
+
assert.ok(result.findings.some((f) => f.filename === "ci.yml" && f.status === "missing"));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("drift flags a public->private visibility flip even with no file drift", async () => {
|
|
43
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
44
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
45
|
+
const result = await driftCommand(dir, PRIVATE_DEPS);
|
|
46
|
+
assert.equal(result.driftDetected, true);
|
|
47
|
+
assert.equal(result.visibility.allowed, false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("findManagedRepos finds every directory carrying a .rightgit.json under a root", () => {
|
|
51
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "right-git-root-"));
|
|
52
|
+
const repoA = makeTempRepo(SAMPLE_MANIFEST);
|
|
53
|
+
const repoB = makeTempRepo(SAMPLE_MANIFEST);
|
|
54
|
+
fs.cpSync(repoA, path.join(root, "repo-a"), { recursive: true });
|
|
55
|
+
fs.cpSync(repoB, path.join(root, "repo-b"), { recursive: true });
|
|
56
|
+
fs.mkdirSync(path.join(root, "not-managed"));
|
|
57
|
+
|
|
58
|
+
const found = findManagedRepos(root).map((p) => path.basename(p)).sort();
|
|
59
|
+
assert.deepEqual(found, ["repo-a", "repo-b"]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// F7 regression: a repo whose .rightgit.json was deleted (or never
|
|
63
|
+
// committed) but whose .github/workflows/ still carries MANAGED_MARKER
|
|
64
|
+
// files is an "orphan" — right-git put those workflows there, but the
|
|
65
|
+
// manifest-only scan in the old findManagedRepos could never see it, so
|
|
66
|
+
// `drift --all` silently skipped exactly the repos most likely to be
|
|
67
|
+
// drifted (missing manifest is itself drift).
|
|
68
|
+
test("findManagedRepos finds an orphan repo: managed workflow files present, .rightgit.json missing", () => {
|
|
69
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "right-git-orphan-root-"));
|
|
70
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
71
|
+
fs.cpSync(dir, path.join(root, "orphan-repo"), { recursive: true });
|
|
72
|
+
|
|
73
|
+
const orphanDir = path.join(root, "orphan-repo");
|
|
74
|
+
// A synced install would leave workflow files; simulate that state
|
|
75
|
+
// directly, then remove the manifest to reproduce "manifest lost, workflow
|
|
76
|
+
// files remain".
|
|
77
|
+
fs.mkdirSync(path.join(orphanDir, ".github", "workflows"), { recursive: true });
|
|
78
|
+
fs.writeFileSync(
|
|
79
|
+
path.join(orphanDir, ".github", "workflows", "ci.yml"),
|
|
80
|
+
"# Managed by right-git — do not hand-edit. Run `right-git sync` to update.\nname: ci\n",
|
|
81
|
+
"utf8",
|
|
82
|
+
);
|
|
83
|
+
fs.rmSync(path.join(orphanDir, ".rightgit.json"));
|
|
84
|
+
|
|
85
|
+
const found = findManagedRepos(root).map((p) => path.basename(p)).sort();
|
|
86
|
+
assert.deepEqual(found, ["orphan-repo"]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("driftCommand reports an orphan repo as drift instead of a hard failure", async () => {
|
|
90
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
91
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
92
|
+
fs.rmSync(path.join(dir, ".rightgit.json"));
|
|
93
|
+
|
|
94
|
+
const result = await driftCommand(dir, PUBLIC_DEPS);
|
|
95
|
+
assert.equal(result.ok, true);
|
|
96
|
+
assert.equal(result.driftDetected, true);
|
|
97
|
+
assert.ok(result.findings.some((f) => f.status === "orphan" && f.filename === "ci.yml"));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Regenerate approval check (drift warns; it is advisory and never changes driftDetected).
|
|
101
|
+
// The stub answers the visibility lookup, `git remote get-url origin`, and `gh api`; any other
|
|
102
|
+
// command throws, so a test cannot reach the real gh or network.
|
|
103
|
+
const REGENERATE_MANIFEST = { ...SAMPLE_MANIFEST, lanes: ["ci", "regenerate"], regenerate: { script: "regenerate" } };
|
|
104
|
+
const PERMISSIONS_PATH = "repos/acme/widgets/actions/permissions/workflow";
|
|
105
|
+
|
|
106
|
+
function workflowSettingsDeps({ approve = true, origin = "git@github.com:acme/widgets.git", gitFails = false, apiError = null, apiStdout = null } = {}) {
|
|
107
|
+
const deps = {
|
|
108
|
+
calls: [],
|
|
109
|
+
execFile: async (cmd, args) => {
|
|
110
|
+
deps.calls.push([cmd, ...args].join(" "));
|
|
111
|
+
if (cmd === "gh" && args[0] === "repo") return { stdout: JSON.stringify({ visibility: "PUBLIC" }) };
|
|
112
|
+
if (cmd === "git" && args[0] === "remote") {
|
|
113
|
+
if (gitFails) throw new Error("fatal: No such remote 'origin'");
|
|
114
|
+
return { stdout: `${origin}\n` };
|
|
115
|
+
}
|
|
116
|
+
if (cmd === "gh" && args[0] === "api") {
|
|
117
|
+
if (apiError) throw apiError;
|
|
118
|
+
return { stdout: apiStdout ?? JSON.stringify({ default_workflow_permissions: "read", can_approve_pull_request_reviews: approve }) };
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`unexpected exec: ${cmd}`);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
return deps;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
test("drift warns when the regenerate lane's pull-request setting is off, without reporting drift", async () => {
|
|
127
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
128
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
129
|
+
const deps = workflowSettingsDeps({ approve: false });
|
|
130
|
+
const result = await driftCommand(dir, deps);
|
|
131
|
+
assert.equal(result.ok, true);
|
|
132
|
+
assert.equal(result.driftDetected, false);
|
|
133
|
+
assert.equal(result.warnings.length, 1);
|
|
134
|
+
assert.match(result.warnings[0], /Allow GitHub Actions to create and approve pull requests/);
|
|
135
|
+
assert.deepEqual(result.notes, []);
|
|
136
|
+
assert.ok(deps.calls.includes(`gh api ${PERMISSIONS_PATH}`), `expected gh api call; got ${deps.calls.join(" | ")}`);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("drift is silent when the regenerate lane's pull-request setting is on", async () => {
|
|
140
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
141
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
142
|
+
const result = await driftCommand(dir, workflowSettingsDeps({ approve: true }));
|
|
143
|
+
assert.equal(result.driftDetected, false);
|
|
144
|
+
assert.deepEqual(result.warnings, []);
|
|
145
|
+
assert.deepEqual(result.notes, []);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("drift skips the approval check with a note when gh is not installed", async () => {
|
|
149
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
150
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
151
|
+
const missing = Object.assign(new Error("spawn gh ENOENT"), { code: "ENOENT" });
|
|
152
|
+
const result = await driftCommand(dir, workflowSettingsDeps({ apiError: missing }));
|
|
153
|
+
assert.equal(result.driftDetected, false);
|
|
154
|
+
assert.deepEqual(result.warnings, []);
|
|
155
|
+
assert.equal(result.notes.length, 1);
|
|
156
|
+
assert.match(result.notes[0], /skipped the Actions pull-request approval check \(gh is not installed\)/);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("drift notes an unreadable or incomplete permissions response instead of guessing", async () => {
|
|
160
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
161
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
162
|
+
const notJson = await driftCommand(dir, workflowSettingsDeps({ apiStdout: "<html>403</html>" }));
|
|
163
|
+
assert.deepEqual(notJson.warnings, []);
|
|
164
|
+
assert.match(notJson.notes[0], /gh api returned no JSON/);
|
|
165
|
+
|
|
166
|
+
const incomplete = await driftCommand(dir, workflowSettingsDeps({ apiStdout: JSON.stringify({ default_workflow_permissions: "read" }) }));
|
|
167
|
+
assert.deepEqual(incomplete.warnings, []);
|
|
168
|
+
assert.match(incomplete.notes[0], /no can_approve_pull_request_reviews/);
|
|
169
|
+
|
|
170
|
+
const forbidden = await driftCommand(dir, workflowSettingsDeps({ apiError: new Error("HTTP 403: Resource not accessible") }));
|
|
171
|
+
assert.deepEqual(forbidden.warnings, []);
|
|
172
|
+
assert.match(forbidden.notes[0], /gh api failed: HTTP 403/);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("drift skips the approval check for a non-GitHub origin and never calls gh api", async () => {
|
|
176
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
177
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
178
|
+
const deps = workflowSettingsDeps({ origin: "https://gitlab.com/acme/widgets.git" });
|
|
179
|
+
const result = await driftCommand(dir, deps);
|
|
180
|
+
assert.deepEqual(result.warnings, []);
|
|
181
|
+
assert.match(result.notes[0], /origin is not a github\.com repository/);
|
|
182
|
+
assert.equal(deps.calls.some((call) => call.startsWith("gh api")), false);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("drift notes a missing origin remote and does not guess the repository", async () => {
|
|
186
|
+
const dir = makeTempRepo(REGENERATE_MANIFEST);
|
|
187
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
188
|
+
const deps = workflowSettingsDeps({ gitFails: true });
|
|
189
|
+
const result = await driftCommand(dir, deps);
|
|
190
|
+
assert.deepEqual(result.warnings, []);
|
|
191
|
+
assert.match(result.notes[0], /no origin remote/);
|
|
192
|
+
assert.equal(deps.calls.some((call) => call.startsWith("gh api")), false);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("drift never asks Actions settings for a manifest without the regenerate lane", async () => {
|
|
196
|
+
const dir = makeTempRepo(SAMPLE_MANIFEST);
|
|
197
|
+
await syncCommand(dir, { deps: PUBLIC_DEPS });
|
|
198
|
+
const deps = workflowSettingsDeps({ approve: false });
|
|
199
|
+
const result = await driftCommand(dir, deps);
|
|
200
|
+
assert.deepEqual(result.warnings, []);
|
|
201
|
+
assert.deepEqual(result.notes, []);
|
|
202
|
+
assert.equal(deps.calls.some((call) => call.startsWith("gh api")), false);
|
|
203
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// F5 regression, two properties layered on top of each other:
|
|
2
|
+
//
|
|
3
|
+
// 1. Reachability (original F5): "every generated workflow's first job
|
|
4
|
+
// carries the private-repo guard" is not the same claim as "no job in a
|
|
5
|
+
// generated workflow can ever run in a private repo." The QA report
|
|
6
|
+
// proved the two diverge in publish-package-managers.yml: `winget-token`
|
|
7
|
+
// had no guard of its own and no `needs`, so it always ran (and always
|
|
8
|
+
// exited 0) regardless of repository visibility, and `winget` depended
|
|
9
|
+
// only on that unguarded job.
|
|
10
|
+
//
|
|
11
|
+
// 2. Loudness (the re-validation finding): even once every job is
|
|
12
|
+
// reachability-guarded, gating the guarded job itself with a job-level
|
|
13
|
+
// `if: !github.event.repository.private` makes GitHub SKIP that job for
|
|
14
|
+
// a private repo — the nested "refuse" step inside it is then
|
|
15
|
+
// unreachable and never runs. A skip is not a failure: the run can read
|
|
16
|
+
// as "nothing to do" instead of the loud, non-zero failure invariant I1
|
|
17
|
+
// requires. The fix is a single `private-repo-guard` job with NO
|
|
18
|
+
// job-level `if` (so it always executes) whose one step's OWN `if`
|
|
19
|
+
// fires only when private and exits 1 — that fails the job outright.
|
|
20
|
+
// Every real job `needs` it instead of gating itself.
|
|
21
|
+
//
|
|
22
|
+
// This test renders every lane and walks the job graph, asserting each job
|
|
23
|
+
// is either itself a "self-guard" job (property 2: no job-level `if`, so it
|
|
24
|
+
// unconditionally runs, plus a step whose own `if` matches the positive
|
|
25
|
+
// private check and whose body exits non-zero — i.e. it cannot SUCCEED in a
|
|
26
|
+
// private repo, and does not merely skip) or transitively guarded: it
|
|
27
|
+
// `needs` at least one (transitively) guarded job, and does not override
|
|
28
|
+
// the default `needs`-implies-`success()` gate with `always()` (which would
|
|
29
|
+
// make it run even after a guarded dependency failed/was skipped). This
|
|
30
|
+
// models real GitHub Actions semantics: an `if:` expression that does not
|
|
31
|
+
// itself call success()/always()/cancelled()/failure() is implicitly ANDed
|
|
32
|
+
// with `success()`, so a job whose only dependency failed is skipped too.
|
|
33
|
+
//
|
|
34
|
+
// A job gated the OLD way — job-level `if: !private` — is deliberately NOT
|
|
35
|
+
// recognized as guarded here: that shape is exactly the loudness bug, so a
|
|
36
|
+
// template that regressed to it must fail this test, not pass it.
|
|
37
|
+
//
|
|
38
|
+
// Fails against the pre-fix templates (winget-token: neither guarded nor
|
|
39
|
+
// depending on a guarded job; every guard job-level-`if` gated instead of
|
|
40
|
+
// self-failing) and passes after the fix.
|
|
41
|
+
|
|
42
|
+
import test from "node:test";
|
|
43
|
+
import assert from "node:assert/strict";
|
|
44
|
+
import fs from "node:fs";
|
|
45
|
+
import path from "node:path";
|
|
46
|
+
import { fileURLToPath } from "node:url";
|
|
47
|
+
import { renderTemplate } from "./render.mjs";
|
|
48
|
+
import { buildRenderContext, LANE_FILENAMES, KNOWN_LANES } from "./manifest.mjs";
|
|
49
|
+
|
|
50
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
|
|
51
|
+
const templatesDir = path.join(packageRoot, "templates");
|
|
52
|
+
|
|
53
|
+
const FULL_MANIFEST = {
|
|
54
|
+
schemaVersion: 1,
|
|
55
|
+
compile: "github-actions-only",
|
|
56
|
+
lanes: [...KNOWN_LANES],
|
|
57
|
+
regenerate: { script: "regenerate" },
|
|
58
|
+
matrix: { os: ["ubuntu-latest", "macos-latest", "windows-latest"], node: ["22.13", "24"] },
|
|
59
|
+
packageManager: "pnpm@11.24.0",
|
|
60
|
+
publish: {
|
|
61
|
+
npm: { oidc: true, provenance: true },
|
|
62
|
+
homebrew: { tap: "acme/homebrew-tap", formulaName: "widgets" },
|
|
63
|
+
winget: { packageIdentifier: "Acme.Widgets" },
|
|
64
|
+
},
|
|
65
|
+
templateVersion: "1.0.0",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const NEGATED_PRIVATE_RE = /!\s*github\.event\.repository\.private/;
|
|
69
|
+
const POSITIVE_PRIVATE_RE = /(?<!!\s*)github\.event\.repository\.private/;
|
|
70
|
+
const ALWAYS_RE = /\balways\(\)/;
|
|
71
|
+
const EXIT_NONZERO_RE = /exit\s+[1-9]/;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Minimal line-based parser for the one shape our templates use: top-level
|
|
75
|
+
* `jobs:` map, each job a ` name:` header, job-level `if:`/`needs:` at
|
|
76
|
+
* exactly 4-space indent, steps introduced by ` - ` at 6-space indent
|
|
77
|
+
* with their own `if:`/`run:` nested under that (see templates/*.yml). Good
|
|
78
|
+
* enough for our own generated YAML; not a general YAML parser.
|
|
79
|
+
*/
|
|
80
|
+
function parseJobs(content) {
|
|
81
|
+
const lines = content.split("\n");
|
|
82
|
+
const jobsIdx = lines.findIndex((l) => /^jobs:\s*$/.test(l));
|
|
83
|
+
assert.ok(jobsIdx !== -1, "rendered workflow has no top-level jobs: map");
|
|
84
|
+
|
|
85
|
+
const jobStarts = [];
|
|
86
|
+
for (let i = jobsIdx + 1; i < lines.length; i++) {
|
|
87
|
+
if (/^ {2}\S.*:\s*$/.test(lines[i])) jobStarts.push(i);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const jobs = new Map();
|
|
91
|
+
for (let idx = 0; idx < jobStarts.length; idx++) {
|
|
92
|
+
const start = jobStarts[idx];
|
|
93
|
+
const end = idx + 1 < jobStarts.length ? jobStarts[idx + 1] : lines.length;
|
|
94
|
+
const name = /^ {2}(\S+):/.exec(lines[start])[1];
|
|
95
|
+
const block = lines.slice(start, end);
|
|
96
|
+
|
|
97
|
+
const ifLine = block.find((l) => /^ {4}if: /.test(l));
|
|
98
|
+
const needsLine = block.find((l) => /^ {4}needs: /.test(l));
|
|
99
|
+
|
|
100
|
+
let needs = [];
|
|
101
|
+
if (needsLine) {
|
|
102
|
+
const inline = /^ {4}needs:\s*\[(.*)\]\s*$/.exec(needsLine);
|
|
103
|
+
if (inline) {
|
|
104
|
+
needs = inline[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
105
|
+
} else {
|
|
106
|
+
const bare = /^ {4}needs:\s*(\S+)\s*$/.exec(needsLine);
|
|
107
|
+
if (bare) needs = [bare[1]];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Self-guard detection: a STEP-level `if:` (any indent deeper than the
|
|
112
|
+
// job-level 4 spaces already captured above as `ifLine`) that positively
|
|
113
|
+
// references repository.private, with a non-zero `exit` appearing before
|
|
114
|
+
// the next step starts. Such a job cannot reach "success" in a private
|
|
115
|
+
// repo regardless of what its job-level `if` says (here, nothing — the
|
|
116
|
+
// fixed templates give these jobs no job-level `if` at all).
|
|
117
|
+
let selfGuardStep = false;
|
|
118
|
+
for (let i = 0; i < block.length; i++) {
|
|
119
|
+
const isStepIfLine = /^\s+if: /.test(block[i]) && !/^ {4}if: /.test(block[i]);
|
|
120
|
+
if (isStepIfLine && POSITIVE_PRIVATE_RE.test(block[i])) {
|
|
121
|
+
const nextStepOffset = block.slice(i + 1).findIndex((l) => /^ {6}- /.test(l));
|
|
122
|
+
const stepBody = nextStepOffset === -1 ? block.slice(i) : block.slice(i, i + 1 + nextStepOffset);
|
|
123
|
+
if (EXIT_NONZERO_RE.test(stepBody.join("\n"))) selfGuardStep = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
jobs.set(name, {
|
|
128
|
+
ifExpr: ifLine ? ifLine.trim().slice("if: ".length) : null,
|
|
129
|
+
needs,
|
|
130
|
+
selfGuardStep,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return jobs;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** True if `jobName` can never SUCCEED in a private repo (fails outright or skips). */
|
|
137
|
+
function isGuarded(jobs, jobName, visiting = new Set()) {
|
|
138
|
+
if (visiting.has(jobName)) return false; // cycle guard, shouldn't happen
|
|
139
|
+
visiting.add(jobName);
|
|
140
|
+
|
|
141
|
+
const job = jobs.get(jobName);
|
|
142
|
+
assert.ok(job, `needs references unknown job '${jobName}'`);
|
|
143
|
+
|
|
144
|
+
// Self-failing job: no job-level `if` gates it away (it always runs), but
|
|
145
|
+
// one of its own steps refuses (fails) when private. This is the LOUD
|
|
146
|
+
// shape — the job runs and fails, it is never silently skipped.
|
|
147
|
+
if (job.selfGuardStep) return true;
|
|
148
|
+
|
|
149
|
+
// The OLD shape (job-level `if: !private`) is deliberately NOT treated as
|
|
150
|
+
// guarded here — gating the whole job away is exactly the "skip instead
|
|
151
|
+
// of fail" bug this suite now guards against. A template that regresses
|
|
152
|
+
// to it must fail this assertion, not pass it via this branch.
|
|
153
|
+
if (job.ifExpr && NEGATED_PRIVATE_RE.test(job.ifExpr) && !job.selfGuardStep) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// A custom `if:` that calls always() bypasses the default needs->success()
|
|
158
|
+
// gate, so a guarded dependency being skipped would NOT stop this job.
|
|
159
|
+
if (job.ifExpr && ALWAYS_RE.test(job.ifExpr)) return false;
|
|
160
|
+
|
|
161
|
+
// Default GitHub Actions semantics: an `if:` that doesn't call
|
|
162
|
+
// success()/always()/cancelled()/failure() is implicitly ANDed with
|
|
163
|
+
// success(), which requires every direct `needs` job to have succeeded.
|
|
164
|
+
// A failed or skipped dependency fails that check, so this job is
|
|
165
|
+
// transitively guarded if ANY one of its needs is guarded.
|
|
166
|
+
return job.needs.some((n) => isGuarded(jobs, n, visiting));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function renderAllLanes() {
|
|
170
|
+
const rendered = {};
|
|
171
|
+
for (const lane of FULL_MANIFEST.lanes) {
|
|
172
|
+
const templatePath = path.join(templatesDir, LANE_FILENAMES[lane]);
|
|
173
|
+
const templateText = fs.readFileSync(templatePath, "utf8");
|
|
174
|
+
rendered[lane] = renderTemplate(templateText, buildRenderContext(FULL_MANIFEST, "/repos/widgets", lane));
|
|
175
|
+
}
|
|
176
|
+
return rendered;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test("F5: every job in every rendered lane is private-guarded or transitively depends on a guarded job", () => {
|
|
180
|
+
const rendered = renderAllLanes();
|
|
181
|
+
for (const lane of KNOWN_LANES) {
|
|
182
|
+
const jobs = parseJobs(rendered[lane]);
|
|
183
|
+
assert.ok(jobs.size > 0, `lane ${lane} has no jobs`);
|
|
184
|
+
for (const jobName of jobs.keys()) {
|
|
185
|
+
assert.ok(
|
|
186
|
+
isGuarded(jobs, jobName),
|
|
187
|
+
`lane ${lane} job '${jobName}' is neither private-guarded nor depends (transitively) on a job that is — a private repo could execute it (F5)`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// F5 loudness proof (the specific gap the re-validation found): a job that
|
|
194
|
+
// is only reachable through a job-level `if: !private` is SKIPPED, not
|
|
195
|
+
// FAILED, for a private repo — GitHub reports skipped jobs as neutral, and
|
|
196
|
+
// a workflow made entirely of skips/successes shows green, not the loud
|
|
197
|
+
// failure invariant I1 demands. This asserts the concrete structural
|
|
198
|
+
// precondition for the loud-failure behavior: the `private-repo-guard` job
|
|
199
|
+
// itself carries NO job-level `if` (so GitHub always schedules and runs it,
|
|
200
|
+
// private or not) and its own step-level `if` positively matches private
|
|
201
|
+
// with a non-zero `exit` — so when private, the job runs and then fails.
|
|
202
|
+
// Fails against the pre-fix shape (guard logic lived inside a job gated by
|
|
203
|
+
// `if: !private`, so the refusing step was itself skipped) and against any
|
|
204
|
+
// regression back to that shape.
|
|
205
|
+
test("F5: private-repo-guard job has no job-level `if` (always runs) and fails outright when private", () => {
|
|
206
|
+
const rendered = renderAllLanes();
|
|
207
|
+
for (const lane of KNOWN_LANES) {
|
|
208
|
+
const jobs = parseJobs(rendered[lane]);
|
|
209
|
+
const guard = jobs.get("private-repo-guard");
|
|
210
|
+
assert.ok(guard, `lane ${lane} has no private-repo-guard job`);
|
|
211
|
+
assert.equal(
|
|
212
|
+
guard.ifExpr,
|
|
213
|
+
null,
|
|
214
|
+
`lane ${lane} private-repo-guard carries a job-level 'if' (${guard.ifExpr}) — that would let it be SKIPPED instead of run-then-failed for a private repo`,
|
|
215
|
+
);
|
|
216
|
+
assert.ok(
|
|
217
|
+
guard.selfGuardStep,
|
|
218
|
+
`lane ${lane} private-repo-guard has no step that positively checks private and exits non-zero`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("qualification preserves failing schema evidence as a unique required artifact", () => {
|
|
224
|
+
const template = fs.readFileSync(path.join(templatesDir, "qualification.yml"), "utf8");
|
|
225
|
+
assert.doesNotMatch(template, /\|\| true/);
|
|
226
|
+
assert.match(template, /set -o pipefail[\s\S]*tee qualification-schema\.log/);
|
|
227
|
+
assert.match(template, /uses: actions\/upload-artifact@v4[\s\S]*github\.run_id[\s\S]*github\.run_attempt[\s\S]*if-no-files-found: error/);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("rust-hybrid ci keeps its work behind the public-repository guard", () => {
|
|
231
|
+
const manifest = { ...FULL_MANIFEST, lanes: ["ci"], profile: "rust-hybrid", gate: { path: "scripts/gate.sh" } };
|
|
232
|
+
const template = fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid/ci.yml"), "utf8");
|
|
233
|
+
const jobs = parseJobs(renderTemplate(template, buildRenderContext(manifest, "/repos/widgets")));
|
|
234
|
+
assert.ok(isGuarded(jobs, "private-repo-guard"));
|
|
235
|
+
assert.ok(isGuarded(jobs, "ci"));
|
|
236
|
+
});
|
package/install.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// First-time setup: write `.rightgit.json` into a target repo and render its
|
|
2
|
+
// workflows (DESIGN.md §4). Refuses private/internal/unknown repos (I1) and
|
|
3
|
+
// refuses to clobber an already-installed repo — that's what `sync` is for.
|
|
4
|
+
//
|
|
5
|
+
// Matrix/packageManager/templateVersion defaults are the exact example
|
|
6
|
+
// values DESIGN.md §4 documents for `.rightgit.json`, not invented policy.
|
|
7
|
+
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { assertPublic } from "./policy/visibility-gate.mjs";
|
|
11
|
+
import { MANIFEST_FILENAME, validateManifest } from "./manifest.mjs";
|
|
12
|
+
import { applyPlan, planSync } from "./sync.mjs";
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_MATRIX = { os: ["ubuntu-latest", "macos-latest", "windows-latest"], node: ["22.13", "24"] };
|
|
15
|
+
export const DEFAULT_PACKAGE_MANAGER = "pnpm@11.24.0";
|
|
16
|
+
export const DEFAULT_TEMPLATE_VERSION = "1.8.0";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* opts: { lanes: string[], matrix?, packageManager?, templateVersion?,
|
|
20
|
+
* provenance?: boolean, homebrewTap?, homebrewFormula?, wingetId? }
|
|
21
|
+
* Never throws. Returns a typed result: { ok, stage, errors, manifestPath?, plan? }
|
|
22
|
+
*/
|
|
23
|
+
export async function installCommand(repoPath, opts = {}, deps = {}) {
|
|
24
|
+
const visibility = await assertPublic(repoPath, deps);
|
|
25
|
+
if (!visibility.allowed) {
|
|
26
|
+
return { ok: false, stage: "visibility", errors: [visibility.reason] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const manifestPath = path.join(repoPath, MANIFEST_FILENAME);
|
|
30
|
+
if (fs.existsSync(manifestPath)) {
|
|
31
|
+
return { ok: false, stage: "exists", errors: [`${manifestPath} already exists; use 'right-git sync' to update an installed repo`] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const lanes = opts.lanes;
|
|
35
|
+
if (!Array.isArray(lanes) || lanes.length === 0) {
|
|
36
|
+
return { ok: false, stage: "lanes", errors: ["--lanes is required, e.g. --lanes ci,qualification,package-smoke"] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const manifest = {
|
|
40
|
+
schemaVersion: 1,
|
|
41
|
+
compile: "github-actions-only",
|
|
42
|
+
lanes,
|
|
43
|
+
matrix: opts.matrix || DEFAULT_MATRIX,
|
|
44
|
+
packageManager: opts.packageManager || DEFAULT_PACKAGE_MANAGER,
|
|
45
|
+
templateVersion: opts.templateVersion || DEFAULT_TEMPLATE_VERSION,
|
|
46
|
+
};
|
|
47
|
+
if (opts.profile) manifest.profile = opts.profile;
|
|
48
|
+
if (opts.gatePath) manifest.gate = { path: opts.gatePath };
|
|
49
|
+
|
|
50
|
+
if (lanes.includes("publish-npm")) {
|
|
51
|
+
manifest.publish = { ...manifest.publish, npm: { oidc: true, provenance: opts.provenance !== false } };
|
|
52
|
+
}
|
|
53
|
+
if (lanes.includes("publish-package-managers")) {
|
|
54
|
+
if (!opts.homebrewTap || !opts.homebrewFormula || !opts.wingetId) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
stage: "publish-package-managers-config",
|
|
58
|
+
errors: ["lane 'publish-package-managers' requires --homebrew-tap, --homebrew-formula, and --winget-id"],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
manifest.publish = {
|
|
62
|
+
...manifest.publish,
|
|
63
|
+
homebrew: { tap: opts.homebrewTap, formulaName: opts.homebrewFormula },
|
|
64
|
+
winget: { packageIdentifier: opts.wingetId },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { valid, errors } = validateManifest(manifest);
|
|
69
|
+
if (!valid) return { ok: false, stage: "manifest-invalid", errors };
|
|
70
|
+
|
|
71
|
+
const manifestBytes = `${JSON.stringify(manifest, null, 2)}\n`;
|
|
72
|
+
const plan = await planSync(repoPath, deps, manifest);
|
|
73
|
+
if (!plan.ok) return { ok: false, stage: plan.stage, errors: plan.errors, plan };
|
|
74
|
+
fs.writeFileSync(manifestPath, manifestBytes, "utf8");
|
|
75
|
+
const applied = applyPlan(repoPath, plan);
|
|
76
|
+
if (!applied.ok) {
|
|
77
|
+
if (fs.readFileSync(manifestPath, "utf8") === manifestBytes) fs.rmSync(manifestPath);
|
|
78
|
+
return { ok: false, stage: applied.stage, errors: applied.errors, plan };
|
|
79
|
+
}
|
|
80
|
+
return { ok: true, stage: "synced", errors: [], manifestPath, plan };
|
|
81
|
+
}
|