yadflow 4.8.0 → 4.10.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 +114 -0
- package/README.md +4 -3
- package/bin/commands.mjs +7 -0
- package/bin/yad.mjs +123 -8
- package/cli/agent-guard.mjs +793 -65
- package/cli/agent-rules.mjs +40 -5
- package/cli/argv-flags.mjs +1 -1
- package/cli/build.mjs +1 -1
- package/cli/ci-check.mjs +45 -1
- package/cli/codeowners-command.mjs +72 -6
- package/cli/commit.mjs +17 -3
- package/cli/docs.mjs +2 -0
- package/cli/doctor.mjs +176 -12
- package/cli/epic-state.mjs +94 -4
- package/cli/epic.mjs +11 -7
- package/cli/fold.mjs +31 -6
- package/cli/guide.mjs +3 -1
- package/cli/hook.mjs +50 -7
- package/cli/issue-links.mjs +61 -0
- package/cli/issues-act.mjs +327 -0
- package/cli/issues-write.mjs +428 -0
- package/cli/issues.mjs +474 -0
- package/cli/lifecycle.mjs +7 -0
- package/cli/machine.mjs +141 -0
- package/cli/manifest.mjs +9 -3
- package/cli/openpr.mjs +69 -9
- package/cli/plan.mjs +2 -0
- package/cli/platform.mjs +157 -2
- package/cli/preview.mjs +253 -0
- package/cli/protection.mjs +21 -3
- package/cli/reconcile.mjs +1 -1
- package/cli/repo.mjs +64 -3
- package/cli/review.mjs +4 -0
- package/cli/run-checks.mjs +10 -2
- package/cli/scan.mjs +314 -0
- package/cli/setup.mjs +12 -3
- package/cli/standup.mjs +33 -7
- package/cli/story-frames.mjs +307 -0
- package/cli/test-agents-file.mjs +378 -11
- package/cli/test-build.mjs +25 -0
- package/cli/test-ci-check.mjs +469 -10
- package/cli/test-guide.mjs +7 -0
- package/cli/test-machine.mjs +140 -0
- package/cli/test-node.mjs +15 -0
- package/cli/test-preview.mjs +511 -0
- package/cli/test-run-checks.mjs +17 -0
- package/cli/test-setup-agent.mjs +14 -0
- package/cli/test-story-frames.mjs +409 -0
- package/cli/toolbox-connect.mjs +244 -0
- package/cli/toolbox.mjs +159 -5
- package/package.json +7 -3
- package/skills/sdlc/config.yaml +1 -1
- package/skills/sdlc/module-help.csv +3 -1
- package/skills/yad-analysis/SKILL.md +4 -0
- package/skills/yad-backfill/SKILL.md +4 -0
- package/skills/yad-change/SKILL.md +4 -0
- package/skills/yad-checks/SKILL.md +13 -7
- package/skills/yad-checks/references/check-gates.md +62 -30
- package/skills/yad-checks/templates/checks/member-check.mjs +3 -2
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/verified-commits.sh +3 -3
- package/skills/yad-checks/templates/github/yad-checks.yml +357 -69
- package/skills/yad-checks/templates/github/yad-pr-text.yml +118 -0
- package/skills/yad-checks/templates/github/yad-product-checks.yml +130 -54
- package/skills/yad-checks/templates/github/yad-product-pr-text.yml +131 -0
- package/skills/yad-checks/templates/github/yad-update-guard.yml +2 -1
- package/skills/yad-checks/templates/github/yad-verified-commits.yml +49 -3
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +79 -20
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +59 -9
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -0
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +49 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +44 -10
- package/skills/yad-checks/templates/hooks/ledger-guard-cursor.mjs +12 -6
- package/skills/yad-commit/SKILL.md +3 -1
- package/skills/yad-connect-design/SKILL.md +48 -13
- package/skills/yad-connect-design/references/design-context.md +56 -3
- package/skills/yad-connect-design/references/design-registry.md +4 -4
- package/skills/yad-connect-learning/SKILL.md +12 -2
- package/skills/yad-connect-repos/SKILL.md +12 -0
- package/skills/yad-connect-testing/SKILL.md +22 -5
- package/skills/yad-connect-testing/references/testing-context.md +1 -1
- package/skills/yad-engineer-review/SKILL.md +13 -0
- package/skills/yad-epic/SKILL.md +4 -0
- package/skills/yad-epic/references/state-schema.md +21 -0
- package/skills/yad-guide/SKILL.md +8 -4
- package/skills/yad-implement/SKILL.md +69 -3
- package/skills/yad-implement/references/implement-conventions.md +2 -1
- package/skills/yad-issues/SKILL.md +53 -0
- package/skills/yad-learn/SKILL.md +4 -0
- package/skills/yad-open-pr/SKILL.md +10 -1
- package/skills/yad-pair-review/SKILL.md +5 -0
- package/skills/yad-pr-template/SKILL.md +2 -1
- package/skills/yad-pr-template/templates/checks/pr-title.sh +34 -2
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -0
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -0
- package/skills/yad-product-bridge/references/bridge.md +28 -0
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +25 -11
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +38 -14
- package/skills/yad-review-companion/SKILL.md +4 -1
- package/skills/yad-run/SKILL.md +5 -0
- package/skills/yad-scan/SKILL.md +51 -0
- package/skills/yad-spec/SKILL.md +32 -0
- package/skills/yad-stories/SKILL.md +22 -0
- package/skills/yad-stories/references/story-schema.md +1 -0
- package/skills/yad-test-cases/SKILL.md +18 -2
- package/skills/yad-ui/SKILL.md +48 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +0 -49
package/cli/test-ci-check.mjs
CHANGED
|
@@ -82,17 +82,19 @@ function fakePlatform({ installed = true, authed = true, calls = [] } = {}) {
|
|
|
82
82
|
|
|
83
83
|
// GitHub, for one repo: the repo, its branch, the rules on the branch, and classic protection.
|
|
84
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 })) } });
|
|
85
|
+
const CHECKS_RULE = (contexts, strict = true) => ({ type: 'required_status_checks', parameters: { strict_required_status_checks_policy: strict, required_status_checks: contexts.map((context) => ({ context })) } });
|
|
86
86
|
const ALL_RULES = (jobs) => [PR_RULE(), CHECKS_RULE(jobs), { type: 'non_fast_forward' }, { type: 'deletion' }];
|
|
87
87
|
const NOT_PROTECTED = [404, { message: 'Branch not protected' }];
|
|
88
88
|
// `rules` is the list of rules; `rulesFail` a refused answer instead, as [status, body].
|
|
89
|
-
|
|
89
|
+
// `queue` is GraphQL's answer for the branch's merge queue (null: none), asked with the repo's name last.
|
|
90
|
+
function gh(repo, { rules, rulesFail = null, classic = NOT_PROTECTED, prot = true, queue = [200, { data: { repository: { mergeQueue: null } } }] } = {}) {
|
|
90
91
|
const at = `repos/acme/${repo}`;
|
|
91
92
|
return [
|
|
92
93
|
[new RegExp(`^${at}$`), 200, { default_branch: 'main' }],
|
|
93
94
|
[new RegExp(`^${at}/branches/main$`), 200, { protected: prot }],
|
|
94
95
|
[new RegExp(`^${at}/rules/branches/main`), ...(rulesFail ?? [200, rules])],
|
|
95
96
|
[new RegExp(`^${at}/branches/main/protection$`), ...classic],
|
|
97
|
+
[new RegExp(`^name=${repo}$`), ...queue],
|
|
96
98
|
];
|
|
97
99
|
}
|
|
98
100
|
const productJobs = [...REQUIRED_CHECKS.github.product, ...REQUIRED_CHECKS.github.productVerified];
|
|
@@ -110,7 +112,7 @@ test('E160b case 1: everything set on GitHub — every row ok, complete, no gap'
|
|
|
110
112
|
for (const repo of r.repos) for (const f of repo.findings) assert.equal(f.status, 'ok', `${repo.name} ${f.id}: ${f.message}`);
|
|
111
113
|
assert.deepEqual(r.repos.map((x) => x.name), ['Product', 'app']);
|
|
112
114
|
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']);
|
|
115
|
+
assert.deepEqual(Object.keys(byId(r, 'app')).sort(), ['deletion', 'files', 'force-push', 'merge-queue', 'protected', 'required-checks', 'signed-commits', 'stale-approvals', 'up-to-date']);
|
|
114
116
|
} finally { done(w); }
|
|
115
117
|
});
|
|
116
118
|
|
|
@@ -174,10 +176,10 @@ test('E160b case 4: force push or deletion allowed is a gap; a full page of rule
|
|
|
174
176
|
// GitLab, for one project: the project and its settings, the branch, protected branches, approvals, push rule.
|
|
175
177
|
// The project is in a person's own namespace unless `project.namespace` says a group's.
|
|
176
178
|
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' }] } = {}) {
|
|
179
|
+
function gl(repo, { project = {}, prot = true, protectedBranches = [NO_ONE], branchesFail = null, approvals = [200, { reset_approvals_on_push: true, merge_requests_author_approval: false, merge_requests_disable_committers_approval: true }], pushRule = [404, { message: '404 Not found' }] } = {}) {
|
|
178
180
|
const at = `projects/acme%2F${repo}`;
|
|
179
181
|
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 }],
|
|
182
|
+
[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, merge_trains_enabled: false, merge_pipelines_enabled: false, ...project }],
|
|
181
183
|
[new RegExp(`^${at}/repository/branches/main$`), 200, { protected: prot }],
|
|
182
184
|
[new RegExp(`^${at}/protected_branches`), ...(branchesFail ?? [200, protectedBranches])],
|
|
183
185
|
[new RegExp(`^${at}/approval_rules`), 200, [{ name: 'All', rule_type: 'any_approver', approvals_required: 1, protected_branches: [] }]],
|
|
@@ -237,6 +239,14 @@ test('E160b case 6: no login, no CLI, reads off, or no platform — the platform
|
|
|
237
239
|
// Read nothing: every row the repo would have is unknown, the suggestions too.
|
|
238
240
|
const off = byId(check(w, allSet(), { env: { ...ON, YAD_PLATFORM_READ: '0' } }).r, 'Product');
|
|
239
241
|
for (const id of ['protected', 'required-checks', 'force-push', 'deletion', 'stale-approvals', 'signed-commits']) assert.equal(off[id].status, 'unknown', id);
|
|
242
|
+
for (const id of ['merge-queue', 'up-to-date']) assert.equal(off[id]?.status, 'unknown', `#433: ${id} is listed, unknown`);
|
|
243
|
+
// GitLab: its merge rows too.
|
|
244
|
+
const glw = workspace({ platform: 'gitlab' });
|
|
245
|
+
try {
|
|
246
|
+
const gloff = byId(check(glw, [], { env: { ...ON, YAD_PLATFORM_READ: '0' } }).r, 'app');
|
|
247
|
+
for (const id of ['merge-trains', 'author-approval', 'committer-approval']) assert.equal(gloff[id]?.status, 'unknown', `#433: ${id} is listed, unknown`);
|
|
248
|
+
assert.equal(gloff['merge-queue'], undefined, 'no GitHub row on GitLab');
|
|
249
|
+
} finally { done(glw); }
|
|
240
250
|
// No platform at all: nothing holds a merge there — one `platform` row, unknown, never a quiet ok.
|
|
241
251
|
const none = workspace({ product: { platform: null, git_url: null }, repos: [] });
|
|
242
252
|
try {
|
|
@@ -301,14 +311,17 @@ test('E160b case 9: REQUIRED_CHECKS equals the jobs in yad\'s workflow templates
|
|
|
301
311
|
const jobs = (file, re) => [...fs.readFileSync(path.join(ROOT, file), 'utf8').matchAll(re)].map((m) => m[1]);
|
|
302
312
|
const ghJob = /^ {2}([a-z][a-z0-9-]*):$/gm;
|
|
303
313
|
const glJob = /^(yad-[a-z0-9-]+):$/gm;
|
|
304
|
-
|
|
305
|
-
|
|
314
|
+
// pr-title and pr-template run from their own file on GitHub (#425), so a list is the jobs of both files.
|
|
315
|
+
const sorted = (a) => [...a].sort();
|
|
316
|
+
const gh = (...files) => sorted(files.flatMap((f) => jobs(`skills/yad-checks/templates/github/${f}`, ghJob)));
|
|
317
|
+
assert.deepEqual(gh('yad-checks.yml', 'yad-pr-text.yml'), sorted(REQUIRED_CHECKS.github.code));
|
|
318
|
+
assert.deepEqual(gh('yad-product-checks.yml', 'yad-product-pr-text.yml'), sorted(REQUIRED_CHECKS.github.product));
|
|
306
319
|
assert.deepEqual(jobs('skills/yad-checks/templates/github/yad-verified-commits.yml', ghJob), REQUIRED_CHECKS.github.productVerified);
|
|
307
320
|
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.code);
|
|
308
321
|
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.product);
|
|
309
322
|
assert.deepEqual(jobs('skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml', glJob), REQUIRED_CHECKS.gitlab.productVerified);
|
|
310
323
|
// 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);
|
|
324
|
+
for (const f of ['yad-checks.yml', 'yad-pr-text.yml', 'yad-product-checks.yml', 'yad-product-pr-text.yml', 'yad-verified-commits.yml']) assert.doesNotMatch(fs.readFileSync(path.join(ROOT, 'skills/yad-checks/templates/github', f), 'utf8'), /^ {4}name:/m, f);
|
|
312
325
|
const doc = fs.readFileSync(path.join(ROOT, 'docs/branch-protection.md'), 'utf8');
|
|
313
326
|
const row = (label) => [...doc.split('\n').find((l) => l.startsWith(`| ${label} |`)).split('|')[3].matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
314
327
|
assert.deepEqual(row('Product'), REQUIRED_CHECKS.github.product);
|
|
@@ -318,14 +331,17 @@ test('E160b case 9: REQUIRED_CHECKS equals the jobs in yad\'s workflow templates
|
|
|
318
331
|
for (const j of [...REQUIRED_CHECKS.gitlab.product, ...REQUIRED_CHECKS.gitlab.productVerified, ...REQUIRED_CHECKS.gitlab.code]) assert.ok(glText.includes(`\`${j}\``), j);
|
|
319
332
|
});
|
|
320
333
|
|
|
321
|
-
test('E160b case 10: never writes — the folders are unchanged, and every platform call is a GET', () => {
|
|
334
|
+
test('E160b case 10: never writes — the folders are unchanged, and every platform call is a GET or a GraphQL query', () => {
|
|
322
335
|
const w = workspace();
|
|
323
336
|
try {
|
|
324
337
|
const snap = (dir) => execFileSync('find', [dir, '-type', 'f', '-not', '-path', '*/.git/*', '-exec', 'shasum', '{}', '+'], { encoding: 'utf8' }).split('\n').sort().join('\n');
|
|
325
338
|
const before = snap(path.dirname(w.root));
|
|
326
339
|
const { asked } = check(w, allSet());
|
|
327
340
|
assert.equal(snap(path.dirname(w.root)), before);
|
|
328
|
-
|
|
341
|
+
// #433: the merge queue is read through GraphQL, which gh sends as a POST: a read-only query, never a mutation.
|
|
342
|
+
const graphql = (call) => / graphql -f query=query\(/.test(call) && !/mutation/.test(call) && !/(-X|--method|--input)/.test(call);
|
|
343
|
+
assert.ok(asked.some(graphql), 'the merge queue is asked');
|
|
344
|
+
for (const call of asked) if (!graphql(call)) assert.doesNotMatch(call, /(-X|--method)\s+(?!GET)|--field|-f |--input/, call);
|
|
329
345
|
assert.ok(asked.some((x) => x.includes('rules/branches/main')));
|
|
330
346
|
} finally { done(w); }
|
|
331
347
|
});
|
|
@@ -614,3 +630,446 @@ test('E160b round 11: a list item whose dash stands alone is read from its next
|
|
|
614
630
|
assert.equal(byId(check(w, [...gl('p'), ...gl('app')]).r, 'app').files.status, 'ok');
|
|
615
631
|
} finally { done(w); }
|
|
616
632
|
});
|
|
633
|
+
|
|
634
|
+
// #424: with no limit, GitHub stops a stuck job after 6 hours and GitLab at the project's default (1 hour
|
|
635
|
+
// unless changed) — a team pays for that runner time. Every job in every CI file yad installs, and in the
|
|
636
|
+
// docs workflow it generates, sets its own limit.
|
|
637
|
+
test('#424: every job in every CI file yad installs has a time limit', async () => {
|
|
638
|
+
const { pagesWorkflow } = await import('../cli/docs.mjs');
|
|
639
|
+
const files = [];
|
|
640
|
+
for (const dir of ['skills/yad-checks/templates/github', 'skills/yad-product-bridge/templates/github',
|
|
641
|
+
'skills/yad-checks/templates/gitlab', 'skills/yad-product-bridge/templates/gitlab']) {
|
|
642
|
+
for (const f of fs.readdirSync(path.join(ROOT, dir))) {
|
|
643
|
+
if (!/\.ya?ml$/.test(f) || f.startsWith('gitlab-ci.include-root')) continue;
|
|
644
|
+
files.push({ name: `${dir}/${f}`, text: fs.readFileSync(path.join(ROOT, dir, f), 'utf8'), gitlab: dir.endsWith('gitlab') });
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
// This repo's own workflows too.
|
|
648
|
+
for (const f of fs.readdirSync(path.join(ROOT, '.github/workflows'))) {
|
|
649
|
+
if (!/\.ya?ml$/.test(f)) continue;
|
|
650
|
+
files.push({ name: `.github/workflows/${f}`, text: fs.readFileSync(path.join(ROOT, '.github/workflows', f), 'utf8'), gitlab: false });
|
|
651
|
+
}
|
|
652
|
+
files.push({ name: 'yad docs (GitHub)', text: pagesWorkflow('github'), gitlab: false });
|
|
653
|
+
files.push({ name: 'yad docs (GitLab)', text: pagesWorkflow('gitlab'), gitlab: true });
|
|
654
|
+
let seen = 0;
|
|
655
|
+
for (const { name, text, gitlab } of files) {
|
|
656
|
+
if (!gitlab) {
|
|
657
|
+
const body = text.slice(text.search(/^jobs:$/m));
|
|
658
|
+
const blocks = body.split(/^(?= {2}['"]?[^\s#'"][^:]*['"]?:\s*(?:#.*)?$)/m).slice(1);
|
|
659
|
+
assert.ok(blocks.length, `${name}: no jobs read`);
|
|
660
|
+
for (const b of blocks) {
|
|
661
|
+
seen++;
|
|
662
|
+
assert.match(b, /^ {4}timeout-minutes: \d+$/m, `${name}: job ${b.split(':')[0].trim()} has no timeout-minutes`);
|
|
663
|
+
}
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
// GitLab: a job is a top-level key that is not a keyword and does not start with a dot; it has a limit when
|
|
667
|
+
// `default:`, its own block, a template it `extends`, or an anchor it merges (`<<: *x`) sets `timeout:`.
|
|
668
|
+
const blocks = new Map();
|
|
669
|
+
const anchors = new Map();
|
|
670
|
+
for (const b of text.split(/^(?=['"]?[^\s#'"-][^:]*['"]?:)/m)) {
|
|
671
|
+
const m = b.match(/^['"]?([^\s#'"-][^:'"]*)['"]?:(?:\s*&([A-Za-z0-9_-]+))?/);
|
|
672
|
+
if (!m) continue;
|
|
673
|
+
blocks.set(m[1], b);
|
|
674
|
+
if (m[2]) anchors.set(m[2], m[1]);
|
|
675
|
+
}
|
|
676
|
+
const all = /^ {2}timeout: \d+ (minutes|hours?)\b/m.test(blocks.get('default') || ''); // `default:` covers every job
|
|
677
|
+
const limited = (key, depth = 0) => {
|
|
678
|
+
if (all) return true;
|
|
679
|
+
const b = blocks.get(key);
|
|
680
|
+
if (!b || depth > 5) return false;
|
|
681
|
+
if (/^ {2}timeout: \d+ (minutes|hours?)\b/m.test(b)) return true;
|
|
682
|
+
const ext = b.match(/^ {2}extends: (\S+)$/m);
|
|
683
|
+
const merge = b.match(/^ {2}<<: \*(\S+)$/m);
|
|
684
|
+
return (ext && limited(ext[1], depth + 1)) || (merge && limited(anchors.get(merge[1]), depth + 1)) || false;
|
|
685
|
+
};
|
|
686
|
+
for (const key of blocks.keys()) {
|
|
687
|
+
if (key.startsWith('.') || ['variables', 'include', 'stages', 'default', 'workflow'].includes(key)) continue;
|
|
688
|
+
seen++;
|
|
689
|
+
assert.ok(limited(key), `${name}: job ${key} has no timeout`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
assert.ok(seen >= 40, `read only ${seen} jobs — the reader missed some`);
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// #426 — a gate job runs the BASE branch's copy of checks/, never the PR's own: a PR that changes a gate script
|
|
696
|
+
// must not be judged by its own copy, nor read a token the job holds. The files that run gates on PR code:
|
|
697
|
+
const GATE_TEMPLATES = [
|
|
698
|
+
...['yad-checks.yml', 'yad-pr-text.yml', 'yad-product-checks.yml', 'yad-product-pr-text.yml', 'yad-verified-commits.yml']
|
|
699
|
+
.map((f) => ({ name: `skills/yad-checks/templates/github/${f}`, gitlab: false })),
|
|
700
|
+
{ name: '.github/workflows/yad-verified-commits.yml', gitlab: false },
|
|
701
|
+
...['yad-checks.gitlab-ci.yml', 'yad-product-checks.gitlab-ci.yml', 'yad-verified-commits.gitlab-ci.yml']
|
|
702
|
+
.map((f) => ({ name: `skills/yad-checks/templates/gitlab/${f}`, gitlab: true })),
|
|
703
|
+
].map((f) => ({ ...f, text: fs.readFileSync(path.join(ROOT, f.name), 'utf8') }));
|
|
704
|
+
const noComments = (t) => t.split('\n').filter((l) => !/^\s*#/.test(l)).join('\n');
|
|
705
|
+
// A YAML block scalar (`key: |` or `- |`) at `at`, as the runner hands it to the shell.
|
|
706
|
+
function blockAt(lines, at) {
|
|
707
|
+
const indent = lines[at + 1].match(/^ */)[0].length;
|
|
708
|
+
const out = [];
|
|
709
|
+
for (let i = at + 1; i < lines.length && (!lines[i].trim() || lines[i].startsWith(' '.repeat(indent))); i++) out.push(lines[i].slice(indent));
|
|
710
|
+
while (out.length && !out[out.length - 1].trim()) out.pop();
|
|
711
|
+
return `${out.join('\n')}\n`;
|
|
712
|
+
}
|
|
713
|
+
const BASE_STEP = '- name: Gate scripts from the base branch (#426)';
|
|
714
|
+
function githubStep(text) {
|
|
715
|
+
const lines = text.split('\n');
|
|
716
|
+
const at = lines.findIndex((l) => l.trim() === BASE_STEP);
|
|
717
|
+
assert.ok(at >= 0, 'no base-copy step');
|
|
718
|
+
const run = lines.findIndex((l, i) => i > at && /^\s+run: \|$/.test(l));
|
|
719
|
+
return blockAt(lines, run);
|
|
720
|
+
}
|
|
721
|
+
function gitlabStep(text) {
|
|
722
|
+
const lines = text.split('\n');
|
|
723
|
+
const at = lines.findIndex((l) => l === '.yad_base_checks:');
|
|
724
|
+
const dash = lines.findIndex((l, i) => i > at && /^\s+- \|$/.test(l));
|
|
725
|
+
return blockAt(lines, dash);
|
|
726
|
+
}
|
|
727
|
+
// The `( … )` the two platforms share, word for word.
|
|
728
|
+
const coreOf = (script) => script.slice(script.indexOf('(\n'), script.lastIndexOf('\n)\n') + 3);
|
|
729
|
+
|
|
730
|
+
test('#426: every gate call runs "$YAD_CHECKS/…", the base branch\'s copy, set up by one shared step; no checkout keeps credentials', () => {
|
|
731
|
+
const cores = new Set();
|
|
732
|
+
const glBlocks = new Set();
|
|
733
|
+
for (const { name, text, gitlab } of GATE_TEMPLATES) {
|
|
734
|
+
const code = noComments(text);
|
|
735
|
+
assert.doesNotMatch(code, /\b(?:bash|node|sh)\s+\.?\/?checks\//, `${name}: a gate call reads checks/ from the PR's tree`);
|
|
736
|
+
assert.match(code, /(?:bash|node) "\$YAD_CHECKS\/[\w.-]+"/, `${name}: no gate call`);
|
|
737
|
+
if (gitlab) {
|
|
738
|
+
// Defined once, and the FIRST line of the script of every job that runs a gate — not a before_script,
|
|
739
|
+
// which would replace the host pipeline's `default: before_script` for these jobs.
|
|
740
|
+
assert.equal((code.match(/^\.yad_base_checks:$/gm) || []).length, 1, name);
|
|
741
|
+
assert.doesNotMatch(code, /^\s*before_script:/m, `${name}: no before_script`);
|
|
742
|
+
const jobs = code.split(/^(?=[\w.-]+:)/m).filter((b) => /"\$YAD_CHECKS\//.test(b) && !b.startsWith('.yad_base_checks:'));
|
|
743
|
+
assert.ok(jobs.length, name);
|
|
744
|
+
for (const j of jobs) assert.match(j, /\n {2}script:\n {4}- !reference \[\.yad_base_checks, script\]\n/, `${name} ${j.split(':')[0]}: the base copy is the script's first line`);
|
|
745
|
+
const s = gitlabStep(text);
|
|
746
|
+
glBlocks.add(s);
|
|
747
|
+
assert.match(s, /^YAD_BASE="\$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"; YAD_CHECKS="\$\(mktemp -d\)\/checks"; export YAD_CHECKS\n/, name);
|
|
748
|
+
cores.add(coreOf(s));
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
// Every job: checkout without credentials, then the step, then the gate.
|
|
752
|
+
const body = text.slice(text.search(/^jobs:$/m));
|
|
753
|
+
const jobs = body.split(/^(?= {2}[\w-]+:\s*$)/m).slice(1);
|
|
754
|
+
assert.ok(jobs.length, name);
|
|
755
|
+
for (const j of jobs) {
|
|
756
|
+
const job = `${name} ${j.split(':')[0].trim()}`;
|
|
757
|
+
const co = j.indexOf('actions/checkout@');
|
|
758
|
+
const step = j.indexOf(BASE_STEP);
|
|
759
|
+
const gate = j.indexOf('"$YAD_CHECKS/');
|
|
760
|
+
assert.ok(co >= 0 && co < step && step < gate, `${job}: checkout, then the base-copy step, then the gate`);
|
|
761
|
+
assert.match(j.slice(co, step), /persist-credentials: false/, `${job}: the checkout keeps no credentials`);
|
|
762
|
+
assert.match(j.slice(co, step), /fetch-depth: 0/, `${job}: the base branch must be in the checkout`);
|
|
763
|
+
assert.equal(j.split(BASE_STEP).length, 2, `${job}: one base-copy step`);
|
|
764
|
+
const s = githubStep(j);
|
|
765
|
+
assert.match(s, /^YAD_CHECKS="\$RUNNER_TEMP\/yad-base-checks\/checks"\n/, job);
|
|
766
|
+
assert.match(s, /\necho "YAD_CHECKS=\$YAD_CHECKS" >> "\$GITHUB_ENV"\n$/, job);
|
|
767
|
+
assert.match(j, /env: \{ YAD_BASE: "\$\{\{ github\.base_ref \}\}" \}/, job);
|
|
768
|
+
cores.add(coreOf(s));
|
|
769
|
+
}
|
|
770
|
+
assert.doesNotMatch(code, /filter:\s*blob:none/, `${name}: a partial clone leaves out the base's changed checks/`);
|
|
771
|
+
}
|
|
772
|
+
assert.equal(cores.size, 1, 'the base-copy step is word for word the same everywhere');
|
|
773
|
+
// Every GitLab fragment defines the same .yad_base_checks key and the file included last wins: one text.
|
|
774
|
+
assert.equal(glBlocks.size, 1, 'the .yad_base_checks block is the same in every GitLab file');
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
// The upgrade PR: the base's (older) script runs with the new workflow's call. So a call may only use what the
|
|
778
|
+
// previous release's script already accepts. A change to this list needs that check, by hand, first.
|
|
779
|
+
test('#426: the gate calls are the ones the previous release\'s scripts accept', () => {
|
|
780
|
+
const calls = new Set();
|
|
781
|
+
for (const { text } of GATE_TEMPLATES) {
|
|
782
|
+
for (const m of noComments(text).matchAll(/(bash|node) "\$YAD_CHECKS\/([\w.-]+)"([^\n]*)/g)) {
|
|
783
|
+
calls.add(`${m[2]} ${[...m[3].matchAll(/(?:^|\s)(--[\w-]+)/g)].map((f) => f[1]).join(' ')}`.trim());
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
assert.deepEqual([...calls].sort(), [
|
|
787
|
+
'build-test-lint.sh', 'commit-message.sh --profile', 'contract-check.sh', 'epic-open.sh', 'install-deps.sh',
|
|
788
|
+
'ledger-guard.sh', 'lineage-check.sh', 'member-check.mjs', 'pr-template.sh --profile',
|
|
789
|
+
'pr-template.sh --profile --head --changed', 'pr-title.sh --profile', 'pr-title.sh --profile --head --changed',
|
|
790
|
+
'product-checkout.sh', 'reconcile-debt-check.sh', 'risk-map-check.sh', 'spec-link.sh', 'verified-commits.sh',
|
|
791
|
+
], 'a new script or flag in a gate call: the base branch\'s copy from the previous release runs it on the upgrade PR — make sure that copy accepts it');
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
// The step itself, run as the runner runs it, in a scratch repo: base `main` and a PR branch.
|
|
795
|
+
function stepRepo({ baseChecks = true } = {}) {
|
|
796
|
+
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-426-'));
|
|
797
|
+
const git = (cwd, ...a) => execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...a], { cwd, encoding: 'utf8' });
|
|
798
|
+
const O = path.join(T, 'origin');
|
|
799
|
+
fs.mkdirSync(O);
|
|
800
|
+
git(O, 'init', '-q', '-b', 'main');
|
|
801
|
+
if (baseChecks) {
|
|
802
|
+
fs.mkdirSync(path.join(O, 'checks'));
|
|
803
|
+
fs.writeFileSync(path.join(O, 'checks/a.sh'), 'echo base-a\n');
|
|
804
|
+
} else fs.writeFileSync(path.join(O, 'README'), 'x\n');
|
|
805
|
+
git(O, 'add', '-A'); git(O, 'commit', '-qm', 'base');
|
|
806
|
+
const P = path.join(T, 'pr');
|
|
807
|
+
git(T, 'clone', '-q', O, P);
|
|
808
|
+
git(P, 'switch', '-qc', 'feat');
|
|
809
|
+
fs.mkdirSync(path.join(P, 'checks'), { recursive: true });
|
|
810
|
+
fs.writeFileSync(path.join(P, 'checks/a.sh'), 'echo pr-a\n');
|
|
811
|
+
fs.writeFileSync(path.join(P, 'checks/b c.sh'), 'echo pr-b\n');
|
|
812
|
+
fs.writeFileSync(path.join(P, 'checks/x.sh'), 'echo pr-x\n', { mode: 0o755 });
|
|
813
|
+
fs.symlinkSync(path.join(T, 'secret'), path.join(P, 'checks/link.sh'));
|
|
814
|
+
fs.writeFileSync(path.join(T, 'secret'), 'echo leaked\n');
|
|
815
|
+
git(P, 'add', '-A'); git(P, 'commit', '-qm', 'pr');
|
|
816
|
+
return { T, P, done: () => fs.rmSync(T, { recursive: true, force: true }) };
|
|
817
|
+
}
|
|
818
|
+
const env = (extra) => ({ ...process.env, GIT_CONFIG_NOSYSTEM: '1', ...extra });
|
|
819
|
+
function runGithubStep(P, T, base = 'main') {
|
|
820
|
+
const step = githubStep(fs.readFileSync(path.join(ROOT, 'skills/yad-checks/templates/github/yad-checks.yml'), 'utf8'));
|
|
821
|
+
const ghenv = path.join(T, 'ghenv');
|
|
822
|
+
const r = spawnSync('bash', ['-e', '-c', step], { cwd: P, encoding: 'utf8', env: env({ RUNNER_TEMP: path.join(T, 'rt'), GITHUB_ENV: ghenv, YAD_BASE: base }) });
|
|
823
|
+
const dir = r.status === 0 ? fs.readFileSync(ghenv, 'utf8').match(/^YAD_CHECKS=(.*)$/m)[1] : null;
|
|
824
|
+
return { ...r, dir };
|
|
825
|
+
}
|
|
826
|
+
const runIn = (dir, f) => execFileSync('bash', [path.join(dir, f)], { encoding: 'utf8' }).trim();
|
|
827
|
+
|
|
828
|
+
test('#426 step (GitHub): the base copy runs; a script the base lacks runs from the PR with a note; a link is never followed', () => {
|
|
829
|
+
const { T, P, done } = stepRepo();
|
|
830
|
+
try {
|
|
831
|
+
const r = runGithubStep(P, T);
|
|
832
|
+
assert.equal(r.status, 0, r.stderr);
|
|
833
|
+
assert.equal(runIn(r.dir, 'a.sh'), 'base-a', 'the PR changed a.sh — the base copy still runs');
|
|
834
|
+
assert.equal(runIn(r.dir, 'b c.sh'), 'pr-b');
|
|
835
|
+
assert.match(r.stdout, /note: checks\/b c\.sh is not on main yet, so the copy from this PR runs \(#426\)/);
|
|
836
|
+
assert.ok(fs.statSync(path.join(r.dir, 'x.sh')).mode & 0o100, 'the execute bit is kept');
|
|
837
|
+
assert.ok(!fs.existsSync(path.join(r.dir, 'link.sh')) && !fs.lstatSync(r.dir).isSymbolicLink(), 'the link is not copied');
|
|
838
|
+
assert.match(r.stdout, /note: checks\/link\.sh in this PR is not a plain file, so it is not run \(#426\)/);
|
|
839
|
+
assert.doesNotMatch(r.stdout, /a\.sh is not on/);
|
|
840
|
+
assert.ok(!r.dir.startsWith(P), 'the copy is outside the work tree');
|
|
841
|
+
} finally { done(); }
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
test('#426 step: a base with no checks/ runs the PR\'s copies with one note; an unknown base fails, never falls back', () => {
|
|
845
|
+
const a = stepRepo({ baseChecks: false });
|
|
846
|
+
try {
|
|
847
|
+
const r = runGithubStep(a.P, a.T);
|
|
848
|
+
assert.equal(r.status, 0, r.stderr);
|
|
849
|
+
assert.equal(runIn(r.dir, 'a.sh'), 'pr-a');
|
|
850
|
+
assert.match(r.stdout, /^note: main has no checks\/ folder yet, so the gate scripts from this PR run: 3 files \(#426\)$/m);
|
|
851
|
+
assert.doesNotMatch(r.stdout, /is not on main yet/, 'one note, not one per file');
|
|
852
|
+
const bad = runGithubStep(a.P, a.T, 'nope');
|
|
853
|
+
assert.notEqual(bad.status, 0);
|
|
854
|
+
assert.match(bad.stderr, /FAIL \[base-checks\]: origin\/nope is not in this checkout/);
|
|
855
|
+
assert.ok(!fs.existsSync(path.join(a.T, 'ghenv')) || !/nope/.test(fs.readFileSync(path.join(a.T, 'ghenv'), 'utf8')));
|
|
856
|
+
} finally { a.done(); }
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
test('#426 step (GitLab): the script\'s first line exports YAD_CHECKS to the rest of it, with the same rules', () => {
|
|
860
|
+
const { T, P, done } = stepRepo();
|
|
861
|
+
try {
|
|
862
|
+
for (const f of ['yad-checks.gitlab-ci.yml', 'yad-product-checks.gitlab-ci.yml', 'yad-verified-commits.gitlab-ci.yml']) {
|
|
863
|
+
const step = gitlabStep(fs.readFileSync(path.join(ROOT, 'skills/yad-checks/templates/gitlab', f), 'utf8'));
|
|
864
|
+
// GitLab runs a job's script lines in one shell, with errexit on.
|
|
865
|
+
const r = spawnSync('bash', ['-c', `set -eo pipefail\n${step}\nbash "$YAD_CHECKS/a.sh"; bash "$YAD_CHECKS/b c.sh"`], { cwd: P, encoding: 'utf8', env: env({ CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'main', TMPDIR: T }) });
|
|
866
|
+
assert.equal(r.status, 0, `${f}: ${r.stderr}`);
|
|
867
|
+
assert.match(r.stdout, /^note: checks\/b c\.sh is not on main yet, so the copy from this PR runs \(#426\)\nnote: checks\/link\.sh in this PR is not a plain file, so it is not run \(#426\)\nnote: checks\/x\.sh is not on main yet, so the copy from this PR runs \(#426\)\nbase-a\npr-b\n$/, f);
|
|
868
|
+
const bad = spawnSync('bash', ['-c', `set -eo pipefail\n${step}\necho ran`], { cwd: P, encoding: 'utf8', env: env({ CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'nope', TMPDIR: T }) });
|
|
869
|
+
assert.notEqual(bad.status, 0, f);
|
|
870
|
+
assert.doesNotMatch(bad.stdout, /ran/, `${f}: the job stops`);
|
|
871
|
+
}
|
|
872
|
+
} finally { done(); }
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
test('#426 step: a base symlink stays a link, a submodule or a control character in the PR is said safely, a base checks that is not a folder fails', () => {
|
|
876
|
+
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-426b-'));
|
|
877
|
+
const git = (cwd, ...a) => execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...a], { cwd, encoding: 'utf8' });
|
|
878
|
+
try {
|
|
879
|
+
const O = path.join(T, 'origin');
|
|
880
|
+
fs.mkdirSync(path.join(O, 'checks'), { recursive: true });
|
|
881
|
+
git(O, 'init', '-q', '-b', 'main');
|
|
882
|
+
fs.writeFileSync(path.join(O, 'checks/a.sh'), 'echo base-a\n');
|
|
883
|
+
fs.symlinkSync('a.sh', path.join(O, 'checks/l.sh'));
|
|
884
|
+
git(O, 'add', '-A'); git(O, 'commit', '-qm', 'base');
|
|
885
|
+
const P = path.join(T, 'pr');
|
|
886
|
+
git(T, 'clone', '-q', O, P);
|
|
887
|
+
git(P, 'switch', '-qc', 'feat');
|
|
888
|
+
fs.rmSync(path.join(P, 'checks/l.sh'));
|
|
889
|
+
fs.writeFileSync(path.join(P, 'checks/l.sh'), 'echo pr-l\n'); // the PR turns the link into a file
|
|
890
|
+
fs.writeFileSync(path.join(P, 'checks/n\nl.sh'), 'echo nl\n');
|
|
891
|
+
git(P, 'add', '-A');
|
|
892
|
+
git(P, 'update-index', '--add', '--cacheinfo', `160000,${git(P, 'rev-parse', 'HEAD').trim()},checks/sub`);
|
|
893
|
+
git(P, 'commit', '-qm', 'pr');
|
|
894
|
+
const r = runGithubStep(P, T);
|
|
895
|
+
assert.equal(r.status, 0, r.stderr);
|
|
896
|
+
assert.ok(fs.lstatSync(path.join(r.dir, 'l.sh')).isSymbolicLink(), 'the base\'s link is kept; the PR\'s file does not replace it');
|
|
897
|
+
assert.equal(runIn(r.dir, 'l.sh'), 'base-a');
|
|
898
|
+
assert.match(r.stdout, /^note: checks\/n\?l\.sh is not on main yet, so the copy from this PR runs \(#426\)$/m, 'a control character is printed as ?');
|
|
899
|
+
assert.match(r.stdout, /^note: checks\/sub in this PR is not a plain file, so it is not run \(#426\)$/m);
|
|
900
|
+
assert.ok(!fs.existsSync(path.join(r.dir, 'sub')));
|
|
901
|
+
// A base whose checks is a file, not a folder: FAIL, never "no checks/ on the base".
|
|
902
|
+
fs.rmSync(path.join(O, 'checks'), { recursive: true });
|
|
903
|
+
fs.writeFileSync(path.join(O, 'checks'), 'x\n');
|
|
904
|
+
git(O, 'add', '-A'); git(O, 'commit', '-qm', 'file');
|
|
905
|
+
git(P, 'fetch', '-q', 'origin');
|
|
906
|
+
const bad = runGithubStep(P, T);
|
|
907
|
+
assert.notEqual(bad.status, 0);
|
|
908
|
+
assert.match(bad.stderr, /FAIL \[base-checks\]: checks on origin\/main is not a folder/);
|
|
909
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
test('#426 step: one file from a base with no checks/ is "1 file"', () => {
|
|
913
|
+
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-426c-'));
|
|
914
|
+
const git = (cwd, ...a) => execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...a], { cwd, encoding: 'utf8' });
|
|
915
|
+
try {
|
|
916
|
+
const O = path.join(T, 'origin'); fs.mkdirSync(O);
|
|
917
|
+
git(O, 'init', '-q', '-b', 'main'); fs.writeFileSync(path.join(O, 'R'), 'x'); git(O, 'add', '-A'); git(O, 'commit', '-qm', 'b');
|
|
918
|
+
const P = path.join(T, 'pr'); git(T, 'clone', '-q', O, P);
|
|
919
|
+
fs.mkdirSync(path.join(P, 'checks')); fs.writeFileSync(path.join(P, 'checks/a.sh'), 'echo a\n'); git(P, 'add', '-A'); git(P, 'commit', '-qm', 'c');
|
|
920
|
+
const r = runGithubStep(P, T);
|
|
921
|
+
assert.equal(r.status, 0, r.stderr);
|
|
922
|
+
assert.match(r.stdout, /run: 1 file \(#426\)$/m);
|
|
923
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
// #428: a newer push to a PR cancels a gate file's older run — every gate re-reads the whole PR range, and a
|
|
927
|
+
// merge waits only on the newest run. A file that checks only its own push's commits, or writes to the repo,
|
|
928
|
+
// never cancels: the update guard checks `before..HEAD` of one push, so a cancelled run leaves those commits
|
|
929
|
+
// unchecked; gate-sync pushes the ledger.
|
|
930
|
+
test('#428: the PR gate files cancel their older run; the update guard, gate-sync and a push to main never do', () => {
|
|
931
|
+
// The PR-text files start on an edit too; their group also names the commit, so an older commit's late edit
|
|
932
|
+
// run cannot cancel a newer push's run.
|
|
933
|
+
const group = (name) => `\nconcurrency:\n group: \${{ github.workflow }}-\${{ github.event.pull_request.number }}${/pr-text/.test(name) ? '-${{ github.event.pull_request.head.sha }}' : ''}\n cancel-in-progress: true\n`;
|
|
934
|
+
let gh = 0, gl = 0;
|
|
935
|
+
for (const { name, text, gitlab } of GATE_TEMPLATES) {
|
|
936
|
+
if (!gitlab) {
|
|
937
|
+
gh++;
|
|
938
|
+
assert.ok(text.includes(group(name)), `${name}: no per-PR concurrency group that cancels`);
|
|
939
|
+
// The group is keyed on the PR number, so the file must start on pull_request only (no empty number).
|
|
940
|
+
const on = text.slice(text.search(/^on:$/m), text.search(/^concurrency:$/m));
|
|
941
|
+
assert.deepEqual(on.match(/^ {2}[a-z_]+:/gm), [' pull_request:'], `${name}: starts on more than pull_request`);
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
// GitLab: every job is interruptible, in its own block or in the template it extends.
|
|
945
|
+
const blocks = new Map();
|
|
946
|
+
for (const b of noComments(text).split(/^(?=['"]?[^\s#'"-][^:]*['"]?:)/m)) {
|
|
947
|
+
const m = b.match(/^['"]?([^\s#'"-][^:'"]*)['"]?:/);
|
|
948
|
+
if (m) blocks.set(m[1], b);
|
|
949
|
+
}
|
|
950
|
+
for (const key of blocks.keys()) {
|
|
951
|
+
if (key.startsWith('.') || ['variables', 'include', 'stages', 'default', 'workflow'].includes(key)) continue;
|
|
952
|
+
gl++;
|
|
953
|
+
const interruptible = (k, depth = 0) => {
|
|
954
|
+
const blk = blocks.get(k);
|
|
955
|
+
if (!blk || depth > 5 || /^ {2}interruptible: false$/m.test(blk)) return false; // the nearest explicit setting wins
|
|
956
|
+
if (/^ {2}interruptible: true$/m.test(blk)) return true;
|
|
957
|
+
const ext = blk.match(/^ {2}extends: (\S+)$/m);
|
|
958
|
+
return Boolean(ext && interruptible(ext[1], depth + 1));
|
|
959
|
+
};
|
|
960
|
+
assert.ok(interruptible(key), `${name}: job ${key} is not interruptible`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
assert.equal(gh, 6, 'GitHub gate files read');
|
|
964
|
+
assert.equal(gl, 17, 'GitLab gate jobs read'); // 21 before #434 removed the old standalone template's 4
|
|
965
|
+
for (const f of ['skills/yad-checks/templates/github/yad-update-guard.yml', 'skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml',
|
|
966
|
+
'skills/yad-product-bridge/templates/github/yad-gate-sync.yml', 'skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml']) {
|
|
967
|
+
const text = noComments(fs.readFileSync(path.join(ROOT, f), 'utf8'));
|
|
968
|
+
assert.doesNotMatch(text, /cancel-in-progress: true|interruptible: true/, `${f} must never cancel a run`);
|
|
969
|
+
}
|
|
970
|
+
// This repo's CI: a PR's older run is cancelled; a push to main has a group of its own (its event + commit), so
|
|
971
|
+
// it is neither cancelled nor left waiting — a shared group cancels a waiting run even without
|
|
972
|
+
// cancel-in-progress — and a nightly or by-hand run of the same commit never waits behind it (#434).
|
|
973
|
+
const ci = fs.readFileSync(path.join(ROOT, '.github/workflows/ci.yml'), 'utf8');
|
|
974
|
+
assert.ok(ci.includes("\nconcurrency:\n group: ci-${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || format('{0}-{1}', github.event_name, github.sha) }}\n cancel-in-progress: ${{ github.event_name == 'pull_request' }}\n"), 'ci.yml concurrency');
|
|
975
|
+
// #434: the macOS legs run on a push to main, nightly and by hand, never on a pull request; the required
|
|
976
|
+
// e2e (ubuntu-latest) leg runs on every event.
|
|
977
|
+
assert.ok(ci.includes(`include: \${{ fromJSON(github.event_name == 'pull_request' && '[]' || '[{"os":"macos-latest","node-version":24}]') }}\n`), 'ci.yml test: macOS off PRs');
|
|
978
|
+
assert.ok(ci.includes(`os: \${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest"]' || '["ubuntu-latest","macos-latest"]') }}\n`), 'ci.yml e2e: macOS off PRs');
|
|
979
|
+
assert.match(ci, /\n {2}schedule:\n {4}- cron: '[^']+'\n {2}workflow_dispatch:\n/, 'ci.yml nightly + by hand');
|
|
980
|
+
// The e2e job installs no dependencies: a `cache: npm` there would save a near-empty cache under the key the
|
|
981
|
+
// test and audit jobs share (#434).
|
|
982
|
+
const e2e = ci.slice(ci.indexOf('\n e2e:\n'), ci.indexOf('\n docs-sites:\n'));
|
|
983
|
+
assert.ok(e2e.length > 0 && e2e.includes('npm run test:e2e'), 'ci.yml e2e job found');
|
|
984
|
+
assert.doesNotMatch(e2e, /^\s+cache:/m, 'ci.yml e2e: no npm cache');
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
// #433: the merge modes yad's checks do not support yet (E166) are gaps; the settings that make the checks
|
|
988
|
+
// judge the right base, or the right approvers, are suggestions. Nothing new is fetched: the same reads.
|
|
989
|
+
test('#433 GitHub: a merge queue is a gap; "up to date" off is a suggestion; a rule unread is unknown', () => {
|
|
990
|
+
const w = workspace();
|
|
991
|
+
try {
|
|
992
|
+
const rules = (extra = [], strict = true) => [PR_RULE(), CHECKS_RULE(REQUIRED_CHECKS.github.code, strict), { type: 'non_fast_forward' }, { type: 'deletion' }, ...extra];
|
|
993
|
+
const run = (appRules, more = {}) => check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: appRules, ...more })]).r;
|
|
994
|
+
const queued = run(rules([{ type: 'merge_queue', parameters: {} }]));
|
|
995
|
+
const q = byId(queued, 'app')['merge-queue'];
|
|
996
|
+
assert.equal(q.status, 'gap');
|
|
997
|
+
assert.match(q.message, /dropped from the queue when its checks time out/);
|
|
998
|
+
assert.match(q.fix.steps.join(' '), /Turn off "Require merge queue"/);
|
|
999
|
+
assert.equal(q.fix.url, 'https://github.com/acme/app/settings/rules');
|
|
1000
|
+
assert.ok(queued.summary.gaps >= 1, 'a gap fails the run');
|
|
1001
|
+
// GraphQL sees a queue that classic branch protection turned on, which no ruleset shows.
|
|
1002
|
+
const classicQueue = byId(run(rules(), { queue: [200, { data: { repository: { mergeQueue: { id: 'MQ_1' } } } }] }), 'app')['merge-queue'];
|
|
1003
|
+
assert.equal(classicQueue.status, 'gap');
|
|
1004
|
+
assert.match(classicQueue.fix.steps.join(' '), /classic branch protection \(https:\/\/github\.com\/acme\/app\/settings\/branches\)/);
|
|
1005
|
+
// GraphQL not answered, or answered with errors: unknown — unless a ruleset's rule proves the queue.
|
|
1006
|
+
for (const queue of [[502, { message: 'Bad Gateway' }], [200, { errors: [{ message: 'x' }], data: null }], [200, { data: { repository: null } }]]) {
|
|
1007
|
+
const row = byId(run(rules(), { queue }), 'app')['merge-queue'];
|
|
1008
|
+
assert.equal(row.status, 'unknown', JSON.stringify(queue));
|
|
1009
|
+
}
|
|
1010
|
+
assert.equal(byId(run(rules([{ type: 'merge_queue' }]), { queue: [502, { message: 'x' }] }), 'app')['merge-queue'].status, 'gap');
|
|
1011
|
+
// The names are sent with -f, as plain strings, never with -F, which would type a name like `123` or `true`.
|
|
1012
|
+
const { asked } = check(w, [...gh('p', { rules: ALL_RULES(productJobs) }), ...gh('app', { rules: rules() })]);
|
|
1013
|
+
const graphqlCalls = asked.filter((x) => / graphql /.test(x));
|
|
1014
|
+
assert.ok(graphqlCalls.length >= 1, 'the queue is asked');
|
|
1015
|
+
for (const call of graphqlCalls) {
|
|
1016
|
+
assert.match(call, / -f owner=acme -f branch=main -f name=\S+$/, call);
|
|
1017
|
+
assert.doesNotMatch(call, / -F /, call);
|
|
1018
|
+
}
|
|
1019
|
+
const loose = byId(run(rules([], false)), 'app');
|
|
1020
|
+
assert.equal(loose['merge-queue'].status, 'ok');
|
|
1021
|
+
assert.equal(loose['up-to-date'].status, 'suggest');
|
|
1022
|
+
assert.match(loose['up-to-date'].message, /older base/);
|
|
1023
|
+
assert.match(loose['up-to-date'].fix.steps.join(' '), /Require branches to be up to date/);
|
|
1024
|
+
// Classic protection alone can turn "up to date" on.
|
|
1025
|
+
const classic = [200, { required_status_checks: { strict: true, contexts: [] } }];
|
|
1026
|
+
assert.equal(byId(run(rules([], false), { classic }), 'app')['up-to-date'].status, 'ok');
|
|
1027
|
+
// The rules not read: "up to date" stays a suggestion that says why (the queue comes from GraphQL).
|
|
1028
|
+
const unread = byId(run(null, { rulesFail: [500, { message: 'boom' }] }), 'app');
|
|
1029
|
+
assert.equal(unread['up-to-date'].status, 'suggest');
|
|
1030
|
+
assert.match(unread['up-to-date'].message, /^not known/);
|
|
1031
|
+
} finally { done(w); }
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
test('#433 GitLab: merge trains are a gap, merged-results pipelines are supported, and self-approval is a suggestion in team mode', () => {
|
|
1035
|
+
const w = workspace({ platform: 'gitlab' });
|
|
1036
|
+
try {
|
|
1037
|
+
const app = (opts) => byId(check(w, [...gl('p'), ...gl('app', opts)]).r, 'app');
|
|
1038
|
+
const trains = app({ project: { merge_trains_enabled: true, merge_pipelines_enabled: true } });
|
|
1039
|
+
assert.equal(trains['merge-trains'].status, 'gap');
|
|
1040
|
+
assert.match(trains['merge-trains'].message, /ahead in the train/);
|
|
1041
|
+
assert.match(trains['merge-trains'].fix.steps.join(' '), /turn off "Enable merge trains"/);
|
|
1042
|
+
assert.equal(trains['merged-results'].status, 'ok');
|
|
1043
|
+
assert.match(trains['merged-results'].message, /are on/);
|
|
1044
|
+
const off = app({ project: { merge_trains_enabled: false, merge_pipelines_enabled: false } });
|
|
1045
|
+
assert.equal(off['merge-trains'].status, 'ok');
|
|
1046
|
+
assert.match(off['merged-results'].message, /are off/);
|
|
1047
|
+
// Neither setting reported (GitLab Free, or a login that cannot see them): not known, never ok.
|
|
1048
|
+
const free = app({ project: { merge_trains_enabled: undefined, merge_pipelines_enabled: undefined } });
|
|
1049
|
+
assert.equal(free['merge-trains'].status, 'unknown');
|
|
1050
|
+
assert.match(free['merge-trains'].message, /Premium, or your login cannot see it/);
|
|
1051
|
+
assert.equal(free['merged-results'], undefined);
|
|
1052
|
+
// Merged-results pipelines off proves no train: a train needs them.
|
|
1053
|
+
assert.equal(app({ project: { merge_trains_enabled: undefined, merge_pipelines_enabled: false } })['merge-trains'].status, 'ok');
|
|
1054
|
+
// Who may approve: the author, or someone who added commits, is a suggestion; unread says Premium.
|
|
1055
|
+
const self = app({ approvals: [200, { reset_approvals_on_push: true, merge_requests_author_approval: true, merge_requests_disable_committers_approval: false }] });
|
|
1056
|
+
assert.equal(self['author-approval'].status, 'suggest');
|
|
1057
|
+
assert.match(self['author-approval'].fix.steps.join(' '), /Prevent approval by author/);
|
|
1058
|
+
assert.equal(self['committer-approval'].status, 'suggest');
|
|
1059
|
+
assert.match(self['committer-approval'].fix.steps.join(' '), /Prevent approvals by users who add commits/);
|
|
1060
|
+
const noPremium = app({ approvals: [403, { message: '403 Forbidden' }] });
|
|
1061
|
+
assert.equal(noPremium['author-approval'].status, 'suggest');
|
|
1062
|
+
assert.match(noPremium['author-approval'].message, /Premium/);
|
|
1063
|
+
const good = app({});
|
|
1064
|
+
assert.equal(good['author-approval'].status, 'ok');
|
|
1065
|
+
assert.equal(good['committer-approval'].status, 'ok');
|
|
1066
|
+
} finally { done(w); }
|
|
1067
|
+
// Solo mode: one person writes and approves, so neither approval row is asked.
|
|
1068
|
+
const solo = workspace({ platform: 'gitlab', product: { solo: true } });
|
|
1069
|
+
try {
|
|
1070
|
+
const app = byId(check(solo, [...gl('p'), ...gl('app', { approvals: [200, { merge_requests_author_approval: true, merge_requests_disable_committers_approval: false }] })]).r, 'app');
|
|
1071
|
+
assert.equal(app['author-approval'], undefined);
|
|
1072
|
+
assert.equal(app['committer-approval'], undefined);
|
|
1073
|
+
assert.equal(app['merge-trains'].status, 'ok', 'trains are asked in solo mode too');
|
|
1074
|
+
} finally { done(solo); }
|
|
1075
|
+
});
|
package/cli/test-guide.mjs
CHANGED
|
@@ -1265,3 +1265,10 @@ test('E158b cases 8 and 10 through yad itself: --push stages the script, never t
|
|
|
1265
1265
|
assert.equal(after.hooks?.PreToolUse, undefined);
|
|
1266
1266
|
} finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
|
|
1267
1267
|
});
|
|
1268
|
+
|
|
1269
|
+
test('E167 (#353): yad guide --json hands agents what the agent guard pre-approves', async () => {
|
|
1270
|
+
const { PREAPPROVED } = await import('./agent-guard.mjs');
|
|
1271
|
+
const g = buildGuide(null, { cwd: os.tmpdir() });
|
|
1272
|
+
assert.deepEqual(g.preapproved, PREAPPROVED);
|
|
1273
|
+
assert.match(g.preapproved.never, /secrets, tokens/);
|
|
1274
|
+
});
|