yadflow 4.9.0 → 4.11.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 +184 -0
- package/README.md +15 -5
- package/bin/commands.mjs +11 -1
- package/bin/yad.mjs +203 -14
- package/cli/agent-guard-worker.mjs +13 -0
- package/cli/agent-guard.mjs +1797 -73
- package/cli/agent-rules.mjs +64 -5
- package/cli/argv-flags.mjs +2 -2
- package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
- package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
- package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
- package/cli/brain/vendor/graphology-library.min.js +2 -0
- package/cli/brain/vendor/graphology.umd.min.js +2 -0
- package/cli/brain/vendor/sigma.min.js +1369 -0
- package/cli/brain/view/app.js +382 -0
- package/cli/brain/view/index.html +63 -0
- package/cli/brain/view/live.css +228 -0
- package/cli/brain/view/live.html +110 -0
- package/cli/brain/view/live.js +884 -0
- package/cli/brain/view/style.css +141 -0
- package/cli/brain-about.mjs +206 -0
- package/cli/brain-activity.mjs +285 -0
- package/cli/brain-skills.mjs +118 -0
- package/cli/brain-vendor.mjs +71 -0
- package/cli/brain-view.mjs +344 -0
- package/cli/brain.mjs +810 -0
- package/cli/ci-check.mjs +48 -4
- package/cli/codeowners-command.mjs +72 -6
- package/cli/commit.mjs +17 -3
- package/cli/docs.mjs +2 -0
- package/cli/doctor.mjs +151 -25
- package/cli/epic-state.mjs +186 -4
- package/cli/epic.mjs +26 -10
- package/cli/errors.mjs +2 -1
- package/cli/find-product.mjs +69 -15
- package/cli/fold.mjs +31 -6
- package/cli/foundation-publish.mjs +256 -0
- package/cli/gate.mjs +29 -3
- package/cli/git-read.mjs +38 -0
- package/cli/guard-stream.mjs +409 -0
- package/cli/guide.mjs +3 -1
- package/cli/hook.mjs +102 -9
- package/cli/issue-links.mjs +61 -0
- package/cli/issues-act.mjs +371 -0
- package/cli/issues-write.mjs +441 -0
- package/cli/issues.mjs +513 -0
- package/cli/lib.mjs +37 -2
- package/cli/lifecycle.mjs +7 -0
- package/cli/local-page.mjs +138 -0
- package/cli/machine.mjs +1 -1
- package/cli/manifest.mjs +59 -3
- package/cli/map/view/app.js +712 -0
- package/cli/map/view/index.html +50 -0
- package/cli/map/view/style.css +142 -0
- package/cli/map-view.mjs +186 -0
- package/cli/map.mjs +637 -0
- package/cli/members.mjs +9 -15
- package/cli/next.mjs +1 -1
- package/cli/openpr.mjs +26 -6
- package/cli/plan.mjs +127 -0
- package/cli/platform.mjs +159 -4
- package/cli/product-index.mjs +1 -1
- package/cli/protection.mjs +53 -3
- package/cli/reconcile.mjs +9 -3
- package/cli/report.mjs +9 -3
- package/cli/reports-dir.mjs +391 -0
- package/cli/reports.mjs +65 -0
- package/cli/run-checks.mjs +15 -4
- package/cli/scan.mjs +314 -0
- package/cli/setup.mjs +42 -8
- package/cli/standup.mjs +120 -78
- package/cli/status.mjs +6 -5
- package/cli/story-frames.mjs +17 -6
- package/cli/test-agents-file.mjs +985 -12
- package/cli/test-brain-activity.mjs +753 -0
- package/cli/test-brain-view.mjs +381 -0
- package/cli/test-brain.mjs +795 -0
- package/cli/test-build.mjs +25 -0
- package/cli/test-ci-check.mjs +469 -10
- package/cli/test-guide.mjs +218 -0
- package/cli/test-machine.mjs +59 -0
- package/cli/test-map.mjs +615 -0
- package/cli/test-node.mjs +15 -0
- package/cli/test-reports.mjs +382 -0
- package/cli/test-run-checks.mjs +21 -0
- package/cli/test-setup-agent.mjs +14 -0
- package/cli/test-story-frames.mjs +74 -4
- package/cli/test-worktree.mjs +24 -3
- package/cli/toolbox-connect.mjs +259 -0
- package/cli/toolbox.mjs +187 -12
- package/cli/update-commit.mjs +101 -9
- package/cli/usage.mjs +8 -4
- package/package.json +12 -4
- 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-architecture/SKILL.md +22 -4
- package/skills/yad-backfill/SKILL.md +4 -0
- package/skills/yad-change/SKILL.md +7 -1
- package/skills/yad-change/references/triage.md +2 -0
- package/skills/yad-checks/SKILL.md +15 -7
- package/skills/yad-checks/references/check-gates.md +70 -35
- package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
- package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
- package/skills/yad-checks/templates/checks/member-check.mjs +3 -2
- package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
- 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 +358 -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 +80 -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-checks/templates/hooks/yad-activity.mjs +238 -0
- package/skills/yad-commit/SKILL.md +3 -1
- package/skills/yad-connect-design/SKILL.md +42 -10
- package/skills/yad-connect-design/references/design-context.md +35 -5
- package/skills/yad-connect-design/references/design-registry.md +3 -3
- package/skills/yad-connect-learning/SKILL.md +12 -2
- package/skills/yad-connect-repos/SKILL.md +18 -0
- package/skills/yad-connect-testing/SKILL.md +22 -5
- package/skills/yad-connect-testing/references/testing-context.md +1 -1
- package/skills/yad-discovery/SKILL.md +11 -0
- package/skills/yad-discovery/references/foundation-schema.md +11 -0
- package/skills/yad-docs/templates/app/package-lock.json +18 -10
- package/skills/yad-docs/templates/app/package.json +6 -1
- package/skills/yad-epic/SKILL.md +7 -0
- package/skills/yad-epic/references/state-schema.md +50 -1
- package/skills/yad-guide/SKILL.md +8 -4
- package/skills/yad-implement/SKILL.md +117 -4
- package/skills/yad-implement/references/implement-conventions.md +2 -1
- package/skills/yad-issues/SKILL.md +54 -0
- package/skills/yad-learn/SKILL.md +4 -0
- package/skills/yad-open-pr/SKILL.md +6 -0
- package/skills/yad-pr-template/SKILL.md +2 -1
- package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +42 -6
- 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-run/SKILL.md +5 -0
- package/skills/yad-scan/SKILL.md +51 -0
- package/skills/yad-spec/SKILL.md +32 -2
- package/skills/yad-stories/SKILL.md +22 -4
- package/skills/yad-stories/references/story-schema.md +1 -1
- package/skills/yad-test-cases/SKILL.md +18 -2
- package/skills/yad-ui/SKILL.md +43 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +0 -49
|
@@ -0,0 +1,795 @@
|
|
|
1
|
+
// E176: the project brain — Graphify's code graph and the work items, merged into one local graph file.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
if (process.env.NODE_TEST_CONTEXT) {
|
|
11
|
+
const write = process.stdout.write;
|
|
12
|
+
for (const k of ['log', 'info']) {
|
|
13
|
+
const orig = console[k];
|
|
14
|
+
console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
process.env.YAD_NO_UPDATE_NOTIFIER = '1';
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
readGraphify, surfacesOf, tasksOf, composeBrain, buildRepoGraph, ensureBrainDir, excludeGraphifyOut,
|
|
21
|
+
writeBrain, readBrain, brainFreshness, queryBrain, graphifyEnv, safeName, BRAIN_FILE, GRAPHIFY_ENV, GRAPHIFY_VERSION,
|
|
22
|
+
} = await import('./brain.mjs');
|
|
23
|
+
const { TOOLBOX } = await import('./toolbox.mjs');
|
|
24
|
+
const { RECIPES } = await import('./toolbox-connect.mjs');
|
|
25
|
+
|
|
26
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
const YAD = path.join(HERE, '..', 'bin', 'yad.mjs');
|
|
28
|
+
const GOLDEN = path.join(HERE, 'fixtures', 'golden-v3');
|
|
29
|
+
|
|
30
|
+
const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-brain-')));
|
|
31
|
+
const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
|
|
32
|
+
const done = (...dirs) => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }));
|
|
33
|
+
// A test that commits sets its own identity and never signs: CI has no identity, and a signing setup
|
|
34
|
+
// on the machine must not reach a throwaway repo.
|
|
35
|
+
const git = (cwd, ...a) => spawnSync('git', ['-c', 'user.email=t@example.com', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...a], { cwd, encoding: 'utf8' });
|
|
36
|
+
// PATH holds only the folder node is in, so no Graphify on the machine is found.
|
|
37
|
+
const yad = (cwd, ...a) => spawnSync(process.execPath, [YAD, ...a], {
|
|
38
|
+
cwd, encoding: 'utf8',
|
|
39
|
+
env: { ...process.env, PATH: path.dirname(process.execPath), NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// The same, with git on PATH too, for a command that asks git: a folder holding only a link to git, so a
|
|
43
|
+
// Graphify installed beside git (Homebrew's one folder) is never found.
|
|
44
|
+
const GIT_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-brain-git-'));
|
|
45
|
+
process.on('exit', () => fs.rmSync(GIT_DIR, { recursive: true, force: true }));
|
|
46
|
+
fs.symlinkSync(spawnSync('sh', ['-c', 'command -v git'], { encoding: 'utf8' }).stdout.trim(), path.join(GIT_DIR, 'git'));
|
|
47
|
+
const yadGit = (cwd, ...a) => spawnSync(process.execPath, [YAD, ...a], {
|
|
48
|
+
cwd, encoding: 'utf8',
|
|
49
|
+
env: { ...process.env, PATH: [path.dirname(process.execPath), GIT_DIR].join(path.delimiter), NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// A Graphify graph as 0.9.108 writes it (read from a real run): edges under `links`.
|
|
53
|
+
const graphifyGraph = ({ key = 'links', schema = 1 } = {}) => ({
|
|
54
|
+
directed: false, multigraph: false, graph: { schema_version: schema, graphify_version: '0.9.108' },
|
|
55
|
+
nodes: [
|
|
56
|
+
{ id: 'src_routes', label: 'routes.js', source_file: 'src/routes.js', source_location: 'L1', file_type: 'code' },
|
|
57
|
+
{ id: 'src_routes_postorders', label: 'postOrders()', source_file: 'src/routes.js', source_location: 'L9', file_type: 'code' },
|
|
58
|
+
{ id: 'src_order_index', label: 'index.js', source_file: 'src/order/index.js', source_location: 'L1', file_type: 'code' },
|
|
59
|
+
{ id: 'src_order_create', label: 'create()', source_file: 'src/order/index.js', source_location: 'L4', file_type: 'code' },
|
|
60
|
+
{ id: 'src_order_order', label: 'Order', source_file: 'src/order/index.js', source_location: 'L2', file_type: 'code' },
|
|
61
|
+
],
|
|
62
|
+
[key]: [
|
|
63
|
+
{ source: 'src_routes_postorders', target: 'src_order_create', relation: 'calls', confidence: 'EXTRACTED', confidence_score: 1 },
|
|
64
|
+
{ source: 'src_routes', target: 'src_routes_postorders', relation: 'contains', confidence: 'EXTRACTED' },
|
|
65
|
+
{ source: 'src_routes', target: 'ghost', relation: 'imports', confidence: 'EXTRACTED' },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// The golden Product, with its backend repo cloned beside it (a git repo holding one story's tasks).
|
|
70
|
+
function product() {
|
|
71
|
+
const ws = tmp();
|
|
72
|
+
const root = path.join(ws, 'product');
|
|
73
|
+
fs.cpSync(GOLDEN, root, { recursive: true });
|
|
74
|
+
const be = path.join(root, 'demo-repos', 'backend');
|
|
75
|
+
put(path.join(be, 'src', 'routes.js'), '// routes\n');
|
|
76
|
+
put(path.join(be, 'specs', 'EP-checkout-S01', 'tasks.md'), [
|
|
77
|
+
'# Tasks — EP-checkout-S01 (backend)', '',
|
|
78
|
+
'## T01 — Add `POST /orders` route + create path',
|
|
79
|
+
'- **Files:** `src/order/index.js`, `src/order/store.js`, `src/routes.js`', '',
|
|
80
|
+
'## T02 — Validate input',
|
|
81
|
+
'- **Files:** `src/order/validate.js`, `../outside.js`, `/etc/passwd`, `package.json`', '',
|
|
82
|
+
].join('\n'));
|
|
83
|
+
put(path.join(be, 'package.json'), '{}\n');
|
|
84
|
+
git(be, 'init', '-q');
|
|
85
|
+
git(be, 'add', '-A');
|
|
86
|
+
git(be, 'commit', '-qm', 'init');
|
|
87
|
+
return { ws, root, be };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// A runner that plays Graphify: `graphify update` writes the graph into graphify-out/.
|
|
91
|
+
function fakeGraphify(graph = graphifyGraph()) {
|
|
92
|
+
const calls = [];
|
|
93
|
+
const runner = (cmd, args = [], opts = {}) => {
|
|
94
|
+
calls.push({ cmd, args, opts });
|
|
95
|
+
if (cmd === 'graphify' && args[0] === 'update') {
|
|
96
|
+
put(path.join(opts.cwd, 'graphify-out', 'graph.json'), JSON.stringify(graph));
|
|
97
|
+
return { ok: true, code: 0, stdout: '', stderr: '' };
|
|
98
|
+
}
|
|
99
|
+
if (cmd === 'graphify' && args[0] === '--version') return { ok: true, code: 0, stdout: `graphify ${GRAPHIFY_VERSION}`, stderr: '' };
|
|
100
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', ...opts });
|
|
101
|
+
return { ok: r.status === 0, code: r.status, stdout: (r.stdout || '').trim(), stderr: (r.stderr || '').trim() };
|
|
102
|
+
};
|
|
103
|
+
return { runner, calls };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test('readGraphify reads edges under links or edges, and refuses an unknown schema or shape', () => {
|
|
107
|
+
assert.equal(readGraphify(JSON.stringify(graphifyGraph())).edges.length, 3);
|
|
108
|
+
assert.equal(readGraphify(JSON.stringify(graphifyGraph({ key: 'edges' }))).edges.length, 3);
|
|
109
|
+
assert.equal(readGraphify(JSON.stringify(graphifyGraph())).graphifyVersion, '0.9.108');
|
|
110
|
+
assert.throws(() => readGraphify(JSON.stringify(graphifyGraph({ schema: 2 }))), (e) => e.code === 'YAD-STATE-011' && /schema_version 2/.test(e.message) && /graphifyy==0\.9\.108/.test(e.hint));
|
|
111
|
+
assert.throws(() => readGraphify('{'), /does not parse/);
|
|
112
|
+
assert.throws(() => readGraphify('[]'), /not an object/);
|
|
113
|
+
assert.throws(() => readGraphify(JSON.stringify({ graph: { schema_version: 1 }, nodes: [] })), /no list of nodes or of links/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('surfacesOf reads the backtick names after "Contract surface touched", never "none"', () => {
|
|
117
|
+
assert.deepEqual(surfacesOf('- Contract surface touched: `POST /orders`, `Order`, `OrderStatus`.'), ['POST /orders', 'Order', 'OrderStatus']);
|
|
118
|
+
assert.deepEqual(surfacesOf('- Contract surface touched: **none** — `none`'), []);
|
|
119
|
+
assert.deepEqual(surfacesOf('no such line'), []);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('tasksOf reads each task and its declared files, dropping paths that leave the repo', () => {
|
|
123
|
+
const t = tasksOf('## T01 — Goal one\r\n- **Files:** `src/a.js`, `./src/b.js`, `src/a.js`\r\n## T02: two\n**Files:** `../x.js`, `/abs.js`, `c\\d.js`\n## Notes\n');
|
|
124
|
+
assert.deepEqual(t, [{ id: 'T01', goal: 'Goal one', files: ['src/a.js', 'src/b.js'] }, { id: 'T02', goal: 'two', files: ['c/d.js'] }]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('ensureBrainDir makes a folder that ignores itself, and refuses a link on the way', () => {
|
|
128
|
+
const root = tmp();
|
|
129
|
+
try {
|
|
130
|
+
ensureBrainDir(root);
|
|
131
|
+
assert.equal(fs.readFileSync(path.join(root, '.sdlc', 'brain', '.gitignore'), 'utf8'), '*\n');
|
|
132
|
+
git(root, 'init', '-q');
|
|
133
|
+
put(path.join(root, '.sdlc', 'brain', 'graph.json'), '{}');
|
|
134
|
+
assert.equal(git(root, 'status', '--porcelain', '--untracked-files=all').stdout.includes('brain'), false, 'nothing under .sdlc/brain/ shows to git');
|
|
135
|
+
const other = tmp();
|
|
136
|
+
const linked = tmp();
|
|
137
|
+
fs.mkdirSync(path.join(linked, '.sdlc'));
|
|
138
|
+
fs.symlinkSync(other, path.join(linked, '.sdlc', 'brain'));
|
|
139
|
+
assert.throws(() => ensureBrainDir(linked), (e) => e.code === 'YAD-STATE-011' && /not a plain folder/.test(e.message));
|
|
140
|
+
assert.deepEqual(fs.readdirSync(other), [], 'nothing written through the link');
|
|
141
|
+
done(other, linked);
|
|
142
|
+
} finally { done(root); }
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('buildRepoGraph runs the vetted command with the LLM pass and the query log off, and keeps graphify-out/ out of git', () => {
|
|
146
|
+
const { ws, root, be } = product();
|
|
147
|
+
try {
|
|
148
|
+
const { runner, calls } = fakeGraphify();
|
|
149
|
+
const r = buildRepoGraph(root, { name: 'backend', target: be }, { runner, env: { PATH: '/x', GRAPHIFY_BACKEND: 'gemini' } });
|
|
150
|
+
assert.deepEqual(r, { ok: true, nodes: 5, edges: 3 });
|
|
151
|
+
const run = calls.find((x) => x.cmd === 'graphify');
|
|
152
|
+
assert.deepEqual(run.args, ['update', '.', '--force']);
|
|
153
|
+
assert.equal(run.opts.cwd, be);
|
|
154
|
+
assert.equal(run.opts.env.GRAPHIFY_BACKEND, 'none', 'ours wins over a backend set in the shell');
|
|
155
|
+
assert.equal(run.opts.env.GRAPHIFY_QUERY_LOG_DISABLE, '1');
|
|
156
|
+
assert.deepEqual(GRAPHIFY_ENV, { GRAPHIFY_BACKEND: 'none', GRAPHIFY_QUERY_LOG_DISABLE: '1' });
|
|
157
|
+
assert.match(fs.readFileSync(path.join(be, '.git', 'info', 'exclude'), 'utf8'), /^graphify-out\/$/m);
|
|
158
|
+
assert.equal(git(be, 'status', '--porcelain').stdout, '', 'graphify-out/ is not seen by git');
|
|
159
|
+
const meta = JSON.parse(fs.readFileSync(path.join(root, '.sdlc', 'brain', 'repos', 'backend', 'meta.json'), 'utf8'));
|
|
160
|
+
assert.equal(meta.head, git(be, 'rev-parse', 'HEAD').stdout.trim());
|
|
161
|
+
assert.equal(meta.schemaVersion, 1);
|
|
162
|
+
// A second run adds the exclude line once.
|
|
163
|
+
excludeGraphifyOut(be, { runner });
|
|
164
|
+
assert.equal(fs.readFileSync(path.join(be, '.git', 'info', 'exclude'), 'utf8').match(/^graphify-out\/$/gm).length, 1);
|
|
165
|
+
} finally { done(ws); }
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('buildRepoGraph reports a failed or unreadable Graphify run, and writes nothing', () => {
|
|
169
|
+
const { ws, root, be } = product();
|
|
170
|
+
try {
|
|
171
|
+
const failing = (cmd, args, opts) => (cmd === 'graphify' ? { ok: false, code: 1, stdout: '', stderr: 'boom\nlast line' } : fakeGraphify().runner(cmd, args, opts));
|
|
172
|
+
assert.deepEqual(buildRepoGraph(root, { name: 'backend', target: be }, { runner: failing }), { ok: false, why: 'graphify failed — last line' });
|
|
173
|
+
const { runner } = fakeGraphify(graphifyGraph({ schema: 9 }));
|
|
174
|
+
assert.match(buildRepoGraph(root, { name: 'backend', target: be }, { runner }).why, /schema_version 9/);
|
|
175
|
+
assert.equal(fs.existsSync(path.join(root, '.sdlc', 'brain', 'repos', 'backend', 'graph.json')), false);
|
|
176
|
+
} finally { done(ws); }
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('composeBrain joins the work items to the code: tasks declare files, surfaces reach handlers and names', () => {
|
|
180
|
+
const { ws, root, be } = product();
|
|
181
|
+
try {
|
|
182
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
183
|
+
const { brain } = composeBrain(root);
|
|
184
|
+
const has = (s, t, rel) => brain.edges.find((e) => e.source === s && e.target === t && e.relation === rel);
|
|
185
|
+
const node = (id) => brain.nodes.find((n) => n.id === id);
|
|
186
|
+
assert.ok(has('epic:EP-checkout', 'story:EP-checkout-S01', 'has-story'));
|
|
187
|
+
assert.ok(has('story:EP-checkout-S01', 'repo:backend', 'builds-in'));
|
|
188
|
+
assert.ok(has('epic:EP-checkout-queue-filter', 'epic:EP-checkout', 'changes'), 'lineage from the index');
|
|
189
|
+
assert.ok(has('story:EP-checkout-S01', 'task:EP-checkout-S01:backend:T01', 'has-task'));
|
|
190
|
+
assert.equal(has('task:EP-checkout-S01:backend:T01', 'file:backend:src/routes.js', 'declares-file').confidence, 'EXTRACTED');
|
|
191
|
+
assert.ok(has('file:backend:src/routes.js', 'code:backend:src_routes_postorders', 'defines'));
|
|
192
|
+
assert.equal(node('file:backend:src/routes.js').missing, undefined, 'a file the code graph knows');
|
|
193
|
+
assert.equal(node('file:backend:src/order/store.js').missing, true, 'declared, and not in the code graph');
|
|
194
|
+
assert.equal(node('file:backend:../outside.js'), undefined);
|
|
195
|
+
assert.ok(has('story:EP-checkout-S01', 'surface:POST /orders', 'touches-surface'));
|
|
196
|
+
assert.equal(has('surface:POST /orders', 'code:backend:src_routes_postorders', 'handled-by').confidence, 'INFERRED', 'from the code-map line');
|
|
197
|
+
assert.equal(has('surface:Order', 'code:backend:src_order_order', 'named-as').confidence, 'INFERRED');
|
|
198
|
+
assert.equal(has('code:backend:src_routes_postorders', 'code:backend:src_order_create', 'calls').score, 1);
|
|
199
|
+
assert.equal(brain.edges.some((e) => e.target === 'code:backend:ghost'), false, 'an edge to a node Graphify never listed is dropped');
|
|
200
|
+
assert.equal(brain.repos.backend.droppedEdges, 1);
|
|
201
|
+
assert.ok(has('task:EP-checkout-S01:backend:T01', 'ship:backend:06edb9e', 'shipped-as'), 'the build log');
|
|
202
|
+
assert.equal(brain.repos.mobile.code, false);
|
|
203
|
+
assert.match(brain.repos.mobile.why, /not cloned here/);
|
|
204
|
+
for (const e of brain.edges) assert.ok(['EXTRACTED', 'INFERRED', 'AMBIGUOUS'].includes(e.confidence), `${e.source} ${e.relation}`);
|
|
205
|
+
} finally { done(ws); }
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('the brain is current until one input changes; Windows line endings hash the same', () => {
|
|
209
|
+
const { ws, root, be } = product();
|
|
210
|
+
try {
|
|
211
|
+
const { runner } = fakeGraphify();
|
|
212
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner });
|
|
213
|
+
writeBrain(root, composeBrain(root).brain);
|
|
214
|
+
assert.equal(brainFreshness(root).state, 'current');
|
|
215
|
+
const story = path.join(root, 'epics', 'EP-checkout', 'stories', 'EP-checkout-S02.md');
|
|
216
|
+
const before = fs.readFileSync(story, 'utf8');
|
|
217
|
+
fs.writeFileSync(story, before.replace(/\n/g, '\r\n'));
|
|
218
|
+
assert.equal(brainFreshness(root).state, 'current', 'CRLF is read as LF');
|
|
219
|
+
fs.writeFileSync(story, `${before}\nmore\n`);
|
|
220
|
+
assert.equal(brainFreshness(root).state, 'behind');
|
|
221
|
+
fs.writeFileSync(story, before);
|
|
222
|
+
fs.appendFileSync(path.join(be, 'specs', 'EP-checkout-S01', 'tasks.md'), '\n## T03 — more\n');
|
|
223
|
+
assert.equal(brainFreshness(root).state, 'behind', 'a code repo\'s tasks.md is an input');
|
|
224
|
+
writeBrain(root, composeBrain(root).brain);
|
|
225
|
+
put(path.join(be, 'src', 'new.js'), '//\n');
|
|
226
|
+
git(be, 'add', '-A');
|
|
227
|
+
git(be, 'commit', '-qm', 'more');
|
|
228
|
+
const f = brainFreshness(root);
|
|
229
|
+
assert.equal(f.state, 'current', 'the merged file still matches the stored graphs');
|
|
230
|
+
assert.equal(f.repos.find((r) => r.name === 'backend').state, 'behind', 'but the code graph is behind the repo');
|
|
231
|
+
} finally { done(ws); }
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('readBrain refuses a file it does not know; queryBrain ranks exact names first', () => {
|
|
235
|
+
const { ws, root, be } = product();
|
|
236
|
+
try {
|
|
237
|
+
assert.equal(readBrain(root), null);
|
|
238
|
+
put(path.join(root, BRAIN_FILE), JSON.stringify({ format: 'other', nodes: [], edges: [] }));
|
|
239
|
+
assert.throws(() => readBrain(root), (e) => e.code === 'YAD-STATE-011' && /format "other"/.test(e.message));
|
|
240
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
241
|
+
const brain = composeBrain(root).brain;
|
|
242
|
+
const m = queryBrain(brain, 'order', { limit: 50 });
|
|
243
|
+
assert.equal(m[0].node.label.toLowerCase(), 'order');
|
|
244
|
+
assert.ok(m.every((x) => x.neighbours.length <= 12));
|
|
245
|
+
assert.deepEqual(queryBrain(brain, ' '), []);
|
|
246
|
+
const s = queryBrain(brain, 'EP-checkout-S01', { limit: 1 })[0];
|
|
247
|
+
assert.ok(s.neighbours.some((x) => x.relation === 'has-story' && x.direction === 'in'));
|
|
248
|
+
} finally { done(ws); }
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('yad brain: build without Graphify writes the work items, query and status read it back, --json answers', () => {
|
|
252
|
+
const { ws, root } = product();
|
|
253
|
+
try {
|
|
254
|
+
let r = yad(root, 'brain', 'status');
|
|
255
|
+
assert.equal(r.status, 0, r.stderr);
|
|
256
|
+
assert.match(r.stdout, /no brain here yet/);
|
|
257
|
+
r = yad(root, 'brain', 'query', 'Order');
|
|
258
|
+
assert.equal(r.status, 1);
|
|
259
|
+
assert.match(r.stdout, /no brain here yet/);
|
|
260
|
+
r = yad(root, 'brain', 'build');
|
|
261
|
+
assert.equal(r.status, 0, r.stderr + r.stdout);
|
|
262
|
+
assert.match(r.stdout, /Graphify is not installed here/);
|
|
263
|
+
assert.match(r.stdout, /wrote \.sdlc\/brain\/graph\.json/);
|
|
264
|
+
const j = JSON.parse(yad(root, 'brain', 'status', '--json').stdout);
|
|
265
|
+
assert.equal(j.state, 'current');
|
|
266
|
+
assert.equal(j.graphify, null);
|
|
267
|
+
assert.equal(j.vetted, GRAPHIFY_VERSION);
|
|
268
|
+
const q = JSON.parse(yad(root, 'brain', 'query', 'POST /orders', '--limit', '2', '--json').stdout);
|
|
269
|
+
assert.equal(q.matches[0].node.id, 'surface:POST /orders');
|
|
270
|
+
assert.equal(q.matches.length, 2);
|
|
271
|
+
assert.equal(yad(root, 'brain', 'query', 'x', '--limit', '0').status, 1);
|
|
272
|
+
assert.equal(yad(root, 'brain', 'frobnicate').status, 1);
|
|
273
|
+
assert.equal(yad(root, 'brain', 'status', 'extra').status, 1);
|
|
274
|
+
assert.equal(yad(root, 'brain', 'build', '--repo', 'nope').status, 1);
|
|
275
|
+
} finally { done(ws); }
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('yad brain refuses a folder that is not a Product', () => {
|
|
279
|
+
const dir = tmp();
|
|
280
|
+
try {
|
|
281
|
+
const r = yad(dir, 'brain', 'status', '--dir', dir);
|
|
282
|
+
assert.equal(r.status, 1);
|
|
283
|
+
assert.match(r.stdout, /no Product here/);
|
|
284
|
+
} finally { done(dir); }
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('the Graphify toolbox entry pins the version the brain runs', () => {
|
|
288
|
+
const t = TOOLBOX.find((x) => x.id === 'graphify');
|
|
289
|
+
assert.equal(t.tier, 'recommended');
|
|
290
|
+
assert.equal(t.vetted.packages[0].version, GRAPHIFY_VERSION);
|
|
291
|
+
assert.ok(t.install.every((i) => / graphifyy$/.test(i.command)), 'the install text names the package; the agent\'s recipe holds the pin');
|
|
292
|
+
assert.deepEqual(RECIPES.graphify.map((s) => s.run), [`uv tool install graphifyy==${GRAPHIFY_VERSION}`]);
|
|
293
|
+
assert.deepEqual(t.usedBy, ['yad brain build']);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// ---- review round 1 ---------------------------------------------------------------------------------
|
|
297
|
+
|
|
298
|
+
const storyFile = (root, id) => path.join(root, 'epics', id.replace(/-S\d+$/, ''), 'stories', `${id}.md`);
|
|
299
|
+
|
|
300
|
+
test('review 1: a repo named like a built-in key never reaches Object.prototype', () => {
|
|
301
|
+
const { ws, root, be } = product();
|
|
302
|
+
try {
|
|
303
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
304
|
+
const f = storyFile(root, 'EP-checkout-S01');
|
|
305
|
+
fs.writeFileSync(f, fs.readFileSync(f, 'utf8').replace('repos: [backend]', 'repos: [backend, constructor, __proto__, toString]'));
|
|
306
|
+
const reg = JSON.parse(fs.readFileSync(path.join(root, '.sdlc', 'repos.json'), 'utf8'));
|
|
307
|
+
reg.repos.push({ ...reg.repos[0], name: '__proto__' }, { ...reg.repos[0], name: 'Backend' });
|
|
308
|
+
put(path.join(root, '.sdlc', 'repos.json'), JSON.stringify(reg));
|
|
309
|
+
const { brain } = composeBrain(root);
|
|
310
|
+
assert.ok(brain.edges.some((e) => e.source === 'story:EP-checkout-S01' && e.target === 'repo:constructor'));
|
|
311
|
+
assert.equal(Object.getPrototypeOf(brain.repos), Object.prototype, 'no prototype was set');
|
|
312
|
+
assert.equal(brain.repos.Backend.why, 'another repo has the same name in another case');
|
|
313
|
+
assert.equal(safeName('__proto__'), false);
|
|
314
|
+
assert.equal(safeName('constructor'), false);
|
|
315
|
+
} finally { done(ws); }
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('review 1: ships come from the Product ledger, so they are drawn when no repo is cloned', () => {
|
|
319
|
+
const { ws, root } = product();
|
|
320
|
+
try {
|
|
321
|
+
fs.rmSync(path.join(root, 'demo-repos'), { recursive: true, force: true });
|
|
322
|
+
const { brain } = composeBrain(root);
|
|
323
|
+
const ships = brain.nodes.filter((n) => n.kind === 'ship');
|
|
324
|
+
assert.ok(ships.length >= 5, `ships: ${ships.length}`);
|
|
325
|
+
assert.ok(brain.edges.some((e) => e.source === 'story:EP-checkout-S01' && e.relation === 'shipped-as'), 'to the story when the task is unknown here');
|
|
326
|
+
} finally { done(ws); }
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test('review 1: a parent epic keeps its own title, whatever order the epics are read in', () => {
|
|
330
|
+
const { ws, root } = product();
|
|
331
|
+
try {
|
|
332
|
+
// The child (EP-checkout-queue-filter) is read after its parent and names it as a placeholder.
|
|
333
|
+
const epic = path.join(root, 'epics', 'EP-checkout', 'epic.md');
|
|
334
|
+
fs.writeFileSync(epic, fs.readFileSync(epic, 'utf8').replace(/^---\n/, '---\ntitle: Checkout for real\n'));
|
|
335
|
+
const { brain } = composeBrain(root);
|
|
336
|
+
assert.equal(brain.nodes.find((n) => n.id === 'epic:EP-checkout').label, 'Checkout for real');
|
|
337
|
+
} finally { done(ws); }
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('review 1: ships with no merge commit stay apart; one merge commit for many tasks is one ship', () => {
|
|
341
|
+
const { ws, root } = product();
|
|
342
|
+
try {
|
|
343
|
+
const log = path.join(root, 'epics', 'EP-checkout', '.sdlc', 'build-log.json');
|
|
344
|
+
const b = JSON.parse(fs.readFileSync(log, 'utf8'));
|
|
345
|
+
b.ships.push(
|
|
346
|
+
{ story: 'EP-checkout-S01', task: 'retro', repo: 'backend', retroactive: true, shippedAt: '2026-01-01' },
|
|
347
|
+
{ story: 'EP-checkout-S03', task: 'retro', repo: 'backend', retroactive: true, shippedAt: '2026-02-01' },
|
|
348
|
+
{ story: 'EP-checkout-S04', task: 'T01', repo: 'mobile', mergeCommit: 'abc1234', pr: 7 },
|
|
349
|
+
{ story: 'EP-checkout-S04', task: 'T02', repo: 'mobile', mergeCommit: 'abc1234', pr: 7 },
|
|
350
|
+
);
|
|
351
|
+
put(log, JSON.stringify(b));
|
|
352
|
+
const { brain } = composeBrain(root);
|
|
353
|
+
const ids = brain.nodes.filter((n) => n.kind === 'ship').map((n) => n.id);
|
|
354
|
+
assert.ok(ids.includes('ship:backend:EP-checkout-S01:retro:') && ids.includes('ship:backend:EP-checkout-S03:retro:'));
|
|
355
|
+
const grouped = brain.nodes.find((n) => n.id === 'ship:mobile:abc1234');
|
|
356
|
+
assert.deepEqual(grouped.tasks, ['EP-checkout-S04/T01', 'EP-checkout-S04/T02']);
|
|
357
|
+
assert.equal(grouped.label, '2 tasks #7');
|
|
358
|
+
} finally { done(ws); }
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('review 1: a declared file git holds is not missing, even when it is not code; a planned one is', () => {
|
|
362
|
+
const { ws, root, be } = product();
|
|
363
|
+
try {
|
|
364
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
365
|
+
const { brain } = composeBrain(root);
|
|
366
|
+
const node = (id) => brain.nodes.find((n) => n.id === id);
|
|
367
|
+
assert.equal(node('file:backend:package.json').missing, undefined);
|
|
368
|
+
assert.equal(node('file:backend:src/order/store.js').missing, true);
|
|
369
|
+
assert.equal(brain.edges.some((e) => e.target === 'file:backend:src/order/store.js' && e.relation === 'holds'), false, 'a repo does not hold a missing file');
|
|
370
|
+
} finally { done(ws); }
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test('review 1: Graphify gets no LLM settings from the shell, matched in any case', () => {
|
|
374
|
+
const env = graphifyEnv({ PATH: '/bin', HOME: '/h', OPENAI_API_KEY: 'k', ANTHROPIC_API_KEY: 'k', gemini_api_key: 'k', OLLAMA_HOST: 'h', AWS_PROFILE: 'p', OPENAI_BASE_URL: 'u', graphify_backend: 'gemini', GRAPHIFY_VIZ_NODE_LIMIT: '1' });
|
|
375
|
+
assert.deepEqual(env, { PATH: '/bin', HOME: '/h', GRAPHIFY_BACKEND: 'none', GRAPHIFY_QUERY_LOG_DISABLE: '1' });
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('review 1: a link or a committed graphify-out/ is refused; a link under .sdlc/brain/repos is never written through', () => {
|
|
379
|
+
const { ws, root, be } = product();
|
|
380
|
+
try {
|
|
381
|
+
const away = tmp();
|
|
382
|
+
fs.symlinkSync(away, path.join(be, 'graphify-out'));
|
|
383
|
+
assert.match(buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner }).why, /not a plain folder/);
|
|
384
|
+
fs.rmSync(path.join(be, 'graphify-out'));
|
|
385
|
+
put(path.join(be, 'graphify-out', 'keep.txt'), 'x');
|
|
386
|
+
git(be, 'add', '-f', 'graphify-out/keep.txt');
|
|
387
|
+
git(be, 'commit', '-qm', 'tracked');
|
|
388
|
+
assert.match(buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner }).why, /committed in this repo/);
|
|
389
|
+
git(be, 'rm', '-rq', 'graphify-out');
|
|
390
|
+
git(be, 'commit', '-qm', 'untracked');
|
|
391
|
+
ensureBrainDir(root);
|
|
392
|
+
fs.symlinkSync(away, path.join(root, '.sdlc', 'brain', 'repos'));
|
|
393
|
+
assert.throws(() => buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner }), /not a plain folder/);
|
|
394
|
+
assert.deepEqual(fs.readdirSync(away), [], 'nothing written through the link');
|
|
395
|
+
done(away);
|
|
396
|
+
} finally { done(ws); }
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test('review 1: status of an unreadable brain exits 1; a flag brain does not take is refused, never searched for', () => {
|
|
400
|
+
const { ws, root } = product();
|
|
401
|
+
try {
|
|
402
|
+
put(path.join(root, BRAIN_FILE), '{');
|
|
403
|
+
let r = yad(root, 'brain', 'status');
|
|
404
|
+
assert.equal(r.status, 1);
|
|
405
|
+
r = yad(root, 'brain', 'status', '--json');
|
|
406
|
+
assert.equal(r.status, 1);
|
|
407
|
+
const j = JSON.parse(r.stdout);
|
|
408
|
+
assert.equal(j.ok, false);
|
|
409
|
+
assert.equal(j.state, 'unreadable');
|
|
410
|
+
r = yad(root, 'brain', 'query', 'Order', '--repoo', 'x');
|
|
411
|
+
assert.equal(r.status, 1);
|
|
412
|
+
assert.match(r.stdout, /does not take --repoo/);
|
|
413
|
+
fs.rmSync(path.join(root, BRAIN_FILE));
|
|
414
|
+
assert.equal(yad(root, 'brain', 'build').status, 0);
|
|
415
|
+
const s = JSON.parse(yad(root, 'brain', 'status', '--json').stdout);
|
|
416
|
+
assert.ok(s.repos.every((x) => !('builtAt' in x)));
|
|
417
|
+
} finally { done(ws); }
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test('review 1: a busy node shows edges in as well as out', () => {
|
|
421
|
+
const nodes = [{ id: 'a', kind: 'k', label: 'center' }, ...Array.from({ length: 30 }, (_, i) => ({ id: `n${i}`, kind: 'k', label: `n${i}` }))];
|
|
422
|
+
const edges = [...Array.from({ length: 20 }, (_, i) => ({ source: 'a', target: `n${i}`, relation: 'out', confidence: 'EXTRACTED' })),
|
|
423
|
+
...Array.from({ length: 10 }, (_, i) => ({ source: `n${20 + i}`, target: 'a', relation: 'in', confidence: 'EXTRACTED' }))];
|
|
424
|
+
const [m] = queryBrain({ nodes, edges }, 'center');
|
|
425
|
+
assert.equal(m.neighbours.length, 12);
|
|
426
|
+
assert.ok(m.neighbours.some((x) => x.direction === 'in') && m.neighbours.some((x) => x.direction === 'out'));
|
|
427
|
+
assert.equal(m.more, 18);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// ---- review round 2 ---------------------------------------------------------------------------------
|
|
431
|
+
|
|
432
|
+
test('review 2: a committed link in place of graph.json, files.txt or meta.json is replaced, never written through', () => {
|
|
433
|
+
const { ws, root, be } = product();
|
|
434
|
+
try {
|
|
435
|
+
const victim = path.join(tmp(), 'victim');
|
|
436
|
+
fs.writeFileSync(victim, 'keep\n');
|
|
437
|
+
const dir = path.join(root, '.sdlc', 'brain', 'repos', 'backend');
|
|
438
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
439
|
+
for (const f of ['graph.json', 'files.txt', 'meta.json']) fs.symlinkSync(victim, path.join(dir, f));
|
|
440
|
+
assert.equal(buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner }).ok, true);
|
|
441
|
+
assert.equal(fs.readFileSync(victim, 'utf8'), 'keep\n');
|
|
442
|
+
for (const f of ['graph.json', 'files.txt', 'meta.json']) assert.equal(fs.lstatSync(path.join(dir, f)).isFile(), true, f);
|
|
443
|
+
assert.deepEqual(fs.readdirSync(dir).filter((f) => f.endsWith('.tmp')), []);
|
|
444
|
+
done(path.dirname(victim));
|
|
445
|
+
} finally { done(ws); }
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test('review 2: a timeout says so; build runs the file found on PATH; one that cannot start is not "installed"', async () => {
|
|
449
|
+
const { ws, root, be } = product();
|
|
450
|
+
try {
|
|
451
|
+
const timedOut = (cmd, args, opts) => (cmd === 'graphify' ? { ok: false, code: null, stdout: '', stderr: 'progress 40%', error: { code: 'ETIMEDOUT' } } : fakeGraphify().runner(cmd, args, opts));
|
|
452
|
+
assert.match(buildRepoGraph(root, { name: 'backend', target: be }, { runner: timedOut }).why, /longer than 20 minutes/);
|
|
453
|
+
const { runBrain, graphifyHere } = await import('./brain.mjs');
|
|
454
|
+
const calls = [];
|
|
455
|
+
const runner = (cmd, args = [], opts = {}) => {
|
|
456
|
+
calls.push(cmd);
|
|
457
|
+
if (cmd === '/opt/x/graphify' && args[0] === '--version') return { ok: true, stdout: `graphify ${GRAPHIFY_VERSION}`, stderr: '' };
|
|
458
|
+
if (cmd === '/opt/x/graphify') { put(path.join(opts.cwd, 'graphify-out', 'graph.json'), JSON.stringify(graphifyGraph())); return { ok: true, stdout: '', stderr: '' }; }
|
|
459
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', ...opts });
|
|
460
|
+
return { ok: r.status === 0, code: r.status, stdout: (r.stdout || '').trim(), stderr: (r.stderr || '').trim() };
|
|
461
|
+
};
|
|
462
|
+
await runBrain(root, { action: 'build', json: false, runner, where: () => '/opt/x/graphify' });
|
|
463
|
+
assert.ok(calls.filter((c) => c === '/opt/x/graphify').length >= 2, 'the version and the update both ran the file found');
|
|
464
|
+
assert.equal(calls.includes('graphify'), false, 'never the bare name');
|
|
465
|
+
assert.equal(composeBrain(root).brain.repos.backend.code, true);
|
|
466
|
+
const cannot = graphifyHere({ where: () => 'C:\\x\\graphify.cmd', runner: () => ({ ok: false, error: { code: 'EINVAL' }, stdout: '', stderr: '' }) });
|
|
467
|
+
assert.deepEqual(cannot, { bin: 'C:\\x\\graphify.cmd', version: null, startError: 'EINVAL' });
|
|
468
|
+
const hung = graphifyHere({ where: () => '/x/graphify', runner: () => ({ ok: false, error: { code: 'ETIMEDOUT' }, stdout: '', stderr: '' }) });
|
|
469
|
+
assert.deepEqual(hung, { bin: '/x/graphify', version: null, startError: 'ETIMEDOUT', hung: true });
|
|
470
|
+
} finally { done(ws); process.exitCode = 0; }
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test('review 2: a grouped ship keeps the first PR found, whatever the row order', () => {
|
|
474
|
+
const { ws, root } = product();
|
|
475
|
+
try {
|
|
476
|
+
const log = path.join(root, 'epics', 'EP-checkout', '.sdlc', 'build-log.json');
|
|
477
|
+
const b = JSON.parse(fs.readFileSync(log, 'utf8'));
|
|
478
|
+
b.ships.push({ story: 'EP-checkout-S04', task: 'T01', repo: 'mobile', mergeCommit: 'def5678', pr: 9 }, { story: 'EP-checkout-S04', task: 'T02', repo: 'mobile', mergeCommit: 'def5678' });
|
|
479
|
+
put(log, JSON.stringify(b));
|
|
480
|
+
assert.equal(composeBrain(root).brain.nodes.find((n) => n.id === 'ship:mobile:def5678').label, '2 tasks #9');
|
|
481
|
+
} finally { done(ws); }
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// ---- review round 3 ---------------------------------------------------------------------------------
|
|
485
|
+
|
|
486
|
+
test('review 3: the merged file is written by a rename too, so a link left at its name is replaced', () => {
|
|
487
|
+
const { ws, root } = product();
|
|
488
|
+
try {
|
|
489
|
+
const victim = path.join(tmp(), 'victim');
|
|
490
|
+
fs.writeFileSync(victim, 'keep\n');
|
|
491
|
+
ensureBrainDir(root);
|
|
492
|
+
fs.symlinkSync(victim, path.join(root, BRAIN_FILE));
|
|
493
|
+
writeBrain(root, composeBrain(root).brain);
|
|
494
|
+
assert.equal(fs.readFileSync(victim, 'utf8'), 'keep\n');
|
|
495
|
+
assert.equal(fs.lstatSync(path.join(root, BRAIN_FILE)).isFile(), true);
|
|
496
|
+
done(path.dirname(victim));
|
|
497
|
+
} finally { done(ws); }
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('review 3: a file name that starts with a space keeps it in the list of files', () => {
|
|
501
|
+
const { ws, root, be } = product();
|
|
502
|
+
try {
|
|
503
|
+
put(path.join(be, ' lead.js'), '//\n');
|
|
504
|
+
git(be, 'add', '-A');
|
|
505
|
+
git(be, 'commit', '-qm', 'lead');
|
|
506
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
507
|
+
const files = fs.readFileSync(path.join(root, '.sdlc', 'brain', 'repos', 'backend', 'files.txt'), 'utf8').split('\n');
|
|
508
|
+
assert.ok(files.includes(' lead.js'), files.slice(0, 3).join('|'));
|
|
509
|
+
} finally { done(ws); }
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
test('review 3: query names the repos whose code moved; status --json says why it cannot read the brain', () => {
|
|
513
|
+
const { ws, root, be } = product();
|
|
514
|
+
try {
|
|
515
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner: fakeGraphify().runner });
|
|
516
|
+
writeBrain(root, composeBrain(root).brain);
|
|
517
|
+
let q = JSON.parse(yadGit(root, 'brain', 'query', 'Order', '--json').stdout);
|
|
518
|
+
assert.deepEqual(q.codeBehind, []);
|
|
519
|
+
put(path.join(be, 'src', 'later.js'), '//\n');
|
|
520
|
+
git(be, 'add', '-A');
|
|
521
|
+
git(be, 'commit', '-qm', 'later');
|
|
522
|
+
q = JSON.parse(yadGit(root, 'brain', 'query', 'Order', '--json').stdout);
|
|
523
|
+
assert.deepEqual(q.codeBehind, ['backend']);
|
|
524
|
+
const b = JSON.parse(fs.readFileSync(path.join(root, BRAIN_FILE), 'utf8'));
|
|
525
|
+
b.repos = ['odd'];
|
|
526
|
+
put(path.join(root, BRAIN_FILE), JSON.stringify(b));
|
|
527
|
+
assert.deepEqual(JSON.parse(yadGit(root, 'brain', 'query', 'Order', '--json').stdout).codeBehind, [], 'an odd repos field is ignored');
|
|
528
|
+
put(path.join(root, BRAIN_FILE), '{');
|
|
529
|
+
const s = JSON.parse(yad(root, 'brain', 'status', '--json').stdout);
|
|
530
|
+
assert.equal(s.code, 'YAD-STATE-011');
|
|
531
|
+
assert.match(s.error, /does not parse/);
|
|
532
|
+
assert.match(s.hint, /yad brain build/);
|
|
533
|
+
} finally { done(ws); }
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
test('review 3: a Graphify that cannot start builds the work items only, and --json names why', async () => {
|
|
537
|
+
const { ws, root } = product();
|
|
538
|
+
try {
|
|
539
|
+
const { runBrain } = await import('./brain.mjs');
|
|
540
|
+
const runner = (cmd, args = [], opts = {}) => {
|
|
541
|
+
if (cmd === '/opt/x/graphify') return { ok: false, code: null, stdout: '', stderr: '', error: { code: 'EINVAL' } };
|
|
542
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', ...opts });
|
|
543
|
+
return { ok: r.status === 0, code: r.status, stdout: (r.stdout || '').trim(), stderr: (r.stderr || '').trim() };
|
|
544
|
+
};
|
|
545
|
+
await runBrain(root, { action: 'build', runner, where: () => '/opt/x/graphify' });
|
|
546
|
+
const brain = readBrain(root);
|
|
547
|
+
assert.ok(brain.nodes.some((n) => n.kind === 'story'));
|
|
548
|
+
assert.equal(brain.repos.backend.code, false);
|
|
549
|
+
assert.equal(fs.existsSync(path.join(root, '.sdlc', 'brain', 'repos', 'backend')), false, 'no repo was built');
|
|
550
|
+
} finally { done(ws); process.exitCode = 0; }
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
test('review 3: a grouped ship keeps the first PR found in either row order', () => {
|
|
554
|
+
const { ws, root } = product();
|
|
555
|
+
try {
|
|
556
|
+
const log = path.join(root, 'epics', 'EP-checkout', '.sdlc', 'build-log.json');
|
|
557
|
+
const b = JSON.parse(fs.readFileSync(log, 'utf8'));
|
|
558
|
+
b.ships.push({ story: 'EP-checkout-S04', task: 'T02', repo: 'mobile', mergeCommit: 'fed9876' }, { story: 'EP-checkout-S04', task: 'T01', repo: 'mobile', mergeCommit: 'fed9876', pr: 11 });
|
|
559
|
+
put(log, JSON.stringify(b));
|
|
560
|
+
assert.equal(composeBrain(root).brain.nodes.find((n) => n.id === 'ship:mobile:fed9876').label, '2 tasks #11');
|
|
561
|
+
} finally { done(ws); }
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
// ---- review round 4 ---------------------------------------------------------------------------------
|
|
565
|
+
|
|
566
|
+
test('review 4: --json build and status name a Graphify that does not start; the key is absent otherwise', () => {
|
|
567
|
+
const { ws, root } = product();
|
|
568
|
+
const bin = fs.mkdtempSync(path.join(os.tmpdir(), 'yad-brain-bin-'));
|
|
569
|
+
try {
|
|
570
|
+
// A `graphify` on PATH that cannot be started: no permission to run it.
|
|
571
|
+
fs.writeFileSync(path.join(bin, 'graphify'), '#!/bin/sh\necho graphify 0.9.108\n', { mode: 0o644 });
|
|
572
|
+
fs.symlinkSync(path.join(GIT_DIR, 'git'), path.join(bin, 'git'));
|
|
573
|
+
const env = { ...process.env, PATH: [path.dirname(process.execPath), bin].join(path.delimiter), NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' };
|
|
574
|
+
const run = (...a) => JSON.parse(spawnSync(process.execPath, [YAD, ...a], { cwd: root, encoding: 'utf8', env }).stdout);
|
|
575
|
+
// whereOnPath skips a file it may not run, so nothing is found: graphify null, no error key.
|
|
576
|
+
let b = run('brain', 'build', '--json');
|
|
577
|
+
assert.equal(b.graphify, null);
|
|
578
|
+
assert.equal('graphifyError' in b, false);
|
|
579
|
+
assert.equal('graphifyError' in run('brain', 'status', '--json'), false);
|
|
580
|
+
// Runnable but failing to start the interpreter it names: the spawn errors.
|
|
581
|
+
fs.writeFileSync(path.join(bin, 'graphify'), '#!/no/such/interpreter\n');
|
|
582
|
+
fs.chmodSync(path.join(bin, 'graphify'), 0o755); // a write to a file that exists keeps its old mode
|
|
583
|
+
b = run('brain', 'build', '--json');
|
|
584
|
+
assert.equal(b.graphify, null);
|
|
585
|
+
assert.equal(typeof b.graphifyError, 'string');
|
|
586
|
+
assert.ok(b.warnings.some((w) => /cannot be started/.test(w)));
|
|
587
|
+
assert.equal(typeof run('brain', 'status', '--json').graphifyError, 'string');
|
|
588
|
+
} finally { done(ws, bin); }
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// ---- E179: focused questions, and the skills that ask them ---------------------------------------------
|
|
592
|
+
|
|
593
|
+
const { fileAbout, storyAbout, fileCandidates } = await import('./brain-about.mjs');
|
|
594
|
+
const { BRAIN_SKILLS, brainBlockLines, syncBrainSkills, BRAIN_BLOCK_BEGIN, BRAIN_BLOCK_END } = await import('./brain-skills.mjs');
|
|
595
|
+
const SKILLS = path.join(HERE, '..', 'skills');
|
|
596
|
+
|
|
597
|
+
// The golden Product with its backend mapped by the fake Graphify, composed and written: a brain with both layers.
|
|
598
|
+
function builtProduct() {
|
|
599
|
+
const p = product();
|
|
600
|
+
buildRepoGraph(p.root, { name: 'backend', target: p.be }, { runner: fakeGraphify().runner });
|
|
601
|
+
const { brain } = composeBrain(p.root);
|
|
602
|
+
writeBrain(p.root, brain);
|
|
603
|
+
return { ...p, brain };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
test('E179 fileAbout: who declares a file, what it defines, the files that use it and that it uses', () => {
|
|
607
|
+
const { ws, brain } = builtProduct();
|
|
608
|
+
try {
|
|
609
|
+
const r = fileAbout(brain, 'backend/src/order/index.js');
|
|
610
|
+
assert.equal(r.found, 'one');
|
|
611
|
+
const a = r.about;
|
|
612
|
+
assert.deepEqual(a.file, { id: 'file:backend:src/order/index.js', repo: 'backend', path: 'src/order/index.js' });
|
|
613
|
+
const t01 = a.declaredBy.find((d) => d.task.short === 'T01');
|
|
614
|
+
assert.equal(t01.story.id, 'story:EP-checkout-S01');
|
|
615
|
+
assert.equal(t01.epic.id, 'epic:EP-checkout');
|
|
616
|
+
assert.deepEqual(a.defines.map((d) => d.label), ['index.js', 'Order', 'create()'], 'in file order');
|
|
617
|
+
assert.deepEqual(a.usedBy.map((u) => [u.file, u.relations, u.confidence]), [['backend/src/routes.js', ['calls'], 'EXTRACTED']]);
|
|
618
|
+
assert.ok(a.surfaces.some((s) => s.label === 'Order' && s.via.includes('named-as')));
|
|
619
|
+
assert.ok(a.shippedIn.length >= 1, 'T01 shipped');
|
|
620
|
+
// The other direction, and an edge inside one file (routes.js contains postOrders) is not a use.
|
|
621
|
+
const routes = fileAbout(brain, 'src/routes.js').about;
|
|
622
|
+
assert.deepEqual(routes.uses.map((u) => u.file), ['backend/src/order/index.js']);
|
|
623
|
+
assert.deepEqual(routes.usedBy, []);
|
|
624
|
+
// A declared file the code does not hold yet.
|
|
625
|
+
const store = fileAbout(brain, 'backend/src/order/store.js').about;
|
|
626
|
+
assert.equal(store.file.missing, true);
|
|
627
|
+
assert.deepEqual(store.defines, []);
|
|
628
|
+
// --limit cuts each list and says how many were left out.
|
|
629
|
+
const cut = fileAbout(brain, 'backend/src/order/index.js', { limit: 1 }).about;
|
|
630
|
+
assert.equal(cut.defines.length, 1);
|
|
631
|
+
assert.equal(cut.more.defines, 2);
|
|
632
|
+
// Not in the brain: suggestions by the file's own name.
|
|
633
|
+
const none = fileAbout(brain, 'backend/src/nope/index.js');
|
|
634
|
+
assert.equal(none.found, 'none');
|
|
635
|
+
assert.equal(none.suggestions[0], 'backend/src/order/index.js', 'the same name in another folder');
|
|
636
|
+
} finally { done(ws); }
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test('E179 fileCandidates: <repo>/<path> or a bare path; a path in two repos is ambiguous', () => {
|
|
640
|
+
const file = (repo, p) => ({ id: `file:${repo}:${p}`, kind: 'file', label: p, repo });
|
|
641
|
+
const brain = { nodes: [file('backend', 'src/a.js'), file('mobile', 'src/a.js'), file('src', 'x.js'), file('web', 'src/x.js')], edges: [] };
|
|
642
|
+
assert.deepEqual(fileCandidates(brain, 'backend/src/a.js').map((n) => n.id), ['file:backend:src/a.js']);
|
|
643
|
+
assert.equal(fileAbout(brain, 'src/a.js').found, 'many');
|
|
644
|
+
assert.deepEqual(fileAbout(brain, 'src/a.js').candidates, ['backend/src/a.js', 'mobile/src/a.js']);
|
|
645
|
+
// A repo named like a folder: both readings are taken, so neither file hides the other.
|
|
646
|
+
assert.deepEqual(fileCandidates(brain, 'src/x.js').map((n) => n.id), ['file:src:x.js', 'file:web:src/x.js']);
|
|
647
|
+
assert.deepEqual(fileCandidates(brain, './backend/src/a.js').map((n) => n.id), ['file:backend:src/a.js']);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
test('E179 storyAbout: tasks with their files and ships; every declared file once; an unknown story suggests', () => {
|
|
651
|
+
const { ws, brain } = builtProduct();
|
|
652
|
+
try {
|
|
653
|
+
const a = storyAbout(brain, 'EP-checkout-S01').about;
|
|
654
|
+
assert.equal(a.epic.id, 'epic:EP-checkout');
|
|
655
|
+
assert.ok(a.repos.includes('backend'));
|
|
656
|
+
assert.deepEqual(a.tasks.map((t) => t.short), ['T01', 'T02']);
|
|
657
|
+
assert.deepEqual(a.tasks[0].files.map((f) => f.path), ['src/order/index.js', 'src/order/store.js', 'src/routes.js']);
|
|
658
|
+
assert.equal(a.tasks[0].files.find((f) => f.path === 'src/order/store.js').missing, true);
|
|
659
|
+
assert.ok(a.tasks[0].shipped.length >= 1);
|
|
660
|
+
assert.equal(new Set(a.files.map((f) => f.file)).size, a.files.length, 'each file once');
|
|
661
|
+
assert.ok(a.surfaces.includes('POST /orders'));
|
|
662
|
+
const none = storyAbout(brain, 'S01');
|
|
663
|
+
assert.equal(none.found, 'none');
|
|
664
|
+
assert.ok(none.suggestions.includes('EP-checkout-S01'));
|
|
665
|
+
} finally { done(ws); }
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
test('E179 yad brain file / story: --json answers, plain text, and every refusal', () => {
|
|
669
|
+
const { ws, root } = product();
|
|
670
|
+
try {
|
|
671
|
+
let r = yadGit(root, 'brain', 'file', 'backend/src/routes.js');
|
|
672
|
+
assert.equal(r.status, 1);
|
|
673
|
+
assert.match(r.stdout, /no brain here yet/);
|
|
674
|
+
buildRepoGraph(root, { name: 'backend', target: path.join(root, 'demo-repos', 'backend') }, { runner: fakeGraphify().runner });
|
|
675
|
+
writeBrain(root, composeBrain(root).brain);
|
|
676
|
+
r = yadGit(root, 'brain', 'file', 'backend/src/order/index.js', '--json');
|
|
677
|
+
assert.equal(r.status, 0, r.stderr + r.stdout);
|
|
678
|
+
const j = JSON.parse(r.stdout);
|
|
679
|
+
assert.equal(j.command, 'brain file');
|
|
680
|
+
assert.deepEqual(j.codeBehind, []);
|
|
681
|
+
for (const k of ['file', 'declaredBy', 'defines', 'usedBy', 'uses', 'shippedIn', 'surfaces', 'more']) assert.ok(k in j, k);
|
|
682
|
+
r = yadGit(root, 'brain', 'file', 'src/order/index.js', '--repo', 'backend');
|
|
683
|
+
assert.equal(r.status, 0, r.stderr);
|
|
684
|
+
assert.match(r.stdout, /Used by\n {2}backend\/src\/routes\.js {2}calls/);
|
|
685
|
+
r = yadGit(root, 'brain', 'story', 'EP-checkout-S01', '--json');
|
|
686
|
+
assert.equal(r.status, 0, r.stderr);
|
|
687
|
+
assert.equal(JSON.parse(r.stdout).command, 'brain story');
|
|
688
|
+
assert.match(yadGit(root, 'brain', 'story', 'EP-checkout-S01').stdout, /T01 — Add `POST \/orders` route/);
|
|
689
|
+
// Refusals: no name, two names, a name the brain does not hold, flags that are not theirs.
|
|
690
|
+
for (const args of [['file'], ['file', 'a', 'b'], ['story'], ['story', 'EP-checkout-S01', '--repo', 'backend'],
|
|
691
|
+
['file', 'backend/nope.js'], ['story', 'EP-nope-S01'], ['file', 'backend/src/routes.js', '--open'], ['story', 'EP-checkout-S01', '--limit', '0']]) {
|
|
692
|
+
const x = yadGit(root, 'brain', ...args);
|
|
693
|
+
assert.equal(x.status, 1, args.join(' '));
|
|
694
|
+
}
|
|
695
|
+
assert.match(yadGit(root, 'brain', 'file', 'backend/src/order/indx.js').stdout, /did you mean: backend\/src\/order\/index\.js/, 'a typo: the folder');
|
|
696
|
+
assert.match(yadGit(root, 'brain', 'file', 'backend/lib/routes.js').stdout, /did you mean: backend\/src\/routes\.js/, 'the wrong folder: the name');
|
|
697
|
+
} finally { done(ws); }
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
test('E179 the four skills hold the brain block exactly, and no other skill holds it', () => {
|
|
701
|
+
assert.deepEqual(Object.keys(BRAIN_SKILLS).sort(), ['yad-architecture', 'yad-implement', 'yad-spec', 'yad-stories']);
|
|
702
|
+
for (const skill of Object.keys(BRAIN_SKILLS)) {
|
|
703
|
+
const text = fs.readFileSync(path.join(SKILLS, skill, 'SKILL.md'), 'utf8');
|
|
704
|
+
const lines = text.split(/\r?\n/);
|
|
705
|
+
const b = lines.indexOf(BRAIN_BLOCK_BEGIN);
|
|
706
|
+
const e = lines.indexOf(BRAIN_BLOCK_END);
|
|
707
|
+
assert.ok(b >= 0 && e > b, `${skill} has the markers`);
|
|
708
|
+
assert.deepEqual(lines.slice(b + 1, e), brainBlockLines(skill), `${skill}: run node scripts/brain-skills.mjs`);
|
|
709
|
+
const block = lines.slice(b + 1, e).join('\n');
|
|
710
|
+
assert.match(block, /`yad brain status --json`/);
|
|
711
|
+
assert.match(block, /`missing` or `unreadable`.*the brain is \*\*none\*\*/);
|
|
712
|
+
assert.match(block, /never stop for it/);
|
|
713
|
+
// Review 1: a repo whose code moved is "behind"; the build is suggested, never run in the step; the
|
|
714
|
+
// record step is done for "none" too; a refusal means go on; the rules above still stand.
|
|
715
|
+
assert.match(block, /any repo `behind` or `unknown`/);
|
|
716
|
+
assert.match(block, /Do not run it inside this step/);
|
|
717
|
+
assert.match(block, /Skip step 2, .*, and still do step 3/);
|
|
718
|
+
assert.match(block, /A refusal .* go on without it/);
|
|
719
|
+
assert.match(block, /never lifts a rule above/);
|
|
720
|
+
}
|
|
721
|
+
assert.match(brainBlockLines('yad-stories').join('\n'), /Never drop scope yourself/);
|
|
722
|
+
assert.match(brainBlockLines('yad-stories').join('\n'), /never change the key after the stories review/);
|
|
723
|
+
// Review 2: the question has a place to go; the stale record keeps its fields; the light spec is re-judged.
|
|
724
|
+
assert.match(brainBlockLines('yad-stories').join('\n'), /ask the person before you write it.*Step 7 report/);
|
|
725
|
+
for (const s of ['yad-architecture', 'yad-stories']) assert.match(brainBlockLines(s).join('\n'), /repos: \[\.\.\.\], loaded: <date>, stale: true, brain: <state>/);
|
|
726
|
+
assert.match(brainBlockLines('yad-spec').join('\n'), /touches the contract surface ends the light spec: it must be redone as a full spec/);
|
|
727
|
+
assert.match(brainBlockLines('yad-spec').join('\n'), /Never write the light spec's `link\.md` \(Step 6\) for it, whatever the answer/);
|
|
728
|
+
assert.match(brainBlockLines('yad-spec').join('\n'), /`high` is the person's choice.*until they answer, do not write `link\.md`.*- Q: the brain added a high-risk file/);
|
|
729
|
+
assert.match(brainBlockLines('yad-spec').join('\n'), /`tasks` leg, which writes nothing, only report/);
|
|
730
|
+
// yad-spec's block comes after its tasks are written (Step 5), not before.
|
|
731
|
+
const spec = fs.readFileSync(path.join(SKILLS, 'yad-spec', 'SKILL.md'), 'utf8');
|
|
732
|
+
assert.ok(spec.indexOf(BRAIN_BLOCK_BEGIN) > spec.indexOf('### Step 5') && spec.indexOf(BRAIN_BLOCK_BEGIN) < spec.indexOf('### Step 6'));
|
|
733
|
+
for (const skill of fs.readdirSync(SKILLS)) {
|
|
734
|
+
if (Object.hasOwn(BRAIN_SKILLS, skill)) continue;
|
|
735
|
+
const f = path.join(SKILLS, skill, 'SKILL.md');
|
|
736
|
+
if (fs.existsSync(f)) assert.equal(fs.readFileSync(f, 'utf8').includes('<!-- generated: brain '), false, skill);
|
|
737
|
+
}
|
|
738
|
+
const r = spawnSync(process.execPath, [path.join(HERE, '..', 'scripts', 'brain-skills.mjs'), '--check'], { encoding: 'utf8' });
|
|
739
|
+
assert.equal(r.status, 0, r.stdout + r.stderr);
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
test('E179 syncBrainSkills writes a stale block, refuses missing markers, and refuses the block in another skill', () => {
|
|
743
|
+
const dir = tmp();
|
|
744
|
+
try {
|
|
745
|
+
const marked = `# x\n\n## Step 1\n${BRAIN_BLOCK_BEGIN}\nold\n${BRAIN_BLOCK_END}\n\n## Step 2\n`;
|
|
746
|
+
put(path.join(dir, 'yad-spec', 'SKILL.md'), marked);
|
|
747
|
+
put(path.join(dir, 'yad-implement', 'SKILL.md'), '# no markers\n');
|
|
748
|
+
put(path.join(dir, 'yad-epic', 'SKILL.md'), marked);
|
|
749
|
+
let r = syncBrainSkills(dir, { check: true });
|
|
750
|
+
assert.deepEqual(r.stale, ['yad-spec']);
|
|
751
|
+
assert.deepEqual(r.wrote, []);
|
|
752
|
+
assert.deepEqual(r.refused.map((x) => x.skill).sort(), ['yad-architecture', 'yad-epic', 'yad-implement', 'yad-stories'], 'two have no SKILL.md, one no markers, one holds a block it must not');
|
|
753
|
+
r = syncBrainSkills(dir);
|
|
754
|
+
assert.deepEqual(r.wrote, ['yad-spec']);
|
|
755
|
+
const text = fs.readFileSync(path.join(dir, 'yad-spec', 'SKILL.md'), 'utf8');
|
|
756
|
+
assert.ok(text.startsWith('# x\n\n## Step 1\n') && text.endsWith(`${BRAIN_BLOCK_END}\n\n## Step 2\n`), 'only the block changed');
|
|
757
|
+
assert.equal(fs.readFileSync(path.join(dir, 'yad-epic', 'SKILL.md'), 'utf8'), marked, 'a refused skill is left as it is');
|
|
758
|
+
assert.deepEqual(syncBrainSkills(dir, { check: true }).stale, []);
|
|
759
|
+
} finally { done(dir); }
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
test('E179 review 1: --repo settles an ambiguity and never answers from another repo; .\\ paths match', () => {
|
|
763
|
+
const file = (repo, p) => ({ id: `file:${repo}:${p}`, kind: 'file', label: p, repo });
|
|
764
|
+
const brain = { nodes: [file('api', 'src/a.js'), file('web', 'api/src/a.js'), file('web', 'api/x.js')], edges: [] };
|
|
765
|
+
// `api/src/a.js` reads two ways; --repo picks one.
|
|
766
|
+
assert.equal(fileAbout(brain, 'api/src/a.js').found, 'many');
|
|
767
|
+
assert.equal(fileAbout(brain, 'src/a.js', { repo: 'api' }).about.file.id, 'file:api:src/a.js');
|
|
768
|
+
assert.equal(fileAbout(brain, 'api/src/a.js', { repo: 'web' }).about.file.id, 'file:web:api/src/a.js');
|
|
769
|
+
// A path only another repo holds is not this repo's file.
|
|
770
|
+
assert.equal(fileAbout(brain, 'x.js', { repo: 'api' }).found, 'none');
|
|
771
|
+
// A Windows-style relative path.
|
|
772
|
+
assert.equal(fileAbout(brain, '.\\src\\a.js', { repo: 'api' }).about.file.id, 'file:api:src/a.js');
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
test('E179 review 1: syncBrainSkills refuses one of the four skills when its SKILL.md is gone', () => {
|
|
776
|
+
const dir = tmp();
|
|
777
|
+
try {
|
|
778
|
+
for (const s of ['yad-architecture', 'yad-stories', 'yad-spec']) put(path.join(dir, s, 'SKILL.md'), `${BRAIN_BLOCK_BEGIN}\n${BRAIN_BLOCK_END}\n`);
|
|
779
|
+
const r = syncBrainSkills(dir, { check: true });
|
|
780
|
+
assert.deepEqual(r.refused.map((x) => x.skill), ['yad-implement']);
|
|
781
|
+
assert.match(r.refused[0].reason, /cannot be read/);
|
|
782
|
+
} finally { done(dir); }
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
test('E179 review 1: yad brain story prints the ships recorded on the story, so done work shows with no repo cloned', () => {
|
|
786
|
+
const { ws, root } = product();
|
|
787
|
+
try {
|
|
788
|
+
// No code graph and the backend's tasks unreadable: the ledger's ships attach to the story itself.
|
|
789
|
+
fs.rmSync(path.join(root, 'demo-repos', 'backend', 'specs'), { recursive: true, force: true });
|
|
790
|
+
writeBrain(root, composeBrain(root).brain);
|
|
791
|
+
const j = JSON.parse(yadGit(root, 'brain', 'story', 'EP-checkout-S01', '--json').stdout);
|
|
792
|
+
assert.ok(j.shipped.length >= 1, 'the ledger has ships for this story');
|
|
793
|
+
assert.match(yadGit(root, 'brain', 'story', 'EP-checkout-S01').stdout, /shipped: /);
|
|
794
|
+
} finally { done(ws); }
|
|
795
|
+
});
|