@orion-qa/orion 3.4.1 → 3.5.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 (68) hide show
  1. package/.claude/agents/change-agent.md +1 -1
  2. package/.claude/agents/requirement-analyst.md +1 -1
  3. package/.claude/agents/test-reporter.md +1 -1
  4. package/.claude/skills/appium/templates/project-java/src/test/java/automation/pageObjects/BaseScreen.java +36 -2
  5. package/.claude/skills/appium/templates/project-java/src/test/java/automation/tests/unit/UtilsTest.java +10 -0
  6. package/.claude/skills/appium/templates/project-java/src/test/java/automation/utils/AutomationError.java +21 -0
  7. package/.claude/skills/automation-implementation/SKILL.md +1 -1
  8. package/.claude/skills/automation-implementation/references/patterns.md +14 -0
  9. package/.claude/skills/change-management/SKILL.md +1 -1
  10. package/.claude/skills/code-review/SKILL.md +1 -1
  11. package/.claude/skills/code-review/references/pattern-rules.md +4 -0
  12. package/.claude/skills/documentation/SKILL.md +2 -1
  13. package/.claude/skills/execution/SKILL.md +1 -0
  14. package/.claude/skills/orion/SKILL.md +6 -3
  15. package/.claude/skills/orion/references/conversation.md +1 -1
  16. package/.claude/skills/orion/references/project-context-files.md +3 -1
  17. package/.claude/skills/orion/references/setup-card.md +2 -1
  18. package/.claude/skills/orion/scripts/browser_setup.mjs +4 -4
  19. package/.claude/skills/orion/scripts/case_check.mjs +69 -0
  20. package/.claude/skills/orion/scripts/cases_coverage.py +179 -0
  21. package/.claude/skills/orion/scripts/cases_export.py +3 -0
  22. package/.claude/skills/orion/scripts/cases_model.py +256 -0
  23. package/.claude/skills/orion/scripts/context_guard.mjs +172 -0
  24. package/.claude/skills/orion/scripts/graph.mjs +112 -22
  25. package/.claude/skills/orion/scripts/lib/scan.mjs +8 -2
  26. package/.claude/skills/orion/scripts/report_make.mjs +15 -11
  27. package/.claude/skills/orion/scripts/run_state.mjs +4 -0
  28. package/.claude/skills/orion/scripts/screen_map.mjs +392 -0
  29. package/.claude/skills/orion/scripts/suite_check.mjs +1 -1
  30. package/.claude/skills/playwright/templates/dotnet/PageObjects/BasePage.cs +46 -0
  31. package/.claude/skills/playwright/templates/dotnet/Tests/Unit/UtilsTests.cs +10 -0
  32. package/.claude/skills/playwright/templates/dotnet/Utils/AutomationError.cs +19 -1
  33. package/.claude/skills/playwright/templates/javascript/pageObjects/basePage.js +52 -0
  34. package/.claude/skills/playwright/templates/javascript/reporters/summaryReporter.js +18 -9
  35. package/.claude/skills/playwright/templates/javascript/tests/unit/basePage.test.js +51 -0
  36. package/.claude/skills/playwright/templates/javascript/utils/errors.js +9 -2
  37. package/.claude/skills/playwright/templates/project/pageObjects/basePage.ts +54 -1
  38. package/.claude/skills/playwright/templates/project/reporters/summaryReporter.ts +18 -9
  39. package/.claude/skills/playwright/templates/project/tests/unit/basePage.test.ts +52 -0
  40. package/.claude/skills/playwright/templates/project/utils/errors.ts +12 -2
  41. package/.claude/skills/playwright/templates/python/page_objects/base_page.py +43 -0
  42. package/.claude/skills/playwright/templates/python/tests/unit/test_fail_fast_helpers.py +57 -0
  43. package/.claude/skills/playwright/templates/python/utils/errors.py +7 -3
  44. package/.claude/skills/requests/templates/python-pytest/src/services/api_client.py +11 -1
  45. package/.claude/skills/requests/templates/python-pytest/tests/unit/test_api_client.py +16 -0
  46. package/.claude/skills/requirement-analysis/references/test-case-import.md +9 -1
  47. package/.claude/skills/requirement-analysis/scripts/tm.py +422 -2
  48. package/.claude/skills/rest-assured/templates/java-testng/src/test/java/automation/config/Flags.java +19 -0
  49. package/.claude/skills/rest-assured/templates/java-testng/src/test/java/automation/services/ApiSpec.java +10 -3
  50. package/.claude/skills/selenium/templates/csharp-nunit/PageObjects/BasePage.cs +89 -11
  51. package/.claude/skills/selenium/templates/csharp-nunit/Tests/Unit/UtilsTests.cs +10 -0
  52. package/.claude/skills/selenium/templates/csharp-nunit/Utils/AutomationError.cs +19 -1
  53. package/.claude/skills/selenium/templates/java-testng/src/test/java/automation/pageObjects/BasePage.java +65 -8
  54. package/.claude/skills/selenium/templates/java-testng/src/test/java/automation/tests/unit/UtilsTest.java +10 -0
  55. package/.claude/skills/selenium/templates/java-testng/src/test/java/automation/utils/AutomationError.java +21 -0
  56. package/.claude/skills/selenium/templates/python-pytest/page_objects/base_page.py +70 -11
  57. package/.claude/skills/selenium/templates/python-pytest/tests/unit/test_fail_fast_helpers.py +43 -0
  58. package/.claude/skills/selenium/templates/python-pytest/utils/errors.py +7 -3
  59. package/.claude/skills/test-design/SKILL.md +1 -1
  60. package/.claude/skills/test-reporting/SKILL.md +1 -0
  61. package/.claude/skills/ui-observation/SKILL.md +4 -1
  62. package/.claude-plugin/plugin.json +1 -1
  63. package/.cursor/rules/orion-quiet.mdc +13 -0
  64. package/AGENTS.md +1 -1
  65. package/README.md +2 -2
  66. package/bin/orion.mjs +5 -1
  67. package/hosts/gemini-extension/gemini-extension.json +1 -1
  68. package/package.json +2 -1
@@ -9,7 +9,10 @@
9
9
  * node .claude/skills/orion/scripts/graph.mjs query (--story <KEY> | --page <file or name> | --test <file>) [--max-bytes 8000]
10
10
  * node .claude/skills/orion/scripts/graph.mjs check [--story <KEY>]
11
11
  * `--suite` defaults to the only `sut/<app>/` folder, else the workspace root. query and check rebuild first when any
12
- * source file changed since the last build (a sha1 per file in manifest.json), so the graph is never stale.
12
+ * source file changed since the last build (a sha1 per file in manifest.json), so the graph is never stale. When no file
13
+ * under the suite or the sources in project-context was added, removed, resized or touched since the last build
14
+ * (graph/stamp.json: size and modification time per file), the saved graph answers without reading the suite; any
15
+ * difference falls back to the sha1 check. `build` always reads everything.
13
16
  *
14
17
  * Sources: the suite (lib/scan.mjs: tests, page objects, fixtures and which files each test uses; desc files: case id,
15
18
  * AC(s), story, title), project-context/test-designs/<story>/design.md (accepted cases, screens, status),
@@ -25,7 +28,8 @@ import fs from 'node:fs';
25
28
  import { insideWorkspace } from './lib/inside.mjs';
26
29
  import path from 'node:path';
27
30
  import crypto from 'node:crypto';
28
- import { scan } from './lib/scan.mjs';
31
+ import { fileURLToPath } from 'node:url';
32
+ import { scan, SKIP_DIRS } from './lib/scan.mjs';
29
33
 
30
34
  const FORMAT = 'orion-graph/1';
31
35
  const KEY = /\b(?!(?:TS|AC|HL|TC)-)([A-Z][A-Z0-9]+-\d+)\b/;
@@ -129,12 +133,31 @@ function sources(o) {
129
133
  const files = [...new Set([...suiteFiles, ...ctx])].sort();
130
134
  const manifest = {};
131
135
  // The scripts that build the graph are sources too: an Orion upgrade rebuilds it.
132
- for (const f of ['graph.mjs', 'lib/scan.mjs']) manifest[`(orion)/${f}`] = crypto.createHash('sha1').update(read(path.join(path.dirname(new URL(import.meta.url).pathname), f)) || '').digest('hex');
136
+ for (const f of ['graph.mjs', 'lib/scan.mjs']) manifest[`(orion)/${f}`] = crypto.createHash('sha1').update(read(path.join(path.dirname(fileURLToPath(import.meta.url)), f)) || '').digest('hex');
133
137
  for (const f of files) { const t = read(f); if (t != null) manifest[f] = crypto.createHash('sha1').update(t).digest('hex'); }
134
138
  return { scan: s, manifest };
135
139
  }
136
140
 
137
- function build(o, pre) {
141
+ /** Size and modification time of every file the graph could read (a superset of its sources), plus its own scripts. */
142
+ function stampOf(o) {
143
+ const files = {};
144
+ const add = (f) => { try { const st = fs.statSync(f); if (st.isFile()) files[rel(f)] = `${st.size}:${Math.round(st.mtimeMs)}`; } catch { /* gone */ } };
145
+ const walk = (d, skip) => {
146
+ let entries; try { entries = fs.readdirSync(d, { withFileTypes: true }); } catch { return; }
147
+ for (const e of entries) {
148
+ const p = path.join(d, e.name);
149
+ if (e.isDirectory()) { if (!skip.has(e.name)) walk(p, skip); } else if (e.isFile()) add(p);
150
+ }
151
+ };
152
+ walk(o.suite, SKIP_DIRS);
153
+ for (const sub of ['assessments', 'test-designs', 'ui-maps', 'results']) walk(path.join(o.context, sub), new Set());
154
+ add(path.join(o.context, 'defects.md'));
155
+ const here = path.dirname(fileURLToPath(import.meta.url));
156
+ for (const f of ['graph.mjs', 'lib/scan.mjs']) add(path.join(here, f));
157
+ return JSON.stringify({ format: FORMAT, suite: rel(o.suite), context: rel(o.context), files });
158
+ }
159
+
160
+ function build(o, pre, stamp = stampOf(o)) {
138
161
  const { scan: s, manifest } = pre || sources(o);
139
162
  const nodes = new Map(); const edges = [];
140
163
  const node = (id, type, attrs = {}) => { if (!nodes.has(id)) nodes.set(id, { id, type, ...attrs }); else Object.assign(nodes.get(id), attrs); return id; };
@@ -158,6 +181,23 @@ function build(o, pre) {
158
181
  }
159
182
  }
160
183
  const caseById = (id) => Object.values(caseIdsByFile).map((m) => m[id]).filter(Boolean);
184
+ // A desc file is named by its stem in the test that uses it (`signIn.desc`, `sign_in_desc`, `SignInDesc`).
185
+ const descStem = (f) => path.basename(f).replace(/\.\w+$/, '').replace(/([._]desc|Desc)$/, '');
186
+ const escapeRe = (x) => x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
187
+ const descRefs = Object.keys(caseIdsByFile).map((df) => [df, new RegExp(`(^|[^\\w])${escapeRe(descStem(df))}([._]desc|Desc)\\b`, 'i')]);
188
+ /** The cases a test id means in this test file: from the desc files it names; else from the story keys it names;
189
+ * else every case with that id (tagged inferred when that is more than one: every story numbers from TS-1). */
190
+ const namedDescs = new Map(); // test file → the desc files it names (worked out once per file)
191
+ const casesFor = (cid, text, f) => {
192
+ if (!namedDescs.has(f)) namedDescs.set(f, descRefs.filter(([, re]) => re.test(text)).map(([df]) => df));
193
+ const named = namedDescs.get(f).map((df) => caseIdsByFile[df][cid]).filter(Boolean);
194
+ if (named.length) return { ts: named, tag: 'confirmed' };
195
+ const all = caseById(cid);
196
+ const keys = new Set(text.match(new RegExp(KEY.source, 'g')) || []);
197
+ const byKey = all.filter((ts) => keys.has(ts.split(':')[1]));
198
+ if (byKey.length) return { ts: byKey, tag: 'confirmed' };
199
+ return { ts: all, tag: all.length > 1 ? 'inferred' : 'confirmed' };
200
+ };
161
201
 
162
202
  // design.md → cases (planned too), screens, status
163
203
  for (const f of Object.keys(manifest).filter((x) => /design\.md$/.test(x))) {
@@ -192,24 +232,30 @@ function build(o, pre) {
192
232
  // tests, and what they use
193
233
  const roleOf = {};
194
234
  for (const [role, fl] of Object.entries(s.files)) for (const f of fl) roleOf[f] = role;
235
+ const edgesFrom = new Map();
236
+ for (const e of s.edges) (edgesFrom.get(e.from) || edgesFrom.set(e.from, []).get(e.from)).push(e);
237
+ const pageStems = s.files.pages.map((p) => [p, path.basename(p).replace(/\.\w+$/, '').toLowerCase().replace(/_/g, '')])
238
+ .filter(([, stem]) => !/^base/.test(stem)).map(([p, stem]) => [p, stem, new RegExp(`\\b${stem}\\b`)]);
195
239
  for (const t of s.tests) {
196
240
  const f = sfile(t.file); const text = read(f) || '';
197
241
  const decls = testCases(text, LANG(t.file));
242
+ const flat = text.toLowerCase().replace(/_/g, '');
243
+ const filePages = pageStems.filter(([, stem]) => flat.includes(stem)); // only pages this file names can match a window
244
+ const fileEdges = edgesFrom.get(t.file) || [];
198
245
  for (const [k, tc] of decls.entries()) {
199
246
  const near = text.split('\n').slice(Math.max(0, tc.line - 4), tc.line + 1).join(' ');
200
247
  if (/(^|\/)(tests?\/unit|Tests\/Unit|unit)\//.test(t.file) || /framework check/i.test(near)) continue; // not story cases
201
248
  const id = node(`test:${f}#${tc.name}`, 'test', { file: at(f, tc.line), name: tc.name });
202
249
  for (const cid of tc.ids) {
203
- const matches = caseById(cid);
204
- for (const ts of matches) edge(ts, id, 'implemented_by', 'confirmed', at(f, tc.line));
250
+ const { ts: matches, tag } = casesFor(cid, text, f);
251
+ for (const ts of matches) edge(ts, id, 'implemented_by', tag, at(f, tc.line));
205
252
  if (!matches.length) edge(node(`ts:UNKNOWN:${cid}`, 'ts', { key: `UNKNOWN:${cid}` }), id, 'implemented_by', 'confirmed', at(f, tc.line));
206
253
  }
207
254
  const window = text.split('\n').slice(tc.line - 1, Math.min(tc.line + 15, k + 1 < decls.length ? decls[k + 1].line - 1 : Infinity)).join('\n').toLowerCase().replace(/_/g, '');
208
- for (const p of s.files.pages) {
209
- const stem = path.basename(p).replace(/\.\w+$/, '').toLowerCase().replace(/_/g, '');
210
- if (!/^base/.test(stem) && new RegExp(`\\b${stem}\\b`).test(window)) edge(id, node(`page:${sfile(p)}`, 'page', { file: sfile(p) }), 'names_page', 'inferred', at(f, tc.line));
255
+ for (const [p, , re] of filePages) {
256
+ if (re.test(window)) edge(id, node(`page:${sfile(p)}`, 'page', { file: sfile(p) }), 'names_page', 'inferred', at(f, tc.line));
211
257
  }
212
- for (const e of s.edges.filter((x) => x.from === t.file)) {
258
+ for (const e of fileEdges) {
213
259
  const type = { page: 'page', fixture: 'fixture', helper: 'helper', service: 'service', data: 'data', config: 'config' }[e.to_role] || 'file';
214
260
  edge(id, node(`${type}:${sfile(e.to)}`, type, { file: sfile(e.to) }), 'uses', e.tag, at(f, null));
215
261
  }
@@ -221,7 +267,9 @@ function build(o, pre) {
221
267
  }
222
268
  for (const p of s.files.pages) node(`page:${sfile(p)}`, 'page', { file: sfile(p) });
223
269
 
224
- // UI maps → screen ↔ page object
270
+ // UI maps → screen ↔ page object (pages indexed by file stem: one lookup per row, not a scan of every node)
271
+ const pageByStem = new Map();
272
+ for (const n of nodes.values()) if (n.type === 'page') { const k = path.basename(n.file).replace(/\.\w+$/, '').toLowerCase(); if (!pageByStem.has(k)) pageByStem.set(k, n); }
225
273
  for (const f of Object.keys(manifest).filter((x) => /ui-maps\/.+\.md$/.test(x))) {
226
274
  for (const t of tables(read(f))) {
227
275
  const cSc = col(t, /screen key/); const cPo = col(t, /page object/);
@@ -230,21 +278,33 @@ function build(o, pre) {
230
278
  const sc = r.cells[cSc]; if (!sc || sc === '—') continue;
231
279
  const scr = node(`screen:${sc}`, 'screen', { key: sc, map: at(f, r.line) });
232
280
  const po = cPo >= 0 ? (r.cells[cPo] || '').replace(/^\(Gate 5\)\s*/, '') : '';
233
- const page = po && [...nodes.values()].find((n) => n.type === 'page' && path.basename(n.file).replace(/\.\w+$/, '').toLowerCase() === po.toLowerCase().replace(/\.\w+$/, ''));
281
+ const page = po && pageByStem.get(po.toLowerCase().replace(/\.\w+$/, ''));
234
282
  if (page) edge(page.id, scr, 'models', 'confirmed', at(f, r.line));
235
283
  }
236
284
  }
237
285
  }
238
286
 
239
- // results → tests (file + case id or name)
287
+ // results → tests (file + case id or name). Indexes keep this linear: tests by file name and stem, cases by test.
288
+ const testList = [...nodes.values()].filter((n) => n.type === 'test');
289
+ const order = new Map(testList.map((n, i) => [n, i]));
290
+ const byBase = new Map(); const byStem = new Map();
291
+ for (const n of testList) {
292
+ const b = path.basename(n.file.split(':')[0]);
293
+ (byBase.get(b) || byBase.set(b, []).get(b)).push(n);
294
+ const st = b.replace(/\.\w+$/, '');
295
+ (byStem.get(st) || byStem.set(st, []).get(st)).push(n);
296
+ }
297
+ const casesOfTest = new Map();
298
+ for (const e of edges) if (e.type === 'implemented_by') (casesOfTest.get(e.to) || casesOfTest.set(e.to, []).get(e.to)).push(e.from);
240
299
  for (const f of Object.keys(manifest).filter((x) => /results\/.+\.json$/.test(x))) {
241
300
  let r; try { r = JSON.parse(read(f)); } catch { continue; }
242
301
  for (const t of r.tests || []) {
243
302
  const rid = node(`result:${r.run_id}#${t.file}#${t.title}`, 'result', { run: r.run_id, status: t.status, failure_sig: t.failure_sig || undefined, source: f });
244
303
  const rfile = t.file.replace(/\\/g, '/').replace(/^\.\//, '');
245
304
  const sameFile = (n) => { const f = n.file.split(':')[0]; return f.endsWith(`/${rfile}`) || f === rfile || path.basename(f) === path.basename(rfile) || path.basename(f).replace(/\.\w+$/, '') === rfile.split('.').pop(); };
246
- const byId = (n) => t.test_id && edges.some((e) => e.to === n.id && e.type === 'implemented_by' && e.from.endsWith(`:${t.test_id}`));
247
- const target = [...nodes.values()].find((n) => n.type === 'test' && sameFile(n) && (byId(n) || t.title.includes(n.name) || n.name.includes(t.title)));
305
+ const byId = (n) => t.test_id && (casesOfTest.get(n.id) || []).some((c) => (t.story ? c === `ts:${t.story}:${t.test_id}` : c.endsWith(`:${t.test_id}`)));
306
+ const pool = [...new Set([...(byBase.get(path.basename(rfile)) || []), ...(byStem.get(rfile.split('.').pop()) || [])])].sort((x, y) => order.get(x) - order.get(y));
307
+ const target = pool.find((n) => sameFile(n) && (byId(n) || t.title.includes(n.name) || n.name.includes(t.title)));
248
308
  if (target) edge(target.id, rid, 'produced', t.test_id ? 'confirmed' : 'inferred', f);
249
309
  }
250
310
  }
@@ -283,7 +343,11 @@ function build(o, pre) {
283
343
  const id = r.cells[cId]; if (!id) continue;
284
344
  const d = node(`defect:${id}`, 'defect', { key: id, line: at(dpath, r.line) });
285
345
  const tc = (r.cells[cCase] || '').match(/(?:([A-Z][A-Z0-9]+-\d+):)?(TS-\d+)/);
286
- if (tc) for (const ts of caseById(tc[2])) edge(ts, d, 'failed_as', 'confirmed', at(dpath, r.line));
346
+ if (!tc) continue;
347
+ // `KEY:TS-n` names one case; a bare TS-n could be any story's (tagged inferred when it matches more than one).
348
+ const named = tc[1] && nodes.has(`ts:${tc[1]}:${tc[2]}`) ? [`ts:${tc[1]}:${tc[2]}`] : null;
349
+ const all = named || caseById(tc[2]);
350
+ for (const ts of all) edge(ts, d, 'failed_as', named || all.length === 1 ? 'confirmed' : 'inferred', at(dpath, r.line));
287
351
  }
288
352
  }
289
353
 
@@ -293,26 +357,53 @@ function build(o, pre) {
293
357
  fs.mkdirSync(dir, { recursive: true });
294
358
  fs.writeFileSync(path.join(dir, 'graph.json'), `${JSON.stringify(g, null, 1)}\n`);
295
359
  fs.writeFileSync(path.join(dir, 'manifest.json'), `${JSON.stringify({ format: FORMAT, suite: rel(o.suite), files: manifest }, null, 1)}\n`);
360
+ fs.writeFileSync(path.join(dir, 'stamp.json'), stamp);
296
361
  const gi = path.join(dir, '.gitignore');
297
362
  if (!fs.existsSync(gi)) fs.writeFileSync(gi, '# Derived from the suite and project-context; rebuilt by graph.mjs.\n*\n!.gitignore\n');
298
363
  return g;
299
364
  }
365
+ /** Edge lookups by node, built once: linear in the edges instead of a scan per lookup. Same order as the edge list. */
366
+ function edgeIndex(g) {
367
+ const out = new Map(); const inn = new Map();
368
+ for (const e of g.edges) {
369
+ (out.get(e.from) || out.set(e.from, []).get(e.from)).push(e);
370
+ (inn.get(e.to) || inn.set(e.to, []).get(e.to)).push(e);
371
+ }
372
+ const pick = (m, id, type) => (m.get(id) || []).filter((e) => !type || e.type === type);
373
+ return { from: (id, type) => pick(out, id, type), to: (id, type) => pick(inn, id, type) };
374
+ }
300
375
  function dedupe(edges) { const seen = new Set(); return edges.filter((e) => { const k = `${e.from}|${e.type}|${e.to}`; if (seen.has(k)) return false; seen.add(k); return true; }); }
301
376
 
302
377
  /** The graph, rebuilt first when any source changed since the last build. */
303
378
  function fresh(o) {
304
379
  const dir = path.join(o.context, 'graph');
380
+ const stamp = stampOf(o); // taken before anything is read: a file changed during this call is seen next time
381
+ const saved = () => { try { return JSON.parse(read(path.join(dir, 'graph.json'))); } catch { return null; } };
382
+ const trace = (how) => { if (process.env.ORION_GRAPH_TRACE) process.stderr.write(`graph: fresh by ${how}\n`); };
383
+ if (read(path.join(dir, 'stamp.json')) === stamp && !racy(stamp, path.join(dir, 'stamp.json'))) {
384
+ const g = saved(); if (g) { trace('stamp'); return { g, rebuilt: false }; }
385
+ }
305
386
  const pre = sources(o);
306
387
  let old = null; try { old = JSON.parse(read(path.join(dir, 'manifest.json'))); } catch { /* none yet */ }
307
388
  const same = old && old.suite === rel(o.suite) && JSON.stringify(old.files) === JSON.stringify(pre.manifest);
308
- if (same) { try { return { g: JSON.parse(read(path.join(dir, 'graph.json'))), rebuilt: false }; } catch { /* rebuild */ } }
309
- return { g: build(o, pre), rebuilt: true };
389
+ if (same) {
390
+ const g = saved();
391
+ if (g) { fs.writeFileSync(path.join(dir, 'stamp.json'), stamp); trace('hash'); return { g, rebuilt: false }; } // touched, not changed
392
+ }
393
+ trace('rebuild');
394
+ return { g: build(o, pre, stamp), rebuilt: true };
395
+ }
396
+
397
+ /** A file modified within 2 s before the stamp was written may have changed again in the same clock tick, unseen by
398
+ * its size and time (as git's "racy" entries): then the stamp is not trusted and the sha1 check decides. */
399
+ function racy(stamp, stampFile) {
400
+ let written; try { written = fs.statSync(stampFile).mtimeMs; } catch { return true; }
401
+ return Object.values(JSON.parse(stamp).files).some((v) => Number(v.split(':')[1]) >= written - 2000);
310
402
  }
311
403
 
312
404
  function gaps(g, story) {
313
405
  const out = [];
314
- const from = (id, type) => g.edges.filter((e) => e.from === id && (!type || e.type === type));
315
- const to = (id, type) => g.edges.filter((e) => e.to === id && (!type || e.type === type));
406
+ const { from, to } = edgeIndex(g);
316
407
  const inStory = (n) => !story || (n.key || '').startsWith(`${story}:`) || n.key === story;
317
408
  for (const n of g.nodes.filter(inStory)) {
318
409
  if (n.type === 'ac' && !from(n.id, 'covered_by').length) out.push(`${n.key}: no test case covers it`);
@@ -334,8 +425,7 @@ function gaps(g, story) {
334
425
  /** A small Markdown slice for one story, page or test; never silently cut. */
335
426
  function query(o, g) {
336
427
  const by = new Map(g.nodes.map((n) => [n.id, n]));
337
- const from = (id, type) => g.edges.filter((e) => e.from === id && (!type || e.type === type));
338
- const to = (id, type) => g.edges.filter((e) => e.to === id && (!type || e.type === type));
428
+ const { from, to } = edgeIndex(g);
339
429
  const lines = [];
340
430
  if (o.story) {
341
431
  const acs = g.nodes.filter((n) => n.type === 'ac' && n.key.startsWith(`${o.story}:`));
@@ -12,7 +12,7 @@
12
12
  * Output: frameworks (with the file that shows each), languages, kind (ui | api | ui+api | unknown), the files by role
13
13
  * (tests with their test names, page objects, fixtures, test data, config, helpers, locator files), edges from tests to
14
14
  * the files they use (`confirmed` when an import names the file, `inferred` when only a class name matches) and
15
- * findings for the rules a script can see (U1, U2, U3, U7, P1, P2, P5, P6/P18, P8, P17), each with file, line and a
15
+ * findings for the rules a script can see (U1, U2, U3, U7, U16, U17, P1, P2, P5, P6/P18, P8, P17), each with file, line and a
16
16
  * short quote. A quote never shows a secret: string values on a line that names a password, token, secret or key are
17
17
  * replaced by `***`. Reads source files only; never `.env` files or saved sessions.
18
18
  */
@@ -20,7 +20,7 @@ import fs from 'node:fs';
20
20
  import path from 'node:path';
21
21
  import { fileURLToPath } from 'node:url';
22
22
 
23
- const SKIP_DIRS = new Set(['node_modules', '.git', 'auth', 'playwright-report', 'test-results', 'allure-results', 'blob-report',
23
+ export const SKIP_DIRS = new Set(['node_modules', '.git', 'auth', 'playwright-report', 'test-results', 'allure-results', 'blob-report',
24
24
  'bin', 'obj', 'target', 'reports', 'TestResults', '.venv', 'venv', '__pycache__', '.pytest_cache', 'test-output', 'dist',
25
25
  'build', '.gradle', '.idea', '.vscode', 'coverage', 'screenshots', 'videos', 'downloads', 'project-context', '.claude',
26
26
  '.cursor', '.github', '.ui-map', 'app']);
@@ -62,6 +62,12 @@ const LINE_RULES = [
62
62
  { rule: 'U7', what: 'position-based locator', langs: ['js', 'ts', 'py', 'java', 'cs', 'kotlin', 'robot'], rx: /:nth-child\(|:nth-of-type\(|\.nth\(\d+\)|\.eq\(\d+\)|\)\[\d+\]['"`]/ },
63
63
  { rule: 'P5', what: 'static driver shared across threads', langs: ['java', 'kotlin'], rx: /\bstatic\s+(?!final\s+ThreadLocal)(?:final\s+)?(Remote)?WebDriver\s+\w+\s*[;=]|\bstatic\s+(AppiumDriver|AndroidDriver|IOSDriver)(<\w+>)?\s+\w+\s*[;=]/ },
64
64
  { rule: 'P5', what: 'static driver shared across threads', langs: ['cs'], rx: /\bstatic\s+(IWebDriver|WebDriver|AppiumDriver)\S*\s+\w+\s*(;|=(?!>)|\{\s*get;\s*set;)/ },
65
+ { rule: 'U16', what: 'unbounded loop (no limit, no named failure)', langs: ['js', 'ts', 'java', 'cs', 'kotlin'], rx: /\bwhile\s*\(\s*true\s*\)|\bfor\s*\(\s*;\s*;\s*\)/ },
66
+ { rule: 'U16', what: 'unbounded loop (no limit, no named failure)', langs: ['py'], rx: /^\s*while\s+True\s*:/ },
67
+ { rule: 'U17', what: 'JavaScript click that bypasses what a user could do', langs: ['js', 'ts'], rx: /\.dispatchEvent\(\s*['"]click['"]/ },
68
+ { rule: 'U17', what: 'JavaScript click that bypasses what a user could do', langs: ['java', 'py', 'cs', 'kotlin'], rx: /[Ee]xecute_?[Ss]cript\([^)]*\.click\(\)/ },
69
+ { rule: 'U17', what: 'flag that can swallow a failure', langs: ['js', 'ts', 'py', 'java', 'cs', 'kotlin'], rx: /\b(throwError|throw_error|raiseOnFail|raise_on_fail|failSilently|fail_silently)\b\s*[=:]/ },
70
+ { rule: 'U17', what: 'failure turned into false', langs: ['js', 'ts', 'java', 'cs', 'kotlin'], rx: /\bcatch\s*(\([^)]*\))?\s*\{\s*return\s+false\s*;?\s*\}/ },
65
71
  { rule: 'P8', what: 'implicit wait', langs: ['java', 'kotlin', 'py', 'cs', 'js', 'ts'], rx: /implicitlyWait\(|implicitly_wait\(|ImplicitWait\s*=|\.implicit\b/ },
66
72
  ];
67
73
 
@@ -69,37 +69,38 @@ export function grouped(files, testFiles = []) {
69
69
  export function draft(o, data) {
70
70
  const { acRows, caseRows, counts, runs, fail, tool, testDir, command, files, date } = data;
71
71
  const ids = [...counts.keys()].sort((a, b) => a.localeCompare(b, 'en', { numeric: true }));
72
- const allPass = ids.length && ids.every((id) => counts.get(id).pass === counts.get(id).runs && counts.get(id).runs >= 3);
72
+ const allPass = ids.length && ids.every((id) => counts.get(id).pass === counts.get(id).runs && counts.get(id).runs >= 1);
73
73
  const passedEach = runs ? `${ids.filter((id) => counts.get(id).pass === counts.get(id).runs).length}/${ids.length}` : '0';
74
74
  const verdict = allPass ? '✅ Ready to accept' : '<⚠️ Ready, with notes | ❌ Not ready>';
75
75
  const failLine = fail ? (fail[0] === fail[1] ? 'each new test also failed when its check was broken' : `fail check: ${fail[0]} of ${fail[1]} new tests`) : '<each new test also failed when its check was broken | fail check not run: reason>';
76
76
  const covered = new Set();
77
77
  const cov = [];
78
78
  const caseOf = (id) => caseRows.find((r) => pick(r, 'id') === id) || {};
79
- const res = (id) => (counts.has(id) ? `${counts.get(id).pass === counts.get(id).runs ? '✅' : '❌'} ${counts.get(id).pass}/${counts.get(id).runs}` : 'not run');
79
+ const res = (id) => (counts.has(id) ? `${counts.get(id).pass === counts.get(id).runs ? '✅' : '❌'}${runs > 1 ? ` ${counts.get(id).pass}/${counts.get(id).runs}` : ''}` : 'not run');
80
80
  for (const ac of acRows) {
81
81
  const acId = pick(ac, 'ac');
82
82
  const cases = caseRows.filter((r) => pick(r, 'ac').split(/[,\s]+/).includes(acId));
83
- if (!cases.length) { cov.push(`| ${pick(ac, 'meaning', 'criterion', 'requirement')} | not covered: <reason> | — |`); continue; }
83
+ if (!cases.length) { cov.push(`| ${acId} · ${pick(ac, 'meaning', 'criterion', 'requirement')} | not covered: <reason> | — |`); continue; }
84
84
  const cids = cases.map((c) => pick(c, 'id'));
85
85
  cids.forEach((id) => covered.add(id));
86
86
  const results = [...new Set(cids.map(res))];
87
- const tests = cids.length === 1 ? `${cids[0]} ${pick(cases[0], 'what')}` : cids.join(', ');
88
- cov.push(`| ${pick(ac, 'meaning', 'criterion', 'requirement')} | ${tests} | ${results.length === 1 ? results[0] + (cids.length > 1 ? ' each' : '') : cids.map((id) => `${id} ${res(id)}`).join(' · ')} |`);
87
+ const tests = cids.join(', ');
88
+ const meaning = pick(ac, 'meaning', 'criterion', 'requirement');
89
+ cov.push(`| ${acId} · ${meaning.length > 70 ? meaning.slice(0, 67).replace(/\s+\S*$/, '') + '…' : meaning} | ${tests} | ${results.length === 1 ? results[0] + (cids.length > 1 ? ' each' : '') : cids.map((id) => `${id} ${res(id)}`).join(' · ')} |`);
89
90
  }
90
- for (const id of ids) if (!covered.has(id)) cov.push(`| ${pick(caseOf(id), 'what') || counts.get(id).title} *(added)* | ${id} ${pick(caseOf(id), 'what') || counts.get(id).title} | ${res(id)} |`);
91
+ for (const id of ids) if (!covered.has(id)) cov.push(`| Added · ${pick(caseOf(id), 'what') || counts.get(id).title} | ${id} | ${res(id)} |`);
91
92
  const n = ids.length;
92
93
  const title = o.title || `<${o.story} story title>`;
93
94
  return `# ${title} · test report
94
95
 
95
- **${verdict}**: ${allPass ? `${n} new test${n === 1 ? '' : 's'}, all passed in ${runs} run${runs === 1 ? '' : 's'} in a row` : '<what was built and how it ran>'}${allPass && fail && fail[0] === fail[1] ? '; each failed when its check was broken' : ''}.
96
+ **${verdict}**: ${allPass ? `${n} new test${n === 1 ? '' : 's'}, ${runs === 1 ? 'all passed with retries off' : `all passed in ${runs} runs in a row`}` : '<what was built and how it ran>'}${allPass && fail && fail[0] === fail[1] ? '; each failed when its check was broken' : ''}.
96
97
 
97
98
  | | |
98
99
  |---|---|
99
100
  | Story | ${o.story}${o.title ? ` · ${o.title}` : ''} |
100
101
  | App | ${o.app || '<base URL> (<test environment>)'} |
101
102
  | Tests | ${n} ${tool} tests · \`${testDir}\` |
102
- | Runs | ${runs} runs, retries off: ${passedEach} passed each time · ${failLine} |
103
+ | Runs | ${runs === 1 ? `1 run, retries off: ${passedEach} passed` : `${runs} runs, retries off: ${passedEach} passed each time`} · ${failLine} |
103
104
  | Date | ${date} |
104
105
 
105
106
  ## Coverage
@@ -108,7 +109,10 @@ export function draft(o, data) {
108
109
  ${cov.join('\n') || '| <requirement> | <TS-n> | <result> |'}
109
110
 
110
111
  ## Needs your attention
111
- - ${allPass ? 'Nothing: every requirement above has a passing test.' : '<one line each, most important first, each ending with what to do>'}
112
+ - ${allPass ? '<Nothing: every requirement above has a passing test. | only a decision the user must make or an app problem seen, one line each, most important first, each ending with what to do>' : '<one line each, most important first, each ending with what to do>'}
113
+
114
+ ## App issues seen
115
+ - <None. | ⚠️ one line each: what the app did wrong (an error message, a server error such as HTTP 500 on /session, a broken element), where, how often; its bug-report draft is in \`project-context/defects.md\` (filed only on your yes)>
112
116
 
113
117
  ## What was added
114
118
  ${files.length ? grouped(files, data.testFiles || []) : '- <files>'}
@@ -122,11 +126,11 @@ ${command}
122
126
  <details>
123
127
  <summary>Details for engineers</summary>
124
128
 
125
- - **Runs:** ${runs} recorded runs in \`project-context/results/\` (${o.run}-1 … ${o.run}-${runs}); the run summary page is \`${path.join(o.project, 'test-summary', 'index.html').split(path.sep).join('/')}\`.
129
+ - **Runs:** ${runs === 1 ? `1 recorded run (\`project-context/results/${o.run}-1.json\`)` : `${runs} recorded runs in \`project-context/results/\` (${o.run}-1 … ${o.run}-${runs})`}; the run summary page is \`${path.join(o.project, 'test-summary', 'index.html').split(path.sep).join('/')}\`.
126
130
  - **Review:** <blocking findings n (fixed) · suggestions n>
127
131
  - **Failures and fixes during the run:** <none | one line each: test · cause · what was done>
128
132
  - **Approvals:** <setup confirmed · test cases accepted · installs approved>
129
- - **Not checked:** <anything not confirmed, and why | nothing>
133
+ - **Not checked:** <what about the app or the tests wasn't confirmed, and why | nothing> (never Orion's own rules, tools or setup)
130
134
 
131
135
  </details>
132
136
 
@@ -37,6 +37,7 @@ import fs from 'node:fs';
37
37
  import path from 'node:path';
38
38
  import { fileURLToPath } from 'node:url';
39
39
  import { insideWorkspace } from './lib/inside.mjs';
40
+ import { ensure as ensureGitignore } from './context_guard.mjs';
40
41
 
41
42
  const HERE = path.dirname(fileURLToPath(import.meta.url));
42
43
  const TEMPLATE = path.join(HERE, '..', 'templates', 'project-context', 'run.md');
@@ -67,6 +68,9 @@ function init(argv) {
67
68
  const t = now();
68
69
  const dir = path.join('project-context', 'runs');
69
70
  fs.mkdirSync(dir, { recursive: true });
71
+ // Local-only files (logs, graph, screenshots) never travel with a commit. Never fails the run start: a write that
72
+ // fails (read-only folder, locked file) is one line on stderr, and context_guard check still guards the commit.
73
+ try { ensureGitignore('project-context'); } catch (e) { console.error(`note: project-context/.gitignore not updated (${String(e.message).split('\n')[0]})`); }
70
74
  const file = path.join(dir, `R-${t.id}-${key}.md`);
71
75
  if (fs.existsSync(file)) die(1, `exists: ${file}`);
72
76
  let text = fs.readFileSync(TEMPLATE, 'utf8')