@delurio/cli 0.8.0 → 0.10.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/dist/check.js CHANGED
@@ -5,22 +5,29 @@
5
5
  import { createHash } from 'node:crypto';
6
6
  import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
7
7
  import { basename, dirname, join, relative, resolve } from 'node:path';
8
- import { keyAt, readYaml } from './yaml.js';
9
- import { GraphError, load } from './graph.js';
8
+ import { keyAt, parsingOnce, readYaml } from './yaml.js';
9
+ import { alternatives, GraphError, load, placed } from './graph.js';
10
10
  import { checkAssertions, explore, Model, ModelError } from './model.js';
11
11
  import { stepsByEvents } from './story.js';
12
12
  import { renderScreens } from './wireframe.js';
13
13
  import { checkStarts } from './starts.js';
14
- import { checkChanges } from './changes.js';
14
+ import { checkChanges, flowDomain } from './changes.js';
15
15
  import { checkUi } from './ui-check.js';
16
+ import { checkInvokes } from './invokes.js';
17
+ import { checkTutorial } from './tutorial-check.js';
16
18
  import { KitError, resolveKit } from './kit.js';
17
19
  import { checkGoals, findings, loadNav, viewOf } from './nav.js';
18
20
  import { schemaKindOf, validateFile } from './schemas.js';
19
21
  import { inReadingOrder, mergeDomain } from './domain.js';
22
+ import { checkDomainNames } from './domain-names.js';
23
+ import { checkNeeds, planned, readNeeds } from './needs.js';
24
+ import { checkAnchors } from './anchors.js';
20
25
  export const CHECK_USAGE = [
21
- ' node src/cli.ts check <graphs folder>... [--strict] [--baseline <sarif>] [--format sarif --output <file>]',
26
+ ' node src/cli.ts check <graphs folder>... [--strict] [--baseline <sarif>] [--format sarif --output <file>] [--app <dir> | --no-app]',
22
27
  ' checks every graph under the folders and writes nothing else: GNU error lines on stdout, or SARIF 2.1.0;',
23
- ' exit 0 clean, 1 a graph cannot be loaded or needs a newer format, 2 an error under --strict (new since --baseline)',
28
+ ' exit 0 clean, 1 a graph cannot be loaded or needs a newer format, 2 an error under --strict (new since --baseline);',
29
+ ' the evidence of needs and the source: anchors are found under --app, the application\'s repository root',
30
+ ' (default: the working directory); --no-app checks the graphs without the code, and does not look for them',
24
31
  ].join('\n');
25
32
  const FORMAT = 'delurio-graph/0';
26
33
  const SKIP = new Set(['viz', 'video', 'recording', 'node_modules', '.git']);
@@ -31,9 +38,11 @@ const RULES = [
31
38
  { id: 'domain-twice', text: 'A value of a domain is given in two of its files (SPEC.md §5)', level: 'error' },
32
39
  { id: 'domain-place', text: 'A domain file is not with the rest of its domain (SPEC.md §1)', level: 'error' },
33
40
  { id: 'server-fn-http', text: 'A server function is given a route, a query or an operationId, which only an HTTP operation has (SPEC.md §5)', level: 'error' },
41
+ { id: 'entity-unknown', text: "An action's returns or a references names an entity its domain does not have (SPEC.md §5)", level: 'error' },
42
+ { id: 'field-unknown', text: "An entity's key or required names a field the entity does not have (SPEC.md §5)", level: 'error' },
34
43
  { id: 'assertion-violated', text: 'A guarantee of the flow is broken by a reachable situation', level: 'error' },
35
44
  { id: 'main-story-unwalkable', text: 'The declared main story cannot be walked', level: 'error' },
36
- { id: 'catalog-key-missing', text: 'A catalog key the screens use is missing', level: 'error' },
45
+ { id: 'catalog-key-missing', text: "A catalog key the screens use is missing from a locale's catalog", level: 'error' },
37
46
  { id: 'sample-missing', text: 'A catalog message has a placeholder with no sample value', level: 'error' },
38
47
  { id: 'no-renderer', text: 'A component has no renderer', level: 'error' },
39
48
  { id: 'kit-uncovered', text: "The kit does not cover a component or an intent", level: 'error' },
@@ -41,14 +50,37 @@ const RULES = [
41
50
  { id: 'hand-over', text: 'A started flow cannot begin with what it is given', level: 'error' },
42
51
  { id: 'changes-note-missing', text: 'A flow whose steps write has no changes note (SPEC.md §4)', level: 'error' },
43
52
  { id: 'changes-note-locale', text: "The changes note is missing from a locale's catalog", level: 'error' },
53
+ { id: 'changes-note-gap', text: 'A writing flow says why it has no changes note yet: counted, and fails nothing (SPEC.md §4)', level: 'note' },
54
+ { id: 'task-locale', text: "The flow's name for its users is missing from a locale's catalog (SPEC.md §4)", level: 'error' },
44
55
  { id: 'source-missing', text: 'A state of a captured flow names no code (SPEC.md §9)', level: 'error' },
56
+ { id: 'source-unresolved', text: 'A source anchor names a file that is not there, or a line past its end (SPEC.md §9)', level: 'error' },
57
+ { id: 'citation-unresolved', text: "Words that cite the code name a file that is not there, or a line past its end (SPEC.md §9)", level: 'warning' },
45
58
  { id: 'focus-not-shown', text: 'A focus or a returnsFocus gives the focus to a node that is not shown there (SPEC.md §4)', level: 'error' },
46
59
  { id: 'returns-focus-not-dialog', text: 'A returnsFocus does not start at a dialog (SPEC.md §4)', level: 'error' },
60
+ { id: 'role-missing', text: 'A field or an action gives no role, by which a screen reader finds it (SPEC.md §4)', level: 'warning' },
61
+ { id: 'state-no-way-out', text: 'A state that is not an exit has no way out (SPEC.md §2)', level: 'error' },
62
+ { id: 'state-unreachable', text: 'No situation the flow starts in reaches the state (SPEC.md §2)', level: 'error' },
63
+ { id: 'tutorial-mismatch', text: 'A tutorial no longer matches its flow (SPEC.md §7)', level: 'error' },
64
+ { id: 'evidence-unresolved', text: "A need's evidence names what is not there (SPEC.md §13)", level: 'error' },
65
+ { id: 'need-no-evidence', text: 'A need that is not missing names no evidence outside the graph (SPEC.md §13)', level: 'error' },
66
+ { id: 'need-names-built', text: 'A missing need names a state that is built as its evidence (SPEC.md §13)', level: 'warning' },
67
+ { id: 'need-unlisted', text: "A missing need is not in the product's gaps (SPEC.md §13)", level: 'error' },
68
+ { id: 'need-twice', text: "A need's id is given twice in its flow's needs (SPEC.md §13)", level: 'error' },
69
+ { id: 'needs-place', text: 'A needs file is beside no flow, or is the needs of another one (SPEC.md §13)', level: 'error' },
70
+ { id: 'gap-met', text: 'The gaps list a need that is met (SPEC.md §13)', level: 'error' },
71
+ { id: 'gap-unknown', text: 'The gaps list a need that no flow under them has (SPEC.md §13)', level: 'error' },
72
+ { id: 'need-gap', text: 'A need that is missing, listed in the gaps: counted, and fails nothing (SPEC.md §13)', level: 'note' },
73
+ { id: 'invoke-unknown', text: "An invoke or a failures entry names an action its flow's domain does not have, or the domain is not found (SPEC.md §5)", level: 'error' },
74
+ { id: 'refusal-unknown', text: 'A failure class lists a code that is neither a refusal of its action nor a transport code (SPEC.md §2, §5)', level: 'error' },
75
+ { id: 'policy-unknown', text: 'A policy names an action or an entity its domain does not have (SPEC.md §5)', level: 'error' },
76
+ { id: 'planned-built', text: 'A planned entity or action names its code (SPEC.md §5)', level: 'error' },
47
77
  { id: 'graph-warning', text: 'Another warning of the graph', level: 'error' },
48
78
  { id: 'nav-problem', text: 'A problem of the navigation graph', level: 'error' },
49
79
  { id: 'nav-note', text: 'A note on the navigation graph', level: 'warning' },
50
80
  ];
51
81
  const LEVEL = new Map(RULES.map((r) => [r.id, r.level]));
82
+ // the rules whose errors stop the run (exit 1) however --strict and --baseline read them
83
+ const BREAKING = new Set(['load', 'format-newer']);
52
84
  export const count = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
53
85
  // the 1-based line and column of the first occurrence of `needle`, else the file's start
54
86
  function placeOf(abs, needle) {
@@ -125,13 +157,83 @@ function fromWarning(dir, graph, w) {
125
157
  return result('changes-note-locale', ui, placeOf(ui, 'changes:'), w, graph, `changes/${m[2]}`);
126
158
  return result('graph-warning', existsSync(ui) ? ui : flow, { line: 1, column: 1 }, w, graph, w);
127
159
  }
128
- function checkFlow(dir) {
160
+ // the words of the screens in each locale but the one ui.yaml names (SPEC.md §4): a key the screens use that a locale's
161
+ // catalog lacks, at the key's line, as for the catalog ui.yaml names; a locale whose catalog is not there, at `locales`
162
+ function checkLocales(g, dir) {
163
+ if (g.ui.absent === true)
164
+ return [];
165
+ const ui = join(dir, 'ui.yaml');
166
+ const named = join(dir, g.ui.catalog);
167
+ const out = [];
168
+ for (const locale of g.ui.locales ?? []) {
169
+ const name = join(dirname(g.ui.catalog), `${locale}.json`);
170
+ const abs = join(dir, name);
171
+ if (abs === named)
172
+ continue;
173
+ let catalog;
174
+ try {
175
+ catalog = JSON.parse(readFileSync(abs, 'utf8'));
176
+ }
177
+ catch (err) {
178
+ const text = readFileSync(ui, 'utf8');
179
+ const why = existsSync(abs) ? `is not JSON: ${err.message}` : 'does not exist';
180
+ out.push(result('catalog-key-missing', ui, keyAt(text, ['locales']), `the ${locale} catalog, ${name}, ${why}: every word the screens use is missing in ${locale}`, g.flow.id, `catalog/${locale}`));
181
+ continue;
182
+ }
183
+ const missing = [];
184
+ const collect = (m) => {
185
+ const key = /^catalog key (\S+) is missing/.exec(m)?.[1];
186
+ if (key !== undefined && !missing.includes(key))
187
+ missing.push(key);
188
+ };
189
+ const other = { ...g, catalog: catalog !== null && typeof catalog === 'object' ? catalog : {} };
190
+ renderScreens(other, collect, null);
191
+ checkUi(other, collect);
192
+ for (const key of missing)
193
+ out.push(result('catalog-key-missing', ui, placeOf(ui, key), `catalog key ${key} is missing from the ${locale} catalog, ${name}`, g.flow.id, `${key}/${locale}`));
194
+ }
195
+ return out;
196
+ }
197
+ // the states that some transition leads to, whatever its guard
198
+ function targeted(g) {
199
+ const out = new Set();
200
+ for (const st of Object.values(g.flow.states)) {
201
+ for (const a of st.always ?? [])
202
+ out.add(a.target);
203
+ for (const spec of Object.values(st.on ?? {}))
204
+ for (const a of alternatives(spec))
205
+ out.add(a.target);
206
+ }
207
+ return out;
208
+ }
209
+ function checkFlow(dir, domains) {
129
210
  const file = join(dir, 'flow.yaml');
130
211
  const g = load(dir);
131
- const kit = resolveKit(dir, g.ui.kit, undefined);
212
+ let kit;
213
+ try {
214
+ kit = resolveKit(dir, g.ui.kit, undefined);
215
+ }
216
+ catch (err) {
217
+ throw g.ui.kit === undefined ? err : placed(err, { file: 'ui.yaml', path: ['kit'] });
218
+ }
132
219
  const model = new Model(g.flow);
133
220
  const ex = explore(model);
134
221
  const out = [];
222
+ const flowText = readFileSync(file, 'utf8');
223
+ // a state the flow stops in for good though it is no exit, and a state no situation reaches (SPEC.md §2)
224
+ const led = targeted(g);
225
+ for (const [name, st] of Object.entries(g.flow.states)) {
226
+ const at = () => keyAt(flowText, ['states', name]);
227
+ const element = `states/${name}`;
228
+ const ways = Object.keys(st.on ?? {}).length + (st.always ?? []).length;
229
+ if (st.type !== 'final' && ways === 0 && st.invoke === undefined) {
230
+ out.push(result('state-no-way-out', file, at(), `state ${name} is not an exit and has no way out: it has no on, always or invoke, so the flow stops there; make it an exit (type: final) or give it a transition (SPEC.md §2)`, g.flow.id, element));
231
+ }
232
+ if (!ex.atState.has(name)) {
233
+ const why = led.has(name) ? 'the transitions that lead to it are never taken: the states they leave are not reached, or their guards never hold' : 'no transition leads to it';
234
+ out.push(result('state-unreachable', file, at(), `state ${name} is reached by no situation the flow starts in: ${why} (SPEC.md §2)`, g.flow.id, element));
235
+ }
236
+ }
135
237
  const warnings = [];
136
238
  const warn = (m) => {
137
239
  if (!warnings.includes(m))
@@ -156,21 +258,50 @@ function checkFlow(dir) {
156
258
  for (const p of checkUi(g, warn))
157
259
  out.push(result(p.rule, ui, keyAt(text, p.path), p.message, g.flow.id, p.element));
158
260
  }
261
+ out.push(...checkLocales(g, dir));
159
262
  for (const h of checkStarts(g, model, ex))
160
263
  for (const p of h.problems)
161
264
  warn(`${h.from} starts ${h.flow}: ${p}`);
162
- for (const p of checkChanges(g)?.problems ?? [])
265
+ // the flow's domain, looked up once for the rules that read it
266
+ let domain;
267
+ const domainOf = () => (domain === undefined ? (domain = flowDomain(g, domains)) : domain);
268
+ const changes = checkChanges(g, domainOf);
269
+ for (const p of changes?.problems ?? [])
163
270
  warn(p);
164
271
  for (const w of warnings)
165
272
  out.push(fromWarning(dir, g.flow.id, w));
273
+ // a writing flow whose app has no changes message yet says why: a gap of the flow, at the level note (SPEC.md §4)
274
+ if (changes !== null && changes.missing !== null) {
275
+ const ui = join(dir, 'ui.yaml');
276
+ const message = `its steps write (${changes.writes.join(', ')}), and its changes note is missing: ${changes.missing}; Rehber does not guide its writing steps (SPEC.md §4)`;
277
+ out.push(result('changes-note-gap', ui, keyAt(readFileSync(ui, 'utf8'), ['changes', 'missing']), message, g.flow.id, 'changes/missing'));
278
+ }
279
+ for (const p of checkInvokes(g, domainOf))
280
+ out.push(result(p.rule, file, keyAt(flowText, p.path), p.message, g.flow.id, p.element));
281
+ const tutorial = join(dir, 'tutorial.yaml');
282
+ if (existsSync(tutorial)) {
283
+ const text = readFileSync(tutorial, 'utf8');
284
+ for (const p of checkTutorial(g, model, ex, text)) {
285
+ const at = p.line === undefined ? keyAt(text, p.path) : { line: p.line, column: p.column ?? 1 };
286
+ out.push(result('tutorial-mismatch', tutorial, at, p.message, g.flow.id, `tutorial.yaml#/${p.path.join('/')}`));
287
+ }
288
+ }
166
289
  // a captured flow is read from code, so every state names the code that makes it true; an exit may leave it out, as
167
- // the transition into it names that code (SPEC.md §9)
290
+ // the transition into it names that code, and so may a state that only missing needs name, which is not built yet
291
+ // (SPEC.md §9, §13)
168
292
  if (g.flow.status === 'captured') {
169
- const text = readFileSync(file, 'utf8');
293
+ let needs = null;
294
+ try {
295
+ needs = readNeeds(dir);
296
+ }
297
+ catch {
298
+ // a needs.yaml that cannot be read plans nothing; its schema check says why
299
+ }
300
+ const notBuilt = planned(needs).states;
170
301
  for (const [name, st] of Object.entries(g.flow.states)) {
171
- if (st.source !== undefined || st.type === 'final')
302
+ if (st.source !== undefined || st.type === 'final' || notBuilt.has(name))
172
303
  continue;
173
- out.push(result('source-missing', file, keyAt(text, ['states', name]), `state ${name} names no code: in a captured flow every state but an exit carries source: <path>:<line> (SPEC.md §9)`, g.flow.id, `states/${name}`));
304
+ out.push(result('source-missing', file, keyAt(flowText, ['states', name]), `state ${name} names no code: in a captured flow every state but an exit carries source: <path>:<line> (SPEC.md §9)`, g.flow.id, `states/${name}`));
174
305
  }
175
306
  }
176
307
  return out;
@@ -216,9 +347,52 @@ function checkServerFunctions(parts, doc, id) {
216
347
  }
217
348
  return out;
218
349
  }
350
+ // an entity or an action that says it is planned, written before its code, and names its code all the same (SPEC.md
351
+ // §5): at its `planned`, with a note where its `source` is given, as the two may come from two files of a split domain
352
+ function checkPlanned(parts, doc, id) {
353
+ const out = [];
354
+ const read = parts.map((p) => {
355
+ try {
356
+ return readYaml(p.text);
357
+ }
358
+ catch {
359
+ return null;
360
+ }
361
+ });
362
+ const given = (section, name, key) => {
363
+ const i = read.findIndex((d) => d?.[section]?.[name]?.[key] !== undefined);
364
+ return i < 0 ? null : { file: parts[i].file, ...keyAt(parts[i].text, [section, name, key]) };
365
+ };
366
+ for (const [section, word] of [['entities', 'entity'], ['actions', 'action']]) {
367
+ const items = (doc[section] ?? {});
368
+ if (items === null || typeof items !== 'object')
369
+ continue;
370
+ for (const [name, item] of Object.entries(items)) {
371
+ if (item === null || typeof item !== 'object' || typeof item.planned !== 'string' || typeof item.source !== 'string')
372
+ continue;
373
+ const at = given(section, name, 'planned');
374
+ const src = given(section, name, 'source');
375
+ if (at === null)
376
+ continue;
377
+ const notes = src === null ? [] : [{ file: rel(src.file), line: src.line, column: src.column, message: `its source is given here` }];
378
+ out.push(result('planned-built', at.file, at, `the ${word} ${name} says it is planned (${item.planned}), and names its code, ${item.source}: a planned ${word} has no code yet; once it is built, take out planned (SPEC.md §5)`, id, `${section}/${name}/planned`, notes));
379
+ }
380
+ }
381
+ return out;
382
+ }
383
+ // whether a domain's file gives the entity
384
+ function givesEntity(text, entity) {
385
+ try {
386
+ const entities = readYaml(text)?.entities;
387
+ return entities !== null && typeof entities === 'object' && Object.hasOwn(entities, entity);
388
+ }
389
+ catch {
390
+ return false;
391
+ }
392
+ }
219
393
  // the domains under root, each the domain files of one directory read as one (SPEC.md §5): a value given in two of
220
- // them, a file whose id is not its directory's, a domain whose files sit in two directories, and a server function
221
- // given what only an HTTP operation has
394
+ // them, a file whose id is not its directory's, a domain whose files sit in two directories, a server function given
395
+ // what only an HTTP operation has, and a name of an entity, a field or an action that the domain does not have
222
396
  function checkDomains(files) {
223
397
  const byDir = new Map();
224
398
  for (const f of files)
@@ -226,14 +400,33 @@ function checkDomains(files) {
226
400
  byDir.set(dirname(f), [...(byDir.get(dirname(f)) ?? []), f]);
227
401
  const out = [];
228
402
  const dirsOf = new Map(); // a domain's id -> the directories that hold it
229
- for (const [dir, list] of byDir) {
403
+ const domains = [...byDir].map(([dir, list]) => {
230
404
  const parts = inReadingOrder(list).map((file) => ({ file, text: readFileSync(file, 'utf8') }));
231
- const merged = mergeDomain(parts);
405
+ return { dir, parts, merged: mergeDomain(parts) };
406
+ });
407
+ // an entity of another domain, for the note of a name that this one does not have
408
+ const elsewhere = (self) => (entity) => {
409
+ for (const { dir, parts, merged } of domains) {
410
+ const id = merged.id ?? rel(dir);
411
+ const entities = merged.doc.entities;
412
+ if (id === self || entities === null || typeof entities !== 'object' || !Object.hasOwn(entities, entity))
413
+ continue;
414
+ const part = parts.find((p) => givesEntity(p.text, entity)) ?? parts[0];
415
+ return { domain: id, file: part.file, ...keyAt(part.text, ['entities', entity]) };
416
+ }
417
+ return null;
418
+ };
419
+ for (const { dir, parts, merged } of domains) {
420
+ const id = merged.id ?? rel(dir);
232
421
  for (const p of merged.problems) {
233
422
  const notes = p.first === undefined ? [] : [{ file: rel(p.first.file), line: p.first.line, column: p.first.column, message: 'given first here' }];
234
- out.push(result(p.rule, p.file, p, p.message, merged.id ?? rel(dir), p.element, notes));
423
+ out.push(result(p.rule, p.file, p, p.message, id, p.element, notes));
424
+ }
425
+ out.push(...checkServerFunctions(parts, merged.doc, id));
426
+ out.push(...checkPlanned(parts, merged.doc, id));
427
+ for (const p of checkDomainNames(parts, merged.doc, id, elsewhere(id))) {
428
+ out.push(result(p.rule, p.file, p, p.message, id, p.element, p.notes.map((n) => ({ ...n, file: rel(n.file) }))));
235
429
  }
236
- out.push(...checkServerFunctions(parts, merged.doc, merged.id ?? rel(dir)));
237
430
  if (merged.id !== null)
238
431
  dirsOf.set(merged.id, [...(dirsOf.get(merged.id) ?? []), dir]);
239
432
  }
@@ -255,6 +448,23 @@ function checkNav(dir) {
255
448
  out.push(result('graph-warning', file, { line: 1, column: 1 }, w, g.id, w));
256
449
  return out;
257
450
  }
451
+ // the level a finding is printed at, and counted at: an error known from the baseline is a warning, as it fails no
452
+ // run, but one that stops the run (it cannot be loaded) is an error however often it was seen
453
+ const printedLevel = (r) => (r.level === 'error' && r.baselineState === 'unchanged' && !BREAKING.has(r.rule) ? 'warning' : r.level);
454
+ // where a load error is (SPEC.md §10): the place the loader or the model gave it, at the keys it names or the line a
455
+ // parser gave, in the file it names; else the line a YAML parser gave; else the start of the graph's own file
456
+ function loadPlace(dir, file, err) {
457
+ const place = err.place;
458
+ const at = place === undefined ? file : join(dir, place.file);
459
+ if (place?.line !== undefined)
460
+ return { file: at, line: place.line, column: place.column ?? 1 };
461
+ const linePos = err.linePos?.[0];
462
+ if (linePos !== undefined)
463
+ return { file: at, line: linePos.line, column: linePos.col };
464
+ if (place?.path !== undefined && existsSync(at))
465
+ return { file: at, ...keyAt(readFileSync(at, 'utf8'), place.path) };
466
+ return { file: at, line: 1, column: 1 };
467
+ }
258
468
  const fingerprint = (r) => createHash('sha256').update(`${r.rule}|${r.graph}|${r.element}`).digest('hex').slice(0, 32);
259
469
  function baselinePrints(file) {
260
470
  const doc = JSON.parse(readFileSync(file, 'utf8'));
@@ -269,7 +479,7 @@ function toolVersion() {
269
479
  const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
270
480
  return pkg.version ?? '0.0.0';
271
481
  }
272
- function sarif(results, exitCode) {
482
+ function sarif(results, exitCode, said) {
273
483
  const used = RULES.filter((r) => results.some((x) => x.rule === r.id));
274
484
  return {
275
485
  $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
@@ -285,7 +495,13 @@ function sarif(results, exitCode) {
285
495
  },
286
496
  },
287
497
  automationDetails: { id: 'delurio/check/' },
288
- invocations: [{ executionSuccessful: exitCode !== 1, exitCode }],
498
+ invocations: [
499
+ {
500
+ executionSuccessful: exitCode !== 1,
501
+ exitCode,
502
+ ...(said.length === 0 ? {} : { toolExecutionNotifications: said.map((text) => ({ level: 'note', message: { text } })) }),
503
+ },
504
+ ],
289
505
  results: results.map((r) => ({
290
506
  ruleId: r.rule,
291
507
  ruleIndex: used.findIndex((u) => u.id === r.rule),
@@ -307,12 +523,16 @@ function sarif(results, exitCode) {
307
523
  ],
308
524
  };
309
525
  }
526
+ // every text the check reads is parsed once in it (`parsingOnce`), however many graphs read it
310
527
  export function checkMain(args) {
528
+ return parsingOnce(() => checkRun(args));
529
+ }
530
+ function checkRun(args) {
311
531
  const flag = (name) => {
312
532
  const i = args.indexOf(name);
313
533
  return i >= 0 ? args[i + 1] : undefined;
314
534
  };
315
- const withValue = ['--baseline', '--format', '--output'];
535
+ const withValue = ['--baseline', '--format', '--output', '--app'];
316
536
  const dirs = args.filter((a, i) => !a.startsWith('--') && !withValue.includes(args[i - 1] ?? ''));
317
537
  if (dirs.length === 0) {
318
538
  console.error(`usage:\n${CHECK_USAGE}`);
@@ -334,7 +554,20 @@ export function checkMain(args) {
334
554
  console.error(`--format is text or sarif, not ${format}`);
335
555
  return 1;
336
556
  }
557
+ const appGiven = flag('--app');
558
+ if (appGiven !== undefined && (!existsSync(appGiven) || !statSync(appGiven).isDirectory())) {
559
+ console.error(`--app ${appGiven} is not a folder\nusage:\n${CHECK_USAGE}`);
560
+ return 1;
561
+ }
562
+ // --no-app: the graphs are here without the application's code, so what they name of it is not looked for (SPEC.md §10)
563
+ const noApp = args.includes('--no-app');
564
+ if (noApp && appGiven !== undefined) {
565
+ console.error(`--app names the application's code and --no-app says it is not here: give one of them\nusage:\n${CHECK_USAGE}`);
566
+ return 1;
567
+ }
568
+ const app = noApp ? null : resolve(appGiven ?? '.');
337
569
  const results = [];
570
+ const domains = new Map(); // the domains found, for every flow that names one
338
571
  let broken = false;
339
572
  for (const d of dirsOfGraphs) {
340
573
  const file = existsSync(join(d, 'flow.yaml')) ? join(d, 'flow.yaml') : join(d, 'nav.yaml');
@@ -345,14 +578,14 @@ export function checkMain(args) {
345
578
  results.push(result('format-newer', file, placeOf(file, 'schema:'), `written in ${newer}; this checker reads ${FORMAT}: pin a version that reads it`, rel(d), 'schema'));
346
579
  continue;
347
580
  }
348
- results.push(...(file.endsWith('flow.yaml') ? checkFlow(d) : checkNav(d)));
581
+ results.push(...(file.endsWith('flow.yaml') ? checkFlow(d, domains) : checkNav(d)));
349
582
  }
350
583
  catch (err) {
351
584
  if (!(err instanceof GraphError || err instanceof ModelError || err instanceof KitError || (err instanceof Error && err.name === 'YAMLParseError')))
352
585
  throw err;
353
586
  broken = true;
354
- const linePos = err.linePos?.[0];
355
- results.push(result('load', file, linePos === undefined ? { line: 1, column: 1 } : { line: linePos.line, column: linePos.col }, err.message.split('\n')[0], rel(d), 'load'));
587
+ const at = loadPlace(d, file, err);
588
+ results.push(result('load', at.file, at, err.message.split('\n')[0], rel(d), 'load'));
356
589
  }
357
590
  }
358
591
  // every graph file against its kind's schema: what an editor with the schemas marks, check reports
@@ -362,16 +595,31 @@ export function checkMain(args) {
362
595
  results.push(result('schema', file, f, f.message, f.graph ?? rel(file), f.element));
363
596
  }
364
597
  results.push(...checkDomains(files));
598
+ // each flow's needs held to their evidence, and the product's gaps to its needs (SPEC.md §13)
599
+ const needs = checkNeeds(files, app);
600
+ for (const p of needs.problems)
601
+ results.push(result(p.rule, p.file, p, p.message, p.graph, p.element));
602
+ // every source anchor, and every citation of the code in a graph's words, held to the application's files (SPEC.md §9)
603
+ const anchors = checkAnchors(files, app);
604
+ for (const p of anchors.problems)
605
+ results.push(result(p.rule, p.file, p, p.message, p.graph, p.element));
365
606
  results.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.rule.localeCompare(b.rule) || a.message.localeCompare(b.message));
366
607
  if (baseline !== undefined) {
367
608
  const prints = baselinePrints(baseline);
368
609
  for (const r of results)
369
610
  r.baselineState = prints.has(fingerprint(r)) ? 'unchanged' : 'new';
370
611
  }
371
- const failing = results.filter((r) => r.level === 'error' && r.rule !== 'load' && r.rule !== 'format-newer' && (r.baselineState === undefined || r.baselineState === 'new'));
612
+ // what --no-app did not look for, said once rather than as a finding each (SPEC.md §10)
613
+ const said = [];
614
+ if (noApp) {
615
+ const of = (n, one, many) => `${n} ${n === 1 ? one : many}`;
616
+ const what = [count(anchors.anchors, 'source anchor'), of(anchors.citations, 'citation in words', 'citations in words'), of(needs.notLookedFor, 'piece of evidence', 'pieces of evidence')];
617
+ said.push(`--no-app: ${what.slice(0, -1).join(', ')} and ${what[what.length - 1]} name files of the application, which are not here, and were not looked for (SPEC.md §10)`);
618
+ }
619
+ const failing = results.filter((r) => r.level === 'error' && !BREAKING.has(r.rule) && (r.baselineState === undefined || r.baselineState === 'new'));
372
620
  const exitCode = broken ? 1 : strict && failing.length > 0 ? 2 : 0;
373
621
  if (format === 'sarif') {
374
- const text = `${JSON.stringify(sarif(results, exitCode), null, 2)}\n`;
622
+ const text = `${JSON.stringify(sarif(results, exitCode, said), null, 2)}\n`;
375
623
  if (output === undefined)
376
624
  process.stdout.write(text);
377
625
  else
@@ -379,15 +627,23 @@ export function checkMain(args) {
379
627
  }
380
628
  if (format === 'text' || output !== undefined) {
381
629
  for (const r of results) {
382
- const level = r.level === 'error' && r.baselineState === 'unchanged' ? 'warning' : r.level;
383
- console.log(`${r.file}:${r.line}:${r.column}: ${level}: ${r.message} [${r.rule}]`);
630
+ console.log(`${r.file}:${r.line}:${r.column}: ${printedLevel(r)}: ${r.message} [${r.rule}]`);
384
631
  for (const n of r.notes)
385
632
  console.log(`${n.file}:${n.line}:${n.column}: note: ${n.message}`);
386
633
  }
387
634
  const graphs = dirsOfGraphs.length;
388
- const errors = results.filter((r) => r.level === 'error').length;
389
- const warnings = results.filter((r) => r.level === 'warning').length;
390
- console.error(`delurio check: ${count(graphs, 'graph')}, ${count(errors, 'error')}, ${count(warnings, 'warning')}; exit ${exitCode}`);
635
+ const errors = results.filter((r) => printedLevel(r) === 'error').length;
636
+ const warnings = results.filter((r) => printedLevel(r) === 'warning').length;
637
+ // the gaps, once a flow has needs: every need that is missing, listed or not, and those the base run did not have
638
+ const fresh = results.filter((r) => r.rule === 'need-gap' && r.baselineState === 'new').length;
639
+ const gaps = needs.files === 0 ? '' : `, ${count(needs.gaps, 'gap')} of ${count(needs.needs, 'need')}${fresh > 0 ? ` (${fresh} new)` : ''}`;
640
+ // the changes notes that writing flows say are missing (SPEC.md §4), once there is one
641
+ const notes = results.filter((r) => r.rule === 'changes-note-gap');
642
+ const newNotes = notes.filter((r) => r.baselineState === 'new').length;
643
+ const missingNotes = notes.length === 0 ? '' : `, ${count(notes.length, 'missing changes note')}${newNotes > 0 ? ` (${newNotes} new)` : ''}`;
644
+ for (const s of said)
645
+ console.error(`delurio check: note: ${s}`);
646
+ console.error(`delurio check: ${count(graphs, 'graph')}, ${count(errors, 'error')}, ${count(warnings, 'warning')}${gaps}${missingNotes}; exit ${exitCode}`);
391
647
  }
392
648
  return exitCode;
393
649
  }
package/dist/diff-nav.js CHANGED
@@ -36,12 +36,20 @@ function entryWords(g, s) {
36
36
  return `${s.how} ${label} on ${fromWords(g, s)}`;
37
37
  }
38
38
  const entryKey = (s) => `entry ${s.id ?? `${fromTokens(s).join(', ')} → ${s.to} (${s.how})`}`;
39
- const pathWords = (v, page) => {
39
+ const pathWords = (g, v, page) => {
40
40
  const words = pathTo(v.reach, page).filter((e) => e.label !== '').map((e) => e.label);
41
+ // a way that starts at a page opened by its address (SPEC.md §6)
42
+ const typed = v.reach.get(page)?.byAddress ?? null;
43
+ if (typed !== null) {
44
+ if (typed === page)
45
+ return 'by its address';
46
+ const at = g.pages[typed] === undefined ? typed : quote(g.pages[typed].title);
47
+ return `by the address of ${at}${words.length === 0 ? '' : `, then ${words.join(' → ')}`}`;
48
+ }
41
49
  return words.length === 0 ? 'automatic' : words.join(' → ');
42
50
  };
43
51
  function pageFields(p) {
44
- return { route: p.route, title: p.titleKey ?? p.title, kind: p.kind, frame: p.frame, opensFor: p.opensFor ?? undefined, refusal: p.refusal ?? undefined, pageCodes: p.pageCodes ?? undefined, source: p.source ?? undefined, evidence: p.evidence ?? undefined };
52
+ return { route: p.route, title: p.titleKey ?? p.title, kind: p.kind, frame: p.frame, opensFor: p.opensFor ?? undefined, refusal: p.refusal ?? undefined, byAddress: p.byAddress ? true : undefined, pageCodes: p.pageCodes ?? undefined, source: p.source ?? undefined, evidence: p.evidence ?? undefined };
45
53
  }
46
54
  export function navStructure(b, a) {
47
55
  const out = [];
@@ -141,7 +149,7 @@ export function navStructure(b, a) {
141
149
  continue;
142
150
  }
143
151
  const name = pageName(ga, id);
144
- out.push(...fieldChanges('pages', key, pageFields(x), pageFields(y), ['route', 'title', 'kind', 'frame', 'opensFor', 'refusal', 'pageCodes', 'source', 'evidence'], (f, p, q) => {
152
+ out.push(...fieldChanges('pages', key, pageFields(x), pageFields(y), ['route', 'title', 'kind', 'frame', 'opensFor', 'refusal', 'byAddress', 'pageCodes', 'source', 'evidence'], (f, p, q) => {
145
153
  if (f === 'route')
146
154
  return `${name} moved to ${String(q)} (was ${String(p)}).`;
147
155
  if (f === 'title')
@@ -154,6 +162,8 @@ export function navStructure(b, a) {
154
162
  return q === undefined ? `${name} now opens for everyone.` : p === undefined ? `${name} now opens only for some people.` : `Who ${name} opens for changed.`;
155
163
  if (f === 'refusal')
156
164
  return q === undefined ? `${name} no longer says how it refuses.` : `${name} now refuses with: ${quote(String(q))}.`;
165
+ if (f === 'byAddress')
166
+ return q === true ? `${name} is now opened by its address.` : `${name} is no longer opened by its address.`;
157
167
  return null;
158
168
  }));
159
169
  }
@@ -299,7 +309,7 @@ export function navBehaviour(rb, ra, s) {
299
309
  const name = ga.pages[page] === undefined ? pageName(gb, page) : pageName(ga, page);
300
310
  if (!inB && inA) {
301
311
  const st = va.standing[page];
302
- add('page', page, null, { clicks: va.reach.get(page)?.clicks, standing: st }, `Can now reach ${name}${st === 'ok' ? '' : `, which ${STANDING_WORDS[st]}`} (${va.reach.get(page)?.clicks ?? 0} clicks: ${pathWords(va, page)}).`);
312
+ add('page', page, null, { clicks: va.reach.get(page)?.clicks, standing: st }, `Can now reach ${name}${st === 'ok' ? '' : `, which ${STANDING_WORDS[st]}`} (${va.reach.get(page)?.clicks ?? 0} clicks: ${pathWords(ga, va, page)}).`);
303
313
  }
304
314
  else if (inB && !inA) {
305
315
  add('page', page, { clicks: vb.reach.get(page)?.clicks, standing: vb.standing[page] }, null, `Can no longer reach ${name}${ga.pages[page] === undefined ? ' (the page was removed)' : ''}.`);
@@ -312,7 +322,7 @@ export function navBehaviour(rb, ra, s) {
312
322
  const cb = vb.reach.get(page)?.clicks ?? 0;
313
323
  const ca = va.reach.get(page)?.clicks ?? 0;
314
324
  if (cb !== ca)
315
- add('clicks', page, cb, ca, `${capital(name)}: ${cb} → ${ca} ${ca === 1 ? 'click' : 'clicks'} (${pathWords(va, page)}).`);
325
+ add('clicks', page, cb, ca, `${capital(name)}: ${cb} → ${ca} ${ca === 1 ? 'click' : 'clicks'} (${pathWords(ga, va, page)}).`);
316
326
  }
317
327
  }
318
328
  // the menu they see
@@ -0,0 +1,18 @@
1
+ import type { DomainPart } from './domain.ts';
2
+ export interface NamePlace {
3
+ file: string;
4
+ line: number;
5
+ column: number;
6
+ }
7
+ export interface NameProblem extends NamePlace {
8
+ rule: 'entity-unknown' | 'field-unknown' | 'policy-unknown';
9
+ message: string;
10
+ element: string;
11
+ notes: Array<NamePlace & {
12
+ message: string;
13
+ }>;
14
+ }
15
+ export type EntityElsewhere = (entity: string) => (NamePlace & {
16
+ domain: string;
17
+ }) | null;
18
+ export declare function checkDomainNames(parts: DomainPart[], doc: Record<string, unknown>, id: string, elsewhere?: EntityElsewhere): NameProblem[];