@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/guard-coverage.test.mjs
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
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
|
-
swift: { check: { runner: "macos-15", xcodeVersion: "16.4", projectDirectory: "ios", spec: "project.yml", project: "Widgets.xcodeproj", scheme: "Widgets", xcodegenVersion: "2.44.1" } },
|
|
58
|
-
regenerate: { script: "regenerate" },
|
|
59
|
-
matrix: { os: ["ubuntu-latest", "macos-latest", "windows-latest"], node: ["22.13", "24"] },
|
|
60
|
-
packageManager: "pnpm@11.24.0",
|
|
61
|
-
publish: {
|
|
62
|
-
npm: { oidc: true, provenance: true },
|
|
63
|
-
homebrew: { tap: "acme/homebrew-tap", formulaName: "widgets" },
|
|
64
|
-
winget: { packageIdentifier: "Acme.Widgets" },
|
|
65
|
-
},
|
|
66
|
-
templateVersion: "1.0.0",
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const NEGATED_PRIVATE_RE = /!\s*github\.event\.repository\.private/;
|
|
70
|
-
const POSITIVE_PRIVATE_RE = /(?<!!\s*)github\.event\.repository\.private/;
|
|
71
|
-
const ALWAYS_RE = /\balways\(\)/;
|
|
72
|
-
const EXIT_NONZERO_RE = /exit\s+[1-9]/;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Minimal line-based parser for the one shape our templates use: top-level
|
|
76
|
-
* `jobs:` map, each job a ` name:` header, job-level `if:`/`needs:` at
|
|
77
|
-
* exactly 4-space indent, steps introduced by ` - ` at 6-space indent
|
|
78
|
-
* with their own `if:`/`run:` nested under that (see templates/*.yml). Good
|
|
79
|
-
* enough for our own generated YAML; not a general YAML parser.
|
|
80
|
-
*/
|
|
81
|
-
function parseJobs(content) {
|
|
82
|
-
const lines = content.split("\n");
|
|
83
|
-
const jobsIdx = lines.findIndex((l) => /^jobs:\s*$/.test(l));
|
|
84
|
-
assert.ok(jobsIdx !== -1, "rendered workflow has no top-level jobs: map");
|
|
85
|
-
|
|
86
|
-
const jobStarts = [];
|
|
87
|
-
for (let i = jobsIdx + 1; i < lines.length; i++) {
|
|
88
|
-
if (/^ {2}\S.*:\s*$/.test(lines[i])) jobStarts.push(i);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const jobs = new Map();
|
|
92
|
-
for (let idx = 0; idx < jobStarts.length; idx++) {
|
|
93
|
-
const start = jobStarts[idx];
|
|
94
|
-
const end = idx + 1 < jobStarts.length ? jobStarts[idx + 1] : lines.length;
|
|
95
|
-
const name = /^ {2}(\S+):/.exec(lines[start])[1];
|
|
96
|
-
const block = lines.slice(start, end);
|
|
97
|
-
|
|
98
|
-
const ifLine = block.find((l) => /^ {4}if: /.test(l));
|
|
99
|
-
const needsLine = block.find((l) => /^ {4}needs: /.test(l));
|
|
100
|
-
|
|
101
|
-
let needs = [];
|
|
102
|
-
if (needsLine) {
|
|
103
|
-
const inline = /^ {4}needs:\s*\[(.*)\]\s*$/.exec(needsLine);
|
|
104
|
-
if (inline) {
|
|
105
|
-
needs = inline[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
106
|
-
} else {
|
|
107
|
-
const bare = /^ {4}needs:\s*(\S+)\s*$/.exec(needsLine);
|
|
108
|
-
if (bare) needs = [bare[1]];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Self-guard detection: a STEP-level `if:` (any indent deeper than the
|
|
113
|
-
// job-level 4 spaces already captured above as `ifLine`) that positively
|
|
114
|
-
// references repository.private, with a non-zero `exit` appearing before
|
|
115
|
-
// the next step starts. Such a job cannot reach "success" in a private
|
|
116
|
-
// repo regardless of what its job-level `if` says (here, nothing — the
|
|
117
|
-
// fixed templates give these jobs no job-level `if` at all).
|
|
118
|
-
let selfGuardStep = false;
|
|
119
|
-
for (let i = 0; i < block.length; i++) {
|
|
120
|
-
const isStepIfLine = /^\s+if: /.test(block[i]) && !/^ {4}if: /.test(block[i]);
|
|
121
|
-
if (isStepIfLine && POSITIVE_PRIVATE_RE.test(block[i])) {
|
|
122
|
-
const nextStepOffset = block.slice(i + 1).findIndex((l) => /^ {6}- /.test(l));
|
|
123
|
-
const stepBody = nextStepOffset === -1 ? block.slice(i) : block.slice(i, i + 1 + nextStepOffset);
|
|
124
|
-
if (EXIT_NONZERO_RE.test(stepBody.join("\n"))) selfGuardStep = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
jobs.set(name, {
|
|
129
|
-
ifExpr: ifLine ? ifLine.trim().slice("if: ".length) : null,
|
|
130
|
-
needs,
|
|
131
|
-
selfGuardStep,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return jobs;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** True if `jobName` can never SUCCEED in a private repo (fails outright or skips). */
|
|
138
|
-
function isGuarded(jobs, jobName, visiting = new Set()) {
|
|
139
|
-
if (visiting.has(jobName)) return false; // cycle guard, shouldn't happen
|
|
140
|
-
visiting.add(jobName);
|
|
141
|
-
|
|
142
|
-
const job = jobs.get(jobName);
|
|
143
|
-
assert.ok(job, `needs references unknown job '${jobName}'`);
|
|
144
|
-
|
|
145
|
-
// Self-failing job: no job-level `if` gates it away (it always runs), but
|
|
146
|
-
// one of its own steps refuses (fails) when private. This is the LOUD
|
|
147
|
-
// shape — the job runs and fails, it is never silently skipped.
|
|
148
|
-
if (job.selfGuardStep) return true;
|
|
149
|
-
|
|
150
|
-
// The OLD shape (job-level `if: !private`) is deliberately NOT treated as
|
|
151
|
-
// guarded here — gating the whole job away is exactly the "skip instead
|
|
152
|
-
// of fail" bug this suite now guards against. A template that regresses
|
|
153
|
-
// to it must fail this assertion, not pass it via this branch.
|
|
154
|
-
if (job.ifExpr && NEGATED_PRIVATE_RE.test(job.ifExpr) && !job.selfGuardStep) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// A custom `if:` that calls always() bypasses the default needs->success()
|
|
159
|
-
// gate, so a guarded dependency being skipped would NOT stop this job.
|
|
160
|
-
if (job.ifExpr && ALWAYS_RE.test(job.ifExpr)) return false;
|
|
161
|
-
|
|
162
|
-
// Default GitHub Actions semantics: an `if:` that doesn't call
|
|
163
|
-
// success()/always()/cancelled()/failure() is implicitly ANDed with
|
|
164
|
-
// success(), which requires every direct `needs` job to have succeeded.
|
|
165
|
-
// A failed or skipped dependency fails that check, so this job is
|
|
166
|
-
// transitively guarded if ANY one of its needs is guarded.
|
|
167
|
-
return job.needs.some((n) => isGuarded(jobs, n, visiting));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function renderAllLanes() {
|
|
171
|
-
const rendered = {};
|
|
172
|
-
for (const lane of FULL_MANIFEST.lanes) {
|
|
173
|
-
const templatePath = path.join(templatesDir, LANE_FILENAMES[lane]);
|
|
174
|
-
const templateText = fs.readFileSync(templatePath, "utf8");
|
|
175
|
-
rendered[lane] = renderTemplate(templateText, buildRenderContext(FULL_MANIFEST, "/repos/widgets", lane));
|
|
176
|
-
}
|
|
177
|
-
return rendered;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
test("F5: every job in every rendered lane is private-guarded or transitively depends on a guarded job", () => {
|
|
181
|
-
const rendered = renderAllLanes();
|
|
182
|
-
for (const lane of KNOWN_LANES) {
|
|
183
|
-
const jobs = parseJobs(rendered[lane]);
|
|
184
|
-
assert.ok(jobs.size > 0, `lane ${lane} has no jobs`);
|
|
185
|
-
for (const jobName of jobs.keys()) {
|
|
186
|
-
assert.ok(
|
|
187
|
-
isGuarded(jobs, jobName),
|
|
188
|
-
`lane ${lane} job '${jobName}' is neither private-guarded nor depends (transitively) on a job that is — a private repo could execute it (F5)`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// F5 loudness proof (the specific gap the re-validation found): a job that
|
|
195
|
-
// is only reachable through a job-level `if: !private` is SKIPPED, not
|
|
196
|
-
// FAILED, for a private repo — GitHub reports skipped jobs as neutral, and
|
|
197
|
-
// a workflow made entirely of skips/successes shows green, not the loud
|
|
198
|
-
// failure invariant I1 demands. This asserts the concrete structural
|
|
199
|
-
// precondition for the loud-failure behavior: the `private-repo-guard` job
|
|
200
|
-
// itself carries NO job-level `if` (so GitHub always schedules and runs it,
|
|
201
|
-
// private or not) and its own step-level `if` positively matches private
|
|
202
|
-
// with a non-zero `exit` — so when private, the job runs and then fails.
|
|
203
|
-
// Fails against the pre-fix shape (guard logic lived inside a job gated by
|
|
204
|
-
// `if: !private`, so the refusing step was itself skipped) and against any
|
|
205
|
-
// regression back to that shape.
|
|
206
|
-
test("F5: private-repo-guard job has no job-level `if` (always runs) and fails outright when private", () => {
|
|
207
|
-
const rendered = renderAllLanes();
|
|
208
|
-
for (const lane of KNOWN_LANES) {
|
|
209
|
-
const jobs = parseJobs(rendered[lane]);
|
|
210
|
-
const guard = jobs.get("private-repo-guard");
|
|
211
|
-
assert.ok(guard, `lane ${lane} has no private-repo-guard job`);
|
|
212
|
-
assert.equal(
|
|
213
|
-
guard.ifExpr,
|
|
214
|
-
null,
|
|
215
|
-
`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`,
|
|
216
|
-
);
|
|
217
|
-
assert.ok(
|
|
218
|
-
guard.selfGuardStep,
|
|
219
|
-
`lane ${lane} private-repo-guard has no step that positively checks private and exits non-zero`,
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("qualification preserves failing schema evidence as a unique required artifact", () => {
|
|
225
|
-
const template = fs.readFileSync(path.join(templatesDir, "qualification.yml"), "utf8");
|
|
226
|
-
assert.doesNotMatch(template, /\|\| true/);
|
|
227
|
-
assert.match(template, /set -o pipefail[\s\S]*tee qualification-schema\.log/);
|
|
228
|
-
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/);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("rust-hybrid ci keeps its work behind the public-repository guard", () => {
|
|
232
|
-
const manifest = { ...FULL_MANIFEST, lanes: ["ci"], profile: "rust-hybrid", gate: { path: "scripts/gate.sh" } };
|
|
233
|
-
const template = fs.readFileSync(path.join(templatesDir, "profiles/rust-hybrid/ci.yml"), "utf8");
|
|
234
|
-
const jobs = parseJobs(renderTemplate(template, buildRenderContext(manifest, "/repos/widgets")));
|
|
235
|
-
assert.ok(isGuarded(jobs, "private-repo-guard"));
|
|
236
|
-
assert.ok(isGuarded(jobs, "ci"));
|
|
237
|
-
});
|