yadflow 4.6.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 +259 -0
- package/README.md +46 -4
- package/bin/commands.mjs +9 -2
- package/bin/yad.mjs +309 -30
- 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/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/ci-check.mjs +492 -0
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +7 -2
- package/cli/doctor.mjs +176 -33
- package/cli/epic-state.mjs +360 -12
- package/cli/errors.mjs +3 -0
- package/cli/find-product.mjs +36 -2
- package/cli/fold.mjs +9 -5
- package/cli/gate-local.mjs +9 -1
- package/cli/gate.mjs +364 -22
- package/cli/guide.mjs +549 -0
- package/cli/history.mjs +22 -2
- package/cli/hook.mjs +35 -4
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- 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 +35 -12
- package/cli/openpr.mjs +81 -5
- package/cli/plan.mjs +326 -22
- package/cli/platform.mjs +21 -0
- package/cli/pr-list.mjs +5 -3
- package/cli/product-index.mjs +6 -3
- package/cli/product-token.mjs +186 -0
- package/cli/productcommit.mjs +33 -0
- package/cli/protection.mjs +50 -0
- package/cli/recommend.mjs +3 -1
- package/cli/reconcile.mjs +187 -26
- package/cli/repo-publish.mjs +2 -2
- package/cli/report.mjs +62 -14
- package/cli/run-checks.mjs +586 -0
- package/cli/setup.mjs +244 -25
- package/cli/ship-drift.mjs +49 -18
- package/cli/signing.mjs +377 -0
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-build.mjs +1559 -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-run-checks.mjs +603 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +37 -6
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +38 -10
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +5 -5
- package/skills/sdlc/module-help.csv +2 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +5 -1
- package/skills/yad-checks/SKILL.md +61 -12
- package/skills/yad-checks/references/check-gates.md +78 -14
- package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
- package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
- package/skills/yad-checks/templates/checks/contract-check.sh +61 -33
- package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
- package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
- package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
- package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -5
- package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
- package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
- package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
- package/skills/yad-checks/templates/github/yad-checks.yml +9 -9
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +4 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +5 -5
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +8 -5
- 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/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +55 -25
- package/skills/yad-engineer-review/references/ship-and-record.md +49 -12
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +76 -17
- package/skills/yad-guide/SKILL.md +192 -0
- package/skills/yad-implement/SKILL.md +75 -13
- package/skills/yad-implement/references/implement-conventions.md +8 -1
- package/skills/yad-implement/templates/.gitmessage +3 -0
- package/skills/yad-open-pr/SKILL.md +21 -0
- package/skills/yad-pair-review/SKILL.md +14 -5
- package/skills/yad-pr-template/SKILL.md +6 -2
- package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
- package/skills/yad-product-bridge/SKILL.md +44 -12
- package/skills/yad-product-bridge/references/bridge.md +11 -5
- 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 +9 -4
- package/skills/yad-reconcile/SKILL.md +9 -3
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +5 -3
- package/skills/yad-review-gate/SKILL.md +16 -8
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +61 -33
- package/skills/yad-run/references/run-loop.md +44 -22
- package/skills/yad-spec/SKILL.md +137 -16
- package/skills/yad-spec/references/spec-handoff.md +50 -3
- package/skills/yad-status/SKILL.md +7 -0
- package/skills/yad-stories/references/story-schema.md +1 -1
- package/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +2 -2
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
// `yad run checks` (issue #347): every pull request gate, run here before the push, as CI runs it.
|
|
2
|
+
// Each test builds a workspace — a Product and a code repo, each with a bare origin — and runs the real CLI
|
|
3
|
+
// from inside the code repo.
|
|
4
|
+
import './fixtures/git-quiet.mjs';
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { execFileSync, spawn, spawnSync } from 'node:child_process';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
13
|
+
|
|
14
|
+
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
15
|
+
const YAD = path.join(ROOT, 'bin/yad.mjs');
|
|
16
|
+
// No CI variable, git identity or base from the shell that runs the suite.
|
|
17
|
+
const ENV = Object.fromEntries(Object.entries(process.env).filter(([k]) =>
|
|
18
|
+
!/^GIT_(AUTHOR|COMMITTER)_/.test(k) && !/^(CI|GITLAB_CI|GITHUB_ACTIONS|SDLC_BASE|SDLC_HUB_CONFIG|SDLC_PRODUCT_CONFIG)$/.test(k) && !/^(CI_|GITHUB_)/.test(k)));
|
|
19
|
+
// Nor the person's own git settings (a signing key, an allowed-signers list).
|
|
20
|
+
ENV.GIT_CONFIG_GLOBAL = '/dev/null';
|
|
21
|
+
const git = (cwd, ...a) => execFileSync('git', a, { cwd, stdio: 'pipe', env: ENV }).toString().trim();
|
|
22
|
+
const fm = (fields) => ['---', ...Object.entries(fields).map(([k, v]) => `${k}: ${v}`), '---', ''].join('\n');
|
|
23
|
+
|
|
24
|
+
function write(dir, files) {
|
|
25
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
26
|
+
const p = path.join(dir, rel);
|
|
27
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
28
|
+
fs.writeFileSync(p, content);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function commitAll(dir, msg, files = {}) {
|
|
32
|
+
write(dir, files);
|
|
33
|
+
git(dir, 'add', '-A');
|
|
34
|
+
git(dir, 'commit', '-q', '-m', msg);
|
|
35
|
+
}
|
|
36
|
+
function initRepo(dir) {
|
|
37
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
38
|
+
git(dir, 'init', '-q', '-b', 'main');
|
|
39
|
+
git(dir, 'config', 'user.name', 'alice');
|
|
40
|
+
git(dir, 'config', 'user.email', 'alice@corp.io');
|
|
41
|
+
git(dir, 'config', 'commit.gpgsign', 'false');
|
|
42
|
+
}
|
|
43
|
+
function addOrigin(dir, bare) {
|
|
44
|
+
git(path.dirname(bare), 'init', '-q', '--bare', '-b', 'main', path.basename(bare));
|
|
45
|
+
git(dir, 'remote', 'add', 'origin', bare);
|
|
46
|
+
git(dir, 'push', '-q', '-u', 'origin', 'main');
|
|
47
|
+
git(dir, 'remote', 'set-head', 'origin', 'main');
|
|
48
|
+
}
|
|
49
|
+
// Every installed gate, as `yad check --fix` puts them in a code repo.
|
|
50
|
+
function installChecks(repo) {
|
|
51
|
+
fs.mkdirSync(path.join(repo, 'checks'), { recursive: true });
|
|
52
|
+
for (const sk of ['yad-checks', 'yad-pr-template']) {
|
|
53
|
+
const from = path.join(ROOT, 'skills', sk, 'templates', 'checks');
|
|
54
|
+
for (const f of fs.readdirSync(from)) fs.copyFileSync(path.join(from, f), path.join(repo, 'checks', f));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// W/product (registers ../backend), W/backend on a `feature` branch with one task commit, both with origins.
|
|
59
|
+
function workspace({ storyStatus = 'in-progress' } = {}) {
|
|
60
|
+
const W = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-run-checks-')));
|
|
61
|
+
fs.mkdirSync(path.join(W, 'remotes'));
|
|
62
|
+
fs.writeFileSync(path.join(W, '.yad-workspace.json'), JSON.stringify({ version: 1, product: 'product' }));
|
|
63
|
+
const product = path.join(W, 'product');
|
|
64
|
+
initRepo(product);
|
|
65
|
+
commitAll(product, 'chore: seed the Product', {
|
|
66
|
+
'.sdlc/product.json': JSON.stringify({ platform: 'github', default_branch: 'main' }),
|
|
67
|
+
'.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'backend', path: '../backend' }] }),
|
|
68
|
+
'epics/EP-demo/epic.md': `${fm({ epic: 'EP-demo', type: 'feature' })}\n# EP-demo\n`,
|
|
69
|
+
'epics/EP-demo/stories/EP-demo-S01.md': `${fm({ story: 'EP-demo-S01', status: storyStatus })}\n# S01\n`,
|
|
70
|
+
});
|
|
71
|
+
addOrigin(product, path.join(W, 'remotes/product.git'));
|
|
72
|
+
|
|
73
|
+
const backend = path.join(W, 'backend');
|
|
74
|
+
initRepo(backend);
|
|
75
|
+
installChecks(backend);
|
|
76
|
+
commitAll(backend, 'chore: wire the gates', {
|
|
77
|
+
'.gitignore': '.yad/\n',
|
|
78
|
+
'.sdlc/product-link.json': JSON.stringify({ git_url: path.join(W, 'remotes/product.git'), path: '.yad/product', default_branch: 'main' }),
|
|
79
|
+
'specs/EP-demo-S01/link.md': fm({ story: 'EP-demo-S01', epic: 'EP-demo', 'product-repo': '../../.yad/product' }),
|
|
80
|
+
});
|
|
81
|
+
addOrigin(backend, path.join(W, 'remotes/backend.git'));
|
|
82
|
+
git(backend, 'checkout', '-q', '-b', 'feature');
|
|
83
|
+
commitAll(backend, 'feat: add thing\n\nTask: EP-demo-S01-T01', { 'src/thing.js': 'x\n' });
|
|
84
|
+
return { W, product, backend };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const yad = (cwd, args) => {
|
|
88
|
+
const r = spawnSync(process.execPath, [YAD, ...args], { cwd, env: { ...ENV, PWD: cwd, YAD_NO_REPORT: '1', YAD_NO_UPDATE_CHECK: '1' }, encoding: 'utf8' });
|
|
89
|
+
return { code: r.status, out: `${r.stdout}${r.stderr}`, stdout: r.stdout };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
test('yad run checks: every gate runs with the Product\'s default branch where CI puts it, and it is removed after', () => {
|
|
93
|
+
const { W, backend } = workspace();
|
|
94
|
+
try {
|
|
95
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
96
|
+
// The only failure is the unsigned test commits: signatures are checked with git here.
|
|
97
|
+
assert.equal(r.code, 1, r.out);
|
|
98
|
+
assert.match(r.out, /the Product's main \([0-9a-f]{12}\) is written to \.yad\/product, as CI checks it out, and removed after these gates/);
|
|
99
|
+
assert.match(r.out, /PASS \[spec-link\]: \w+ EP-demo-S01-T01 -> specs\/EP-demo-S01\/link\.md/);
|
|
100
|
+
assert.match(r.out, /PASS \[epic-open\]: \w+ EP-demo-S01-T01 -> EP-demo \(epic is open/);
|
|
101
|
+
assert.match(r.out, /PASS \[lineage-check\]: \w+ EP-demo-S01-T01 -> EP-demo \(genesis feature epic\)/);
|
|
102
|
+
assert.match(r.out, /PASS \[pr-title\]/);
|
|
103
|
+
assert.match(r.out, /the title is the branch's one commit subject/);
|
|
104
|
+
assert.match(r.out, /skipped: pr-template — no description: pass --body <file/);
|
|
105
|
+
assert.match(r.out, /skipped: install-deps — skipped with --no-build/);
|
|
106
|
+
assert.match(r.out, /FAIL \[verified-commits\]: \w+ is not signed/);
|
|
107
|
+
assert.match(r.out, /the platform's Verified badge .* is judged in CI after the push/);
|
|
108
|
+
assert.match(r.out, /1 gate failed: verified-commits/);
|
|
109
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad')), 'the Product copy is removed after the run');
|
|
110
|
+
assert.equal(git(backend, 'status', '--porcelain'), '', 'nothing is left in the work tree');
|
|
111
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('yad run checks: the Product is read from its default branch, not from local unmerged edits — as in CI', () => {
|
|
115
|
+
const { W, product, backend } = workspace({ storyStatus: 'shipped' });
|
|
116
|
+
try {
|
|
117
|
+
// Locally the story is reopened, but not merged: CI would still read it as shipped.
|
|
118
|
+
write(product, { 'epics/EP-demo/stories/EP-demo-S01.md': `${fm({ story: 'EP-demo-S01', status: 'in-progress' })}\n# S01\n` });
|
|
119
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
120
|
+
assert.equal(r.code, 1, r.out);
|
|
121
|
+
assert.match(r.out, /FAIL \[epic-open\]: \w+ EP-demo-S01-T01 targets SEALED epic EP-demo/);
|
|
122
|
+
assert.match(git(product, 'status', '--porcelain'), /EP-demo-S01\.md/, 'the Product clone is left exactly as it was');
|
|
123
|
+
assert.equal(git(product, 'rev-parse', '--abbrev-ref', 'HEAD'), 'main');
|
|
124
|
+
assert.equal(git(product, 'diff', '--cached', '--name-only'), '', 'its index is untouched');
|
|
125
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('yad run checks: a contract file the base changed after the branch split is not this branch\'s change (#363 shape)', () => {
|
|
129
|
+
const { W, backend } = workspace();
|
|
130
|
+
try {
|
|
131
|
+
git(backend, 'checkout', '-q', 'main');
|
|
132
|
+
commitAll(backend, 'feat: a slice lands on main\n\nTask: EP-demo-S01-T02\nContract-Change: yes', { 'specs/EP-demo-S01/contracts/api.md': 'GET /x\n' });
|
|
133
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
134
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
135
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
136
|
+
assert.match(r.out, /PASS \[contract-check\]: diff does not touch the contract surface/);
|
|
137
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('yad run checks: --title and --body are checked, and the run fails on any FAIL', () => {
|
|
141
|
+
const { W, backend } = workspace();
|
|
142
|
+
try {
|
|
143
|
+
const body = path.join(W, 'body.md');
|
|
144
|
+
fs.writeFileSync(body, '## Summary\nx\n');
|
|
145
|
+
const r = yad(backend, ['run', 'checks', '--no-build', '--title', 'Add a thing.', '--body', body, '--json']);
|
|
146
|
+
assert.equal(r.code, 1, r.out);
|
|
147
|
+
const json = JSON.parse(r.stdout);
|
|
148
|
+
const byName = Object.fromEntries(json.gates.map((g) => [g.name, g]));
|
|
149
|
+
assert.equal(byName['pr-title'].status, 'fail');
|
|
150
|
+
assert.ok(byName['pr-title'].fails.some((l) => /is not '<type>\(<scope>\)\?!\?: <description>'/.test(l)), JSON.stringify(byName['pr-title']));
|
|
151
|
+
assert.equal(byName['pr-template'].status, 'fail');
|
|
152
|
+
assert.ok(byName['pr-template'].fails.some((l) => /missing section '## Impact & Risk'/.test(l)), JSON.stringify(byName['pr-template']));
|
|
153
|
+
assert.equal(byName['spec-link'].status, 'pass');
|
|
154
|
+
assert.equal(json.kind, 'code');
|
|
155
|
+
assert.equal(json.base, 'origin/main');
|
|
156
|
+
assert.equal(json.product.placed, true);
|
|
157
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('yad run checks: a gate that differs from the shipped one is named; no checks/ folder is refused', () => {
|
|
161
|
+
const { W, backend } = workspace();
|
|
162
|
+
try {
|
|
163
|
+
fs.appendFileSync(path.join(backend, 'checks/spec-link.sh'), '\n# a local edit\n');
|
|
164
|
+
let r = yad(backend, ['run', 'checks', '--no-build']);
|
|
165
|
+
assert.match(r.out, /checks\/spec-link\.sh is not the gate this yadflow ships — CI runs the committed copy; if it is an older one, `yad update` replaces it/);
|
|
166
|
+
fs.rmSync(path.join(backend, 'checks'), { recursive: true, force: true });
|
|
167
|
+
r = yad(backend, ['run', 'checks']);
|
|
168
|
+
assert.equal(r.code, 1, r.out);
|
|
169
|
+
assert.match(r.out, /no checks\/ folder in .* — the gates are not installed here/);
|
|
170
|
+
r = yad(backend, ['run', 'nope']);
|
|
171
|
+
assert.equal(r.code, 1, r.out);
|
|
172
|
+
assert.match(r.out, /unknown run action: nope \(checks\)/);
|
|
173
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('yad run checks: commits signed with a key git can check pass verified-commits here', { skip: spawnSync('ssh-keygen', ['-?']).error && 'needs ssh-keygen' }, () => {
|
|
177
|
+
const { W, backend } = workspace();
|
|
178
|
+
try {
|
|
179
|
+
const key = path.join(W, 'key');
|
|
180
|
+
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-f', key], { stdio: 'pipe' });
|
|
181
|
+
fs.writeFileSync(path.join(W, 'allowed'), `alice@corp.io ${fs.readFileSync(`${key}.pub`, 'utf8')}`);
|
|
182
|
+
for (const [k, v] of [['gpg.format', 'ssh'], ['user.signingkey', key], ['gpg.ssh.allowedSignersFile', path.join(W, 'allowed')]]) git(backend, 'config', k, v);
|
|
183
|
+
git(backend, 'commit', '-q', '--amend', '--no-edit', '-S');
|
|
184
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
185
|
+
assert.match(r.out, /PASS \[verified-commits\]: \w+ is signed/);
|
|
186
|
+
assert.equal(r.code, 0, r.out);
|
|
187
|
+
assert.match(r.out, /passed, \d+ skipped \(a skipped gate is not a pass\) — push when ready/);
|
|
188
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('yad run checks: install-deps and build/test/lint run by default', () => {
|
|
192
|
+
const { W, backend } = workspace();
|
|
193
|
+
try {
|
|
194
|
+
commitAll(backend, 'chore: scripts\n\nTask: EP-demo-S01-T01', {
|
|
195
|
+
// The build job never has the Product checked out in CI, so the copy must not be there yet.
|
|
196
|
+
'package.json': JSON.stringify({ name: 'b', version: '0.0.0', scripts: { lint: 'node -e "process.exit(require(\'fs\').existsSync(\'.yad/product\') ? 1 : 0)"', build: 'node -e ""', test: 'node -e "process.exit(1)"' } }),
|
|
197
|
+
'package-lock.json': JSON.stringify({ name: 'b', version: '0.0.0', lockfileVersion: 3, requires: true, packages: { '': { name: 'b', version: '0.0.0' } } }),
|
|
198
|
+
});
|
|
199
|
+
const r = yad(backend, ['run', 'checks', '--title', 'feat: add thing']);
|
|
200
|
+
assert.match(r.out, /✓ install-deps/);
|
|
201
|
+
assert.doesNotMatch(r.out, /npm run lint' failed/, 'lint did not see a Product copy');
|
|
202
|
+
assert.match(r.out, /FAIL \[build\/test\/lint\]: '.*npm run test' failed/);
|
|
203
|
+
assert.equal(r.code, 1, r.out);
|
|
204
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('yad run checks: from the Product, the Product gates run with the branch and changed paths CI passes', () => {
|
|
208
|
+
const { W, product } = workspace();
|
|
209
|
+
try {
|
|
210
|
+
fs.mkdirSync(path.join(product, 'checks'), { recursive: true });
|
|
211
|
+
for (const sk of ['yad-checks', 'yad-pr-template']) {
|
|
212
|
+
const from = path.join(ROOT, 'skills', sk, 'templates', 'checks');
|
|
213
|
+
for (const f of fs.readdirSync(from)) fs.copyFileSync(path.join(from, f), path.join(product, 'checks', f));
|
|
214
|
+
}
|
|
215
|
+
commitAll(product, 'chore: wire the gates', {});
|
|
216
|
+
git(product, 'push', '-q', 'origin', 'main');
|
|
217
|
+
git(product, 'checkout', '-q', '-b', 'tooling');
|
|
218
|
+
commitAll(product, 'ci: tune a workflow', { 'notes.md': 'x\n' });
|
|
219
|
+
const r = yad(product, ['run', 'checks']);
|
|
220
|
+
assert.match(r.out, /Product product · branch tooling · base origin\/main/);
|
|
221
|
+
assert.match(r.out, /PASS \[commit-message\]/);
|
|
222
|
+
assert.match(r.out, /PASS \[pr-title\]/);
|
|
223
|
+
assert.match(r.out, /✓ ledger-guard/);
|
|
224
|
+
assert.match(r.out, /✓ member-check/);
|
|
225
|
+
assert.doesNotMatch(r.out, /spec-link|contract-check|written to/);
|
|
226
|
+
// A Shape artifact on a tooling branch fails, because the changed paths are passed as CI passes them.
|
|
227
|
+
commitAll(product, 'docs: edit the epic', { 'epics/EP-demo/epic.md': `${fm({ epic: 'EP-demo', type: 'feature' })}\n# EP-demo, edited\n` });
|
|
228
|
+
const r2 = yad(product, ['run', 'checks', '--title', 'docs: edit the epic']);
|
|
229
|
+
assert.match(r2.out, /FAIL \[pr-title\]: head 'tooling' changes Shape artifacts/);
|
|
230
|
+
assert.equal(r2.code, 1, r2.out);
|
|
231
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('yad run checks: a Product review branch takes no commit subject as its title', () => {
|
|
235
|
+
const { W, product } = workspace();
|
|
236
|
+
try {
|
|
237
|
+
fs.mkdirSync(path.join(product, 'checks'), { recursive: true });
|
|
238
|
+
for (const f of fs.readdirSync(path.join(ROOT, 'skills/yad-pr-template/templates/checks'))) fs.copyFileSync(path.join(ROOT, 'skills/yad-pr-template/templates/checks', f), path.join(product, 'checks', f));
|
|
239
|
+
commitAll(product, 'chore: wire the gates', {});
|
|
240
|
+
git(product, 'push', '-q', 'origin', 'main');
|
|
241
|
+
git(product, 'checkout', '-q', '-b', 'review/EP-demo/epic');
|
|
242
|
+
commitAll(product, 'docs: draft the epic', { 'epics/EP-demo/epic.md': `${fm({ epic: 'EP-demo', type: 'feature' })}\n# EP-demo, drafted\n` });
|
|
243
|
+
let r = yad(product, ['run', 'checks']);
|
|
244
|
+
assert.match(r.out, /skipped: pr-title — a review branch: pass --title "review: <artifact> \(EP-<slug>\)"/);
|
|
245
|
+
r = yad(product, ['run', 'checks', '--title', 'review: epic (EP-demo)']);
|
|
246
|
+
assert.match(r.out, /PASS \[pr-title\]/);
|
|
247
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('yad run checks: --base picks the base, and --no-fetch reads the last fetched one', () => {
|
|
251
|
+
const { W, backend } = workspace();
|
|
252
|
+
try {
|
|
253
|
+
// A commit on the remote main this clone has not fetched.
|
|
254
|
+
const other = path.join(W, 'other');
|
|
255
|
+
git(W, 'clone', '-q', '-b', 'main', path.join(W, 'remotes/backend.git'), other);
|
|
256
|
+
git(other, 'config', 'user.name', 'bob');
|
|
257
|
+
git(other, 'config', 'user.email', 'bob@corp.io');
|
|
258
|
+
commitAll(other, 'chore: on main meanwhile', { 'b.txt': 'b\n' });
|
|
259
|
+
git(other, 'push', '-q', 'origin', 'main');
|
|
260
|
+
const before = git(backend, 'rev-parse', 'origin/main');
|
|
261
|
+
yad(backend, ['run', 'checks', '--no-build', '--no-fetch']);
|
|
262
|
+
assert.equal(git(backend, 'rev-parse', 'origin/main'), before, '--no-fetch fetches nothing');
|
|
263
|
+
yad(backend, ['run', 'checks', '--no-build']);
|
|
264
|
+
assert.notEqual(git(backend, 'rev-parse', 'origin/main'), before, 'the base is fetched first');
|
|
265
|
+
const r = yad(backend, ['run', 'checks', '--no-build', '--base', 'main']);
|
|
266
|
+
assert.match(r.out, /base main\b/);
|
|
267
|
+
const bad = yad(backend, ['run', 'checks', '--base', 'nope']);
|
|
268
|
+
assert.equal(bad.code, 1, bad.out);
|
|
269
|
+
assert.match(bad.out, /base 'nope' is not a commit here/);
|
|
270
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('yad run checks: a path CI refuses fails here too, and nothing outside the repo is written', () => {
|
|
274
|
+
const { W, backend } = workspace();
|
|
275
|
+
try {
|
|
276
|
+
// .yad is a symlink to a folder outside the repo.
|
|
277
|
+
fs.mkdirSync(path.join(W, 'shared'));
|
|
278
|
+
fs.symlinkSync(path.join(W, 'shared'), path.join(backend, '.yad'));
|
|
279
|
+
let r = yad(backend, ['run', 'checks', '--no-build']);
|
|
280
|
+
assert.equal(r.code, 1, r.out);
|
|
281
|
+
assert.match(r.out, /FAIL \[product-checkout\]: '\.yad' is a symlink — the Product is not written through it/);
|
|
282
|
+
assert.deepEqual(fs.readdirSync(path.join(W, 'shared')), [], 'nothing written through the link');
|
|
283
|
+
fs.rmSync(path.join(backend, '.yad'));
|
|
284
|
+
// A default_branch that git would read as an option.
|
|
285
|
+
git(backend, 'checkout', '-q', 'main');
|
|
286
|
+
commitAll(backend, 'chore: odd record', { '.sdlc/product-link.json': JSON.stringify({ git_url: 'x', path: '.yad/product', default_branch: `--upload-pack=touch ${path.join(W, 'PWNED')};git-upload-pack` }) });
|
|
287
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
288
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
289
|
+
r = yad(backend, ['run', 'checks', '--no-build']);
|
|
290
|
+
assert.match(r.out, /FAIL \[product-checkout\]: \.sdlc\/product-link\.json on origin\/main names a default_branch git cannot use as a branch name/);
|
|
291
|
+
assert.ok(!fs.existsSync(path.join(W, 'PWNED')), 'the value never reaches git as an option');
|
|
292
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('yad run checks: a record CI refuses says what to change, as product-checkout does (#382)', () => {
|
|
296
|
+
const { W, backend } = workspace();
|
|
297
|
+
try {
|
|
298
|
+
const onBase = (record) => {
|
|
299
|
+
git(backend, 'checkout', '-q', 'main');
|
|
300
|
+
commitAll(backend, 'chore: change the record', { '.sdlc/product-link.json': record });
|
|
301
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
302
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
303
|
+
return yad(backend, ['run', 'checks', '--no-build']);
|
|
304
|
+
};
|
|
305
|
+
// A path that is set but outside the repo: `yad check --fix` keeps it, so it is changed and merged first.
|
|
306
|
+
let r = onBase(JSON.stringify({ git_url: 'x', path: '../elsewhere' }));
|
|
307
|
+
assert.equal(r.code, 1, r.out);
|
|
308
|
+
assert.match(r.out, /says path "\.\.\/elsewhere", which is not a folder inside this repo — .*\. Change path in it to one, such as \.yad\/product, and merge that change first: the record is read from origin\/main, so changing it on this branch does not help$/m);
|
|
309
|
+
// No path: `yad check --fix --push` writes one.
|
|
310
|
+
r = onBase(JSON.stringify({ git_url: 'x' }));
|
|
311
|
+
assert.equal(r.code, 1, r.out);
|
|
312
|
+
assert.match(r.out, /names no path — .*; run `yad check --fix --push` from the Product, on a machine that has this repo cloned and on its default branch; it writes path \.yad\/product to the record there\. Or set path yourself and merge that change first$/m);
|
|
313
|
+
// Set but not a folder (only spaces), and set but unreadable by the gate (a quote): change it.
|
|
314
|
+
r = onBase(JSON.stringify({ git_url: 'x', path: ' ' }));
|
|
315
|
+
assert.equal(r.code, 1, r.out);
|
|
316
|
+
assert.ok(r.out.includes('says path " ", which is not a folder inside this repo'), r.out);
|
|
317
|
+
r = onBase(JSON.stringify({ git_url: 'x', path: 'a"b' }));
|
|
318
|
+
assert.equal(r.code, 1, r.out);
|
|
319
|
+
assert.match(r.out, /names a path the gate cannot read \(it is written with a JSON escape, a quote or a backslash\) — .*\. Change path in it to a plain folder such as \.yad\/product, and merge that change first: the record is read from origin\/main$/m);
|
|
320
|
+
// A path written with a JSON escape: the gate reads the raw text, so it cannot read this one either.
|
|
321
|
+
r = onBase('{"git_url": "x", "path": ".yad\\/product"}');
|
|
322
|
+
assert.equal(r.code, 1, r.out);
|
|
323
|
+
assert.match(r.out, /names a path the gate cannot read/);
|
|
324
|
+
// A git_url written with an escape: the gate reads none and checks nothing out, so nothing fails here.
|
|
325
|
+
r = onBase('{"git_url": "https:\\/\\/host\\/org\\/p.git", "path": "../elsewhere"}');
|
|
326
|
+
assert.doesNotMatch(r.out, /FAIL \[product-checkout\]/, r.out);
|
|
327
|
+
assert.match(r.out, /names a git_url CI's product-checkout cannot read \(it is written with a JSON escape, a quote or a backslash\), so CI checks no Product out — write it in the record without escapes and merge that change first\. Nothing is written here/);
|
|
328
|
+
assert.ok(!fs.existsSync(path.join(W, 'elsewhere')), r.out);
|
|
329
|
+
// An empty file, or one that does not parse with no git_url the gate can read: as in CI, a note.
|
|
330
|
+
for (const text of ['', '{"path": "../elsewhere"']) {
|
|
331
|
+
r = onBase(text);
|
|
332
|
+
assert.doesNotMatch(r.out, /FAIL \[product-checkout\]/, r.out);
|
|
333
|
+
assert.match(r.out, /names no git_url, so CI checks no Product out/);
|
|
334
|
+
}
|
|
335
|
+
// A path that is not ASCII comes back as written, and a no-break space is not a space to the gate.
|
|
336
|
+
r = onBase(JSON.stringify({ git_url: 'x', path: '../café' }));
|
|
337
|
+
assert.ok(r.out.includes('says path "../café"'), r.out);
|
|
338
|
+
r = onBase(JSON.stringify({ git_url: 'x', path: '\u00a0' }));
|
|
339
|
+
assert.doesNotMatch(r.out, /says path/, r.out);
|
|
340
|
+
assert.ok(r.out.includes('is written to \u00a0, as CI checks it out'), r.out);
|
|
341
|
+
assert.ok(!fs.existsSync(path.join(backend, '\u00a0')), 'the copy is removed after the gates');
|
|
342
|
+
// A NUL byte in the value: the gate reads past it, so the value comes back without it…
|
|
343
|
+
r = onBase('{"git_url": "x", "path": "../a\u0000b"}');
|
|
344
|
+
assert.match(r.out, /says path "\.\.\/ab"/);
|
|
345
|
+
r = onBase('{"git_url": "x", "path": ".yad/a\u0000b"}');
|
|
346
|
+
// …and one that passes the path checks reaches git with the NUL gone: the Product is written to .yad/ab.
|
|
347
|
+
assert.doesNotMatch(r.out, /ERR_INVALID_ARG_VALUE|null bytes/, r.out);
|
|
348
|
+
assert.match(r.out, /is written to \.yad\/ab, as CI checks it out/, r.out);
|
|
349
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad/ab')), 'the copy is removed after the gates');
|
|
350
|
+
// A nested key: the gate reads the last "path" in the text, wherever it sits, and so does this.
|
|
351
|
+
r = onBase('{"git_url": "x", "path": ".yad/product", "meta": {"path": "../n"}}');
|
|
352
|
+
assert.equal(r.code, 1, r.out);
|
|
353
|
+
assert.match(r.out, /says path "\.\.\/n", which is not a folder inside this repo/);
|
|
354
|
+
// An escaped default_branch reads as none, as in CI (which then clones the remote's default branch).
|
|
355
|
+
r = onBase('{"git_url": "x", "path": "../e", "default_branch": "ma\\/in"}');
|
|
356
|
+
assert.doesNotMatch(r.out, /default_branch git cannot use/, r.out);
|
|
357
|
+
assert.match(r.out, /says path "\.\.\/e"/);
|
|
358
|
+
// A duplicate key whose last copy is escaped: the gate reads the earlier one, and so does this.
|
|
359
|
+
r = onBase('{"git_url": "x", "path": "../a", "path": "b\\/c"}');
|
|
360
|
+
assert.equal(r.code, 1, r.out);
|
|
361
|
+
assert.match(r.out, /says path "\.\.\/a", which is not a folder inside this repo/);
|
|
362
|
+
// A path that is not a string: `yad check --fix` replaces it.
|
|
363
|
+
r = onBase(JSON.stringify({ git_url: 'x', path: 5 }));
|
|
364
|
+
assert.equal(r.code, 1, r.out);
|
|
365
|
+
assert.match(r.out, /names no path — /);
|
|
366
|
+
// A record that does not parse is read field by field, as CI reads it: its path still fails.
|
|
367
|
+
r = onBase('{"git_url": "x", "path": "../elsewhere"');
|
|
368
|
+
assert.equal(r.code, 1, r.out);
|
|
369
|
+
assert.match(r.out, /says path "\.\.\/elsewhere", which is not a folder inside this repo/);
|
|
370
|
+
// No git_url: CI clones nothing and says so before it reads the path, so neither fails here.
|
|
371
|
+
r = onBase(JSON.stringify({ path: '../elsewhere' }));
|
|
372
|
+
assert.doesNotMatch(r.out, /FAIL \[product-checkout\]/, r.out);
|
|
373
|
+
assert.match(r.out, /names no git_url, so CI checks no Product out/);
|
|
374
|
+
// A tracked folder: untrack it here, or move the path on the base.
|
|
375
|
+
git(backend, 'checkout', '-q', 'main');
|
|
376
|
+
commitAll(backend, 'chore: a tracked folder', { '.sdlc/product-link.json': JSON.stringify({ git_url: 'x', path: 'prod' }), 'prod/x.txt': 'x\n' });
|
|
377
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
378
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
379
|
+
git(backend, 'merge', '-q', '--no-edit', 'main');
|
|
380
|
+
r = yad(backend, ['run', 'checks', '--no-build']);
|
|
381
|
+
assert.equal(r.code, 1, r.out);
|
|
382
|
+
assert.match(r.out, /'prod' holds files this repo tracks — .*Untrack them only if they do not belong in this repo \(git rm -r --cached -- 'prod', and add the folder to \.gitignore\), or change path in \.sdlc\/product-link\.json to an untracked folder such as \.yad\/product and merge that change first \(the record is read from origin\/main\)$/m);
|
|
383
|
+
// A quote in the path is written the shell's way in the command to paste, as the gate writes it.
|
|
384
|
+
git(backend, 'checkout', '-q', 'main');
|
|
385
|
+
commitAll(backend, 'chore: a quoted folder', { '.sdlc/product-link.json': JSON.stringify({ git_url: 'x', path: "it's" }), "it's/x.txt": 'x\n' });
|
|
386
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
387
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
388
|
+
git(backend, 'merge', '-q', '--no-edit', 'main');
|
|
389
|
+
r = yad(backend, ['run', 'checks', '--no-build']);
|
|
390
|
+
assert.ok(r.out.includes("(git rm -r --cached -- 'it'\\''s', and add the folder to .gitignore)"), r.out);
|
|
391
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test('yad run checks: an SSH signature git has no allowed-signers list for is "cannot check here", not "not signed"', { skip: spawnSync('ssh-keygen', ['-?']).error && 'needs ssh-keygen' }, () => {
|
|
395
|
+
const { W, backend } = workspace();
|
|
396
|
+
try {
|
|
397
|
+
const key = path.join(W, 'key');
|
|
398
|
+
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-f', key], { stdio: 'pipe' });
|
|
399
|
+
for (const [k, v] of [['gpg.format', 'ssh'], ['user.signingkey', key]]) git(backend, 'config', k, v);
|
|
400
|
+
git(backend, 'commit', '-q', '--amend', '--no-edit', '-S');
|
|
401
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
402
|
+
assert.match(r.out, /note \[verified-commits\]: \w+ is signed, but this machine cannot check the key/);
|
|
403
|
+
assert.doesNotMatch(r.out, /is not signed/);
|
|
404
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('yad run checks: Ctrl-C stops the run even when the gate catches it, and the copy is gone', { skip: process.platform === 'win32' && 'process groups' }, async () => {
|
|
408
|
+
const { W, backend } = workspace();
|
|
409
|
+
try {
|
|
410
|
+
commitAll(backend, 'chore: scripts\n\nTask: EP-demo-S01-T01', {
|
|
411
|
+
'package.json': JSON.stringify({ name: 'b', version: '0.0.0', scripts: { lint: 'node -e "process.on(\'SIGINT\',()=>process.exit(130));process.on(\'SIGTERM\',()=>process.exit(143));setTimeout(()=>{},30000)"', build: 'node -e ""', test: 'node -e ""' } }),
|
|
412
|
+
'package-lock.json': JSON.stringify({ name: 'b', version: '0.0.0', lockfileVersion: 3, requires: true, packages: { '': { name: 'b', version: '0.0.0' } } }),
|
|
413
|
+
});
|
|
414
|
+
for (const sig of ['SIGINT', 'SIGTERM']) {
|
|
415
|
+
const child = spawn(process.execPath, [YAD, 'run', 'checks', '--title', 'feat: x'], { cwd: backend, env: { ...ENV, PWD: backend, YAD_NO_REPORT: '1' }, detached: true });
|
|
416
|
+
let out = '';
|
|
417
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
418
|
+
child.stderr.on('data', (d) => { out += d; });
|
|
419
|
+
const started = Date.now();
|
|
420
|
+
while (!/build\/test\/lint\]? lint…|\[build\/test\/lint\] lint/.test(out) && Date.now() - started < 20000) await sleep(100);
|
|
421
|
+
await sleep(500);
|
|
422
|
+
// Ctrl-C reaches the whole group; a plain kill reaches yad alone.
|
|
423
|
+
if (sig === 'SIGINT') process.kill(-child.pid, sig); else process.kill(child.pid, sig);
|
|
424
|
+
const code = await new Promise((r) => child.on('close', r));
|
|
425
|
+
assert.equal(code, sig === 'SIGINT' ? 130 : 143, `${sig}: ${out}`);
|
|
426
|
+
assert.match(out, /stopped \(SIG(INT|TERM)\) — nothing after that gate ran/, out);
|
|
427
|
+
assert.doesNotMatch(out, /\ncontract-check\n/, `${sig}: no later gate ran`);
|
|
428
|
+
assert.ok(Date.now() - started < 25000, `${sig}: it stopped promptly`);
|
|
429
|
+
}
|
|
430
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad')));
|
|
431
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test('yad run checks: member-check is left to CI when a member file changes; a missing --body file is refused', () => {
|
|
435
|
+
const { W, product } = workspace();
|
|
436
|
+
try {
|
|
437
|
+
fs.mkdirSync(path.join(product, 'checks'), { recursive: true });
|
|
438
|
+
fs.copyFileSync(path.join(ROOT, 'skills/yad-checks/templates/checks/member-check.mjs'), path.join(product, 'checks/member-check.mjs'));
|
|
439
|
+
commitAll(product, 'chore: wire the gate', {});
|
|
440
|
+
git(product, 'push', '-q', 'origin', 'main');
|
|
441
|
+
git(product, 'checkout', '-q', '-b', 'join');
|
|
442
|
+
commitAll(product, 'chore: join', { '.sdlc/members/github-alice.json': '{"accounts":[]}\n' });
|
|
443
|
+
let r = yad(product, ['run', 'checks']);
|
|
444
|
+
assert.match(r.out, /skipped: member-check — a member file changes, and the gate needs the PR's author, which only CI has/);
|
|
445
|
+
r = yad(product, ['run', 'checks', '--body', 'nope.md']);
|
|
446
|
+
assert.equal(r.code, 1, r.out);
|
|
447
|
+
assert.match(r.out, /--body file not found: nope\.md/);
|
|
448
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('yad run checks: the base follows the registry like yad open-pr, and GitLab warns at the 2700-character cut', () => {
|
|
452
|
+
const { W, product, backend } = workspace();
|
|
453
|
+
try {
|
|
454
|
+
git(backend, 'checkout', '-q', '-b', 'develop', 'main');
|
|
455
|
+
git(backend, 'push', '-q', 'origin', 'develop');
|
|
456
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
457
|
+
write(product, { '.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'backend', path: '../backend', default_branch: 'develop', platform: 'gitlab' }] }) });
|
|
458
|
+
const body = path.join(W, 'body.md');
|
|
459
|
+
fs.writeFileSync(body, `## Summary\n${'x'.repeat(2800)}\n`);
|
|
460
|
+
const r = yad(backend, ['run', 'checks', '--no-build', '--body', body]);
|
|
461
|
+
assert.match(r.out, /base origin\/develop/);
|
|
462
|
+
assert.match(r.out, /the description is \d+ characters; GitLab hands CI only the first 2700/);
|
|
463
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test('yad run checks: a gate that exits 143 on its own is a FAIL, and the gates after it still run', () => {
|
|
467
|
+
const { W, backend } = workspace();
|
|
468
|
+
try {
|
|
469
|
+
fs.writeFileSync(path.join(backend, 'checks/risk-map-check.sh'), '#!/usr/bin/env bash\necho "FAIL [risk-map]: a helper got SIGTERM"\nexit 143\n');
|
|
470
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
471
|
+
assert.equal(r.code, 1, r.out);
|
|
472
|
+
assert.match(r.out, /✗ risk-map/);
|
|
473
|
+
assert.match(r.out, /PASS \[epic-open\]/, 'the gates after it ran');
|
|
474
|
+
assert.doesNotMatch(r.out, /stopped/);
|
|
475
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test('yad run checks: the Product copy is gone before any other gate, whichever Product gates are installed', () => {
|
|
479
|
+
const { W, backend } = workspace();
|
|
480
|
+
try {
|
|
481
|
+
fs.rmSync(path.join(backend, 'checks/reconcile-debt-check.sh'));
|
|
482
|
+
fs.writeFileSync(path.join(backend, 'checks/backfill-check.sh'), '#!/usr/bin/env bash\nif [ -e .yad/product ]; then echo "FAIL [backfill]: COPY PRESENT"; exit 1; fi\necho "PASS [backfill]: no copy"\n');
|
|
483
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
484
|
+
assert.match(r.out, /PASS \[epic-open\]/);
|
|
485
|
+
assert.match(r.out, /PASS \[backfill\]: no copy/, r.out);
|
|
486
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test('yad run checks: a record with no default_branch reads the Product clone\'s own default branch', () => {
|
|
490
|
+
const { W, product, backend } = workspace({ storyStatus: 'shipped' });
|
|
491
|
+
try {
|
|
492
|
+
// The Product's trunk is master; main is gone.
|
|
493
|
+
git(product, 'branch', '-m', 'main', 'master');
|
|
494
|
+
git(product, 'push', '-q', 'origin', 'master');
|
|
495
|
+
git(path.join(W, 'remotes/product.git'), 'symbolic-ref', 'HEAD', 'refs/heads/master');
|
|
496
|
+
git(product, 'push', '-q', 'origin', '--delete', 'main');
|
|
497
|
+
git(product, 'remote', 'set-head', 'origin', '-a');
|
|
498
|
+
git(backend, 'checkout', '-q', 'main');
|
|
499
|
+
commitAll(backend, 'chore: record with no branch', { '.sdlc/product-link.json': JSON.stringify({ git_url: path.join(W, 'remotes/product.git'), path: '.yad/product', default_branch: null }) });
|
|
500
|
+
git(backend, 'push', '-q', 'origin', 'main');
|
|
501
|
+
git(backend, 'checkout', '-q', 'feature');
|
|
502
|
+
git(backend, 'rebase', '-q', 'main');
|
|
503
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
504
|
+
assert.match(r.out, /the record names no default_branch, so the Product clone's origin\/HEAD says it: master/);
|
|
505
|
+
assert.match(r.out, /FAIL \[epic-open\]: \w+ EP-demo-S01-T01 targets SEALED epic EP-demo/, 'master was read');
|
|
506
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test('yad run checks: a stop during a Product gate removes the copy; a gate that ignores the signal is killed', { skip: process.platform === 'win32' && 'process groups' }, async () => {
|
|
510
|
+
const { W, backend } = workspace();
|
|
511
|
+
try {
|
|
512
|
+
fs.writeFileSync(path.join(backend, 'checks/lineage-check.sh'), '#!/usr/bin/env bash\necho "lineage started"\ntrap "" INT TERM HUP\nsleep 30\n');
|
|
513
|
+
const child = spawn(process.execPath, [YAD, 'run', 'checks', '--no-build'], { cwd: backend, env: { ...ENV, PWD: backend, YAD_NO_REPORT: '1' } });
|
|
514
|
+
let out = '';
|
|
515
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
516
|
+
child.stderr.on('data', (d) => { out += d; });
|
|
517
|
+
const started = Date.now();
|
|
518
|
+
while (!/lineage started/.test(out) && Date.now() - started < 20000) await sleep(100);
|
|
519
|
+
assert.ok(fs.existsSync(path.join(backend, '.yad/product')), 'the copy is there while the gate runs');
|
|
520
|
+
child.kill('SIGINT');
|
|
521
|
+
const t = Date.now();
|
|
522
|
+
const code = await new Promise((r) => child.on('close', r));
|
|
523
|
+
assert.equal(code, 130, out);
|
|
524
|
+
assert.ok(Date.now() - t < 12000, 'killed after the grace period, not after the gate\'s 30 seconds');
|
|
525
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad')), 'the copy is gone');
|
|
526
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test('yad run checks: a product-checkout FAIL skips the four gates; uncommitted work is named, a rename once', () => {
|
|
530
|
+
const { W, backend } = workspace();
|
|
531
|
+
try {
|
|
532
|
+
write(backend, { 'src/new.js': 'not added\n' });
|
|
533
|
+
git(backend, 'mv', 'src/thing.js', 'src/moved.js');
|
|
534
|
+
// A rename in the work tree (intent to add) is one entry too: ` R new\0old\0`.
|
|
535
|
+
fs.renameSync(path.join(backend, '.gitignore'), path.join(backend, 'ignore.txt'));
|
|
536
|
+
git(backend, 'add', '-N', 'ignore.txt');
|
|
537
|
+
fs.mkdirSync(path.join(W, 'shared'));
|
|
538
|
+
fs.symlinkSync(path.join(W, 'shared'), path.join(backend, '.yad'));
|
|
539
|
+
const r = yad(backend, ['run', 'checks', '--no-build']);
|
|
540
|
+
assert.match(r.out, /uncommitted changes are built and tested here but are not in the push \((ignore\.txt, src\/moved\.js, src\/new\.js|src\/moved\.js, ignore\.txt, src\/new\.js)\)/);
|
|
541
|
+
assert.match(r.out, /skipped: contract-check — product-checkout failed, so it was not run \(as in CI\)/);
|
|
542
|
+
assert.match(r.out, /✗ product-checkout — the Product could not be put where CI puts it/);
|
|
543
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test('yad run checks: a folder already there is read as it is and kept; a run removes only what it wrote', () => {
|
|
547
|
+
const { W, backend } = workspace();
|
|
548
|
+
try {
|
|
549
|
+
write(backend, { '.yad/notes.txt': 'mine\n' });
|
|
550
|
+
let r = yad(backend, ['run', 'checks', '--no-build']);
|
|
551
|
+
assert.ok(fs.existsSync(path.join(backend, '.yad/notes.txt')), 'a .yad/ of the user\'s own is kept');
|
|
552
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad/product')), 'only the copy is removed');
|
|
553
|
+
// A copy a killed run left behind, or anyone's folder: read as it is, never removed.
|
|
554
|
+
write(backend, { '.yad/product/epics/x.md': 'left\n' });
|
|
555
|
+
r = yad(backend, ['run', 'checks', '--no-build']);
|
|
556
|
+
assert.match(r.out, /\.yad\/product is already there, so it is read as it is — it may not be the Product's default branch \(another run may be using it, or a run that was killed left it\): remove it to read the default branch/);
|
|
557
|
+
assert.ok(fs.existsSync(path.join(backend, '.yad/product/epics/x.md')));
|
|
558
|
+
fs.rmSync(path.join(backend, '.yad'), { recursive: true });
|
|
559
|
+
// A file put into the folder the run made, while it runs, stays; the copy goes.
|
|
560
|
+
fs.writeFileSync(path.join(backend, 'checks/lineage-check.sh'), '#!/usr/bin/env bash\necho note > .yad/notes.md\necho "PASS [lineage-check]: wrote a note"\n');
|
|
561
|
+
r = yad(backend, ['run', 'checks', '--no-build']);
|
|
562
|
+
assert.match(r.out, /PASS \[lineage-check\]: wrote a note/);
|
|
563
|
+
assert.ok(fs.existsSync(path.join(backend, '.yad/notes.md')), 'the file someone put there stays');
|
|
564
|
+
assert.ok(!fs.existsSync(path.join(backend, '.yad/product')), 'the copy is gone');
|
|
565
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test('removeParents and removeCopy: only the folders a run made, and only while each is empty', async () => {
|
|
569
|
+
const { removeCopy, removeParents } = await import('../cli/run-checks.mjs');
|
|
570
|
+
const T = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-rm-'));
|
|
571
|
+
try {
|
|
572
|
+
const top = path.join(T, 'a', 'b');
|
|
573
|
+
const dest = path.join(top, 'c', 'd');
|
|
574
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
575
|
+
fs.writeFileSync(path.join(top, 'stray.txt'), 'kept\n');
|
|
576
|
+
fs.writeFileSync(path.join(dest, 'x.md'), 'copy\n');
|
|
577
|
+
removeCopy(dest, top);
|
|
578
|
+
assert.ok(!fs.existsSync(dest), 'the copy goes');
|
|
579
|
+
assert.ok(!fs.existsSync(path.join(top, 'c')), 'an empty folder the run made goes');
|
|
580
|
+
assert.ok(fs.existsSync(path.join(top, 'stray.txt')), 'a folder with a file in it stays');
|
|
581
|
+
// On Windows, Node 18/20 report what mkdir made in the long \\?\ form; it is read as path.join writes it.
|
|
582
|
+
const { plainPath } = await import('../cli/run-checks.mjs');
|
|
583
|
+
assert.equal(plainPath('\\\\?\\C:\\r\\.yad', path.win32), 'C:\\r\\.yad');
|
|
584
|
+
assert.equal(plainPath('\\\\?\\UNC\\srv\\share\\r\\.yad', path.win32), '\\\\srv\\share\\r\\.yad');
|
|
585
|
+
assert.equal(plainPath('C:\\r\\.yad', path.win32), 'C:\\r\\.yad');
|
|
586
|
+
// A `created` that is not above dest removes nothing.
|
|
587
|
+
fs.mkdirSync(path.join(T, 'e', 'f'), { recursive: true });
|
|
588
|
+
removeParents(path.join(T, 'e', 'f', 'g'), path.join(T, 'other'));
|
|
589
|
+
assert.ok(fs.existsSync(path.join(T, 'e', 'f')));
|
|
590
|
+
} finally { fs.rmSync(T, { recursive: true, force: true }); }
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test('yad run checks: a folder read as it was, removed while the Product gates read it, is said to be gone', () => {
|
|
594
|
+
const { W, backend } = workspace();
|
|
595
|
+
try {
|
|
596
|
+
write(backend, { '.yad/product/epics/EP-demo/epic.md': 'someone else\'s copy\n' });
|
|
597
|
+
// Another run ending: its copy goes while this run's Product gates run.
|
|
598
|
+
fs.writeFileSync(path.join(backend, 'checks/lineage-check.sh'), '#!/usr/bin/env bash\nrm -rf .yad/product\necho "PASS [lineage-check]: x"\n');
|
|
599
|
+
const r = yad(backend, ['run', 'checks', '--no-build', '--json']);
|
|
600
|
+
assert.match(r.out, /\.yad\/product was removed while the Product gates read it \(another run ended\) — their answers may be wrong; run again/);
|
|
601
|
+
assert.equal(JSON.parse(r.stdout).product.vanished, true);
|
|
602
|
+
} finally { fs.rmSync(W, { recursive: true, force: true }); }
|
|
603
|
+
});
|