yadflow 4.7.0 → 4.8.0
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/CHANGELOG.md +89 -0
- package/README.md +43 -4
- package/bin/commands.mjs +4 -1
- package/bin/yad.mjs +147 -20
- package/cli/agent-guard.mjs +511 -0
- package/cli/agent-guide.mjs +83 -0
- package/cli/agent-rules.mjs +381 -0
- package/cli/argv-flags.mjs +7 -0
- package/cli/ci-check.mjs +492 -0
- package/cli/docs.mjs +1 -1
- package/cli/doctor.mjs +43 -7
- package/cli/epic-state.mjs +3 -3
- package/cli/errors.mjs +1 -0
- package/cli/guide.mjs +549 -0
- package/cli/hook.mjs +32 -3
- package/cli/lib.mjs +46 -0
- package/cli/lifecycle/defaults/2.json +124 -0
- package/cli/lifecycle/lifecycle.schema.json +5 -2
- package/cli/lifecycle.mjs +16 -3
- package/cli/manifest.mjs +75 -0
- package/cli/marked-block.mjs +48 -0
- package/cli/members.mjs +19 -5
- package/cli/migrate.mjs +17 -19
- package/cli/next.mjs +1 -1
- package/cli/plan.mjs +326 -22
- package/cli/protection.mjs +50 -0
- package/cli/reconcile.mjs +187 -26
- package/cli/report.mjs +62 -14
- package/cli/setup.mjs +244 -25
- package/cli/signing.mjs +377 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-ci-check.mjs +616 -0
- package/cli/test-guide.mjs +1267 -0
- package/cli/test-node.mjs +129 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/toolbox.mjs +1 -1
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +37 -12
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +4 -4
- package/skills/sdlc/module-help.csv +1 -0
- package/skills/yad-change/SKILL.md +3 -2
- package/skills/yad-checks/SKILL.md +29 -9
- package/skills/yad-checks/references/check-gates.md +9 -4
- package/skills/yad-checks/templates/checks/package-manager.sh +1 -1
- package/skills/yad-checks/templates/github/yad-checks.yml +1 -1
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +4 -3
- package/skills/yad-connect-repos/SKILL.md +5 -3
- package/skills/yad-connect-repos/references/code-context.md +2 -1
- package/skills/yad-connect-repos/references/repos-registry.md +2 -1
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +12 -7
- package/skills/yad-engineer-review/references/ship-and-record.md +7 -4
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +1 -1
- package/skills/yad-guide/SKILL.md +192 -0
- package/skills/yad-open-pr/SKILL.md +1 -1
- package/skills/yad-pair-review/SKILL.md +14 -5
- package/skills/yad-product-bridge/SKILL.md +32 -13
- package/skills/yad-product-bridge/references/bridge.md +6 -3
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +2 -2
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +1 -1
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +5 -3
- package/skills/yad-review-gate/SKILL.md +13 -9
- package/skills/yad-review-gate/references/gating.md +1 -1
- package/skills/yad-run/SKILL.md +10 -6
- package/skills/yad-run/references/run-loop.md +2 -1
- package/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +2 -2
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
// E160b: `yad ci check`. The rules each test pins (the case list is in the E160 roadmap row):
|
|
2
|
+
// - yad's CI files on disk: missing → `yad check --fix`, outdated → `yad update`, edited → ask, or `yad report`;
|
|
3
|
+
// - the platform, on each default branch: protected (approvals by mode), the checks required before a merge
|
|
4
|
+
// (GitHub: every job in REQUIRED_CHECKS, from the rulesets and classic protection; GitLab: "Pipelines must
|
|
5
|
+
// succeed" and skipped pipelines), force pushes, deletion; suggestions for stale approvals, threads, and
|
|
6
|
+
// signed commits on a code repo — and a gap when signed commits are required on the Product;
|
|
7
|
+
// - a read that fails is `unknown` with its reason, never `ok`; nothing is written, and only GETs are made.
|
|
8
|
+
import { test } from 'node:test';
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import { spawnSync, execFileSync } from 'node:child_process';
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
|
|
16
|
+
if (process.env.NODE_TEST_CONTEXT) {
|
|
17
|
+
const write = process.stdout.write;
|
|
18
|
+
for (const k of ['log', 'info']) {
|
|
19
|
+
const orig = console[k];
|
|
20
|
+
console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
process.env.YAD_NO_UPDATE_NOTIFIER = '1';
|
|
24
|
+
|
|
25
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
26
|
+
const { ciCheck } = await import('./ci-check.mjs');
|
|
27
|
+
const { REQUIRED_CHECKS } = await import('./manifest.mjs');
|
|
28
|
+
const { repoActions, productActions } = await import('./plan.mjs');
|
|
29
|
+
const { classify, readAllowList } = await import('./agent-rules.mjs');
|
|
30
|
+
|
|
31
|
+
const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-ci-')));
|
|
32
|
+
const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
|
|
33
|
+
const isCi = (item) => /^(\.github\/workflows\/|\.gitlab\/ci\/|checks\/)/.test(item) || item === '.sdlc/product-link.json';
|
|
34
|
+
const GIT_ENV = { GIT_CONFIG_NOSYSTEM: '1', GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@example.com', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@example.com' };
|
|
35
|
+
const ON = { ...process.env, YAD_PLATFORM_READ: '' };
|
|
36
|
+
|
|
37
|
+
// A workspace: the Product and one code repo beside it, each a git repo; yad's CI files written as yad
|
|
38
|
+
// writes them (unless `wire` is false).
|
|
39
|
+
function workspace({ platform = 'github', product = {}, repos, wire = true, clone = true, include = true } = {}) {
|
|
40
|
+
const T = tmp();
|
|
41
|
+
const root = path.join(T, 'product');
|
|
42
|
+
fs.mkdirSync(root);
|
|
43
|
+
execFileSync('git', ['init', '-q'], { cwd: root, env: { ...process.env, ...GIT_ENV } });
|
|
44
|
+
const host = platform === 'github' ? 'github.com' : 'gitlab.com';
|
|
45
|
+
put(path.join(root, '.sdlc/product.json'), { platform, git_url: `git@${host}:acme/p.git`, default_branch: 'main', ledger: 'verified', ...product });
|
|
46
|
+
const list = repos ?? [{ name: 'app', path: '../app', platform, git_url: `git@${host}:acme/app.git`, default_branch: 'main' }];
|
|
47
|
+
put(path.join(root, '.sdlc/repos.json'), { repos: list });
|
|
48
|
+
if (clone) for (const r of list) { fs.mkdirSync(path.resolve(root, r.path), { recursive: true }); execFileSync('git', ['init', '-q'], { cwd: path.resolve(root, r.path), env: { ...process.env, ...GIT_ENV } }); }
|
|
49
|
+
if (wire) {
|
|
50
|
+
for (const a of productActions(root)) if (isCi(a.item) && a.status !== 'ok') a.apply();
|
|
51
|
+
if (clone) for (const r of list) for (const a of repoActions(root, r)) if (isCi(a.item) && a.status !== 'ok') a.apply();
|
|
52
|
+
// GitLab runs a fragment only when the root pipeline includes it.
|
|
53
|
+
if (platform === 'gitlab' && include) {
|
|
54
|
+
for (const dir of [root, ...(clone ? list.map((r) => path.resolve(root, r.path)) : [])]) {
|
|
55
|
+
const frags = fs.existsSync(path.join(dir, '.gitlab/ci')) ? fs.readdirSync(path.join(dir, '.gitlab/ci')).map((f) => `.gitlab/ci/${f}`) : [];
|
|
56
|
+
put(path.join(dir, '.gitlab-ci.yml'), `# yad\ninclude:\n${frags.map((f) => ` - local: '${f}'\n`).join('')}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { T, root };
|
|
61
|
+
}
|
|
62
|
+
const done = (w) => fs.rmSync(w.T, { recursive: true, force: true });
|
|
63
|
+
|
|
64
|
+
// The platform CLIs, answered from an ordered list of [path regex, status, body]; everything asked is kept.
|
|
65
|
+
function fakePlatform({ installed = true, authed = true, calls = [] } = {}) {
|
|
66
|
+
const asked = [];
|
|
67
|
+
const runner = (cmd, args) => {
|
|
68
|
+
asked.push([cmd, ...args].join(' '));
|
|
69
|
+
if (cmd === 'which' || cmd === 'where') return { ok: installed, stdout: '', stderr: '' };
|
|
70
|
+
if (args[0] === 'auth') return { ok: authed, stdout: '', stderr: '' };
|
|
71
|
+
const p = args[args.length - 1];
|
|
72
|
+
for (const [re, code, body] of calls) {
|
|
73
|
+
if (!re.test(p)) continue;
|
|
74
|
+
if (code === 200) return { ok: true, stdout: JSON.stringify(body), stderr: '' };
|
|
75
|
+
const msg = typeof body?.message === 'string' ? body.message : `${code} Error`;
|
|
76
|
+
return { ok: false, stdout: JSON.stringify(body ?? { message: msg }), stderr: cmd === 'gh' ? `gh: ${msg} (HTTP ${code})` : `glab: ${msg} (HTTP ${code})` };
|
|
77
|
+
}
|
|
78
|
+
return { ok: false, stdout: '', stderr: cmd === 'gh' ? 'gh: Not Found (HTTP 404)' : 'glab: 404 Not Found (HTTP 404)' };
|
|
79
|
+
};
|
|
80
|
+
return { runner, asked };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// GitHub, for one repo: the repo, its branch, the rules on the branch, and classic protection.
|
|
84
|
+
const PR_RULE = (n = 1, extra = {}) => ({ type: 'pull_request', parameters: { required_approving_review_count: n, dismiss_stale_reviews_on_push: true, ...extra } });
|
|
85
|
+
const CHECKS_RULE = (contexts) => ({ type: 'required_status_checks', parameters: { required_status_checks: contexts.map((context) => ({ context })) } });
|
|
86
|
+
const ALL_RULES = (jobs) => [PR_RULE(), CHECKS_RULE(jobs), { type: 'non_fast_forward' }, { type: 'deletion' }];
|
|
87
|
+
const NOT_PROTECTED = [404, { message: 'Branch not protected' }];
|
|
88
|
+
// `rules` is the list of rules; `rulesFail` a refused answer instead, as [status, body].
|
|
89
|
+
function gh(repo, { rules, rulesFail = null, classic = NOT_PROTECTED, prot = true } = {}) {
|
|
90
|
+
const at = `repos/acme/${repo}`;
|
|
91
|
+
return [
|
|
92
|
+
[new RegExp(`^${at}$`), 200, { default_branch: 'main' }],
|
|
93
|
+
[new RegExp(`^${at}/branches/main$`), 200, { protected: prot }],
|
|
94
|
+
[new RegExp(`^${at}/rules/branches/main`), ...(rulesFail ?? [200, rules])],
|
|
95
|
+
[new RegExp(`^${at}/branches/main/protection$`), ...classic],
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
const productJobs = [...REQUIRED_CHECKS.github.product, ...REQUIRED_CHECKS.github.productVerified];
|
|
99
|
+
const allSet = () => [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [...ALL_RULES(REQUIRED_CHECKS.github.code), { type: 'required_signatures' }] })];
|
|
100
|
+
const byId = (r, name) => Object.fromEntries(r.repos.find((x) => x.name === name).findings.map((f) => [f.id, f]));
|
|
101
|
+
const check = (w, calls, opts = {}) => {
|
|
102
|
+
const f = fakePlatform({ calls, ...opts.spec });
|
|
103
|
+
return { r: ciCheck(w.root, { runner: f.runner, env: ON, ...opts }), asked: f.asked };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
test('E160b case 1: everything set on GitHub — every row ok, complete, no gap', () => {
|
|
107
|
+
const w = workspace();
|
|
108
|
+
try {
|
|
109
|
+
const { r } = check(w, allSet());
|
|
110
|
+
for (const repo of r.repos) for (const f of repo.findings) assert.equal(f.status, 'ok', `${repo.name} ${f.id}: ${f.message}`);
|
|
111
|
+
assert.deepEqual(r.repos.map((x) => x.name), ['Product', 'app']);
|
|
112
|
+
assert.deepEqual(r.summary, { gaps: 0, suggestions: 0, unknown: 0, complete: true });
|
|
113
|
+
assert.deepEqual(Object.keys(byId(r, 'app')).sort(), ['deletion', 'files', 'force-push', 'protected', 'required-checks', 'signed-commits', 'stale-approvals']);
|
|
114
|
+
} finally { done(w); }
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('E160b case 2: a required job missing from the ruleset is a gap that names it, with the settings page', () => {
|
|
118
|
+
const w = workspace();
|
|
119
|
+
try {
|
|
120
|
+
const jobs = REQUIRED_CHECKS.github.code.filter((j) => j !== 'contract-check' && j !== 'member-check');
|
|
121
|
+
const { r } = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: ALL_RULES(jobs) })]);
|
|
122
|
+
const row = byId(r, 'app')['required-checks'];
|
|
123
|
+
assert.equal(row.status, 'gap');
|
|
124
|
+
assert.match(row.message, /not required before a merge: contract-check/);
|
|
125
|
+
assert.equal(row.fix.actor, 'person');
|
|
126
|
+
assert.equal(row.fix.url, 'https://github.com/acme/app/settings/rules');
|
|
127
|
+
assert.match(row.fix.steps.join(' '), /Require status checks to pass.*contract-check/);
|
|
128
|
+
} finally { done(w); }
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('E160b case 3: classic protection — read as an admin it counts; not readable and not covered by rulesets, it is unknown', () => {
|
|
132
|
+
const w = workspace();
|
|
133
|
+
try {
|
|
134
|
+
const classic = { required_status_checks: { contexts: REQUIRED_CHECKS.github.code.slice(0, 5), checks: REQUIRED_CHECKS.github.code.slice(5).map((context) => ({ context })) },
|
|
135
|
+
allow_force_pushes: { enabled: false }, allow_deletions: { enabled: false }, required_pull_request_reviews: { dismiss_stale_reviews: true }, required_signatures: { enabled: true } };
|
|
136
|
+
const admin = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE()], classic: [200, classic] })]).r;
|
|
137
|
+
for (const id of ['required-checks', 'force-push', 'deletion', 'stale-approvals', 'signed-commits']) assert.equal(byId(admin, 'app')[id].status, 'ok', id);
|
|
138
|
+
// Not an admin: a bare 404. The rulesets hold only the pull request rule, so nothing else is proven.
|
|
139
|
+
const notAdmin = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE()], classic: [404, { message: 'Not Found' }] })]).r;
|
|
140
|
+
const row = byId(notAdmin, 'app');
|
|
141
|
+
for (const id of ['required-checks', 'force-push', 'deletion']) {
|
|
142
|
+
assert.equal(row[id].status, 'unknown', id);
|
|
143
|
+
assert.match(row[id].message, /readable by a repo admin only/, id);
|
|
144
|
+
}
|
|
145
|
+
assert.equal(notAdmin.summary.complete, false);
|
|
146
|
+
// Not an admin, but the rulesets require every job and block both: proven without classic protection.
|
|
147
|
+
const covered = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code), classic: [404, { message: 'Not Found' }] })]).r;
|
|
148
|
+
for (const id of ['required-checks', 'force-push', 'deletion', 'stale-approvals']) assert.equal(byId(covered, 'app')[id].status, 'ok', id);
|
|
149
|
+
} finally { done(w); }
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('E160b case 4: force push or deletion allowed is a gap; a full page of rules proves nothing', () => {
|
|
153
|
+
const w = workspace();
|
|
154
|
+
try {
|
|
155
|
+
const rules = [PR_RULE(), CHECKS_RULE(REQUIRED_CHECKS.github.code)];
|
|
156
|
+
const { r } = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules })]);
|
|
157
|
+
assert.equal(byId(r, 'app')['force-push'].status, 'gap');
|
|
158
|
+
assert.match(byId(r, 'app')['force-push'].fix.steps[0], /Block force pushes/);
|
|
159
|
+
assert.equal(byId(r, 'app').deletion.status, 'gap');
|
|
160
|
+
// Not protected at all: classic is proven absent, and so is every rule the list does not hold.
|
|
161
|
+
const bare = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [], prot: false })]).r;
|
|
162
|
+
assert.equal(byId(bare, 'app').protected.status, 'gap');
|
|
163
|
+
assert.equal(byId(bare, 'app')['force-push'].status, 'gap');
|
|
164
|
+
// 100 rules came back and none blocks a force push: what is past the page is not known.
|
|
165
|
+
const full = Array.from({ length: 100 }, () => ({ type: 'creation' }));
|
|
166
|
+
const paged = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE(), CHECKS_RULE(REQUIRED_CHECKS.github.code), ...full] })]).r;
|
|
167
|
+
assert.equal(byId(paged, 'app')['force-push'].status, 'unknown');
|
|
168
|
+
// The rules could not be read at all.
|
|
169
|
+
const unread = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rulesFail: [500, { message: 'boom' }] })]).r;
|
|
170
|
+
assert.equal(byId(unread, 'app')['required-checks'].status, 'unknown');
|
|
171
|
+
} finally { done(w); }
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// GitLab, for one project: the project and its settings, the branch, protected branches, approvals, push rule.
|
|
175
|
+
// The project is in a person's own namespace unless `project.namespace` says a group's.
|
|
176
|
+
const NO_ONE = { name: 'main', allow_force_push: false, push_access_levels: [{ access_level: 0 }] };
|
|
177
|
+
function gl(repo, { project = {}, prot = true, protectedBranches = [NO_ONE], branchesFail = null, approvals = [200, { reset_approvals_on_push: true }], pushRule = [404, { message: '404 Not found' }] } = {}) {
|
|
178
|
+
const at = `projects/acme%2F${repo}`;
|
|
179
|
+
return [
|
|
180
|
+
[new RegExp(`^${at}$`), 200, { default_branch: 'main', namespace: { kind: 'user' }, ci_config_path: '', only_allow_merge_if_pipeline_succeeds: true, allow_merge_on_skipped_pipeline: false, only_allow_merge_if_all_discussions_are_resolved: true, ...project }],
|
|
181
|
+
[new RegExp(`^${at}/repository/branches/main$`), 200, { protected: prot }],
|
|
182
|
+
[new RegExp(`^${at}/protected_branches`), ...(branchesFail ?? [200, protectedBranches])],
|
|
183
|
+
[new RegExp(`^${at}/approval_rules`), 200, [{ name: 'All', rule_type: 'any_approver', approvals_required: 1, protected_branches: [] }]],
|
|
184
|
+
[new RegExp(`^${at}/approvals$`), ...approvals],
|
|
185
|
+
[new RegExp(`^${at}/push_rule$`), ...pushRule],
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
test('E160b case 5: GitLab — pipelines must succeed, skipped pipelines, threads, approval reset (Premium), force push', () => {
|
|
190
|
+
const w = workspace({ platform: 'gitlab' });
|
|
191
|
+
try {
|
|
192
|
+
const good = check(w, [...gl('p'), ...gl('app', { pushRule: [200, { reject_unsigned_commits: true }] })]).r;
|
|
193
|
+
for (const repo of good.repos) for (const f of repo.findings) assert.equal(f.status, 'ok', `${repo.name} ${f.id}: ${f.message}`);
|
|
194
|
+
const { r } = check(w, [...gl('p'), ...gl('app', {
|
|
195
|
+
project: { only_allow_merge_if_pipeline_succeeds: false, allow_merge_on_skipped_pipeline: true, only_allow_merge_if_all_discussions_are_resolved: false },
|
|
196
|
+
protectedBranches: [{ ...NO_ONE, allow_force_push: true }], approvals: [403, { message: '403 Forbidden' }],
|
|
197
|
+
})]);
|
|
198
|
+
const row = byId(r, 'app');
|
|
199
|
+
assert.equal(row['required-checks'].status, 'gap');
|
|
200
|
+
assert.equal(row['required-checks'].fix.url, 'https://gitlab.com/acme/app/-/settings/merge_requests');
|
|
201
|
+
assert.equal(row['skipped-pipelines'].status, 'gap');
|
|
202
|
+
assert.equal(row.discussions.status, 'suggest');
|
|
203
|
+
assert.equal(row['stale-approvals'].status, 'suggest', 'not Premium: a suggestion, never a gap');
|
|
204
|
+
assert.match(row['stale-approvals'].message, /Premium/);
|
|
205
|
+
assert.equal(row['force-push'].status, 'gap');
|
|
206
|
+
assert.equal(row['signed-commits'].status, 'suggest');
|
|
207
|
+
// Protected by a group's rule, which the project's list leaves out: not known.
|
|
208
|
+
const group = check(w, [...gl('p'), ...gl('app', { protectedBranches: [] })]).r;
|
|
209
|
+
assert.equal(byId(group, 'app')['force-push'].status, 'unknown');
|
|
210
|
+
// A group's project: its own entry saying "no" proves nothing, since a group's rule wins over it.
|
|
211
|
+
const inGroup = byId(check(w, [...gl('p'), ...gl('app', { project: { namespace: { kind: 'group' } } })]).r, 'app');
|
|
212
|
+
assert.equal(inGroup['force-push'].status, 'unknown');
|
|
213
|
+
assert.match(inGroup['force-push'].message, /group's protected-branch rule/);
|
|
214
|
+
assert.equal(inGroup['direct-push'].status, 'unknown');
|
|
215
|
+
// The protected branches could not be read.
|
|
216
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app', { branchesFail: [500, { message: '500' }] })]).r, 'app')['force-push'].status, 'unknown');
|
|
217
|
+
// Not protected: force push and direct push are gaps; the default branch still cannot be deleted.
|
|
218
|
+
const bare = check(w, [...gl('p'), ...gl('app', { prot: false, protectedBranches: [] })]).r;
|
|
219
|
+
assert.equal(byId(bare, 'app')['force-push'].status, 'gap');
|
|
220
|
+
assert.match(byId(bare, 'app')['force-push'].fix.steps[0], /protect main/);
|
|
221
|
+
assert.equal(byId(bare, 'app')['direct-push'].status, 'gap');
|
|
222
|
+
assert.equal(byId(bare, 'app').deletion.status, 'ok');
|
|
223
|
+
assert.match(byId(bare, 'app').deletion.message, /default branch/);
|
|
224
|
+
} finally { done(w); }
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('E160b case 6: no login, no CLI, reads off, or no platform — the platform rows are unknown with the reason', () => {
|
|
228
|
+
const w = workspace();
|
|
229
|
+
try {
|
|
230
|
+
for (const [why, opts] of [['not logged in', { spec: { authed: false } }], ['not installed', { spec: { installed: false } }], ['turned off', { env: { ...ON, YAD_PLATFORM_READ: '0' } }]]) {
|
|
231
|
+
const { r } = check(w, allSet(), opts);
|
|
232
|
+
const row = byId(r, 'app');
|
|
233
|
+
for (const id of ['protected', 'required-checks', 'force-push', 'deletion']) assert.equal(row[id].status, 'unknown', `${why}: ${id}`);
|
|
234
|
+
assert.equal(row.files.status, 'ok', `${why}: the files are read from disk`);
|
|
235
|
+
assert.equal(r.summary.complete, false, why);
|
|
236
|
+
}
|
|
237
|
+
// Read nothing: every row the repo would have is unknown, the suggestions too.
|
|
238
|
+
const off = byId(check(w, allSet(), { env: { ...ON, YAD_PLATFORM_READ: '0' } }).r, 'Product');
|
|
239
|
+
for (const id of ['protected', 'required-checks', 'force-push', 'deletion', 'stale-approvals', 'signed-commits']) assert.equal(off[id].status, 'unknown', id);
|
|
240
|
+
// No platform at all: nothing holds a merge there — one `platform` row, unknown, never a quiet ok.
|
|
241
|
+
const none = workspace({ product: { platform: null, git_url: null }, repos: [] });
|
|
242
|
+
try {
|
|
243
|
+
const { r } = check(none, []);
|
|
244
|
+
assert.deepEqual(Object.keys(byId(r, 'Product')), ['files', 'platform']);
|
|
245
|
+
assert.equal(byId(r, 'Product').platform.status, 'unknown');
|
|
246
|
+
assert.equal(r.summary.complete, false);
|
|
247
|
+
} finally { done(none); }
|
|
248
|
+
} finally { done(w); }
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('E160b case 7: yad\'s files missing, older, or edited — each with its next step', () => {
|
|
252
|
+
const w = workspace({ wire: false });
|
|
253
|
+
try {
|
|
254
|
+
const missing = byId(check(w, allSet()).r, 'app').files;
|
|
255
|
+
assert.equal(missing.status, 'gap');
|
|
256
|
+
assert.deepEqual(missing.fix.commands, ['yad check --fix']);
|
|
257
|
+
for (const a of repoActions(w.root, { name: 'app', path: '../app', platform: 'github' })) if (isCi(a.item)) a.apply();
|
|
258
|
+
fs.appendFileSync(path.join(w.root, '../app/.github/workflows/yad-checks.yml'), '\n# changed\n');
|
|
259
|
+
const outdated = byId(check(w, allSet()).r, 'app').files;
|
|
260
|
+
assert.equal(outdated.status, 'gap');
|
|
261
|
+
assert.match(outdated.message, /older than this yadflow: \.github\/workflows\/yad-checks\.yml/);
|
|
262
|
+
assert.deepEqual(outdated.fix.commands, ['yad update']);
|
|
263
|
+
// The ledger says yad wrote other content there: the team edited yad's file. Never "edit it".
|
|
264
|
+
put(path.join(w.root, '../app/.sdlc/managed.json'), { files: { '.github/workflows/yad-checks.yml': 'a-sha-yad-wrote-before' } });
|
|
265
|
+
const edited = byId(check(w, allSet()).r, 'app').files;
|
|
266
|
+
assert.equal(edited.status, 'gap');
|
|
267
|
+
assert.match(edited.message, /edited by hand: \.github\/workflows\/yad-checks\.yml/);
|
|
268
|
+
assert.match(edited.fix.steps.join(' '), /Ask the person first.*yad report.*do not edit it/);
|
|
269
|
+
// Not cloned here: not read, with the command that clones it.
|
|
270
|
+
fs.rmSync(path.join(w.root, '../app'), { recursive: true, force: true });
|
|
271
|
+
const gone = byId(check(w, allSet()).r, 'app').files;
|
|
272
|
+
assert.equal(gone.status, 'unknown');
|
|
273
|
+
assert.deepEqual(gone.fix.commands, ['yad repo clone app']);
|
|
274
|
+
} finally { done(w); }
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('E160b case 8: one repo by name, an unknown name, and the default from the Product vs a code repo (CLI)', () => {
|
|
278
|
+
// The code repo inside the Product's folder, so `yad` finds the Product from it (a workspace file beside
|
|
279
|
+
// them is not read in a temp folder).
|
|
280
|
+
const w = workspace({ repos: [{ name: 'app', path: 'app', platform: 'github', git_url: 'git@github.com:acme/app.git', default_branch: 'main' }] });
|
|
281
|
+
try {
|
|
282
|
+
const one = check(w, allSet(), { repo: 'app' }).r;
|
|
283
|
+
assert.deepEqual(one.repos.map((x) => x.name), ['app']);
|
|
284
|
+
const nope = ciCheck(w.root, { repo: 'nope', env: { ...ON, YAD_PLATFORM_READ: '0' } });
|
|
285
|
+
assert.deepEqual([nope.unknownRepo, nope.names], ['nope', ['app']]);
|
|
286
|
+
const yad = (cwd, ...args) => spawnSync(process.execPath, [path.join(ROOT, 'bin/yad.mjs'), 'ci', 'check', '--json', ...args], { cwd, env: { ...process.env, NO_COLOR: '1', YAD_PLATFORM_READ: '0' }, encoding: 'utf8' });
|
|
287
|
+
const fromProduct = JSON.parse(yad(w.root).stdout);
|
|
288
|
+
assert.equal(fromProduct.command, 'ci check');
|
|
289
|
+
assert.deepEqual(fromProduct.repos.map((x) => x.name), ['Product', 'app']);
|
|
290
|
+
const fromRepo = JSON.parse(yad(path.join(w.root, 'app')).stdout);
|
|
291
|
+
assert.deepEqual(fromRepo.repos.map((x) => x.name), ['app'], 'inside a code repo: that repo');
|
|
292
|
+
assert.deepEqual(JSON.parse(yad(path.join(w.root, 'app'), '--all').stdout).repos.map((x) => x.name), ['Product', 'app']);
|
|
293
|
+
const refused = yad(w.root, '--repo', 'nope');
|
|
294
|
+
assert.equal(refused.status, 1);
|
|
295
|
+
assert.match(JSON.parse(refused.stdout).error, /no repo named nope is registered/);
|
|
296
|
+
assert.match(JSON.parse(yad(w.root, '--repo', 'app', '--all').stdout).error, /--repo and --all/);
|
|
297
|
+
} finally { done(w); }
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('E160b case 9: REQUIRED_CHECKS equals the jobs in yad\'s workflow templates and the table in docs/branch-protection.md', () => {
|
|
301
|
+
const jobs = (file, re) => [...fs.readFileSync(path.join(ROOT, file), 'utf8').matchAll(re)].map((m) => m[1]);
|
|
302
|
+
const ghJob = /^ {2}([a-z][a-z0-9-]*):$/gm;
|
|
303
|
+
const glJob = /^(yad-[a-z0-9-]+):$/gm;
|
|
304
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/github/yad-checks.yml', ghJob), REQUIRED_CHECKS.github.code);
|
|
305
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/github/yad-product-checks.yml', ghJob), REQUIRED_CHECKS.github.product);
|
|
306
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/github/yad-verified-commits.yml', ghJob), REQUIRED_CHECKS.github.productVerified);
|
|
307
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.code);
|
|
308
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.product);
|
|
309
|
+
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.productVerified);
|
|
310
|
+
// No job sets `name:`, so GitHub names each check after its job.
|
|
311
|
+
for (const f of ['yad-checks.yml', 'yad-product-checks.yml', 'yad-verified-commits.yml']) assert.doesNotMatch(fs.readFileSync(path.join(ROOT, 'skills/yad-checks/templates/github', f), 'utf8'), /^ {4}name:/m, f);
|
|
312
|
+
const doc = fs.readFileSync(path.join(ROOT, 'docs/branch-protection.md'), 'utf8');
|
|
313
|
+
const row = (label) => [...doc.split('\n').find((l) => l.startsWith(`| ${label} |`)).split('|')[3].matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
314
|
+
assert.deepEqual(row('Product'), REQUIRED_CHECKS.github.product);
|
|
315
|
+
assert.deepEqual(row('Product, when the file is there'), REQUIRED_CHECKS.github.productVerified);
|
|
316
|
+
assert.deepEqual(row('Each code repo'), REQUIRED_CHECKS.github.code);
|
|
317
|
+
const glText = doc.slice(doc.indexOf('The checks run as jobs in the merge request pipeline'));
|
|
318
|
+
for (const j of [...REQUIRED_CHECKS.gitlab.product, ...REQUIRED_CHECKS.gitlab.productVerified, ...REQUIRED_CHECKS.gitlab.code]) assert.ok(glText.includes(`\`${j}\``), j);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('E160b case 10: never writes — the folders are unchanged, and every platform call is a GET', () => {
|
|
322
|
+
const w = workspace();
|
|
323
|
+
try {
|
|
324
|
+
const snap = (dir) => execFileSync('find', [dir, '-type', 'f', '-not', '-path', '*/.git/*', '-exec', 'shasum', '{}', '+'], { encoding: 'utf8' }).split('\n').sort().join('\n');
|
|
325
|
+
const before = snap(path.dirname(w.root));
|
|
326
|
+
const { asked } = check(w, allSet());
|
|
327
|
+
assert.equal(snap(path.dirname(w.root)), before);
|
|
328
|
+
for (const call of asked) assert.doesNotMatch(call, /(-X|--method)\s+(?!GET)|--field|-f |--input/, call);
|
|
329
|
+
assert.ok(asked.some((x) => x.includes('rules/branches/main')));
|
|
330
|
+
} finally { done(w); }
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('E160b case 11: "Require signed commits" — a gap on the Product, a suggestion on a code repo', () => {
|
|
334
|
+
const w = workspace();
|
|
335
|
+
try {
|
|
336
|
+
const signedRule = { type: 'required_signatures' };
|
|
337
|
+
const { r } = check(w, [...gh('p', { rules: [...ALL_RULES(productJobs), signedRule] }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code) })]);
|
|
338
|
+
assert.equal(byId(r, 'Product')['signed-commits'].status, 'gap');
|
|
339
|
+
assert.match(byId(r, 'Product')['signed-commits'].message, /unsigned commits/);
|
|
340
|
+
assert.match(byId(r, 'Product')['signed-commits'].fix.steps[0], /turn off/);
|
|
341
|
+
assert.equal(byId(r, 'app')['signed-commits'].status, 'suggest');
|
|
342
|
+
assert.match(byId(r, 'app')['signed-commits'].fix.steps[0], /turn on/);
|
|
343
|
+
// A Product with a local ledger writes no bot commits: not asked.
|
|
344
|
+
const local = workspace({ product: { ledger: 'local' } });
|
|
345
|
+
try {
|
|
346
|
+
const lr = check(local, [...gh('p', { rules: [] }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code) })]).r;
|
|
347
|
+
assert.equal(byId(lr, 'Product')['signed-commits'], undefined);
|
|
348
|
+
assert.equal(byId(lr, 'Product')['required-checks'], undefined, 'no yad CI on the Product: no checks to require');
|
|
349
|
+
} finally { done(local); }
|
|
350
|
+
} finally { done(w); }
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test('E160b case 12: `ci check` is a read the agent runs without asking; solo mode reads approvals the other way', () => {
|
|
354
|
+
assert.equal(classify(['ci', 'check']), 'read');
|
|
355
|
+
assert.equal(classify(['ci']), 'read', 'its default action');
|
|
356
|
+
assert.ok(readAllowList().includes('Bash(yad ci check:*)'));
|
|
357
|
+
const w = workspace({ product: { solo: true } });
|
|
358
|
+
try {
|
|
359
|
+
// Classic protection read (as an admin) and holding no review rule: zero approvals is then proven.
|
|
360
|
+
const one = (n) => [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE(n), CHECKS_RULE(REQUIRED_CHECKS.github.code), { type: 'non_fast_forward' }, { type: 'deletion' }], classic: [200, {}] })];
|
|
361
|
+
const blocks = byId(check(w, one(1)).r, 'app');
|
|
362
|
+
assert.equal(blocks.protected.status, 'gap');
|
|
363
|
+
assert.match(blocks.protected.message, /solo mode/);
|
|
364
|
+
assert.equal(blocks['stale-approvals'], undefined, 'solo: no approvals to dismiss');
|
|
365
|
+
assert.equal(byId(check(w, one(0)).r, 'app').protected.status, 'ok');
|
|
366
|
+
// Classic protection not readable: zero approvals cannot be proven, so it is not known.
|
|
367
|
+
const hidden = [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE(0)], classic: [404, { message: 'Not Found' }] })];
|
|
368
|
+
assert.equal(byId(check(w, hidden).r, 'app').protected.status, 'unknown');
|
|
369
|
+
} finally { done(w); }
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('E160b round 1: a protection GitHub\'s answers disagree about is not known; the bot\'s steps on a verified Product', () => {
|
|
373
|
+
const w = workspace();
|
|
374
|
+
try {
|
|
375
|
+
// The branch flag says "not protected" while GitHub lists an active rule on it.
|
|
376
|
+
const odd = byId(check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [{ type: 'deletion' }], prot: false })]).r, 'app');
|
|
377
|
+
assert.equal(odd.protected.status, 'unknown');
|
|
378
|
+
// The Product's checks: the steps say to put the gate token's owner on the bypass list.
|
|
379
|
+
const product = byId(check(w, [...gh('p', { rules: [PR_RULE(), { type: 'non_fast_forward' }, { type: 'deletion' }] }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code) })]).r, 'Product');
|
|
380
|
+
assert.equal(product['required-checks'].status, 'gap');
|
|
381
|
+
assert.match(product['required-checks'].fix.steps.join(' '), /bypass list/);
|
|
382
|
+
// Turning "Require signed commits" off names the classic protection page too.
|
|
383
|
+
const signed = byId(check(w, [...gh('p', { rules: [...ALL_RULES(productJobs), { type: 'required_signatures' }] }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code) })]).r, 'Product');
|
|
384
|
+
assert.match(signed['signed-commits'].fix.steps[0], /settings\/branches/);
|
|
385
|
+
// Classic protection that lets admins bypass: the ok says so.
|
|
386
|
+
const admins = byId(check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE()], classic: [200, { required_status_checks: { contexts: REQUIRED_CHECKS.github.code }, allow_force_pushes: { enabled: false }, allow_deletions: { enabled: false }, enforce_admins: { enabled: false } }] })]).r, 'app');
|
|
387
|
+
assert.equal(admins['required-checks'].status, 'ok');
|
|
388
|
+
assert.match(admins['required-checks'].message, /admins bypass/);
|
|
389
|
+
} finally { done(w); }
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('E160b round 1: GitLab — yad\'s jobs must be in the root pipeline; direct push; the gate token on a verified Product', () => {
|
|
393
|
+
const w = workspace({ platform: 'gitlab', include: false });
|
|
394
|
+
try {
|
|
395
|
+
const calls = [...gl('p'), ...gl('app')];
|
|
396
|
+
const files = byId(check(w, calls).r, 'app').files;
|
|
397
|
+
assert.equal(files.status, 'gap', 'no root .gitlab-ci.yml: no yad job runs');
|
|
398
|
+
assert.match(files.message, /there is no \.gitlab-ci\.yml/);
|
|
399
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n # - local: '.gitlab/ci/yad-checks.yml'\n - local: '.gitlab/ci/yad-update-guard.yml'\n");
|
|
400
|
+
const partial = byId(check(w, calls).r, 'app').files;
|
|
401
|
+
assert.equal(partial.status, 'gap', 'a commented-out include does not count');
|
|
402
|
+
assert.match(partial.message, /does not include \.gitlab\/ci\/yad-checks\.yml/);
|
|
403
|
+
assert.match(partial.fix.steps[0], /under its top-level `include:`/);
|
|
404
|
+
assert.ok(partial.fix.steps.some((x) => x.startsWith("- local: '.gitlab/ci/yad-checks.yml'")));
|
|
405
|
+
// Maintainers may push straight to main: a gap on a code repo (a suggestion in solo mode).
|
|
406
|
+
const push = byId(check(w, [...gl('p'), ...gl('app', { protectedBranches: [{ ...NO_ONE, push_access_levels: [{ access_level: 40 }] }] })]).r, 'app')['direct-push'];
|
|
407
|
+
assert.equal(push.status, 'gap');
|
|
408
|
+
assert.match(push.fix.steps[0], /No one/);
|
|
409
|
+
// A verified Product: its gate token must push, so direct push is not asked, and the protect step says so.
|
|
410
|
+
const product = byId(check(w, [...gl('p', { prot: false, protectedBranches: [] }), ...gl('app')]).r, 'Product');
|
|
411
|
+
assert.equal(product['direct-push'], undefined);
|
|
412
|
+
assert.match(product.protected.fix.steps[0], /gate token \(SDLC_GATE_TOKEN\)/);
|
|
413
|
+
} finally { done(w); }
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('E160b round 1: a refused registry entry says why; a gap exits 1 under --json', () => {
|
|
417
|
+
const w = workspace({ repos: [{ name: 'far', path: '../../far', platform: 'github', git_url: 'git@github.com:acme/far.git' }], clone: false });
|
|
418
|
+
try {
|
|
419
|
+
const far = byId(check(w, []).r, 'far').files;
|
|
420
|
+
assert.equal(far.status, 'unknown');
|
|
421
|
+
assert.match(far.message, /outside the workspace/);
|
|
422
|
+
assert.equal(far.fix, undefined, 'no clone command for an entry yad refuses');
|
|
423
|
+
const r = spawnSync(process.execPath, [path.join(ROOT, 'bin/yad.mjs'), 'ci', 'check', '--json'], { cwd: w.root, env: { ...process.env, NO_COLOR: '1', YAD_PLATFORM_READ: '0' }, encoding: 'utf8' });
|
|
424
|
+
fs.rmSync(path.join(w.root, '.github'), { recursive: true, force: true });
|
|
425
|
+
const gap = spawnSync(process.execPath, [path.join(ROOT, 'bin/yad.mjs'), 'ci', 'check', '--json'], { cwd: w.root, env: { ...process.env, NO_COLOR: '1', YAD_PLATFORM_READ: '0' }, encoding: 'utf8' });
|
|
426
|
+
assert.equal(r.status, 0, 'unknown rows alone do not fail the run');
|
|
427
|
+
assert.equal(gap.status, 1, 'a missing file is a gap');
|
|
428
|
+
assert.equal(JSON.parse(gap.stdout).ok, false);
|
|
429
|
+
} finally { done(w); }
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('E160b round 2: GitLab — an entry with no platform, a custom CI file, a full page of rules, rules that disagree', () => {
|
|
433
|
+
const w = workspace({ platform: 'gitlab' });
|
|
434
|
+
try {
|
|
435
|
+
// The entry names no platform; GitLab is told from the URL. yad wired no GitLab files: a gap, never ok.
|
|
436
|
+
const reg = path.join(w.root, '.sdlc/repos.json');
|
|
437
|
+
const entry = JSON.parse(fs.readFileSync(reg, 'utf8')).repos[0];
|
|
438
|
+
put(reg, { repos: [{ ...entry, platform: null }] });
|
|
439
|
+
const unnamed = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
440
|
+
assert.equal(unnamed.status, 'gap');
|
|
441
|
+
assert.match(unnamed.fix.steps[0], /"platform": "gitlab"/);
|
|
442
|
+
put(reg, { repos: [entry] });
|
|
443
|
+
// The project runs another CI file: the root one is not what GitLab reads.
|
|
444
|
+
const custom = byId(check(w, [...gl('p'), ...gl('app', { project: { ci_config_path: 'ci/main.yml' } })]).r, 'app').files;
|
|
445
|
+
assert.equal(custom.status, 'gap');
|
|
446
|
+
assert.match(custom.message, /no ci\/main\.yml/);
|
|
447
|
+
put(path.join(w.root, '../app/ci/main.yml'), fs.readFileSync(path.join(w.root, '../app/.gitlab-ci.yml'), 'utf8'));
|
|
448
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app', { project: { ci_config_path: 'ci/main.yml' } })]).r, 'app').files.status, 'ok');
|
|
449
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app', { project: { ci_config_path: 'ci.yml@acme/shared' } })]).r, 'app').files.status, 'unknown', 'a CI file in another project');
|
|
450
|
+
// A fragment named only in a trailing comment does not count; the steps give one YAML line per file.
|
|
451
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n - local: '.gitlab/ci/yad-update-guard.yml'\nstages: [test] # .gitlab/ci/yad-checks.yml\n");
|
|
452
|
+
const trailing = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
453
|
+
assert.equal(trailing.status, 'gap');
|
|
454
|
+
assert.ok(trailing.fix.steps.some((x) => x.startsWith("- local: '.gitlab/ci/yad-checks.yml'")));
|
|
455
|
+
// 100 protected branches: page one says "No one" and no force push, but page two could say otherwise.
|
|
456
|
+
const many = [NO_ONE, ...Array.from({ length: 99 }, (_, i) => ({ name: `rel-${i}`, allow_force_push: false, push_access_levels: [{ access_level: 0 }] }))];
|
|
457
|
+
const full = byId(check(w, [...gl('p'), ...gl('app', { protectedBranches: many })]).r, 'app');
|
|
458
|
+
assert.equal(full['force-push'].status, 'unknown');
|
|
459
|
+
assert.equal(full['direct-push'].status, 'unknown');
|
|
460
|
+
// Two rules match main and disagree about force push: which one applies is not read.
|
|
461
|
+
const mixed = byId(check(w, [...gl('p'), ...gl('app', { protectedBranches: [NO_ONE, { ...NO_ONE, name: 'ma*', allow_force_push: true }] })]).r, 'app');
|
|
462
|
+
assert.equal(mixed['force-push'].status, 'unknown');
|
|
463
|
+
} finally { done(w); }
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test('E160b round 2: each platform path is asked once per repo', () => {
|
|
467
|
+
const w = workspace();
|
|
468
|
+
try {
|
|
469
|
+
const { asked } = check(w, allSet());
|
|
470
|
+
const api = asked.filter((x) => x.startsWith('gh api'));
|
|
471
|
+
assert.equal(new Set(api).size, api.length, api.join('\n'));
|
|
472
|
+
} finally { done(w); }
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test('E160b round 3: an unread CI file setting, a path named outside an include, a verified Product with no platform, admins on classic protection', () => {
|
|
476
|
+
const w = workspace({ platform: 'gitlab' });
|
|
477
|
+
try {
|
|
478
|
+
// The project's settings were not read, or the answer left the CI file setting out: not "the default".
|
|
479
|
+
const at = /^projects\/acme%2Fapp$/;
|
|
480
|
+
const noKey = gl('app').map((c) => (c[0].source === at.source ? [c[0], 200, { default_branch: 'main', namespace: { kind: 'user' }, only_allow_merge_if_pipeline_succeeds: true }] : c));
|
|
481
|
+
const unread = byId(check(w, [...gl('p'), ...noKey]).r, 'app').files;
|
|
482
|
+
assert.equal(unread.status, 'unknown');
|
|
483
|
+
assert.match(unread.message, /settings were not read/);
|
|
484
|
+
// The path appears in a script line, not in an include: GitLab runs none of those jobs.
|
|
485
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n - local: '.gitlab/ci/yad-update-guard.yml'\ncheck:\n script: cat .gitlab/ci/yad-checks.yml\n");
|
|
486
|
+
const scripted = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
487
|
+
assert.equal(scripted.status, 'gap');
|
|
488
|
+
// Every include form yad reads: a list item, a local: value, a bare quoted path.
|
|
489
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n - local: \"/.gitlab/ci/yad-update-guard.yml\"\n - '.gitlab/ci/yad-checks.yml'\n");
|
|
490
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files.status, 'ok');
|
|
491
|
+
} finally { done(w); }
|
|
492
|
+
// A Product asked to keep a verified ledger, with no platform set: yad wired none of its CI.
|
|
493
|
+
const p = workspace({ product: { platform: null }, repos: [] });
|
|
494
|
+
try {
|
|
495
|
+
const files = byId(check(p, gh('p', { rules: [] })).r, 'Product').files;
|
|
496
|
+
assert.equal(files.status, 'gap');
|
|
497
|
+
assert.match(files.fix.steps[0], /"platform": "github"/);
|
|
498
|
+
} finally { done(p); }
|
|
499
|
+
// Classic protection that lets admins bypass: the force-push and deletion oks say so.
|
|
500
|
+
const g = workspace();
|
|
501
|
+
try {
|
|
502
|
+
const classic = { required_status_checks: { contexts: REQUIRED_CHECKS.github.code }, allow_force_pushes: { enabled: false }, allow_deletions: { enabled: false }, enforce_admins: { enabled: false } };
|
|
503
|
+
const row = byId(check(g, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: [PR_RULE()], classic: [200, classic] })]).r, 'app');
|
|
504
|
+
for (const id of ['force-push', 'deletion']) assert.match(row[id].message, /admins bypass/, id);
|
|
505
|
+
} finally { done(g); }
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test('E160b round 4: only the top-level include counts — not a child pipeline, rules: changes, another project, a text block', () => {
|
|
509
|
+
const w = workspace({ platform: 'gitlab' });
|
|
510
|
+
const file = (text) => { put(path.join(w.root, '../app/.gitlab-ci.yml'), text); return byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files; };
|
|
511
|
+
const guard = "include:\n - local: '.gitlab/ci/yad-update-guard.yml'\n";
|
|
512
|
+
try {
|
|
513
|
+
for (const [why, text] of [
|
|
514
|
+
['a child pipeline', `${guard}yad-child:\n trigger:\n include:\n - local: .gitlab/ci/yad-checks.yml\n`],
|
|
515
|
+
['rules: changes', `${guard}job:\n rules:\n - changes:\n - .gitlab/ci/yad-checks.yml\n`],
|
|
516
|
+
['another project\'s file', `${guard} - project: other/x\n file:\n - .gitlab/ci/yad-checks.yml\n`],
|
|
517
|
+
['another project, with a local: key too', `${guard} - project: other/x\n local: .gitlab/ci/yad-checks.yml\n`],
|
|
518
|
+
['-local: with no space (a key named -local)', `${guard} -local: .gitlab/ci/yad-checks.yml\n`],
|
|
519
|
+
['a text block', `${guard}job:\n script:\n - |\n .gitlab/ci/yad-checks.yml\n`],
|
|
520
|
+
]) assert.equal(file(text).status, 'gap', why);
|
|
521
|
+
// Included only under its own rules: whether it runs is not known.
|
|
522
|
+
const gated = file(`${guard} - local: .gitlab/ci/yad-checks.yml\n rules:\n - if: $CI_PIPELINE_SOURCE == "push"\n`);
|
|
523
|
+
assert.equal(gated.status, 'unknown');
|
|
524
|
+
assert.match(gated.message, /only under its own `rules:`/);
|
|
525
|
+
// A list at the key's own column.
|
|
526
|
+
assert.equal(file("include:\n- local: .gitlab/ci/yad-update-guard.yml\n- .gitlab/ci/yad-checks.yml\nstages: [test]\n").status, 'ok');
|
|
527
|
+
// Two top-level include keys: GitLab keeps only the last, so it is not known.
|
|
528
|
+
const twice = file("include:\n - local: .gitlab/ci/yad-checks.yml\n - local: .gitlab/ci/yad-update-guard.yml\nstages: [a]\ninclude:\n - local: other.yml\n");
|
|
529
|
+
assert.equal(twice.status, 'unknown');
|
|
530
|
+
assert.match(twice.message, /two top-level `include:` keys/);
|
|
531
|
+
} finally { done(w); }
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test('E160b round 5: the map form of include; the admin note only when classic protection is the block; a verified Product with no platform at all', () => {
|
|
535
|
+
const w = workspace({ platform: 'gitlab', repos: [{ name: 'app', path: '../app', platform: 'gitlab', git_url: 'git@gitlab.com:acme/app.git', default_branch: 'main' }] });
|
|
536
|
+
try {
|
|
537
|
+
// yad's code repo has two fragments; the map form takes one `local:`, so name the other in a list item first.
|
|
538
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n local: .gitlab/ci/yad-checks.yml\n");
|
|
539
|
+
const map = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
540
|
+
assert.equal(map.status, 'gap', 'the map form names one file: the other is missing');
|
|
541
|
+
assert.match(map.message, /yad-update-guard/);
|
|
542
|
+
assert.doesNotMatch(map.message, /yad-checks\.yml/, 'the map form\'s file counts');
|
|
543
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n local: .gitlab/ci/yad-checks.yml\n rules:\n - if: $X\n");
|
|
544
|
+
assert.match(byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files.message, /yad-update-guard/, 'still missing the other one');
|
|
545
|
+
} finally { done(w); }
|
|
546
|
+
const g = workspace();
|
|
547
|
+
try {
|
|
548
|
+
// A ruleset blocks force pushes and deletion; classic protection lets admins bypass. The ruleset holds them.
|
|
549
|
+
const classic = { required_status_checks: { contexts: REQUIRED_CHECKS.github.code }, allow_force_pushes: { enabled: false }, allow_deletions: { enabled: false }, enforce_admins: { enabled: false } };
|
|
550
|
+
const row = byId(check(g, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: ALL_RULES(REQUIRED_CHECKS.github.code), classic: [200, classic] })]).r, 'app');
|
|
551
|
+
for (const id of ['force-push', 'deletion']) {
|
|
552
|
+
assert.equal(row[id].status, 'ok', id);
|
|
553
|
+
assert.doesNotMatch(row[id].message, /admins bypass/, id);
|
|
554
|
+
}
|
|
555
|
+
} finally { done(g); }
|
|
556
|
+
// Verified asked for, no platform set and none in the git URL: files ok (kept locally), platform unknown.
|
|
557
|
+
const none = workspace({ product: { platform: null, git_url: null }, repos: [] });
|
|
558
|
+
try {
|
|
559
|
+
const r = byId(check(none, []).r, 'Product');
|
|
560
|
+
assert.equal(r.files.status, 'ok');
|
|
561
|
+
assert.match(r.files.message, /set to verified, but with no platform set it is kept locally/);
|
|
562
|
+
assert.equal(r.platform.status, 'unknown');
|
|
563
|
+
} finally { done(none); }
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
test('E160b round 5: a list item with its own rules is gated', () => {
|
|
567
|
+
const w = workspace({ platform: 'gitlab' });
|
|
568
|
+
try {
|
|
569
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n - local: .gitlab/ci/yad-update-guard.yml\n - local: .gitlab/ci/yad-checks.yml\n rules:\n - if: $X\n");
|
|
570
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files.status, 'unknown');
|
|
571
|
+
} finally { done(w); }
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
test('E160b round 6: the fix lines are pure YAML; the map form is named; a repo with no platform anywhere', () => {
|
|
575
|
+
const w = workspace({ platform: 'gitlab' });
|
|
576
|
+
try {
|
|
577
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n local: .gitlab/ci/yad-checks.yml\n");
|
|
578
|
+
const map = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
579
|
+
assert.match(map.fix.steps[0], /exactly as written \(quotes and braces too\)/);
|
|
580
|
+
assert.match(map.fix.steps[0], /every other line of it moves two more spaces in/);
|
|
581
|
+
assert.doesNotMatch(map.fix.steps[0], /- local: '<|'<that value>'/, 'never new quotes, never a new kind');
|
|
582
|
+
for (const line of map.fix.steps.filter((x) => x.startsWith('- local:'))) assert.match(line, /^- local: '[^']+'$/, line);
|
|
583
|
+
fs.rmSync(path.join(w.root, '../app/.gitlab-ci.yml'));
|
|
584
|
+
const none = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
585
|
+
assert.match(none.fix.steps[0], /^Create \.gitlab-ci\.yml/);
|
|
586
|
+
assert.doesNotMatch(none.fix.steps.join(' '), /already there/);
|
|
587
|
+
} finally { done(w); }
|
|
588
|
+
const x = workspace({ repos: [{ name: 'app', path: '../app', git_url: 'git@git.example.org:acme/app.git', default_branch: 'main' }] });
|
|
589
|
+
try {
|
|
590
|
+
const row = byId(check(x, gh('p', { rules: ALL_RULES(productJobs) })).r, 'app');
|
|
591
|
+
assert.equal(row.files.status, 'unknown', 'gate scripts with no workflow are not an ok');
|
|
592
|
+
assert.equal(row.platform.status, 'unknown');
|
|
593
|
+
} finally { done(x); }
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
test('E160b round 9: an include written in [ ] or { } (flow style) is not read — unknown, with no rewrite step', () => {
|
|
597
|
+
const w = workspace({ platform: 'gitlab' });
|
|
598
|
+
try {
|
|
599
|
+
for (const text of ["include: ['.gitlab/ci/yad-update-guard.yml', other.yml]\n", 'include: {local: other.yml}\n',
|
|
600
|
+
'include:\n [a.yml, b.yml]\n', 'include:\n {local: a.yml}\n', 'include:\n- [a.yml]\n', 'include:\n -\n {local: a.yml}\n', 'include:\n-\n [a.yml]\n', "include:\n - local: '.gitlab/ci/yad-update-guard.yml'\n - {local: a.yml}\n"]) {
|
|
601
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), text);
|
|
602
|
+
const row = byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files;
|
|
603
|
+
assert.equal(row.status, 'unknown', text);
|
|
604
|
+
assert.match(row.message, /flow style/, text);
|
|
605
|
+
assert.doesNotMatch(row.fix.steps.join(' '), /- local:/, 'no rewrite to get wrong');
|
|
606
|
+
}
|
|
607
|
+
} finally { done(w); }
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
test('E160b round 11: a list item whose dash stands alone is read from its next line', () => {
|
|
611
|
+
const w = workspace({ platform: 'gitlab' });
|
|
612
|
+
try {
|
|
613
|
+
put(path.join(w.root, '../app/.gitlab-ci.yml'), "include:\n -\n local: .gitlab/ci/yad-update-guard.yml\n -\n '.gitlab/ci/yad-checks.yml'\n");
|
|
614
|
+
assert.equal(byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files.status, 'ok');
|
|
615
|
+
} finally { done(w); }
|
|
616
|
+
});
|