yadflow 4.8.0 → 4.9.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.
@@ -0,0 +1,296 @@
1
+ // #354 — each story records the design frames it builds, so the developer never has to ask which ones.
2
+ //
3
+ // The stories step writes the frame IDs into the story's frontmatter, as one inline list:
4
+ //
5
+ // design-frames: [12:34, 56:78]
6
+ //
7
+ // The IDs only. Each one is a `nodeId` the UI step already recorded in the epic's
8
+ // `.sdlc/design-links.json` (`screens[]`: name, platform, nodeId, url), and the name and URL are read
9
+ // from there, so they are written down once. `design-frames: []` says the story has no screens (a
10
+ // backend story); no key at all says nobody recorded them.
11
+ //
12
+ // ONE RULE, TWO READERS. `frameFindings` decides every problem; `yad story frames` and `yad doctor` both
13
+ // print what it returns, and every finding is a warning in both, so the two can never disagree about a
14
+ // story. The only refusals are about the command line itself: a word that is not a story id, or a story
15
+ // with no file.
16
+ //
17
+ // The frontmatter reader is `readFrontmatter`: one line per key, a `[ … ]` value split on commas, and
18
+ // everything else kept as the rest of the line. So a trailing `# note` turns the list into a plain
19
+ // string, and a YAML `- item` list on the next lines is not read at all (the key reads as blank). Both
20
+ // are reported here instead of being read as "no frames".
21
+ import fs from 'node:fs';
22
+ import path from 'node:path';
23
+
24
+ import { c, emitJSON, forTerminal, hand, info, log, ok, readJSONStrict, refuse, stripAnsi, warn } from './lib.mjs';
25
+ import { epicRoot, parseFrontmatter } from './epic-state.mjs';
26
+ import { STORY_RE, storyEpic } from './build.mjs';
27
+ import { PROJECT_FILES } from './manifest.mjs';
28
+ import { reachFor } from './toolbox.mjs';
29
+
30
+ export const FRAMES_KEY = 'design-frames';
31
+ export const DESIGN_LINKS_FILE = path.join('.sdlc', 'design-links.json');
32
+
33
+ // A character an ID cannot hold and still be read back the same: whitespace splits it in a person's
34
+ // eye, `#` is the comment trap, and a bracket ends or starts the list. A comma cannot be tested here —
35
+ // the reader has already split on it — so an ID holding one reads as two halves, and neither is found.
36
+ const BAD_ID = /[\s#[\]]/;
37
+
38
+ const quote = (s) => `\`${forTerminal(s)}\``;
39
+
40
+ // The epic's design-links.json as { state: 'missing' | 'unreadable' | 'ok', screens, tool, fileUrl, why }.
41
+ // A file that does not parse, or parses without a `screens` list, is `unreadable` — never "no screens",
42
+ // which would report every recorded frame as missing for the wrong reason.
43
+ export function readDesignLinks(epicDir) {
44
+ const file = path.join(epicDir, DESIGN_LINKS_FILE);
45
+ if (!fs.existsSync(file)) return { state: 'missing' };
46
+ let data;
47
+ try {
48
+ data = readJSONStrict(file, null);
49
+ } catch {
50
+ return { state: 'unreadable', why: 'it does not parse as JSON' };
51
+ }
52
+ if (!data || typeof data !== 'object' || Array.isArray(data) || !Array.isArray(data.screens)) {
53
+ return { state: 'unreadable', why: 'it has no `screens` list' };
54
+ }
55
+ const str = (v) => (typeof v === 'string' ? v : null);
56
+ return {
57
+ state: 'ok',
58
+ tool: str(data.tool),
59
+ fileUrl: str(data.fileUrl),
60
+ screens: data.screens.filter((s) => s && typeof s === 'object' && typeof s.nodeId === 'string'),
61
+ };
62
+ }
63
+
64
+ // The key spelled another way — `Design-Frames`, `design_frames`, `designFrames`. It is never read as
65
+ // the key, but it is said: a story that misspells it must not read as "nobody recorded frames".
66
+ const keyVariant = (fm) => Object.keys(fm).find((k) => k !== FRAMES_KEY && k.toLowerCase().replace(/[_-]/g, '') === 'designframes');
67
+ export const recordsFrames = (fm = {}) => Object.hasOwn(fm, FRAMES_KEY) || keyVariant(fm) !== undefined;
68
+
69
+ // `"12:34"` and `'12:34'` — a YAML habit. The reader keeps the quote marks, so they are taken off here
70
+ // (and said), rather than reported as an ID that is not in design-links.json.
71
+ const unquote = (id) => (id.length >= 3 && /^(["']).+\1$/.test(id) ? id.slice(1, -1) : id);
72
+
73
+ // The pure rule. `fm` is the story's parsed frontmatter, `links` what `readDesignLinks` returned.
74
+ // Returns { recorded, ids, frames, findings }: `recorded` is false only when the key is absent;
75
+ // `findings` are { kind, message } — every one a warning.
76
+ export function frameFindings(fm = {}, links = { state: 'missing' }) {
77
+ if (!Object.hasOwn(fm, FRAMES_KEY)) {
78
+ const k = keyVariant(fm);
79
+ const findings = k === undefined ? [] : [{ kind: 'key-spelling', message: `\`${forTerminal(k)}:\` is not read — the key is spelled \`${FRAMES_KEY}\`, exactly` }];
80
+ return { recorded: false, ids: [], frames: [], findings };
81
+ }
82
+ const v = fm[FRAMES_KEY];
83
+ const findings = [];
84
+ // The right key AND a misspelled one: the second is never read, so its IDs would be lost in silence.
85
+ const twin = keyVariant(fm);
86
+ if (twin !== undefined) findings.push({ kind: 'key-spelling', message: `\`${forTerminal(twin)}:\` is not read — only \`${FRAMES_KEY}\` is; move its IDs into that line and delete it` });
87
+ if (!Array.isArray(v)) {
88
+ const text = String(v ?? '');
89
+ findings.push(text.includes('#')
90
+ ? { kind: 'commented', message: `\`${FRAMES_KEY}: ${forTerminal(text)}\` has a \`#\` after it, so it is read as text, not a list — write the list bare, with no comment on the line` }
91
+ : text === ''
92
+ ? { kind: 'not-a-list', message: `\`${FRAMES_KEY}:\` is blank — write the IDs on the same line, as \`${FRAMES_KEY}: [id, id]\` (a \`- id\` list on the lines below is not read), or \`${FRAMES_KEY}: []\` for a story with no screens` }
93
+ : { kind: 'not-a-list', message: `\`${FRAMES_KEY}: ${forTerminal(text)}\` is not a list — write the IDs inside one pair of brackets, as \`${FRAMES_KEY}: [id, id]\`` });
94
+ return { recorded: true, ids: [], frames: [], findings };
95
+ }
96
+ const quoted = v.filter((id) => unquote(id) !== id);
97
+ if (quoted.length) findings.push({ kind: 'quoted', message: `frame IDs should be written without quotes: ${quoted.map(quote).join(', ')} — they are read without them` });
98
+ const ids = v.map(unquote);
99
+ const seen = new Set();
100
+ for (const id of ids) {
101
+ if (BAD_ID.test(id)) findings.push({ kind: 'bad-id', message: `frame ID ${quote(id)} holds a space, \`#\` or bracket, so it cannot be read back — give the frame a plain ID in the design tool` });
102
+ if (seen.has(id)) findings.push({ kind: 'duplicate', message: `frame ID ${quote(id)} is listed twice` });
103
+ seen.add(id);
104
+ }
105
+ const unique = [...seen];
106
+ if (!unique.length) return { recorded: true, ids, frames: [], findings };
107
+ if (links.state === 'missing') {
108
+ findings.push({ kind: 'no-design-links', message: `${unique.length} frame ID(s) are recorded, but there is no ${DESIGN_LINKS_FILE} to read their names and links from — the UI step writes it` });
109
+ return { recorded: true, ids, frames: unique.map((id) => ({ id, found: false })), findings };
110
+ }
111
+ if (links.state === 'unreadable') {
112
+ findings.push({ kind: 'design-links-unreadable', message: `${DESIGN_LINKS_FILE} cannot be read (${links.why}), so the frame IDs cannot be checked` });
113
+ return { recorded: true, ids, frames: unique.map((id) => ({ id, found: false })), findings };
114
+ }
115
+ const frames = unique.map((id) => {
116
+ const s = links.screens.find((x) => x.nodeId === id);
117
+ if (!s) return { id, found: false };
118
+ const str = (x) => (typeof x === 'string' ? x : null);
119
+ return { id, found: true, name: str(s.name), platform: str(s.platform), url: str(s.url) };
120
+ });
121
+ const missing = frames.filter((f) => !f.found);
122
+ if (missing.length) {
123
+ findings.push({ kind: 'not-found', message: `frame ID(s) ${missing.map((f) => quote(f.id)).join(', ')} are not in ${DESIGN_LINKS_FILE} — copy the \`nodeId\` exactly, or re-run the UI step if the screen is new` });
124
+ }
125
+ return { recorded: true, ids, frames, findings };
126
+ }
127
+
128
+ // A story file's frontmatter, read the same way by both readers. A byte-order mark, Windows line endings
129
+ // (git's `core.autocrlf` writes them on checkout) and spaces at the end of a line are taken out first:
130
+ // the shared reader matches `---\n` and `[ … ]` to the end of the line, so without this a story checked
131
+ // out on Windows would read as "nobody recorded frames", and `[12:34] ` as not a list.
132
+ export function readStoryFrontmatter(file) {
133
+ const text = fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n').replace(/[ \t]+$/gm, '');
134
+ return parseFrontmatter(text);
135
+ }
136
+
137
+ // The Product's design.json as { state: 'missing' | 'unreadable' | 'ok', data }. Read safely, like
138
+ // design-links.json: a file that does not parse is said, never thrown out of the command.
139
+ export function readDesignConfig(root) {
140
+ const file = path.join(root, PROJECT_FILES.designConfig);
141
+ if (!fs.existsSync(file)) return { state: 'missing' };
142
+ try {
143
+ const data = readJSONStrict(file, null);
144
+ return data && typeof data === 'object' && !Array.isArray(data) ? { state: 'ok', data } : { state: 'unreadable' };
145
+ } catch {
146
+ return { state: 'unreadable' };
147
+ }
148
+ }
149
+
150
+ // #358 — before UI work, can the agent reach the design tool with the right file open? yad cannot ask:
151
+ // an MCP server belongs to the agent's session. So this says HOW to ask, and what to tell the person
152
+ // when the answer is no; the yad-spec and yad-implement skills make the call and stop on a failure.
153
+ // null when the story names no frame (no UI task, nothing to check). `reachable` is `check` (probe, and
154
+ // stop when it fails) or `not-checkable` (nothing to probe: go on with the links). `appBound` is true (read
155
+ // through the running app), false (a hosted server: sign in) or null (yad cannot tell: `stop` names both).
156
+ export function designPreflight(design, links, frames) {
157
+ if (!frames.length) return null;
158
+ const d = design.state === 'ok' ? design.data : null;
159
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : null);
160
+ const tool = str(d?.tool);
161
+ const notCheckable = (why) => ({ tool, reachable: 'not-checkable', why });
162
+ if (design.state === 'missing') return notCheckable('no .sdlc/design.json: no design tool is connected');
163
+ if (design.state === 'unreadable') return notCheckable('.sdlc/design.json cannot be read');
164
+ if (!tool || tool === 'none') return notCheckable('design.json connects no design tool');
165
+ if (d.source === 'unavailable') return notCheckable(`design.json records ${forTerminal(tool)} as unavailable (source: unavailable)`);
166
+ const reach = reachFor(tool);
167
+ if (!reach) return notCheckable(`yad has no reachability check for ${forTerminal(tool)}`);
168
+ const provider = str(d.provider) ?? str(d.source);
169
+ // The MCP id is free text: `Figma-Desktop`, `html.to.design` and ` html_to_design ` are the names yad
170
+ // knows, so names are compared on their letters and digits alone.
171
+ const fold = (s) => String(s).toLowerCase().replace(/[^a-z0-9]/g, '');
172
+ const key = provider === null ? null : fold(provider);
173
+ const listed = (list) => key !== null && Array.isArray(list) && list.some((p) => fold(p) === key);
174
+ // A provider that only writes (html-to-design) has no call that reads a frame: probing it would fail
175
+ // on every story and make the person override each time.
176
+ if (listed(reach.writers)) return notCheckable(`the connected provider ${forTerminal(provider)} cannot read a frame`);
177
+ // The frames come from design-links.json. Without it — or with one the UI step wrote for ANOTHER tool —
178
+ // the IDs belong to nothing this tool can open, and a probe would blame the app.
179
+ if (links.state === 'missing') return notCheckable('there is no design-links.json for the frame IDs — re-run the UI step');
180
+ if (links.state === 'unreadable') return notCheckable(`design-links.json cannot be read (${links.why})`);
181
+ if (links.tool && fold(links.tool) !== fold(tool)) {
182
+ return notCheckable(`design-links.json was recorded for ${forTerminal(links.tool)}, but design.json now connects ${forTerminal(tool)} — re-run the UI step`);
183
+ }
184
+ // Every recorded ID is unresolved: the bad IDs are the problem (the warnings name them), not the app.
185
+ const found = frames.find((f) => f.found);
186
+ if (!found) return notCheckable('no recorded frame is in design-links.json — fix the frame IDs first');
187
+ const appBound = reach.appBound === true || listed(reach.appBound) ? true : listed(reach.signInOnly) ? false : null;
188
+ // design.json's project_url is a project, not a file, so it is never compared against.
189
+ const file = links.fileUrl;
190
+ const fill = (s) => s.replace(/<file>/g, file ? `\`${forTerminal(file)}\`` : 'the design file').replace(/<frame>/g, `\`${forTerminal(found.id)}\``);
191
+ return {
192
+ tool, provider, reachable: 'check', appBound, file, frame: found.id,
193
+ probe: fill(reach.probe),
194
+ stop: fill(appBound === true ? reach.open : appBound === false ? reach.signIn : reach.either),
195
+ };
196
+ }
197
+
198
+ const isFile = (p) => { try { return fs.statSync(p).isFile(); } catch { return false; } };
199
+
200
+ // One story's frames. Throws { message, hint } only for the command line: a word that is not a story
201
+ // id, or a story with no file. Everything about the frames themselves comes back in `findings`.
202
+ export function readStoryFrames(root, story) {
203
+ if (!story || story === true) {
204
+ throw Object.assign(new Error('yad story frames needs a story id'), { hint: 'use: yad story frames <story-id>, such as EP-checkout-S01' });
205
+ }
206
+ if (!STORY_RE.test(String(story))) {
207
+ throw Object.assign(new Error(`'${forTerminal(story)}' is not a story id`), { hint: 'expected EP-<slug>-S<n>, such as EP-checkout-S01' });
208
+ }
209
+ const epic = storyEpic(story);
210
+ const epicDir = epicRoot(root, epic);
211
+ const file = path.join(epicDir, 'stories', `${story}.md`);
212
+ if (!isFile(file)) {
213
+ throw Object.assign(new Error(`no story file epics/${epic}/stories/${story}.md`), { hint: 'check the story id; the stories step writes one file per story' });
214
+ }
215
+ const links = readDesignLinks(epicDir);
216
+ const r = frameFindings(readStoryFrontmatter(file), links);
217
+ return {
218
+ story, epic,
219
+ tool: links.state === 'ok' ? links.tool : null,
220
+ fileUrl: links.state === 'ok' ? links.fileUrl : null,
221
+ ...r,
222
+ preflight: designPreflight(readDesignConfig(root), links, r.frames),
223
+ };
224
+ }
225
+
226
+ // Every story that records frames (or misspells the key), for `yad doctor`:
227
+ // [{ epic, story, recorded, frames: <how many IDs>, findings }]. The epic folders are the caller's to
228
+ // pick. A story file the command cannot reach — named for another epic, or not `EP-<slug>-S<n>.md` — is
229
+ // reported as that, never with advice to run a command that would refuse it.
230
+ export function allStoryFrames(root, epicIds) {
231
+ const out = [];
232
+ for (const epic of epicIds) {
233
+ const epicDir = epicRoot(root, epic);
234
+ const dir = path.join(epicDir, 'stories');
235
+ let names;
236
+ try {
237
+ // `isFile` follows a symlink, as the command's own check does, so the two read the same stories.
238
+ names = fs.readdirSync(dir).filter((n) => n.endsWith('.md') && isFile(path.join(dir, n))).sort();
239
+ } catch {
240
+ continue;
241
+ }
242
+ let links = null; // read once per epic, and only when a story there records frames
243
+ for (const f of names) {
244
+ const fm = readStoryFrontmatter(path.join(dir, f));
245
+ if (!recordsFrames(fm)) continue;
246
+ const story = f.replace(/\.md$/, '');
247
+ if (!STORY_RE.test(story) || storyEpic(story) !== epic) {
248
+ out.push({ epic, story, recorded: true, frames: 0, findings: [{ kind: 'not-a-story-file', message: `stories/${forTerminal(f)} records design frames, but its name is not ${epic}-S<n>.md, so \`yad story frames\` cannot read it — rename the file` }] });
249
+ continue;
250
+ }
251
+ links ??= readDesignLinks(epicDir);
252
+ const r = frameFindings(fm, links);
253
+ out.push({ epic, story, recorded: r.recorded, frames: r.ids.length, findings: r.findings });
254
+ }
255
+ }
256
+ return out;
257
+ }
258
+
259
+ // `yad story frames <story> [--json]`. Read only: it prints the story's frames and every finding as a
260
+ // warning, and exits 1 only for a refusal (an unknown action, a word that is not a story id, a story
261
+ // with no file).
262
+ export async function runStory(root, { action, story, json = false } = {}) {
263
+ if (action !== 'frames') {
264
+ refuse(action ? `unknown action: ${forTerminal(action)}` : 'yad story needs an action', 'use: yad story frames <story-id> [--json]', { json });
265
+ return { ok: false };
266
+ }
267
+ let r;
268
+ try {
269
+ r = readStoryFrames(root, story);
270
+ } catch (e) {
271
+ refuse(e.message, e.hint ?? null, { json });
272
+ return { ok: false };
273
+ }
274
+ const warnings = r.findings.map((f) => f.message);
275
+ if (json) {
276
+ emitJSON({
277
+ ok: true, story: r.story, epic: r.epic, tool: r.tool, fileUrl: r.fileUrl, recorded: r.recorded, preflight: r.preflight,
278
+ frames: r.frames, findings: r.findings.map((f) => ({ kind: f.kind, message: stripAnsi(f.message) })), warnings,
279
+ });
280
+ return { ok: true, ...r };
281
+ }
282
+ log(c.bold(`\n${r.story} — design frames${r.tool ? ` (${forTerminal(r.tool)})` : ''}`));
283
+ if (!r.recorded) info(`no design frames recorded — the stories step adds \`${FRAMES_KEY}: [id, …]\` to the story`);
284
+ else if (!r.ids.length && !r.findings.length) info(`no screens (\`${FRAMES_KEY}: []\`)`);
285
+ for (const f of r.frames) {
286
+ const id = forTerminal(f.id);
287
+ if (!f.found) { warn(`${id} — not found`); continue; }
288
+ ok(`${id} ${forTerminal(f.name ?? '(no name)')}${f.platform ? ` [${forTerminal(f.platform)}]` : ''}`);
289
+ if (f.url) log(` ${c.dim(forTerminal(f.url))}`);
290
+ }
291
+ for (const w of warnings) warn(w);
292
+ const p = r.preflight;
293
+ if (p?.reachable === 'check') hand(`before UI work: ${p.probe} — if that fails, stop: ${p.stop}`);
294
+ else if (p) info(`before UI work: the design tool is not checked (${p.why}) — build from the frame links`);
295
+ return { ok: true, ...r };
296
+ }
@@ -0,0 +1,140 @@
1
+ // #352: `yad doctor` checks the machine setup local work depends on — the active Node against each repo's
2
+ // pinned version, Docker only where a repo asks for it, and more than one glab config file.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import { execFileSync } from 'node:child_process';
6
+ import fs from 'node:fs';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
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 { nodePins, satisfies, nodeFix, dockerReasons, dockerState, glabConfigs } = await import('./machine.mjs');
20
+ const { machineChecks } = await import('./doctor.mjs');
21
+
22
+ const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-machine-')));
23
+ const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
24
+ const done = (T) => fs.rmSync(T, { recursive: true, force: true });
25
+
26
+ test('#352: satisfies reads the version forms repos pin, and says "not known" for the rest', () => {
27
+ const yes = [['24.22.1', '>= 22'], ['24.22.1', '>=22.0.0 <25'], ['25.0.0', '>24'], ['0.0.3', '^0.0.3'], ['24.22.1', '24'], ['24.22.1', 'v24.22.1'], ['24.22.1', '>=22'], ['24.22.1', '^24.1.0'], ['24.22.1', '~24.22.0'],
28
+ ['24.22.1', '22 || 24'], ['24.22.1', '>=20 <25'], ['24.22.1', '20 - 24.30'], ['24.22.1', '24.x'], ['24.22.1', '*'], ['22.8.0', '>=22.8'], ['24.22.1', '<=24']];
29
+ const no = [['22.8.0', '>22'], ['24.5.0', '>24.x'], ['24.1.9', '>24.1'], ['0.0.4', '^0.0.3'], ['20.19.5', '>= 22'], ['20.19.5', '24'], ['20.19.5', '>=22'], ['25.0.0', '^24.1.0'], ['24.23.0', '~24.22.0'], ['24.22.1', '<24'], ['24.22.1', '18 || 20'], ['21.0.0', '>=20 <21']];
30
+ for (const [v, s] of yes) assert.equal(satisfies(v, s), true, `${v} ${s}`);
31
+ for (const [v, s] of no) assert.equal(satisfies(v, s), false, `${v} ${s}`);
32
+ for (const s of ['lts/*', 'node', 'lts/iron', 'https://x', '24.0.0-rc.1']) assert.equal(satisfies('24.22.1', s), null, s);
33
+ assert.equal(satisfies('25.0.0-nightly', '>=22'), null, 'a pre-release Node is not judged');
34
+ });
35
+
36
+ test('#352: nodePins reads .nvmrc, .node-version, .tool-versions, engines.node and volta.node', () => {
37
+ const T = tmp();
38
+ try {
39
+ put(path.join(T, '.nvmrc'), '# the team\'s Node\n24\n');
40
+ put(path.join(T, '.node-version'), 'v24.1.0\n');
41
+ put(path.join(T, '.tool-versions'), 'python 3.12.1\nnodejs 24.2.0 # pinned\n');
42
+ put(path.join(T, 'package.json'), { engines: { node: '>=22' }, volta: { node: '24.3.0' } });
43
+ assert.deepEqual(nodePins(T), [
44
+ { source: '.nvmrc', want: '24' }, { source: '.node-version', want: 'v24.1.0' }, { source: '.tool-versions', want: '24.2.0' },
45
+ { source: 'package.json engines.node', want: '>=22' }, { source: 'package.json volta.node', want: '24.3.0' }]);
46
+ fs.rmSync(path.join(T, 'package.json'));
47
+ put(path.join(T, 'package.json'), '{ not json');
48
+ assert.equal(nodePins(T).length, 3, 'a package.json that does not parse pins nothing');
49
+ } finally { done(T); }
50
+ });
51
+
52
+ test('#352: the fix names nvm\'s commands when nvm is here, plain words otherwise', () => {
53
+ assert.match(nodeFix('24', { env: { NVM_DIR: '/x' }, home: '/nowhere' }), /^nvm install 24 && nvm use 24 \(and `nvm alias default 24`/);
54
+ assert.match(nodeFix('>=22', { env: { NVM_DIR: '/x' }, home: '/nowhere' }), /a version that meets >=22/);
55
+ assert.match(nodeFix('24', { env: {}, home: '/nowhere' }), /^install Node 24/);
56
+ });
57
+
58
+ test('#352: Docker is asked about only where a repo names it', () => {
59
+ const T = tmp();
60
+ try {
61
+ assert.deepEqual(dockerReasons(T), []);
62
+ put(path.join(T, 'package.json'), { scripts: {
63
+ test: 'node --test', scan: 'docker run --rm zricethezav/gitleaks', up: 'npm ci && docker compose up', full: '/usr/local/bin/docker build .',
64
+ notdocker: 'echo dockerfile', lint: 'eslint . --ignore-pattern docker', say: 'echo run docker', '\u001b]8;;x\u0007odd': 'docker ps' } });
65
+ assert.deepEqual(dockerReasons(T), ['package.json scripts: scan, up, full, ]8;;x odd'], 'a script name is cleaned for the terminal');
66
+ put(path.join(T, 'compose.yaml'), 'services: {}\n');
67
+ put(path.join(T, 'Dockerfile.dev'), 'FROM node\n');
68
+ put(path.join(T, '.pre-commit-config.yaml'), 'repos:\n - repo: local\n hooks:\n - id: x\n language: "docker_image" # the scanner\n');
69
+ assert.deepEqual(dockerReasons(T).sort(), ['.pre-commit-config.yaml (a docker hook)', 'Dockerfile.dev', 'compose.yaml', 'package.json scripts: scan, up, full, ]8;;x odd'].sort());
70
+ const runner = (answers) => (cmd, args) => ({ ok: answers[`${cmd} ${args[0]}`] ?? false });
71
+ assert.equal(dockerState({ runner: runner({}) }), 'missing');
72
+ assert.equal(dockerState({ runner: runner({ 'which docker': true }) }), 'stopped');
73
+ assert.equal(dockerState({ runner: runner({ 'which docker': true, 'docker info': true }) }), 'running');
74
+ } finally { done(T); }
75
+ });
76
+
77
+ test('#352: more than one glab config file is found where glab looks', () => {
78
+ const T = tmp();
79
+ try {
80
+ assert.deepEqual(glabConfigs({ env: {}, home: T, platform: 'darwin' }), []);
81
+ put(path.join(T, '.config/glab-cli/config.yml'), 'hosts: {}\n');
82
+ put(path.join(T, 'Library/Application Support/glab-cli/config.yml'), 'hosts: {}\n');
83
+ assert.equal(glabConfigs({ env: {}, home: T, platform: 'darwin' }).length, 2);
84
+ assert.equal(glabConfigs({ env: {}, home: T, platform: 'linux' }).length, 1, 'not the macOS folder on Linux');
85
+ // GLAB_CONFIG_DIR or XDG_CONFIG_HOME names the one place glab reads: no duplicate is possible.
86
+ put(path.join(T, 'own/config.yml'), 'hosts: {}\n');
87
+ assert.deepEqual(glabConfigs({ env: { GLAB_CONFIG_DIR: path.join(T, 'own') }, home: T, platform: 'darwin' }), [path.join(T, 'own/config.yml')]);
88
+ put(path.join(T, 'xdg/glab-cli/config.yml'), 'hosts: {}\n');
89
+ assert.deepEqual(glabConfigs({ env: { XDG_CONFIG_HOME: path.join(T, 'xdg') }, home: T, platform: 'darwin' }), [path.join(T, 'xdg/glab-cli/config.yml')]);
90
+ } finally { done(T); }
91
+ });
92
+
93
+ test('#352: yad doctor rows — a Node a repo does not accept, Docker stopped where a repo needs it, two glab configs', () => {
94
+ const T = tmp();
95
+ try {
96
+ const root = path.join(T, 'product');
97
+ put(path.join(root, '.sdlc/product.json'), { platform: null });
98
+ put(path.join(root, '.nvmrc'), '24\n');
99
+ put(path.join(root, 'package.json'), { engines: { node: '>=24.1' } });
100
+ const app = path.join(T, 'app');
101
+ put(path.join(app, 'package.json'), { engines: { node: '>=22' }, scripts: { scan: 'docker compose run gitleaks' } });
102
+ execFileSync('git', ['init', '-q'], { cwd: app });
103
+ put(path.join(root, '.sdlc/repos.json'), { repos: [{ name: 'app', path: '../app' }] });
104
+ const home = path.join(T, 'home');
105
+ put(path.join(home, '.config/glab-cli/config.yml'), 'hosts: {}\n');
106
+ put(path.join(home, 'Library/Application Support/glab-cli/config.yml'), 'hosts: {}\n');
107
+ const runner = (cmd, args) => ({ ok: `${cmd} ${args[0]}` === 'which docker' });
108
+ const rows = (nodeVersion) => { const checks = []; machineChecks(checks, root, { nodeVersion, env: { NVM_DIR: '/x' }, home, platform: 'darwin', runner }); return Object.fromEntries(checks.map((c) => [c.id, c])); };
109
+ const old = rows('20.19.5');
110
+ assert.equal(old['node-version:product'].status, 'warn');
111
+ assert.match(old['node-version:product'].message, /node 20\.19\.5 does not meet what the Product pins: 24 \(\.nvmrc\), >=24\.1 \(package\.json engines\.node\)/, 'both pins, one row');
112
+ assert.match(old['node-version:product'].hint, /nvm install 24 && nvm use 24/);
113
+ assert.equal(old['node-version:repo:app'].status, 'warn');
114
+ assert.equal(old.docker.status, 'warn');
115
+ assert.match(old.docker.message, /Docker is not running, and app \(package\.json scripts: scan\) asks for it/);
116
+ assert.equal(old['glab-config'].status, 'warn');
117
+ assert.match(old['glab-config'].message, /glab has 2 config files: ~\/\.config\/glab-cli\/config\.yml, ~\/Library\/Application Support\/glab-cli\/config\.yml/);
118
+ const now = rows('24.22.1');
119
+ assert.equal(now['node-version'].status, 'ok');
120
+ assert.match(now['node-version'].message, /meets every Node version the repos pin \(3 read\)/);
121
+ assert.equal(now['node-version:product'], undefined);
122
+ // The glab hint says what goes wrong: one file is ignored.
123
+ assert.match(old['glab-config'].hint, /reads only one of them and ignores the other/);
124
+ // A pin yad does not read is counted as skipped, never judged.
125
+ put(path.join(app, '.nvmrc'), 'lts/*\n');
126
+ assert.match(rows('24.22.1')['node-version'].message, /\(3 read, 1 not a version yad reads\)/);
127
+ } finally { done(T); }
128
+ });
129
+
130
+ test('#352: a repo that names no pin and no Docker adds no rows, and Docker is never run', () => {
131
+ const T = tmp();
132
+ try {
133
+ put(path.join(T, '.sdlc/product.json'), { platform: null });
134
+ let asked = 0;
135
+ const checks = [];
136
+ machineChecks(checks, T, { nodeVersion: '24.22.1', env: {}, home: path.join(T, 'home'), platform: 'linux', runner: () => { asked += 1; return { ok: false }; } });
137
+ assert.deepEqual(checks, []);
138
+ assert.equal(asked, 0, 'docker is not asked about');
139
+ } finally { done(T); }
140
+ });