yadflow 4.10.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +12 -3
  3. package/bin/commands.mjs +5 -1
  4. package/bin/yad.mjs +109 -15
  5. package/cli/agent-guard-worker.mjs +13 -0
  6. package/cli/agent-guard.mjs +1053 -57
  7. package/cli/agent-rules.mjs +34 -3
  8. package/cli/argv-flags.mjs +2 -2
  9. package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
  10. package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
  11. package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
  12. package/cli/brain/vendor/graphology-library.min.js +2 -0
  13. package/cli/brain/vendor/graphology.umd.min.js +2 -0
  14. package/cli/brain/vendor/sigma.min.js +1369 -0
  15. package/cli/brain/view/app.js +382 -0
  16. package/cli/brain/view/index.html +63 -0
  17. package/cli/brain/view/live.css +228 -0
  18. package/cli/brain/view/live.html +110 -0
  19. package/cli/brain/view/live.js +884 -0
  20. package/cli/brain/view/style.css +141 -0
  21. package/cli/brain-about.mjs +206 -0
  22. package/cli/brain-activity.mjs +285 -0
  23. package/cli/brain-skills.mjs +118 -0
  24. package/cli/brain-vendor.mjs +71 -0
  25. package/cli/brain-view.mjs +344 -0
  26. package/cli/brain.mjs +810 -0
  27. package/cli/ci-check.mjs +3 -3
  28. package/cli/doctor.mjs +80 -13
  29. package/cli/epic-state.mjs +93 -1
  30. package/cli/epic.mjs +15 -3
  31. package/cli/errors.mjs +2 -1
  32. package/cli/find-product.mjs +69 -15
  33. package/cli/foundation-publish.mjs +256 -0
  34. package/cli/gate.mjs +29 -3
  35. package/cli/git-read.mjs +38 -0
  36. package/cli/guard-stream.mjs +409 -0
  37. package/cli/hook.mjs +59 -9
  38. package/cli/issues-act.mjs +57 -13
  39. package/cli/issues-write.mjs +19 -6
  40. package/cli/issues.mjs +62 -23
  41. package/cli/lib.mjs +37 -2
  42. package/cli/local-page.mjs +138 -0
  43. package/cli/machine.mjs +1 -1
  44. package/cli/manifest.mjs +50 -0
  45. package/cli/map/view/app.js +712 -0
  46. package/cli/map/view/index.html +50 -0
  47. package/cli/map/view/style.css +142 -0
  48. package/cli/map-view.mjs +186 -0
  49. package/cli/map.mjs +637 -0
  50. package/cli/members.mjs +9 -15
  51. package/cli/next.mjs +1 -1
  52. package/cli/openpr.mjs +2 -2
  53. package/cli/plan.mjs +125 -0
  54. package/cli/platform.mjs +5 -5
  55. package/cli/product-index.mjs +1 -1
  56. package/cli/protection.mjs +32 -0
  57. package/cli/reconcile.mjs +8 -2
  58. package/cli/report.mjs +9 -3
  59. package/cli/reports-dir.mjs +391 -0
  60. package/cli/reports.mjs +65 -0
  61. package/cli/run-checks.mjs +5 -2
  62. package/cli/scan.mjs +1 -1
  63. package/cli/setup.mjs +30 -5
  64. package/cli/standup.mjs +87 -71
  65. package/cli/status.mjs +6 -5
  66. package/cli/test-agents-file.mjs +614 -8
  67. package/cli/test-brain-activity.mjs +753 -0
  68. package/cli/test-brain-view.mjs +381 -0
  69. package/cli/test-brain.mjs +795 -0
  70. package/cli/test-guide.mjs +211 -0
  71. package/cli/test-machine.mjs +59 -0
  72. package/cli/test-map.mjs +615 -0
  73. package/cli/test-reports.mjs +382 -0
  74. package/cli/test-run-checks.mjs +4 -0
  75. package/cli/test-worktree.mjs +24 -3
  76. package/cli/toolbox-connect.mjs +21 -6
  77. package/cli/toolbox.mjs +59 -4
  78. package/cli/update-commit.mjs +101 -9
  79. package/cli/usage.mjs +8 -4
  80. package/package.json +8 -4
  81. package/skills/yad-architecture/SKILL.md +22 -4
  82. package/skills/yad-change/SKILL.md +3 -1
  83. package/skills/yad-change/references/triage.md +2 -0
  84. package/skills/yad-checks/SKILL.md +2 -0
  85. package/skills/yad-checks/references/check-gates.md +8 -5
  86. package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
  87. package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
  88. package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
  89. package/skills/yad-checks/templates/github/yad-checks.yml +3 -2
  90. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +3 -2
  91. package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
  92. package/skills/yad-connect-repos/SKILL.md +14 -0
  93. package/skills/yad-discovery/SKILL.md +11 -0
  94. package/skills/yad-discovery/references/foundation-schema.md +11 -0
  95. package/skills/yad-docs/templates/app/package-lock.json +18 -10
  96. package/skills/yad-docs/templates/app/package.json +6 -1
  97. package/skills/yad-epic/SKILL.md +3 -0
  98. package/skills/yad-epic/references/state-schema.md +35 -1
  99. package/skills/yad-guide/SKILL.md +4 -4
  100. package/skills/yad-implement/SKILL.md +76 -15
  101. package/skills/yad-issues/SKILL.md +2 -1
  102. package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
  103. package/skills/yad-pr-template/templates/checks/pr-title.sh +8 -4
  104. package/skills/yad-spec/SKILL.md +19 -0
  105. package/skills/yad-stories/SKILL.md +22 -4
  106. package/skills/yad-stories/references/story-schema.md +1 -1
@@ -0,0 +1,615 @@
1
+ // E181 — `yad map`: the progress map's model, its people, the page and the command. Every name is invented.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { createHash } from 'node:crypto';
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
+ import { setTimeout } from 'node:timers';
12
+
13
+ if (process.env.NODE_TEST_CONTEXT) {
14
+ const write = process.stdout.write;
15
+ for (const k of ['log', 'info']) {
16
+ const orig = console[k];
17
+ console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
18
+ }
19
+ }
20
+ process.env.YAD_NO_UPDATE_NOTIFIER = '1';
21
+
22
+ const { mapModel, gatherMap, digestOf, initials, personLetter, hueOf, storyTitle, portFor } = await import('./map.mjs');
23
+ const { runMap, mapSnapshot, startMapServer, buildMap } = await import('./map-view.mjs');
24
+ const { classify, readAllowList } = await import('./agent-rules.mjs');
25
+ const { endJSON } = await import('./lib.mjs');
26
+ const { REPORTS_ENV, readCatalog } = await import('./reports-dir.mjs');
27
+
28
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
29
+ const YAD = path.join(HERE, '..', 'bin', 'yad.mjs');
30
+ const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-map-')));
31
+ const put = (f, d) => { fs.mkdirSync(path.dirname(f), { recursive: true }); fs.writeFileSync(f, typeof d === 'string' ? d : JSON.stringify(d, null, 2)); };
32
+ const done = (...dirs) => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }));
33
+ const NOW = Date.parse('2026-11-14T12:00:00Z');
34
+ const daysAgo = (n) => new Date(NOW - n * 864e5).toISOString();
35
+ const PEOPLE = { kit: ['Kit Ansel', 'kit@example.com'], bo: ['Bo Lindqvist', 'bo@example.com'], mae: ['Mae Torvik', 'mae@example.com'] };
36
+ function git(cwd, args, who = PEOPLE.kit, date = daysAgo(1)) {
37
+ const r = spawnSync('git', ['-c', 'commit.gpgsign=false', '-c', 'init.defaultBranch=main', ...args], { cwd, encoding: 'utf8',
38
+ env: { ...process.env, GIT_AUTHOR_NAME: who[0], GIT_AUTHOR_EMAIL: who[1], GIT_COMMITTER_NAME: who[0], GIT_COMMITTER_EMAIL: who[1], GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date } });
39
+ if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
40
+ return r.stdout.trim();
41
+ }
42
+ async function captured(fn) {
43
+ const out = []; const orig = console.log;
44
+ console.log = (s) => out.push(String(s));
45
+ let ret;
46
+ try { ret = await fn(); } finally { console.log = orig; endJSON(); }
47
+ return { json: out.length ? JSON.parse(out.join('\n')) : null, ret };
48
+ }
49
+
50
+ // ---- the pure model ------------------------------------------------------------------------------
51
+
52
+ const baseInputs = (over = {}) => ({
53
+ product: { name: 'Orchard', branch: 'main', sha: 'a'.repeat(40) },
54
+ staleDays: 60, groups: [], members: [],
55
+ epics: [
56
+ { id: 'EP-login', title: 'Log in', currentStep: 'ready-for-build', steps: [{ id: 'epic', status: 'done' }], owner: 'Kit Ansel', repos: [], onMain: true, stepOwners: {}, approvals: [{ step: 'epic-review', approver: 'bo' }] },
57
+ { id: 'EP-later', title: 'Later', currentStep: 'epic', steps: [{ id: 'epic', status: 'todo' }], owner: null, repos: [], onMain: true, stepOwners: {}, approvals: [] },
58
+ { id: 'EP-solo', title: 'Solo', currentStep: 'ready-for-build', steps: [{ id: 'epic', status: 'done' }], owner: 'Mae Torvik', repos: [], onMain: true, stepOwners: {}, approvals: [] },
59
+ ],
60
+ stories: [
61
+ { id: 'EP-login-S01', epic: 'EP-login', title: 'Sign in', status: 'shipped', owner: 'Kit Ansel', repos: ['api'], build: {} },
62
+ { id: 'EP-login-S02', epic: 'EP-login', title: 'Remember me', status: 'approved', owner: 'Bo Lindqvist', repos: ['api'], build: {} },
63
+ { id: 'EP-solo-S01', epic: 'EP-solo', title: 'One', status: 'shipped', owner: 'Mae Torvik', repos: ['api'], build: {} },
64
+ ],
65
+ tasks: [
66
+ { story: 'EP-login-S01', epic: 'EP-login', task: 'T01', repo: 'api', branch: 'feat/EP-login-S01-T01', pr: 'https://git.example.org/orchard/api/pull/4', builder: 'Kit Ansel', reviewers: ['bo'], reach: { found: true, prod: true, integ: true } },
67
+ { story: 'EP-solo-S01', epic: 'EP-solo', task: 'T01', repo: 'api', branch: 'feat/EP-solo-S01-T01', pr: null, builder: 'Mae Torvik', reviewers: ['Mae Torvik'], reach: { found: true, prod: false, integ: true } },
68
+ ],
69
+ repos: [{ name: 'api', available: true, integrationBranch: 'dev', productionBranch: 'main', productionGuessed: true, waitingCommits: 3, productionAhead: 0, production: { date: daysAgo(10), author: 'Kit Ansel' }, integration: { date: daysAgo(1), author: 'Bo Lindqvist' } },
70
+ { name: 'web', available: false, integrationBranch: 'dev' }],
71
+ branches: [
72
+ { repo: 'api', name: 'feat/EP-login-S01-T01', sha: 'b'.repeat(40), date: daysAgo(20), author: 'Kit Ansel', inProd: true, inInteg: true, ahead: 0 },
73
+ { repo: 'api', name: 'feat/EP-login-S02-remember', sha: 'c'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 2 },
74
+ { repo: 'api', name: 'yad/wip/bo-lindqvist/EP-login', sha: 'd'.repeat(40), date: daysAgo(90), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
75
+ { repo: 'api', name: 'chore/kit-cleanup', sha: 'e'.repeat(40), date: daysAgo(3), author: 'Kit Ansel', inProd: false, inInteg: true, ahead: 0 },
76
+ ],
77
+ waits: [{ epic: 'EP-login', step: 'stories-review', kind: 'gate', owner: 'Kit Ansel' }],
78
+ ...over,
79
+ });
80
+
81
+ test('the roll-up: tasks, branches, stories and epics get the prototype\'s states', () => {
82
+ const m = mapModel(baseInputs(), { now: NOW });
83
+ const st = (list, id) => list.find((x) => x.id === id);
84
+ assert.equal(st(m.tasks, 'EP-login-S01-T01-api').state, 'live');
85
+ assert.equal(st(m.tasks, 'EP-solo-S01-T01-api').state, 'merged');
86
+ assert.equal(st(m.stories, 'EP-login-S01').state, 'live');
87
+ assert.equal(st(m.stories, 'EP-login-S02').state, 'active', 'an open branch names it');
88
+ assert.equal(st(m.epics, 'EP-login').state, 'active');
89
+ assert.equal(st(m.epics, 'EP-later').state, 'planned');
90
+ assert.equal(st(m.epics, 'EP-solo').state, 'merged');
91
+ const b = (name) => m.branches.find((x) => x.name === name);
92
+ assert.equal(b('feat/EP-login-S02-remember').state, 'active');
93
+ assert.equal(b('feat/EP-login-S02-remember').story, 'EP-login-S02');
94
+ assert.equal(b('yad/wip/bo-lindqvist/EP-login').state, 'idle');
95
+ assert.equal(b('chore/kit-cleanup').state, 'merged');
96
+ assert.equal(b('chore/kit-cleanup').group, 'other', 'a branch with no epic falls into the one default group');
97
+ assert.equal(m.repos[0].productionGuessed, true);
98
+ assert.equal(m.summary.stories.shipped, 2);
99
+ assert.equal(m.tasks[0].pr, 'https://git.example.org/orchard/api/pull/4');
100
+ assert.equal(JSON.stringify(m).includes('subject'), false, 'no commit subject is carried');
101
+ });
102
+
103
+ test('a task in a repo not on this machine is shipped but unchecked; one not registered says so', () => {
104
+ const i = baseInputs();
105
+ i.tasks.push({ story: 'EP-login-S01', epic: 'EP-login', task: 'T02', repo: 'web', builder: null, reviewers: [], reach: null },
106
+ { story: 'EP-login-S01', epic: 'EP-login', task: 'T03', repo: 'ghost', builder: null, reviewers: [], reach: null },
107
+ { story: 'EP-login-S01', epic: 'EP-login', task: 'T04', repo: 'api', builder: null, reviewers: [], reach: { found: true, prod: false, integ: false, via: { branch: 'feat/EP-login-S01-hotfix', date: daysAgo(4) } } });
108
+ const m = mapModel(i, { now: NOW });
109
+ const t = (id) => m.tasks.find((x) => x.task === id);
110
+ assert.equal(t('T02').verified, false);
111
+ assert.match(t('T02').note, /not on this machine/);
112
+ assert.match(t('T03').note, /not a registered repo/);
113
+ assert.equal(t('T04').state, 'live');
114
+ assert.match(t('T04').note, /through its own branch “feat\/EP-login-S01-hotfix”/);
115
+ assert.equal(m.stories.find((s) => s.id === 'EP-login-S01').state, 'merged', 'not every task is in Production');
116
+ });
117
+
118
+ test('people: roles, never counts; one badge per person through the member files; a name on two members is said', () => {
119
+ const member = (login, names) => ({ primary: { platform: 'github', host: 'github.com', login }, accounts: [{ platform: 'github', host: 'github.com', login }], names, emails: [], matchLogins: [login] });
120
+ const m = mapModel(baseInputs({ members: [member('kit', ['Kit Ansel']), member('bo', ['Bo Lindqvist']), member('mae', ['Mae Torvik'])] }), { now: NOW });
121
+ const names = m.people.map((p) => p.name);
122
+ assert.deepEqual(names, ['Bo Lindqvist', 'Kit Ansel', 'Mae Torvik'], 'sorted by name, one each');
123
+ const bo = m.people.find((p) => p.name === 'Bo Lindqvist');
124
+ assert.deepEqual(bo.roles, ['approver', 'builder', 'owner', 'reviewer']);
125
+ assert.equal(bo.initials, 'BL');
126
+ assert.equal(Object.keys(bo).some((k) => /count|score|rank/i.test(k)), false);
127
+ assert.equal(m.waiting[0].person, 'm:kit');
128
+ assert.deepEqual(m.notes.onePerson, ['EP-solo'], 'every part of EP-solo is Mae\'s');
129
+ // Without member files, a login and a git name stay two people — never a guess.
130
+ const loose = mapModel(baseInputs(), { now: NOW });
131
+ assert.ok(loose.people.some((p) => p.name === 'bo') && loose.people.some((p) => p.name === 'Bo Lindqvist'));
132
+ // A name two member files hold is matched to neither, and says so.
133
+ const twice = mapModel(baseInputs({ members: [member('kit', ['Kit Ansel']), member('kit2', ['Kit Ansel'])] }), { now: NOW });
134
+ assert.deepEqual(twice.people.find((p) => p.name === 'Kit Ansel').ambiguous, ['kit', 'kit2']);
135
+ // An email is never shown.
136
+ const at = mapModel(baseInputs({ stories: [{ id: 'EP-login-S09', epic: 'EP-login', status: 'draft', owner: 'kit@example.com', repos: [] }] }), { now: NOW });
137
+ const addr = at.people.find((x) => x.key.startsWith('n:@'));
138
+ assert.ok(addr, 'the address is a person with a fingerprint key');
139
+ assert.match(addr.key, /^n:@[0-9a-f]{16}$/, 'the key is a fingerprint');
140
+ assert.equal(addr.name, 'a name with an @ in it');
141
+ assert.equal(JSON.stringify(at).split('kit@').length, 1, 'not the address');
142
+ assert.equal(JSON.stringify(at).split('example.com').length, 1, 'not even the domain');
143
+ const lead = mapModel(baseInputs({ stories: [{ id: 'EP-login-S09', epic: 'EP-login', status: 'draft', owner: '@example.com', repos: [] }] }), { now: NOW });
144
+ assert.equal(JSON.stringify(lead).split('example.com').length, 1, 'a leading @ is an address too');
145
+ });
146
+
147
+ test('--anonymous: Person A…, and no name, capture branch, PR link or host survives', () => {
148
+ const m = mapModel(baseInputs(), { now: NOW, anonymous: true });
149
+ const text = JSON.stringify(m).toLowerCase();
150
+ for (const word of ['kit', 'ansel', 'lindqvist', 'mae', 'torvik', 'git.example.org']) assert.equal(text.includes(word), false, word);
151
+ assert.ok(m.people.every((p) => /^Person [A-Z]+$/.test(p.name)));
152
+ assert.ok(m.branches.some((b) => b.name === 'yad/wip/someone/EP-login'));
153
+ assert.ok(m.branches.some((b) => b.name === 'chore/someone-cleanup'));
154
+ assert.equal(m.anonymous, true);
155
+ assert.equal(personLetter(0), 'Person A');
156
+ assert.equal(personLetter(25), 'Person Z');
157
+ assert.equal(personLetter(26), 'Person AA');
158
+ });
159
+
160
+ test('what moved: a later map lights each item whose state changed, and each new one', () => {
161
+ const first = mapModel(baseInputs(), { now: NOW });
162
+ const digest = digestOf(first);
163
+ const i = baseInputs();
164
+ i.tasks[1].reach = { found: true, prod: true, integ: true };
165
+ i.stories.push({ id: 'EP-later-S01', epic: 'EP-later', status: 'draft', owner: null, repos: [] });
166
+ const second = mapModel(i, { now: NOW + 864e5, previous: digest });
167
+ const ids = second.moved.map((x) => x.id);
168
+ assert.ok(ids.includes('task:EP-solo-S01-T01-api'));
169
+ assert.ok(ids.includes('story:EP-solo-S01'));
170
+ assert.deepEqual(second.moved.find((x) => x.id === 'story:EP-later-S01'), { id: 'story:EP-later-S01', from: null, to: 'planned' });
171
+ assert.equal(second.since, digest.at);
172
+ assert.deepEqual(mapModel(baseInputs(), { now: NOW, previous: digest }).moved, [], 'nothing moved, nothing lit');
173
+ });
174
+
175
+ test('small helpers: initials, hues and story titles', () => {
176
+ assert.equal(initials('Kit Ansel'), 'KA');
177
+ assert.equal(initials('bo.lindqvist'), 'BL');
178
+ assert.equal(initials('mae'), 'MA');
179
+ assert.equal(initials(''), '?');
180
+ assert.equal(hueOf('m:kit'), hueOf('m:kit'));
181
+ assert.ok(hueOf('x') >= 0 && hueOf('x') < 8);
182
+ assert.equal(storyTitle('---\nid: x\n---\n# EP-x-S01\n\n## Story\nAs a buyer, I want it.\n'), 'As a buyer, I want it.');
183
+ });
184
+
185
+ // ---- gathering from git --------------------------------------------------------------------------
186
+
187
+ // A Product with one epic and a code repo with dev and main (Production), pushed to a bare origin.
188
+ function workspace({ production = undefined } = {}) {
189
+ const ws = tmp();
190
+ const bare = path.join(ws, 'origin-api.git');
191
+ fs.mkdirSync(bare);
192
+ git(bare, ['init', '-q', '--bare', '-b', 'dev']);
193
+ const api = path.join(ws, 'api');
194
+ fs.mkdirSync(api);
195
+ git(api, ['init', '-q', '-b', 'dev']);
196
+ git(api, ['remote', 'add', 'origin', bare]);
197
+ put(path.join(api, 'a.txt'), 'a');
198
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 'start'], PEOPLE.kit, daysAgo(30));
199
+ git(api, ['branch', 'main']);
200
+ git(api, ['checkout', '-q', '-b', 'feat/EP-login-S01-T01']);
201
+ put(path.join(api, 'b.txt'), 'b');
202
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 'sign in'], PEOPLE.bo, daysAgo(5));
203
+ git(api, ['checkout', '-q', 'dev']);
204
+ git(api, ['merge', '-q', '--no-ff', 'feat/EP-login-S01-T01', '-m', "Merge branch 'feat/EP-login-S01-T01' into 'dev'"], PEOPLE.mae, daysAgo(4));
205
+ const merge = git(api, ['rev-parse', 'HEAD']);
206
+ git(api, ['checkout', '-q', '-b', 'feat/EP-login-S02-open']);
207
+ put(path.join(api, 'c.txt'), 'c');
208
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 'wip'], PEOPLE.mae, daysAgo(1));
209
+ git(api, ['checkout', '-q', 'dev']);
210
+ git(api, ['push', '-q', 'origin', '--all']);
211
+ git(api, ['fetch', '-q', 'origin']);
212
+ const root = path.join(ws, 'product');
213
+ put(path.join(root, '.sdlc', 'product.json'), { name: 'Orchard', ...(production !== undefined ? { map: { production } } : {}) });
214
+ put(path.join(root, '.sdlc', 'repos.json'), { repos: [{ name: 'api', path: '../api', default_branch: 'dev' }, { name: 'web', path: '../web', default_branch: 'dev' }] });
215
+ const steps = [{ id: 'epic', type: 'author', artifact: 'epic.md', status: 'done' }, { id: 'epic-review', type: 'review+approve', artifact: 'epic.md', status: 'done' }];
216
+ put(path.join(root, 'epics', 'EP-login', '.sdlc', 'state.json'), { epicId: 'EP-login', currentStep: 'ready-for-build', createdAt: '2026-10-01', steps });
217
+ put(path.join(root, 'epics', 'EP-login', 'epic.md'), '---\nid: EP-login\nowner: Kit Ansel\n---\n# People log in </script><img src=x>\n');
218
+ put(path.join(root, 'epics', 'EP-login', 'stories', 'EP-login-S01.md'), '---\nid: EP-login-S01\nepic: EP-login\nstatus: shipped\nowner: Bo Lindqvist\nrepos: [api]\n---\n\n## Story\nAs a person, I want to sign in.\n');
219
+ put(path.join(root, 'epics', 'EP-login', 'stories', 'EP-login-S02.md'), '---\nid: EP-login-S02\nepic: EP-login\nstatus: approved\nowner: Mae Torvik\nrepos: [api]\n---\n\n## Story\nAs a person, I want to stay signed in.\n');
220
+ put(path.join(root, 'epics', 'EP-login', '.sdlc', 'build-log.json'), { epic: 'EP-login', ships: [{ story: 'EP-login-S01', task: 'T01', repo: 'api', branch: 'feat/EP-login-S01-T01', pr: 'https://git.example.org/orchard/api/pull/1', mergeCommit: merge, shippedAt: '2026-11-10', engineer_review: [{ approver: 'kit' }] }] });
221
+ git(root, ['init', '-q', '-b', 'main']);
222
+ git(root, ['add', '-A']); git(root, ['commit', '-q', '-m', 'record']);
223
+ return { ws, root, api };
224
+ }
225
+
226
+ test('gathering: read-only git finds Production, where each ship reached, and who built it', () => {
227
+ const { ws, root, api } = workspace();
228
+ try {
229
+ const before = git(api, ['for-each-ref', '--format=%(refname) %(objectname)']);
230
+ const { inputs, problems } = gatherMap(root, { now: NOW });
231
+ assert.deepEqual(problems, []);
232
+ const repo = inputs.repos.find((r) => r.name === 'api');
233
+ assert.equal(repo.productionBranch, 'main');
234
+ assert.equal(repo.productionGuessed, true, 'no map.production: guessed, and said');
235
+ assert.equal(inputs.repos.find((r) => r.name === 'web').available, false);
236
+ const t = inputs.tasks[0];
237
+ assert.deepEqual({ found: t.reach.found, prod: t.reach.prod, integ: t.reach.integ }, { found: true, prod: false, integ: true });
238
+ assert.equal(t.builder, 'Bo Lindqvist', 'the merged branch\'s author, not the person who merged it');
239
+ assert.equal(repo.waitingCommits, 2, 'the feature commit and its merge');
240
+ const m = mapModel(inputs, { now: NOW });
241
+ assert.equal(m.stories.find((s) => s.id === 'EP-login-S02').state, 'active');
242
+ assert.equal(git(api, ['for-each-ref', '--format=%(refname) %(objectname)']), before, 'nothing in the repo changed');
243
+ } finally { done(ws); }
244
+ });
245
+
246
+ test('map.production picks the branch; a name origin lacks is said, and nothing is guessed', () => {
247
+ const a = workspace({ production: { api: 'main' } });
248
+ const b = workspace({ production: { api: 'release' } });
249
+ try {
250
+ const ra = gatherMap(a.root, { now: NOW }).inputs.repos.find((r) => r.name === 'api');
251
+ assert.deepEqual([ra.productionBranch, ra.productionGuessed], ['main', false]);
252
+ const gb = gatherMap(b.root, { now: NOW });
253
+ assert.equal(gb.inputs.repos.find((r) => r.name === 'api').productionBranch, null);
254
+ assert.match(gb.problems[0], /map\.production names "release", which origin does not have/);
255
+ } finally { done(a.ws, b.ws); }
256
+ });
257
+
258
+ // ---- the page and the command --------------------------------------------------------------------
259
+
260
+ test('the file: everything inline, hashed by the CSP, and no name can close its script', () => {
261
+ const { ws, root } = workspace();
262
+ try {
263
+ const html = mapSnapshot(buildMap(root, { now: NOW, env: { [REPORTS_ENV]: path.join(ws, 'r') } }).model);
264
+ assert.equal(html.includes('<script src='), false, 'the served script tags are gone');
265
+ assert.equal(html.includes('</script><img'), false, 'a title is data, never markup');
266
+ const csp = /<meta http-equiv="Content-Security-Policy" content="([^"]+)">/.exec(html)[1];
267
+ assert.match(csp, /default-src 'none'/);
268
+ const hashes = new Set([...csp.matchAll(/'sha256-([^']+)'/g)].map((x) => x[1]));
269
+ // Every executable inline block (a <script> with no type) must be allowed by its hash; matched in any case.
270
+ const blocks = [...html.matchAll(/<script>([\s\S]*?)<\/script[^>]*>/gi)].map((x) => x[1]);
271
+ assert.equal(blocks.length, 1, 'the one app script is inline');
272
+ for (const block of blocks) assert.ok(hashes.has(createHash('sha256').update(block, 'utf8').digest('base64')));
273
+ assert.equal(blocks.length, 1, 'the one app script is inline');
274
+ assert.equal(html.split(/<script/i).length - 1, blocks.length + 1, 'every script tag is a bare inline block, plus the one data block');
275
+ assert.ok(html.includes('id="yad-map-data"'));
276
+ } finally { done(ws); }
277
+ });
278
+
279
+ test('the server: the key, the Host and GET only; map.json is the model', async () => {
280
+ const { ws, root } = workspace();
281
+ const s = await startMapServer(root, { env: { [REPORTS_ENV]: path.join(ws, 'r') } });
282
+ const ask = (p, { method = 'GET', host = `127.0.0.1:${s.port}` } = {}) => new Promise((resolve, reject) => {
283
+ const req = http.request({ host: '127.0.0.1', port: s.port, path: p, method, headers: { Host: host } }, (res) => { let b = ''; res.on('data', (c) => { b += c; }); res.on('end', () => resolve({ status: res.statusCode, body: b, csp: res.headers['content-security-policy'] })); });
284
+ req.on('error', reject); req.end();
285
+ });
286
+ try {
287
+ assert.equal((await ask('/map.json')).status, 403, 'no key');
288
+ assert.equal((await ask(`/map.json?t=${'0'.repeat(48)}`)).status, 403, 'a wrong key');
289
+ assert.equal((await ask(`/map.json?t=${s.token}`, { host: 'evil.example:80' })).status, 403, 'a rebinding Host');
290
+ assert.equal((await ask(`/map.json?t=${s.token}`, { method: 'POST' })).status, 405);
291
+ assert.equal((await ask(`/../package.json?t=${s.token}`)).status, 404);
292
+ const r = await ask(`/map.json?t=${s.token}`);
293
+ assert.equal(r.status, 200);
294
+ assert.match(r.csp, /default-src 'none'/);
295
+ assert.equal(JSON.parse(r.body).product.name, 'Orchard');
296
+ const page = await ask(`/?t=${s.token}`);
297
+ assert.ok(page.body.includes(`app.js?t=${s.token}`));
298
+ } finally { await s.close(); done(ws); }
299
+ });
300
+
301
+ test('the live stream says it is live, and a change in the ledger sends "rebuilt"', async () => {
302
+ const { ws, root } = workspace();
303
+ const s = await startMapServer(root, { live: true, debounce: 50, env: { [REPORTS_ENV]: path.join(ws, 'r') } });
304
+ try {
305
+ const events = await new Promise((resolve, reject) => {
306
+ const seen = [];
307
+ const req = http.request({ host: '127.0.0.1', port: s.port, path: `/events?t=${s.token}`, headers: { Host: `127.0.0.1:${s.port}` } }, (res) => {
308
+ res.on('data', (c) => {
309
+ seen.push(String(c));
310
+ const all = seen.join('');
311
+ if (all.includes('event: status') && !all.includes('touched')) { seen.push('touched'); setTimeout(() => put(path.join(root, 'epics', 'EP-login', 'epic.md'), '# changed\n'), 100); }
312
+ if (all.includes('event: rebuilt')) { req.destroy(); resolve(all); }
313
+ });
314
+ });
315
+ req.on('error', (e) => { if (e.code !== 'ECONNRESET') reject(e); });
316
+ req.end();
317
+ setTimeout(() => { req.destroy(); resolve(seen.join('')); }, 5000).unref();
318
+ });
319
+ assert.match(events, /event: status\ndata: \{"live":true,"watching":\d+\}/);
320
+ assert.match(events, /event: rebuilt/);
321
+ } finally { await s.close(); done(ws); }
322
+ });
323
+
324
+ test('yad map --html saves into the reports folder with a digest; the next map says what moved; --anonymous keeps no digest', async () => {
325
+ const { ws, root } = workspace();
326
+ const env = { [REPORTS_ENV]: path.join(ws, 'reports') };
327
+ try {
328
+ const a = await captured(() => runMap(root, { html: true, json: true, env, now: NOW }));
329
+ assert.match(path.basename(a.json.file), /--progress-map--all-epics--1-of-2-stories-shipped\.html$/);
330
+ assert.ok(fs.existsSync(`${a.json.file}.digest.json`));
331
+ assert.equal(a.json.moved, 0);
332
+ put(path.join(root, 'epics', 'EP-login', 'stories', 'EP-login-S02.md'), '---\nid: EP-login-S02\nepic: EP-login\nstatus: shipped\nowner: Mae Torvik\nrepos: [api]\n---\n');
333
+ const b = await captured(() => runMap(root, { html: true, json: true, env, now: NOW + 60000 }));
334
+ assert.ok(b.json.moved >= 1, 'the story changed state since the first map');
335
+ const anon = await captured(() => runMap(root, { html: true, anonymous: true, json: true, env, now: NOW + 120000 }));
336
+ assert.match(anon.json.file, /-anonymous\.html$/);
337
+ assert.equal(fs.existsSync(`${anon.json.file}.digest.json`), false);
338
+ const text = fs.readFileSync(anon.json.file, 'utf8');
339
+ for (const word of ['Kit Ansel', 'Lindqvist', 'Torvik', 'git.example.org']) assert.equal(text.includes(word), false, word);
340
+ assert.deepEqual(readCatalog(env[REPORTS_ENV]).entries.map((e) => e.anonymous), [false, false, true]);
341
+ // A file named by the person: written there, no catalog entry, no digest.
342
+ const own = path.join(ws, 'mine.html');
343
+ await captured(() => runMap(root, { html: true, args: [own], json: true, env, now: NOW }));
344
+ assert.ok(fs.existsSync(own));
345
+ assert.equal(fs.existsSync(`${own}.digest.json`), false);
346
+ // --html and --live together is refused.
347
+ assert.equal((await captured(() => runMap(root, { html: true, live: true, json: true, env }))).json.ok, false);
348
+ process.exitCode = 0;
349
+ } finally { done(ws); }
350
+ });
351
+
352
+ test('the CLI: unknown flags are refused, and agents may run it but are never pre-approved', () => {
353
+ const { ws, root } = workspace();
354
+ try {
355
+ const r = spawnSync(process.execPath, [YAD, 'map', '--frob', '--json'], { cwd: root, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1' } });
356
+ assert.equal(r.status, 1);
357
+ assert.match(r.stdout + r.stderr, /yad map does not take --frob/);
358
+ const j = spawnSync(process.execPath, [YAD, 'map', '--json'], { cwd: root, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1', [REPORTS_ENV]: path.join(ws, 'r') } });
359
+ assert.equal(j.status, 0, j.stderr);
360
+ assert.equal(JSON.parse(j.stdout).command, 'map');
361
+ assert.equal(classify(['map']), 'local-write', 'it runs a server until Ctrl-C, as brain view does');
362
+ assert.equal(classify(['map'], ['html']), 'local-write');
363
+ assert.equal(readAllowList().includes('Bash(yad map:*)'), false);
364
+ } finally { done(ws); }
365
+ });
366
+
367
+ // ---- review 1 ------------------------------------------------------------------------------------
368
+
369
+ test('review 1: --anonymous masks names joined by dots, underscores or nothing, and says nothing moved', () => {
370
+ const i = baseInputs();
371
+ i.branches.push(
372
+ { repo: 'api', name: 'kit.ansel/EP-login-S01-try', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 },
373
+ { repo: 'api', name: 'feat/EP-login-bo_lindqvist', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
374
+ { repo: 'api', name: 'fix/kitansel-typo', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 });
375
+ const digest = digestOf(mapModel(baseInputs(), { now: NOW }));
376
+ const m = mapModel(i, { now: NOW, anonymous: true, previous: digest });
377
+ const text = JSON.stringify(m).toLowerCase();
378
+ for (const word of ['kit', 'ansel', 'lindqvist', 'kitansel']) assert.equal(text.includes(word), false, word);
379
+ assert.ok(m.branches.some((b) => b.name === 'someone/EP-login-S01-try'));
380
+ assert.ok(m.branches.some((b) => b.name === 'feat/EP-login-someone_someone'));
381
+ assert.deepEqual(m.moved, []);
382
+ assert.equal(m.since, null);
383
+ });
384
+
385
+ test('review 7: under --anonymous an address hides the part before its @, never the placeholder words or the domain', () => {
386
+ const i = baseInputs({ stories: [{ id: 'EP-login-S09', epic: 'EP-login', status: 'draft', owner: 'zed@example.com', repos: [] },
387
+ { id: 'EP-login-S08', epic: 'EP-login', status: 'draft', owner: '@quinn', repos: [] },
388
+ { id: 'EP-login-S07', epic: 'EP-login', status: 'draft', owner: 'ula@example.com Ula Marsh', repos: [] },
389
+ { id: 'EP-login-S06', epic: 'EP-login', status: 'draft', owner: 'vic@nash@example.com', repos: [] },
390
+ { id: 'EP-login-S05', epic: 'EP-login', status: 'draft', owner: 'Rae Moss <wren@example.com>', repos: [] },
391
+ { id: 'EP-login-S04', epic: 'EP-login', status: 'draft', owner: 'yul @ example.com', repos: [] },
392
+ { id: 'EP-login-S03', epic: 'EP-login', status: 'draft', owner: '__@example.com', repos: [] },
393
+ { id: 'EP-login-S10', epic: 'EP-login', status: 'draft', owner: 'प्रिया शर्मा <p@example.com>', repos: [] },
394
+ { id: 'EP-login-S11', epic: 'EP-login', status: 'draft', owner: 'Jose\u0301 Ruiz <jr@example.com>', repos: [] },
395
+ { id: 'EP-login-S12', epic: 'EP-login', status: 'draft', owner: "Sean O'Brien <sean@example.com>", repos: [] },
396
+ { id: 'EP-login-S13', epic: 'EP-login', status: 'draft', owner: 'tam+map@example.com', repos: [] },
397
+ { id: 'EP-login-S14', epic: 'EP-login', status: 'draft', owner: '"lou"@example.com', repos: [] },
398
+ { id: 'EP-login-S15', epic: 'EP-login', status: 'draft', owner: 'Ned @kip', repos: [] }] });
399
+ i.branches.push(
400
+ { repo: 'api', name: 'feat/sign-in-with-google', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
401
+ { repo: 'api', name: 'fix/com-name-zed', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
402
+ { repo: 'api', name: 'quinn/try', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
403
+ { repo: 'api', name: 'fix/marsh-x', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
404
+ { repo: 'api', name: 'fix/nash-y', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
405
+ { repo: 'api', name: 'feat/ulamarsh', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
406
+ { repo: 'api', name: 'wren/go', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
407
+ { repo: 'api', name: 'feat/raemoss', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
408
+ { repo: 'api', name: 'yul/example-z', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
409
+ { repo: 'api', name: 'fix/प्रिया', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
410
+ { repo: 'api', name: 'fix/jose\u0301', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
411
+ { repo: 'api', name: "fix/o'brien", sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
412
+ { repo: 'api', name: 'tam+map/try', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
413
+ { repo: 'api', name: 'kip/x', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
414
+ { repo: 'api', name: 'lou/go', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 },
415
+ { repo: 'api', name: 'fix-', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 });
416
+ const m = mapModel(i, { now: NOW, anonymous: true });
417
+ const names = m.branches.map((b) => b.name);
418
+ assert.ok(names.includes('feat/sign-in-with-google'), 'the words of the placeholder are not names');
419
+ assert.ok(names.includes('fix/com-name-someone'), 'the local part is masked, the domain is not');
420
+ assert.ok(names.includes('someone/try'), 'a handle is masked without its @');
421
+ assert.ok(names.includes('fix/someone-x'), 'a name written after an address is masked');
422
+ assert.ok(names.includes('fix/someone-y'), 'each part between two @ signs is masked');
423
+ assert.ok(names.includes('feat/someone'), 'the name beside an address, written joined, is masked');
424
+ assert.ok(names.includes('someone/go'), 'the part before the @ in `Name <addr>` is masked');
425
+ assert.equal(names.filter((n) => n === 'feat/someone').length, 2, '`Name <addr>` masks the joined name too');
426
+ assert.ok(names.includes('someone/example-z'), 'spaces round an @ still give only the part before it');
427
+ assert.ok(names.includes('fix-'), 'an empty piece is never a name');
428
+ const masked = (from) => !names.includes(from);
429
+ assert.ok(masked('fix/प्रिया'), 'a name with combining marks is masked whole');
430
+ assert.ok(masked('fix/jose\u0301'), 'a decomposed accent is part of the name');
431
+ assert.ok(masked("fix/o'brien"), "a name with an ' is masked whole");
432
+ assert.ok(masked('tam+map/try'), 'a local part with a + is masked whole');
433
+ assert.ok(masked('kip/x'), 'a handle after a name, with a space before its @, is masked');
434
+ assert.ok(names.includes('someone/go'), 'a quoted local part is masked');
435
+ assert.equal(names.filter((n) => n === 'someone/go').length, 2, '…and both `Name <addr>` and `"name"@x` give theirs');
436
+ assert.ok(names.includes('someone/example-z') && !names.includes('someone/someone-z'), 'a quoted local part leaves its domain alone');
437
+ // A leading-@ value may be a handle or a domain: it is masked whole, on purpose, even when that over-masks.
438
+ const dom = mapModel(baseInputs({ stories: [{ id: 'EP-login-S09', epic: 'EP-login', status: 'draft', owner: '@example.com', repos: [] }],
439
+ branches: [{ repo: 'api', name: 'fix/com-z', sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 }] }), { now: NOW, anonymous: true });
440
+ assert.ok(dom.branches.some((b) => b.name === 'fix/someone-z'), 'a leading-@ domain is masked, on purpose');
441
+ });
442
+
443
+ test('review 10: under --anonymous the words of the address placeholder are never masked; the raw values still are', () => {
444
+ const branch = (name) => ({ repo: 'api', name, sha: 'f'.repeat(40), date: daysAgo(2), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 });
445
+ const i = baseInputs({ stories: [{ id: 'EP-login-S09', epic: 'EP-login', status: 'draft', owner: 'ula@example.com Ula Marsh', repos: [] }] });
446
+ i.branches.push(branch('feat/sign-in-with-google'), branch('fix/marsh-x'));
447
+ const names = mapModel(i, { now: NOW, anonymous: true }).branches.map((b) => b.name);
448
+ assert.ok(names.includes('feat/sign-in-with-google'), 'the placeholder words are not names');
449
+ assert.ok(names.includes('fix/someone-x'), 'a name in the raw value is still masked');
450
+ });
451
+
452
+ test('review 1: the person a gate waits on, and who released last, are on the people list', () => {
453
+ const i = baseInputs({ waits: [{ epic: 'EP-later', step: 'epic-review', kind: 'gate', owner: 'Ida Quell' }] });
454
+ const m = mapModel(i, { now: NOW });
455
+ const ida = m.people.find((p) => p.name === 'Ida Quell');
456
+ assert.deepEqual(ida.roles, ['owner'], 'the person a gate waits on owns that step');
457
+ assert.equal(m.waiting[0].person, ida.key);
458
+ assert.ok(m.people.some((p) => p.key === m.repos[0].integration.by), 'every "by" can be looked up');
459
+ const anon = mapModel(i, { now: NOW, anonymous: true });
460
+ assert.ok(anon.waiting[0].person, 'anonymous keeps the link to the badge');
461
+ assert.ok(anon.people.some((p) => p.key === anon.repos[0].production.by));
462
+ });
463
+
464
+ test('review 1: a bad group pattern is left out, an epic id matches only whole, and a task-named port counts for that task only', () => {
465
+ const i = baseInputs({ groups: [{ id: 'broken', label: 'Broken', pattern: '([' }, { id: 'chores', label: 'Chores', pattern: '^chore/' }, { id: 'rest', label: 'Rest' }] });
466
+ i.epics.push({ id: 'EP-log', title: 'Logs', currentStep: 'epic', steps: [], owner: null, repos: [], onMain: true, stepOwners: {}, approvals: [] });
467
+ const m = mapModel(i, { now: NOW });
468
+ assert.equal(m.groups.some((g) => g.id === 'broken'), false);
469
+ assert.equal(m.branches.find((b) => b.name === 'chore/kit-cleanup').group, 'chores');
470
+ assert.equal(m.branches.find((b) => b.name === 'feat/EP-login-S02-remember').epic, 'EP-login', 'EP-log is not a match for EP-login');
471
+ // A direct-to-Production branch named for T01 makes T01 live, not T02.
472
+ const j = baseInputs();
473
+ j.tasks.push({ story: 'EP-login-S01', epic: 'EP-login', task: 'T02', repo: 'api', builder: null, reviewers: [], reach: { found: true, prod: false, integ: true, via: null } });
474
+ const mm = mapModel(j, { now: NOW });
475
+ assert.equal(mm.tasks.find((t) => t.task === 'T02').state, 'merged');
476
+ });
477
+
478
+ test('review 1: gathering says when a group pattern is invalid, and reads a story-named port for every task of it', () => {
479
+ const { ws, root, api } = workspace({ production: { api: 'main' } });
480
+ try {
481
+ // A second task of S01, only on dev; then the story rebuilt on its own branch, merged straight into main.
482
+ git(api, ['checkout', '-q', '-b', 'feat/EP-login-S01-T02', 'dev']);
483
+ put(path.join(api, 't2.txt'), 't2');
484
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 't2'], PEOPLE.bo, daysAgo(3));
485
+ git(api, ['checkout', '-q', 'dev']);
486
+ git(api, ['merge', '-q', '--no-ff', 'feat/EP-login-S01-T02', '-m', "Merge branch 'feat/EP-login-S01-T02' into 'dev'"], PEOPLE.mae, daysAgo(3));
487
+ const t2 = git(api, ['rev-parse', 'HEAD']);
488
+ git(api, ['checkout', '-q', '-b', 'feat/EP-login-S01-T02-production', 'main']);
489
+ put(path.join(api, 't2p.txt'), 'p');
490
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 'port'], PEOPLE.bo, daysAgo(2));
491
+ git(api, ['checkout', '-q', 'main']);
492
+ git(api, ['merge', '-q', '--no-ff', 'feat/EP-login-S01-T02-production', '-m', "Merge branch 'feat/EP-login-S01-T02-production' into 'main'"], PEOPLE.mae, daysAgo(2));
493
+ git(api, ['checkout', '-q', 'dev']);
494
+ git(api, ['push', '-q', 'origin', '--all']); git(api, ['fetch', '-q', 'origin']);
495
+ const logf = path.join(root, 'epics', 'EP-login', '.sdlc', 'build-log.json');
496
+ const log = JSON.parse(fs.readFileSync(logf, 'utf8'));
497
+ log.ships.push({ story: 'EP-login-S01', task: 'T02', repo: 'api', branch: 'feat/EP-login-S01-T02', mergeCommit: t2, shippedAt: '2026-11-11', engineer_review: [] });
498
+ put(logf, log);
499
+ const cfg = JSON.parse(fs.readFileSync(path.join(root, '.sdlc', 'product.json'), 'utf8'));
500
+ cfg.map.groups = [{ id: 'broken', pattern: '([' }];
501
+ put(path.join(root, '.sdlc', 'product.json'), cfg);
502
+ const g = gatherMap(root, { now: NOW });
503
+ assert.match(g.problems.join('\n'), /the pattern of "broken" is not a valid pattern/);
504
+ const t = (id) => g.inputs.tasks.find((x) => x.task === id);
505
+ assert.equal(t('T02').reach.via?.branch, 'feat/EP-login-S01-T02-production', 'its own port');
506
+ assert.equal(t('T01').reach.via, null, 'a port named for T02 is not T01\'s');
507
+ } finally { done(ws); }
508
+ });
509
+
510
+ // ---- review 2 ------------------------------------------------------------------------------------
511
+
512
+ test('review 2: a port names a task by any separator and by its number; a story-only port is every task\'s', () => {
513
+ const d = (branch) => [{ date: '2026-11-01T00:00:00Z', branch }];
514
+ const is = (branch, task) => !!portFor(d(branch), 'EP-login-S01', task);
515
+ for (const b of ['feat/EP-login-S01-T01', 'fix/EP-login-S01-T01-redo', 'EP-login-S01_T01', 'EP-login-S01.T1', 'EP-login-S01/T01']) assert.equal(is(b, 'T01'), true, b);
516
+ for (const b of ['feat/EP-login-S01-T02', 'EP-login-S01_T02', 'EP-login-S01.T02', 'EP-login-S01/T2', 'EP-login-S010', 'EP-login-S01-T010', 'feat/EP-login-S01-fix-T02', 'EP-login-S01-v2.T3', 'EP-login-S01-T02/EP-login-S01-hotfix']) assert.equal(is(b, 'T01'), false, b);
517
+ for (const b of ['feat/EP-login-S01-hotfix', 'EP-login-S01', 'EP-login-S01-production']) { assert.equal(is(b, 'T01'), true, b); assert.equal(is(b, 'T02'), true, b); }
518
+ assert.equal(is('EP-login-S01-T1', 'T1'), true);
519
+ assert.equal(portFor([], 'EP-login-S01', 'T01'), null);
520
+ });
521
+
522
+ test('review 2: gathering reads a story-only port for every task of that story', () => {
523
+ const { ws, root, api } = workspace({ production: { api: 'main' } });
524
+ try {
525
+ git(api, ['checkout', '-q', '-b', 'feat/EP-login-S01-production', 'main']);
526
+ put(path.join(api, 'p.txt'), 'p');
527
+ git(api, ['add', '-A']); git(api, ['commit', '-q', '-m', 'port'], PEOPLE.bo, daysAgo(2));
528
+ git(api, ['checkout', '-q', 'main']);
529
+ git(api, ['merge', '-q', '--no-ff', 'feat/EP-login-S01-production', '-m', "Merge branch 'feat/EP-login-S01-production' into 'main'"], PEOPLE.mae, daysAgo(2));
530
+ git(api, ['checkout', '-q', 'dev']);
531
+ git(api, ['push', '-q', 'origin', '--all']); git(api, ['fetch', '-q', 'origin']);
532
+ const m = mapModel(gatherMap(root, { now: NOW }).inputs, { now: NOW });
533
+ const t = m.tasks.find((x) => x.task === 'T01');
534
+ assert.equal(t.state, 'live');
535
+ assert.equal(t.via, 'feat/EP-login-S01-production');
536
+ } finally { done(ws); }
537
+ });
538
+
539
+ test('review 2: where a recursive watch is not offered, each folder is watched; with nothing to watch, yad says so', async () => {
540
+ const { ws, root } = workspace();
541
+ const watch = fs.watch;
542
+ let recursiveAsked = 0, plain = 0;
543
+ fs.watch = (p, opts, cb) => { if (opts && opts.recursive) { recursiveAsked++; const e = new Error('no recursive watch'); e.code = 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM'; throw e; } plain++; return watch(p, opts, cb); };
544
+ let s = null;
545
+ try {
546
+ s = await startMapServer(root, { live: true, debounce: 50, env: { [REPORTS_ENV]: path.join(ws, 'r') } });
547
+ const status = await new Promise((resolve, reject) => {
548
+ const req = http.request({ host: '127.0.0.1', port: s.port, path: `/events?t=${s.token}`, headers: { Host: `127.0.0.1:${s.port}` } }, (res) => {
549
+ res.on('data', (c) => { if (String(c).includes('event: status')) { req.destroy(); resolve(String(c)); } });
550
+ });
551
+ req.on('error', (e) => { if (e.code !== 'ECONNRESET') reject(e); });
552
+ req.end();
553
+ });
554
+ assert.ok(recursiveAsked >= 1);
555
+ assert.ok(plain > 2, 'each folder of the record is watched on its own');
556
+ assert.match(status, /"live":true/);
557
+ } finally { fs.watch = watch; if (s) await s.close(); }
558
+ // A folder with nothing to watch: the server still starts, and says the page will not change by itself.
559
+ const bare = path.join(ws, 'bare');
560
+ put(path.join(bare, 'x.txt'), 'x');
561
+ const out = [];
562
+ const log = console.log;
563
+ console.log = (x) => out.push(String(x));
564
+ try {
565
+ const srv = await runMap(bare, { live: true, wait: false, env: { [REPORTS_ENV]: path.join(ws, 'r') } });
566
+ await srv.close();
567
+ } finally { console.log = log; done(ws); }
568
+ assert.match(out.join('\n'), /nothing here can be watched/);
569
+ });
570
+
571
+ // ---- review 7 ------------------------------------------------------------------------------------
572
+
573
+ test('review 7: a branch name holding an address shows "an-address" in every map; a login with an @ is fingerprinted', () => {
574
+ const i = baseInputs();
575
+ i.branches.push({ repo: 'api', name: 'kit@example.com/EP-login-S02-try', sha: 'a'.repeat(40), date: daysAgo(1), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 });
576
+ i.tasks[0].branch = 'feat/kit@example.com';
577
+ i.tasks[0].reach = { found: true, prod: false, integ: false, via: { branch: 'port/kit@example.com', date: daysAgo(1) } };
578
+ const member = { primary: { platform: 'github', host: 'github.com', login: 'kit@example.com' }, accounts: [{ platform: 'github', host: 'github.com', login: 'kit@example.com' }], names: ['Kit Ansel'], emails: [], matchLogins: ['kit@example.com'] };
579
+ for (const anonymous of [false, true]) {
580
+ const m = mapModel({ ...i, members: [member] }, { now: NOW, anonymous });
581
+ assert.equal(JSON.stringify(m).split('example.com').length, 1, `anonymous: ${anonymous}`);
582
+ }
583
+ const named = mapModel({ ...i, members: [member] }, { now: NOW });
584
+ assert.ok(named.branches.some((b) => /^an-address-[0-9a-f]{6}\/EP-login-S02-try$/.test(b.name) && b.story === 'EP-login-S02'), 'the rest of the name still links it');
585
+ assert.equal(JSON.stringify(named).includes('rawName'), false, 'the raw name never reaches the model');
586
+ assert.match(named.people.find((p) => p.name === 'Kit Ansel').key, /^m:@[0-9a-f]{16}$/);
587
+ });
588
+
589
+ test('review 8: two address branches keep apart; the epic is read before masking; the checkout branch and a link with an address are masked', () => {
590
+ const i = baseInputs({ product: { name: 'Orchard', branch: 'feat/kit@example.com', sha: 'a'.repeat(40) } });
591
+ i.branches.push(
592
+ { repo: 'api', name: 'feat/a@example.com', sha: 'a'.repeat(40), date: daysAgo(1), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 },
593
+ { repo: 'api', name: 'feat/b@example.com', sha: 'b'.repeat(40), date: daysAgo(1), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 },
594
+ { repo: 'api', name: 'EP-login-S02@bo', sha: 'c'.repeat(40), date: daysAgo(1), author: 'Bo Lindqvist', inProd: false, inInteg: false, ahead: 1 });
595
+ i.tasks[0].pr = 'https://kit@example.com@git.example.org/orchard/api/pull/4';
596
+ const m = mapModel(i, { now: NOW });
597
+ assert.equal(JSON.stringify(m).split('example.com').length, 1);
598
+ const ids = m.branches.map((b) => b.id);
599
+ assert.equal(new Set(ids).size, ids.length, 'no two branches share an id');
600
+ assert.equal(m.branches.find((b) => b.name.startsWith('an-address') && b.repo === 'api' && b.sha === 'c'.repeat(10)).story, 'EP-login-S02');
601
+ assert.equal(m.tasks[0].pr, null);
602
+ assert.match(m.product.branch, /^feat\/an-address-[0-9a-f]{6}$/);
603
+ });
604
+
605
+ test('review 9: an anonymous map numbers masked addresses, so no hash of an address is left to match', () => {
606
+ const i = baseInputs({ product: { name: 'Orchard', branch: 'kit-ansel/notes', sha: 'a'.repeat(40) } });
607
+ i.branches.push(
608
+ { repo: 'api', name: 'feat/a@example.com', sha: 'a'.repeat(40), date: daysAgo(1), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 },
609
+ { repo: 'api', name: 'feat/b@example.com', sha: 'b'.repeat(40), date: daysAgo(1), author: 'Kit Ansel', inProd: false, inInteg: false, ahead: 1 });
610
+ const m = mapModel(i, { now: NOW, anonymous: true });
611
+ const names = m.branches.filter((b) => b.name.includes('an-address')).map((b) => b.name).sort();
612
+ assert.deepEqual(names, ['feat/an-address-1', 'feat/an-address-2']);
613
+ assert.doesNotMatch(JSON.stringify(m), /an-address-[0-9a-f]{6}/);
614
+ assert.equal(m.product.branch, 'someone/notes', 'the checkout branch is masked too');
615
+ });