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,381 @@
|
|
|
1
|
+
// E177: `yad brain view` — the brain drawn in a browser, from a locked-down local server or one file.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import http from 'node:http';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
|
|
12
|
+
if (process.env.NODE_TEST_CONTEXT) {
|
|
13
|
+
const write = process.stdout.write;
|
|
14
|
+
for (const k of ['log', 'info']) {
|
|
15
|
+
const orig = console[k];
|
|
16
|
+
console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
process.env.YAD_NO_UPDATE_NOTIFIER = '1';
|
|
20
|
+
|
|
21
|
+
const { viewModel, startBrainServer, snapshotHTML, scriptSafeJSON, runBrainView, CSP, WARN_ABOVE } = await import('./brain-view.mjs');
|
|
22
|
+
const { VENDORED } = await import('./brain-vendor.mjs');
|
|
23
|
+
const { composeBrain, buildRepoGraph, writeBrain, BRAIN_FILE, GRAPHIFY_VERSION } = await import('./brain.mjs');
|
|
24
|
+
const { vettingProblems } = await import('./toolbox.mjs');
|
|
25
|
+
const { classify, readAllowList } = await import('./agent-rules.mjs');
|
|
26
|
+
|
|
27
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
const YAD = path.join(HERE, '..', 'bin', 'yad.mjs');
|
|
29
|
+
const GOLDEN = path.join(HERE, 'fixtures', 'golden-v3');
|
|
30
|
+
const VENDOR = path.join(HERE, 'brain', 'vendor');
|
|
31
|
+
|
|
32
|
+
const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-brain-view-')));
|
|
33
|
+
const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
|
|
34
|
+
const done = (...dirs) => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }));
|
|
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
|
+
const yad = (cwd, ...a) => spawnSync(process.execPath, [YAD, ...a], {
|
|
37
|
+
cwd, encoding: 'utf8',
|
|
38
|
+
env: { ...process.env, PATH: path.dirname(process.execPath), NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' },
|
|
39
|
+
});
|
|
40
|
+
// A runner that plays git for `codeBehind` (rev-parse) and nothing else: no repo's code has moved.
|
|
41
|
+
const quiet = () => ({ ok: false, code: 1, stdout: '', stderr: '' });
|
|
42
|
+
|
|
43
|
+
// Graphify's graph as 0.9.108 writes it: edges under `links`.
|
|
44
|
+
const graphifyGraph = () => ({
|
|
45
|
+
directed: false, multigraph: false, graph: { schema_version: 1, graphify_version: '0.9.108' },
|
|
46
|
+
nodes: [
|
|
47
|
+
{ id: 'src_routes', label: 'routes.js', source_file: 'src/routes.js', source_location: 'L1' },
|
|
48
|
+
{ id: 'src_routes_postorders', label: 'postOrders()', source_file: 'src/routes.js', source_location: 'L9' },
|
|
49
|
+
{ id: 'src_order_index', label: 'index.js', source_file: 'src/order/index.js', source_location: 'L1' },
|
|
50
|
+
{ id: 'src_order_create', label: 'create()', source_file: 'src/order/index.js', source_location: 'L4' },
|
|
51
|
+
{ id: 'src_order_order', label: 'Order', source_file: 'src/order/index.js', source_location: 'L2' },
|
|
52
|
+
{ id: 'lib_util', label: 'util.js', source_file: 'lib/util.js', source_location: 'L1' },
|
|
53
|
+
{ id: 'lib_util_pad', label: 'pad()', source_file: 'lib/util.js', source_location: 'L3' },
|
|
54
|
+
],
|
|
55
|
+
links: [
|
|
56
|
+
{ source: 'src_routes_postorders', target: 'src_order_create', relation: 'calls', confidence: 'EXTRACTED' },
|
|
57
|
+
{ source: 'src_routes', target: 'src_routes_postorders', relation: 'contains', confidence: 'EXTRACTED' },
|
|
58
|
+
{ source: 'lib_util', target: 'lib_util_pad', relation: 'contains', confidence: 'EXTRACTED' },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// The golden Product, its backend cloned with one story's tasks, and the brain built from it.
|
|
63
|
+
function product() {
|
|
64
|
+
const ws = tmp();
|
|
65
|
+
const root = path.join(ws, 'product');
|
|
66
|
+
fs.cpSync(GOLDEN, root, { recursive: true });
|
|
67
|
+
const be = path.join(root, 'demo-repos', 'backend');
|
|
68
|
+
put(path.join(be, 'src', 'routes.js'), '// routes\n');
|
|
69
|
+
put(path.join(be, 'specs', 'EP-checkout-S01', 'tasks.md'), [
|
|
70
|
+
'# Tasks — EP-checkout-S01 (backend)', '',
|
|
71
|
+
'## T01 — Add `POST /orders` route + create path',
|
|
72
|
+
'- **Files:** `src/order/index.js`, `src/routes.js`', '',
|
|
73
|
+
].join('\n'));
|
|
74
|
+
git(be, 'init', '-q');
|
|
75
|
+
git(be, 'add', '-A');
|
|
76
|
+
git(be, 'commit', '-qm', 'init');
|
|
77
|
+
const runner = (cmd, args = [], opts = {}) => {
|
|
78
|
+
if (cmd === 'graphify' && args[0] === 'update') {
|
|
79
|
+
put(path.join(opts.cwd, 'graphify-out', 'graph.json'), JSON.stringify(graphifyGraph()));
|
|
80
|
+
return { ok: true, code: 0, stdout: '', stderr: '' };
|
|
81
|
+
}
|
|
82
|
+
if (cmd === 'graphify') return { ok: true, code: 0, stdout: `graphify ${GRAPHIFY_VERSION}`, stderr: '' };
|
|
83
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', ...opts });
|
|
84
|
+
return { ok: r.status === 0, code: r.status, stdout: (r.stdout || '').trim(), stderr: (r.stderr || '').trim() };
|
|
85
|
+
};
|
|
86
|
+
buildRepoGraph(root, { name: 'backend', target: be }, { runner });
|
|
87
|
+
const { brain } = composeBrain(root);
|
|
88
|
+
writeBrain(root, brain);
|
|
89
|
+
return { ws, root, be, brain };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// A raw request, so the test controls the Host header and the path exactly (fetch would normalise both).
|
|
93
|
+
function raw(port, { method = 'GET', pathname = '/', host = `127.0.0.1:${port}` } = {}) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const req = http.request({ host: '127.0.0.1', port, method, path: pathname, headers: { Host: host } }, (res) => {
|
|
96
|
+
let body = '';
|
|
97
|
+
res.on('data', (d) => { body += d; });
|
|
98
|
+
res.on('end', () => resolve({ status: res.statusCode, headers: res.headers, body }));
|
|
99
|
+
});
|
|
100
|
+
req.on('error', reject);
|
|
101
|
+
req.end();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
test('the view model: two layers, a colour per kind, the work and the code it names by default, and filters', () => {
|
|
106
|
+
const { ws, brain } = product();
|
|
107
|
+
try {
|
|
108
|
+
const m = viewModel(brain, { codeBehind: [], builtAt: '2026-11-13T00:00:00.000Z' });
|
|
109
|
+
const at = (id) => m.nodes.find((n) => n.id === id);
|
|
110
|
+
assert.equal(at('epic:EP-checkout').layer, 'work');
|
|
111
|
+
assert.equal(at('story:EP-checkout-S01').layer, 'work');
|
|
112
|
+
assert.equal(at('code:backend:src_routes_postorders').layer, 'code');
|
|
113
|
+
assert.notEqual(at('epic:EP-checkout').colour, at('story:EP-checkout-S01').colour);
|
|
114
|
+
assert.equal(at('file:backend:src/routes.js').inDefault, true, 'a file a task declares');
|
|
115
|
+
assert.equal(at('code:backend:src_routes_postorders').inDefault, true, 'code a declared file defines');
|
|
116
|
+
assert.equal(at('file:backend:lib/util.js').inDefault, false, 'a file no work names');
|
|
117
|
+
assert.equal(at('code:backend:lib_util_pad').inDefault, false, 'code no work names');
|
|
118
|
+
assert.equal(m.defaultCount, m.nodes.filter((n) => n.inDefault).length);
|
|
119
|
+
assert.ok(m.defaultCount < m.nodes.length);
|
|
120
|
+
for (const e of m.edges) assert.ok(Number.isInteger(e.s) && Number.isInteger(e.t) && m.nodes[e.s] && m.nodes[e.t]);
|
|
121
|
+
assert.ok(m.edges.some((e) => e.confidence === 'INFERRED'));
|
|
122
|
+
const epic = m.filters.epics.find((f) => f.id === 'epic:EP-checkout');
|
|
123
|
+
const ids = new Set(epic.nodes.map((i) => m.nodes[i].id));
|
|
124
|
+
for (const id of ['epic:EP-checkout', 'story:EP-checkout-S01', 'task:EP-checkout-S01:backend:T01', 'file:backend:src/routes.js', 'code:backend:src_routes_postorders', 'repo:backend']) assert.ok(ids.has(id), id);
|
|
125
|
+
assert.equal(ids.has('code:backend:lib_util_pad'), false, 'code the epic never names');
|
|
126
|
+
const repo = m.filters.repos.find((f) => f.id === 'repo:backend');
|
|
127
|
+
assert.ok(repo.nodes.map((i) => m.nodes[i].id).includes('story:EP-checkout-S01'), 'a story that builds in it');
|
|
128
|
+
const repoIds = repo.nodes.map((i) => m.nodes[i].id);
|
|
129
|
+
assert.ok(repoIds.includes('file:backend:lib/util.js') && repoIds.includes('code:backend:lib_util_pad'), 'the file and its code; "All the code" decides whether they are drawn');
|
|
130
|
+
assert.ok(m.filters.stories.some((f) => f.id === 'story:EP-checkout-S01'));
|
|
131
|
+
assert.deepEqual(m.meta, { format: 'yad-brain-1', inputs: brain.inputs, builtAt: '2026-11-13T00:00:00.000Z', codeBehind: [] });
|
|
132
|
+
assert.match(m.meta.inputs, /^sha256:/, 'the live view compares it, to say when the brain was rebuilt (E178)');
|
|
133
|
+
assert.equal(m.warnAbove, WARN_ABOVE);
|
|
134
|
+
assert.ok(m.legend.every((k) => /^#[0-9a-f]{6}$/.test(k.colour)));
|
|
135
|
+
} finally { done(ws); }
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('the view model takes any brain: hostile names stay data, unknown kinds get a colour, loose edges drop', () => {
|
|
139
|
+
const evil = '</script><img src=x onerror=alert(1)>';
|
|
140
|
+
const m = viewModel({
|
|
141
|
+
format: 'yad-brain-1',
|
|
142
|
+
nodes: [
|
|
143
|
+
{ id: '__proto__', kind: 'epic', label: evil },
|
|
144
|
+
{ id: 'constructor', kind: 'mystery', label: 'x'.repeat(5000), file: 42, summary: { not: 'text' } },
|
|
145
|
+
{ kind: 'epic' }, null,
|
|
146
|
+
],
|
|
147
|
+
edges: [{ source: '__proto__', target: 'constructor', relation: 'has-story' }, { source: '__proto__', target: 'ghost' }, null],
|
|
148
|
+
});
|
|
149
|
+
assert.equal(m.nodes.length, 2);
|
|
150
|
+
assert.equal(m.nodes[0].label, evil, 'kept as text; the page sets it with textContent');
|
|
151
|
+
assert.equal(m.nodes[1].kind, 'mystery');
|
|
152
|
+
assert.equal(m.nodes[1].label.length, 300);
|
|
153
|
+
assert.equal(m.nodes[1].file, '42');
|
|
154
|
+
assert.equal(m.nodes[1].summary, undefined);
|
|
155
|
+
assert.ok(m.legend.some((k) => k.kind === 'other'));
|
|
156
|
+
assert.deepEqual(m.edges, [{ s: 0, t: 1, relation: 'has-story', confidence: 'INFERRED' }]);
|
|
157
|
+
assert.equal(Object.getPrototypeOf({}).polluted, undefined);
|
|
158
|
+
assert.deepEqual(viewModel(null).nodes, []);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('the server: 127.0.0.1 only, a key on every request, its own Host only, GET only, fixed routes, strict headers', async () => {
|
|
162
|
+
const { ws, root } = product();
|
|
163
|
+
const s = await startBrainServer(root, { runner: quiet });
|
|
164
|
+
try {
|
|
165
|
+
assert.equal(s.server.address().address, '127.0.0.1');
|
|
166
|
+
assert.match(s.token, /^[0-9a-f]{48}$/);
|
|
167
|
+
const q = `?t=${s.token}`;
|
|
168
|
+
const page = await raw(s.port, { pathname: `/${q}` });
|
|
169
|
+
assert.equal(page.status, 200);
|
|
170
|
+
assert.ok(page.body.includes(`app.js?t=${s.token}`), 'the page asks for its scripts with its key');
|
|
171
|
+
assert.equal(page.headers['content-security-policy'], CSP);
|
|
172
|
+
assert.equal(page.headers['x-content-type-options'], 'nosniff');
|
|
173
|
+
assert.equal(page.headers['cache-control'], 'no-store');
|
|
174
|
+
assert.equal(page.headers['referrer-policy'], 'no-referrer');
|
|
175
|
+
assert.equal(page.headers['access-control-allow-origin'], undefined, 'no CORS');
|
|
176
|
+
for (const pathname of ['/', '/?t=', `/?t=${'0'.repeat(48)}`, `/?t=${s.token}0`, `/?t=${s.token.slice(1)}`, `/graph.json?t=${s.token.toUpperCase()}`]) {
|
|
177
|
+
assert.equal((await raw(s.port, { pathname })).status, 403, pathname);
|
|
178
|
+
}
|
|
179
|
+
for (const host of ['localhost:' + s.port, 'evil.example', `127.0.0.1:${s.port + 1}`, '127.0.0.1', `127.0.0.1:${s.port}.evil.example`]) {
|
|
180
|
+
assert.equal((await raw(s.port, { pathname: `/${q}`, host })).status, 403, host);
|
|
181
|
+
}
|
|
182
|
+
const post = await raw(s.port, { method: 'POST', pathname: `/graph.json${q}` });
|
|
183
|
+
assert.equal(post.status, 405);
|
|
184
|
+
assert.equal(post.headers.allow, 'GET, HEAD');
|
|
185
|
+
for (const pathname of [`/vendor/../brain.mjs${q}`, `/../cli/brain.mjs${q}`, `/vendor/x.js${q}`, `/package.json${q}`, `/vendor/LICENSE-sigma.txt${q}`, `//etc/passwd${q}`]) {
|
|
186
|
+
assert.equal((await raw(s.port, { pathname })).status, 404, pathname);
|
|
187
|
+
}
|
|
188
|
+
const head = await raw(s.port, { method: 'HEAD', pathname: `/app.js${q}` });
|
|
189
|
+
assert.equal(head.status, 200);
|
|
190
|
+
assert.equal(head.body, '');
|
|
191
|
+
for (const v of VENDORED) {
|
|
192
|
+
const r = await raw(s.port, { pathname: `/vendor/${v.file}${q}` });
|
|
193
|
+
assert.equal(r.status, 200, v.file);
|
|
194
|
+
assert.match(r.headers['content-type'], /^text\/javascript/);
|
|
195
|
+
}
|
|
196
|
+
const g = await raw(s.port, { pathname: `/graph.json${q}` });
|
|
197
|
+
assert.equal(g.status, 200);
|
|
198
|
+
assert.ok(JSON.parse(g.body).nodes.some((n) => n.id === 'epic:EP-checkout'));
|
|
199
|
+
} finally { await s.close(); done(ws); }
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('the server reads the brain on each request, and says why when there is none', async () => {
|
|
203
|
+
const { ws, root, brain } = product();
|
|
204
|
+
const s = await startBrainServer(root, { runner: quiet });
|
|
205
|
+
try {
|
|
206
|
+
const get = async () => raw(s.port, { pathname: `/graph.json?t=${s.token}` });
|
|
207
|
+
const before = JSON.parse((await get()).body).counts.nodes;
|
|
208
|
+
writeBrain(root, { ...brain, nodes: brain.nodes.slice(0, 3), edges: [] });
|
|
209
|
+
assert.equal(JSON.parse((await get()).body).counts.nodes, 3, 'a rebuild shows on reload');
|
|
210
|
+
assert.ok(before > 3);
|
|
211
|
+
fs.rmSync(path.join(root, BRAIN_FILE));
|
|
212
|
+
const gone = await get();
|
|
213
|
+
assert.equal(gone.status, 404);
|
|
214
|
+
assert.match(JSON.parse(gone.body).hint, /yad brain build/);
|
|
215
|
+
} finally { await s.close(); done(ws); }
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('each vendored library is the copy its record names: the hash, the licence, a complete vetting record', () => {
|
|
219
|
+
assert.deepEqual(VENDORED.map((v) => v.id).sort(), ['graphology', 'graphology-library', 'sigma']);
|
|
220
|
+
const shipped = fs.readdirSync(VENDOR).sort();
|
|
221
|
+
assert.deepEqual(shipped, VENDORED.flatMap((v) => [v.file, v.licenceFile]).sort(), 'nothing in the folder without a record');
|
|
222
|
+
for (const v of VENDORED) {
|
|
223
|
+
const bytes = fs.readFileSync(path.join(VENDOR, v.file));
|
|
224
|
+
assert.equal(createHash('sha256').update(bytes).digest('hex'), v.sha256, `${v.file} is not the vetted copy`);
|
|
225
|
+
assert.equal(v.licence, 'MIT');
|
|
226
|
+
assert.match(fs.readFileSync(path.join(VENDOR, v.licenceFile), 'utf8'), /Permission is hereby granted, free of charge/);
|
|
227
|
+
assert.deepEqual(vettingProblems(v), [], v.id);
|
|
228
|
+
const pkg = v.vetted.packages[0];
|
|
229
|
+
assert.equal(v.tarball, `https://registry.npmjs.org/${pkg.name}/-/${pkg.name}-${pkg.version}.tgz`);
|
|
230
|
+
assert.match(v.integrity, /^sha512-[A-Za-z0-9+/]+=*$/);
|
|
231
|
+
const text = bytes.toString('utf8');
|
|
232
|
+
assert.doesNotMatch(text, /\beval\(|new Function\(/, `${v.file} needs no eval, so the strict CSP holds`);
|
|
233
|
+
assert.doesNotMatch(text, /<\/script/i, `${v.file} can be inlined in a <script>`);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('--html: one file, no network, a CSP that names each inline block, and no name can close its tag', () => {
|
|
238
|
+
const evil = '</script><img src=x onerror=alert(1)><!--';
|
|
239
|
+
const model = viewModel({ format: 'yad-brain-1', nodes: [{ id: 'epic:a', kind: 'epic', label: evil }, { id: 'x
y', kind: 'code', label: '& run __TOKEN__ check' }], edges: [] });
|
|
240
|
+
const html = snapshotHTML(model);
|
|
241
|
+
assert.doesNotMatch(html, /<[a-z][^>]*\s(src|href)=/i, 'no tag loads anything from anywhere');
|
|
242
|
+
assert.ok(!html.includes(evil) && !html.includes('</script><img'), 'the label never appears raw');
|
|
243
|
+
assert.equal(html.includes('
'), false);
|
|
244
|
+
// The inline blocks, found by their exact tags (the file writes them exactly so).
|
|
245
|
+
const between = (open, close) => html.split(open).slice(1).map((part) => part.slice(0, part.indexOf(close)));
|
|
246
|
+
const [data] = between('<script type="application/json" id="yad-brain-data">', '</script>');
|
|
247
|
+
assert.deepEqual(JSON.parse(data), JSON.parse(JSON.stringify(model)), 'the data reads back unchanged');
|
|
248
|
+
const csp = /<meta http-equiv="Content-Security-Policy" content="([^"]+)">/.exec(html)[1];
|
|
249
|
+
assert.match(csp, /^default-src 'none'; /);
|
|
250
|
+
assert.doesNotMatch(csp, /connect-src|'self'|unsafe/);
|
|
251
|
+
const hashes = new Set([...csp.matchAll(/'sha256-([^']+)'/g)].map((x) => x[1]));
|
|
252
|
+
const blocks = between('<script>', '</script>');
|
|
253
|
+
assert.equal(blocks.length, VENDORED.length + 1, 'the vendored libraries and app.js');
|
|
254
|
+
for (const b of [...blocks, ...between('<style>', '</style>')]) {
|
|
255
|
+
assert.ok(hashes.has(createHash('sha256').update(b, 'utf8').digest('base64')), 'each inline block is allowed by its hash');
|
|
256
|
+
}
|
|
257
|
+
assert.equal(hashes.size, blocks.length + 1, 'and nothing else is');
|
|
258
|
+
assert.equal(html.replace(/run __TOKEN__ check/g, '').includes('__TOKEN__'), false, 'the page\'s own placeholders are gone');
|
|
259
|
+
assert.ok(html.includes('run __TOKEN__ check'), 'and a name that holds the same text keeps it (review 1)');
|
|
260
|
+
assert.equal(scriptSafeJSON({ a: '<>&
' }), '{"a":"\\u003c\\u003e\\u0026\\u2028\\u2029"}');
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('yad brain view --html saves into the local reports folder, or a named file, never through a link', async () => {
|
|
264
|
+
const { ws, root } = product();
|
|
265
|
+
try {
|
|
266
|
+
const r = yad(root, 'brain', 'view', '--html', '--json');
|
|
267
|
+
assert.equal(r.status, 0, r.stderr);
|
|
268
|
+
const out = JSON.parse(r.stdout);
|
|
269
|
+
const reports = path.join(path.dirname(fs.realpathSync(root)), `${path.basename(root)}--reports`);
|
|
270
|
+
assert.equal(path.dirname(fs.realpathSync(out.file)), path.join(reports, 'brain-view'), 'E180: beside the Product, in its kind\'s folder');
|
|
271
|
+
assert.match(path.basename(out.file), /^\d{4}-\d{2}-\d{2}-\d{4}--brain-view--code-and-work--\d+-nodes\.html$/);
|
|
272
|
+
assert.equal(out.warning, undefined);
|
|
273
|
+
assert.match(fs.readFileSync(out.file, 'utf8'), /^<!doctype html>/);
|
|
274
|
+
assert.match(fs.readFileSync(path.join(reports, '.gitignore'), 'utf8'), /^\*$/m, 'never committed');
|
|
275
|
+
|
|
276
|
+
// A named file inside a git work tree that does not ignore it: written, with a warning.
|
|
277
|
+
const repo = tmp();
|
|
278
|
+
git(repo, 'init', '-q');
|
|
279
|
+
const named = await captured(() => runBrainView(root, { args: [path.join(repo, 'brain.html')], html: true, json: true, runner: quiet }));
|
|
280
|
+
assert.match(named.warning, /not ignored: it holds the names in your code/);
|
|
281
|
+
assert.ok(fs.existsSync(path.join(repo, 'brain.html')));
|
|
282
|
+
put(path.join(repo, '.gitignore'), 'brain.html\n');
|
|
283
|
+
assert.equal((await captured(() => runBrainView(root, { args: [path.join(repo, 'brain.html')], html: true, json: true, runner: quiet }))).warning, undefined);
|
|
284
|
+
|
|
285
|
+
// A link at the target is refused, and what it points at is untouched.
|
|
286
|
+
const victim = path.join(repo, 'victim.txt');
|
|
287
|
+
put(victim, 'keep me');
|
|
288
|
+
fs.symlinkSync(victim, path.join(repo, 'link.html'));
|
|
289
|
+
const linked = yad(root, 'brain', 'view', '--html', path.join(repo, 'link.html'));
|
|
290
|
+
assert.notEqual(linked.status, 0);
|
|
291
|
+
assert.match(linked.stderr + linked.stdout, /not a plain file/);
|
|
292
|
+
assert.equal(fs.readFileSync(victim, 'utf8'), 'keep me');
|
|
293
|
+
done(repo);
|
|
294
|
+
} finally { done(ws); }
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Run a --json command in-process and return what it printed. It collects console.log, never stdout itself:
|
|
298
|
+
// the test runner reports on stdout, and catching that would both break this parse and corrupt the run.
|
|
299
|
+
async function captured(fn) {
|
|
300
|
+
const log = console.log;
|
|
301
|
+
const lines = [];
|
|
302
|
+
console.log = (...a) => { lines.push(a.join(' ')); };
|
|
303
|
+
try { await fn(); } finally { console.log = log; }
|
|
304
|
+
return JSON.parse(lines.join('\n'));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
test('yad brain view refuses with no brain, extra words, and flags of other actions; --open is view\'s alone', () => {
|
|
308
|
+
const { ws, root } = product();
|
|
309
|
+
try {
|
|
310
|
+
fs.rmSync(path.join(root, BRAIN_FILE));
|
|
311
|
+
const none = yad(root, 'brain', 'view', '--html');
|
|
312
|
+
assert.notEqual(none.status, 0);
|
|
313
|
+
assert.match(none.stderr + none.stdout, /no brain here yet[\s\S]*yad brain build/);
|
|
314
|
+
for (const args of [['view', 'a', 'b'], ['view', 'extra'], ['view', '--repo', 'backend'], ['view', '--limit', '3'], ['build', '--open'], ['status', '--html'], ['query', 'x', '--open']]) {
|
|
315
|
+
const r = yad(root, 'brain', ...args, '--json');
|
|
316
|
+
assert.notEqual(r.status, 0, args.join(' '));
|
|
317
|
+
assert.equal(JSON.parse(r.stdout).ok, false, args.join(' '));
|
|
318
|
+
}
|
|
319
|
+
} finally { done(ws); }
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('brain view is a local write, never pre-approved for an agent', () => {
|
|
323
|
+
assert.equal(classify(['brain', 'view']), 'local-write');
|
|
324
|
+
assert.equal(classify(['brain', 'view'], ['html', 'open']), 'local-write');
|
|
325
|
+
assert.equal(readAllowList().some((r) => r.includes('brain view')), false);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('review 1: a change-epic shows its parent, never the parent\'s tree; a repo shows its files with their code; one node per id', () => {
|
|
329
|
+
const m = viewModel({
|
|
330
|
+
format: 'yad-brain-1',
|
|
331
|
+
nodes: [
|
|
332
|
+
{ id: 'epic:A', kind: 'epic', label: 'A' }, { id: 'epic:B', kind: 'epic', label: 'B' },
|
|
333
|
+
{ id: 'story:A-S1', kind: 'story', label: 'A-S1' }, { id: 'story:B-S1', kind: 'story', label: 'B-S1' },
|
|
334
|
+
{ id: 'repo:be', kind: 'repo', label: 'be' },
|
|
335
|
+
{ id: 'file:be:x.js', kind: 'file', label: 'x.js', repo: 'be' }, { id: 'code:be:x', kind: 'code', label: 'x', repo: 'be' },
|
|
336
|
+
{ id: 'epic:A', kind: 'epic', label: 'a second A' },
|
|
337
|
+
],
|
|
338
|
+
edges: [
|
|
339
|
+
{ source: 'epic:B', target: 'epic:A', relation: 'changes', confidence: 'EXTRACTED' },
|
|
340
|
+
{ source: 'epic:A', target: 'story:A-S1', relation: 'has-story', confidence: 'EXTRACTED' },
|
|
341
|
+
{ source: 'epic:B', target: 'story:B-S1', relation: 'has-story', confidence: 'EXTRACTED' },
|
|
342
|
+
{ source: 'repo:be', target: 'file:be:x.js', relation: 'holds', confidence: 'EXTRACTED' },
|
|
343
|
+
{ source: 'file:be:x.js', target: 'code:be:x', relation: 'defines', confidence: 'EXTRACTED' },
|
|
344
|
+
],
|
|
345
|
+
});
|
|
346
|
+
const ids = (f) => f.nodes.map((i) => m.nodes[i].id).sort();
|
|
347
|
+
assert.deepEqual(ids(m.filters.epics.find((f) => f.id === 'epic:B')), ['epic:A', 'epic:B', 'story:B-S1']);
|
|
348
|
+
assert.deepEqual(ids(m.filters.epics.find((f) => f.id === 'epic:A')), ['epic:A', 'story:A-S1']);
|
|
349
|
+
assert.deepEqual(ids(m.filters.repos[0]), ['code:be:x', 'file:be:x.js', 'repo:be']);
|
|
350
|
+
assert.equal(m.nodes.filter((n) => n.id === 'epic:A').length, 1);
|
|
351
|
+
assert.equal(m.nodes.find((n) => n.id === 'epic:A').label, 'A', 'the first wins');
|
|
352
|
+
assert.equal(m.filters.epics.length, 2);
|
|
353
|
+
assert.equal(m.counts.nodes, 7);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test('review 1: --open finds a real opener on each system, explorer on Windows, and says when there is none', async () => {
|
|
357
|
+
const { openUrl } = await import('./report.mjs');
|
|
358
|
+
for (const [platform, cmd] of [['darwin', 'open'], ['linux', 'xdg-open'], ['win32', 'explorer']]) {
|
|
359
|
+
const ran = [];
|
|
360
|
+
assert.equal(openUrl('http://127.0.0.1:1/?t=k', { platform, exists: (c) => c === cmd, runner: (c, a) => ran.push([c, ...a]) }), true, platform);
|
|
361
|
+
assert.deepEqual(ran, [[cmd, 'http://127.0.0.1:1/?t=k']], platform);
|
|
362
|
+
}
|
|
363
|
+
assert.equal(openUrl('x', { platform: 'linux', exists: () => false, runner: () => assert.fail('nothing to run') }), false);
|
|
364
|
+
|
|
365
|
+
const { ws, root } = product();
|
|
366
|
+
const opened = [];
|
|
367
|
+
const printed = [];
|
|
368
|
+
const log = console.log;
|
|
369
|
+
console.log = (...a) => printed.push(a.join(' '));
|
|
370
|
+
let s;
|
|
371
|
+
try {
|
|
372
|
+
s = await runBrainView(root, { open: true, wait: false, runner: quiet, opener: (u) => { opened.push(u); return false; } });
|
|
373
|
+
assert.equal(opened[0], s.url, 'the address with its key');
|
|
374
|
+
assert.match(printed.join('\n'), /no browser opener was found here/);
|
|
375
|
+
console.log = log;
|
|
376
|
+
const asJSON = await captured(() => runBrainView(root, { args: [path.join(ws, 'v.html')], html: true, open: true, json: true, runner: quiet, opener: () => false }));
|
|
377
|
+
assert.equal(asJSON.opened, false, 'said under --json too (review 2)');
|
|
378
|
+
assert.equal((await captured(() => runBrainView(root, { html: true, json: true, runner: quiet }))).opened, undefined, 'absent without --open');
|
|
379
|
+
assert.equal((await raw(s.port, { pathname: new URL(s.url).pathname + new URL(s.url).search })).status, 200);
|
|
380
|
+
} finally { console.log = log; await s?.close(); done(ws); }
|
|
381
|
+
});
|