@codyswann/lisa 4.23.39 → 4.24.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 (79) hide show
  1. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  2. package/dist/core/lisa-owned-hash-ledger.js +4 -0
  3. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  4. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  5. package/dist/core/nightly-e2e-guard-behavior-certificate.js.map +1 -1
  6. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  7. package/dist/core/upstream-evidence-manifest.js +16 -5
  8. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  9. package/expo/copy-overwrite/scripts/classify-maestro-failures.mjs +535 -47
  10. package/expo/create-only/.maestro/flake-classification.json +6 -0
  11. package/package.json +3 -3
  12. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  13. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  14. package/plugins/lisa/.codex-plugin/skills/lisa-github-write-issue/SKILL.md +1 -1
  15. package/plugins/lisa/.codex-plugin/skills/lisa-validate-tracker-mapping/SKILL.md +111 -1
  16. package/plugins/lisa/scripts/scoping-label-audit.mjs +474 -0
  17. package/plugins/lisa/skills/lisa-github-write-issue/SKILL.md +1 -1
  18. package/plugins/lisa/skills/lisa-validate-tracker-mapping/SKILL.md +112 -2
  19. package/plugins/lisa-agy/plugin.json +1 -1
  20. package/plugins/lisa-agy/scripts/scoping-label-audit.mjs +474 -0
  21. package/plugins/lisa-agy/skills/lisa-github-write-issue/SKILL.md +1 -1
  22. package/plugins/lisa-agy/skills/lisa-validate-tracker-mapping/SKILL.md +112 -2
  23. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  25. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  26. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  28. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  29. package/plugins/lisa-copilot/scripts/scoping-label-audit.mjs +474 -0
  30. package/plugins/lisa-copilot/skills/lisa-github-write-issue/SKILL.md +1 -1
  31. package/plugins/lisa-copilot/skills/lisa-validate-tracker-mapping/SKILL.md +112 -2
  32. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-cursor/scripts/scoping-label-audit.mjs +474 -0
  34. package/plugins/lisa-cursor/skills/lisa-github-write-issue/SKILL.md +1 -1
  35. package/plugins/lisa-cursor/skills/lisa-validate-tracker-mapping/SKILL.md +112 -2
  36. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  38. package/plugins/lisa-expo-agy/plugin.json +1 -1
  39. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  48. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  49. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  53. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  54. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  58. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  59. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  63. package/plugins/lisa-rails-agy/plugin.json +1 -1
  64. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  68. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  69. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  73. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  74. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  76. package/plugins/src/base/scripts/scoping-label-audit.mjs +474 -0
  77. package/plugins/src/base/skills/lisa-github-write-issue/SKILL.md +1 -1
  78. package/plugins/src/base/skills/lisa-validate-tracker-mapping/SKILL.md +112 -2
  79. package/typescript/copy-contents/.husky/pre-push +76 -0
@@ -11,6 +11,7 @@
11
11
  * node scripts/classify-maestro-failures.mjs --json <report.xml>
12
12
  * node scripts/classify-maestro-failures.mjs --markdown <report.xml>
13
13
  * node scripts/classify-maestro-failures.mjs --platform=android <report.xml>
14
+ * node scripts/classify-maestro-failures.mjs --debug-output=maestro-debug <report.xml>
14
15
  *
15
16
  * ## This is a DIAGNOSTIC, never a gate
16
17
  *
@@ -86,6 +87,46 @@
86
87
  *
87
88
  * No gate should be raised again without quoting this number.
88
89
  *
90
+ * ## The DEVICE column, and why it cannot read the report
91
+ *
92
+ * A third verdict sits beside `preamble` and `product`: DEVICE, meaning the
93
+ * harness fell over and the product was never exercised. That is the first
94
+ * question anyone asks of a red nightly, and the JUnit report cannot answer it.
95
+ *
96
+ * Two device deaths are measured in `maestro-native-e2e.yml`'s own retry
97
+ * rationale: a `maestro.android.DeviceServerDiedException` during `eraseText`,
98
+ * whose `<failure>` element was BLANK, and a stuck IME-insets animation
99
+ * starving UiAutomator's `waitForIdle`, whose only signature was 25
100
+ * `animations-not-complete` events on the two affected flows against 0-1 across
101
+ * the other thirty-nine. The sibling arm has a third whose `<failure>` read, in
102
+ * its entirety, `Unknown error`. A classifier keyed on the failure TEXT would
103
+ * have caught none of them, and would have looked correct throughout, because
104
+ * it would still have sorted every ordinary assertion failure correctly.
105
+ *
106
+ * So the device verdict is derived from the RUN rather than from its report —
107
+ * specifically from Maestro's `--debug-output` tree, which it writes
108
+ * independently of the JUnit XML. Two signals, neither of which reads
109
+ * `<failure>`:
110
+ *
111
+ * 1. A FAULT marker present in a flow's own debug artifacts. Presence is
112
+ * enough: `DeviceServerDiedException` is not a thing a product bug emits.
113
+ * 2. An INSTABILITY marker whose count for one flow towers over the run's own
114
+ * baseline. Counting against a baseline is what the IME case was actually
115
+ * diagnosed by, and it is robust to a blank `<failure>` precisely because
116
+ * it never needs the failure to carry any text at all.
117
+ *
118
+ * With no `--debug-output` supplied there is no evidence, so nothing is ever a
119
+ * device fault and this file behaves exactly as it did before — the same
120
+ * silence-produces-the-safe-column asymmetry the preamble split has.
121
+ *
122
+ * ## The device column is REPORTING, and must never become an input to retry
123
+ *
124
+ * Per-flow retry is keyed on WHICH flow failed and never on why, because the
125
+ * text is unreliable — the whole argument is in the driver's own comment block.
126
+ * A device classifier feeding that decision would reintroduce the too-narrow
127
+ * regex the current design rejects. The suite driver reads the report; this
128
+ * runs afterwards, off to one side, and nothing consumes its output.
129
+ *
89
130
  * ## Known-intermittent registry
90
131
  *
91
132
  * `.maestro/flake-classification.json` (create-only; the project owns it) also
@@ -130,6 +171,57 @@ export const DEFAULT_SIGN_IN_MARKERS = [
130
171
  "signin:email-input",
131
172
  ];
132
173
 
174
+ /**
175
+ * Markers whose PRESENCE in a flow's debug artifacts proves the device died.
176
+ *
177
+ * Exactly the fault this repository has a measurement for, and no more. A
178
+ * speculative list of exception names nobody has seen would be indistinguishable
179
+ * from a working one right up until it mattered, so projects extend this
180
+ * through `deviceFaultMarkers` in `.maestro/flake-classification.json` when they
181
+ * measure their own.
182
+ */
183
+ export const DEFAULT_DEVICE_FAULT_MARKERS = ["DeviceServerDiedException"];
184
+
185
+ /**
186
+ * Markers whose RATE, against the run's own baseline, shows a degraded device.
187
+ *
188
+ * Presence proves nothing here — a healthy flow emits one or two — so these are
189
+ * counted rather than matched. See {@link deviceVerdict} for the thresholds.
190
+ */
191
+ export const DEFAULT_DEVICE_INSTABILITY_MARKERS = ["animations-not-complete"];
192
+
193
+ /** Events a flow must carry before its count can mean anything at all. */
194
+ export const DEVICE_INSTABILITY_FLOOR = 5;
195
+
196
+ /** ...and the multiple of the run's own median it must also clear. */
197
+ export const DEVICE_INSTABILITY_MULTIPLE = 5;
198
+
199
+ /**
200
+ * Suffixes whose bytes are not text and must never be scanned for markers.
201
+ *
202
+ * Maestro names a screenshot after the flow AND the failure, so a file that
203
+ * merely mentions a marker in its own NAME would otherwise read as evidence of
204
+ * one. Decoding image bytes as UTF-8 also produces arbitrary byte sequences,
205
+ * which is a second way to manufacture a match nobody's device produced.
206
+ */
207
+ const OPAQUE_SUFFIXES = [
208
+ ".png",
209
+ ".jpg",
210
+ ".jpeg",
211
+ ".gif",
212
+ ".webp",
213
+ ".heic",
214
+ ".mp4",
215
+ ".mov",
216
+ ".webm",
217
+ ".zip",
218
+ ".gz",
219
+ ".tar",
220
+ ".jar",
221
+ ".apk",
222
+ ".ipa",
223
+ ];
224
+
133
225
  /** Project-owned configuration file, relative to the project root. */
134
226
  export const CONFIG_REL_PATH = path.join(
135
227
  ".maestro",
@@ -164,6 +256,9 @@ const ID_LINE = /^[ \t]*id:[ \t]*((?:\S.*)?)$/;
164
256
  /** A `text:` line, read the same way. */
165
257
  const TEXT_LINE = /^[ \t]*text:[ \t]*((?:\S.*)?)$/;
166
258
 
259
+ /** A `name:` line, read the same way. Only the flow HEADER's copy is used. */
260
+ const NAME_LINE = /^[ \t]*name:[ \t]*((?:\S.*)?)$/;
261
+
167
262
  /**
168
263
  * A scalar value with one layer of matching quotes removed.
169
264
  *
@@ -384,8 +479,15 @@ export function messageNamesSelector(message, { kind, selector }) {
384
479
 
385
480
  /**
386
481
  * Parse the `<testcase>` rows out of a Maestro JUnit report.
482
+ *
483
+ * `failed` and `message` are SEPARATE, and the separation is load-bearing. The
484
+ * measured `DeviceServerDiedException` loss wrote a BLANK `<failure>` element,
485
+ * so a reader that treats "no failure text" as "no failure" drops the very row
486
+ * this file's device column exists to explain — and drops it silently, one
487
+ * short in the failing-flow count, filed under neither product nor preamble.
488
+ * Presence of the element is what marks a failure; its text is commentary.
387
489
  * @param {string} xml - JUnit report source
388
- * @returns {{file: string, status: string, durationSec: number, message: string | null}[]} Rows
490
+ * @returns {{file: string, status: string, durationSec: number, message: string | null, failed: boolean}[]} Rows
389
491
  */
390
492
  export function parseReport(xml) {
391
493
  const cases = [];
@@ -401,15 +503,19 @@ export function parseReport(xml) {
401
503
  const body = match[2] ?? "";
402
504
  const attr = name =>
403
505
  (attrs.match(new RegExp(`${name}="([^"]*)"`)) || [])[1];
506
+ // The self-closing form is an alternative of the SAME match, for the same
507
+ // reason `<testcase/>` is above — and because `<failure/>` is one of the two
508
+ // shapes a device death with nothing to say arrives in.
404
509
  const failure = body.match(
405
- /<(?:failure|error)\b[^>]*>([\s\S]*?)<\/(?:failure|error)>/
510
+ /<(?:failure|error)\b[^>]*?(?:\/>|>([\s\S]*?)<\/(?:failure|error)>)/
406
511
  );
407
512
  cases.push({
408
513
  file: attr("file") || "",
409
514
  status: attr("status") || "",
410
515
  durationSec: Number(attr("time") || 0),
516
+ failed: Boolean(failure),
411
517
  message: failure
412
- ? decodeEntities(failure[1].trim().split("\n")[0].trim())
518
+ ? decodeEntities((failure[1] ?? "").trim().split("\n")[0].trim())
413
519
  : null,
414
520
  });
415
521
  }
@@ -430,6 +536,209 @@ function decodeEntities(value) {
430
536
  .replace(/&amp;/g, "&");
431
537
  }
432
538
 
539
+ /** The flow-header separator. `[ \t]` deliberately, never `\s` — see ID_LINE. */
540
+ const HEADER_SEPARATOR = /^---[ \t]*$/m;
541
+
542
+ /**
543
+ * Whether an artifact's bytes are not text and must not be scanned.
544
+ * @param {string} artifactPath - Path of the artifact
545
+ * @returns {boolean} True when it must be skipped
546
+ */
547
+ function isOpaque(artifactPath) {
548
+ const lowered = artifactPath.toLowerCase();
549
+ return OPAQUE_SUFFIXES.some(suffix => lowered.endsWith(suffix));
550
+ }
551
+
552
+ /**
553
+ * The tokens a debug artifact's filename may carry to belong to this flow.
554
+ *
555
+ * Maestro names per-flow debug artifacts after the flow's NAME, which is the
556
+ * `name:` its header declares and the file stem otherwise. Both are returned
557
+ * because a project that adopts `name:` would otherwise silently stop being
558
+ * attributable — the same drift failure the preamble split is derived to avoid.
559
+ *
560
+ * Only the HEADER's `name:` counts. `runFlow` blocks and several commands take
561
+ * a `name:` of their own, and reading those would attribute another flow's
562
+ * artifacts to this one.
563
+ * @param {string} reportedFile - `file` attribute from the testcase row
564
+ * @param {string | null} source - The flow's YAML, when it is on disk
565
+ * @returns {string[]} Tokens naming this flow
566
+ */
567
+ export function flowArtifactKeys(reportedFile, source) {
568
+ const stem = path.basename(reportedFile).replace(/\.ya?ml$/i, "");
569
+ const keys = stem === "" ? [] : [stem];
570
+ const header = (source ?? "").split(HEADER_SEPARATOR)[0] ?? "";
571
+ for (const line of header.split("\n")) {
572
+ const declared = scalarSelector(line, NAME_LINE);
573
+ if (declared !== null && !keys.includes(declared)) keys.push(declared);
574
+ }
575
+ return keys;
576
+ }
577
+
578
+ /**
579
+ * Attribute one debug artifact to at most one flow.
580
+ *
581
+ * LONGEST key wins, and that is the whole rule. `commands-(card-detail-2).json`
582
+ * contains `card-detail` as a substring, so a first-match scan would read one
583
+ * flow's device death as its sibling's — and a boundary heuristic cannot help,
584
+ * because the delimiter it would look for (`-`) is inside the keys themselves.
585
+ *
586
+ * The artifact's OWN directory counts as well as its filename, because Maestro
587
+ * has shipped both layouts — a flow's name in the file (`commands-(x).json`)
588
+ * and a directory per flow. Only the last two segments are considered: reaching
589
+ * further up would let the run's own directory name decide every artifact.
590
+ *
591
+ * An artifact naming NO flow — logcat, written once per run — belongs to none
592
+ * of them. Spreading its faults across every failing flow would launder a real
593
+ * product regression, which is the expensive direction to be wrong in.
594
+ * @param {string} artifactPath - Absolute path of the artifact
595
+ * @param {readonly {flow: string, keys: readonly string[]}[]} flowKeys - Candidates
596
+ * @returns {string | null} The flow it belongs to, or null
597
+ */
598
+ export function attributeArtifact(artifactPath, flowKeys) {
599
+ const name = path.join(
600
+ path.basename(path.dirname(artifactPath)),
601
+ path.basename(artifactPath)
602
+ );
603
+ let best = null;
604
+ for (const entry of flowKeys)
605
+ for (const key of entry.keys) {
606
+ if (key === "" || !name.includes(key)) continue;
607
+ if (best === null || key.length > best.key.length)
608
+ best = { key, flow: entry.flow };
609
+ }
610
+ return best === null ? null : best.flow;
611
+ }
612
+
613
+ /**
614
+ * Count non-overlapping occurrences of a literal needle.
615
+ *
616
+ * `split` rather than a `RegExp`: markers come from project config, and a
617
+ * config value containing `.` or `(` would otherwise be compiled as a pattern
618
+ * and match text nobody's device emitted.
619
+ * @param {string} haystack - Text to scan
620
+ * @param {string} needle - Literal marker
621
+ * @returns {number} Occurrences
622
+ */
623
+ function countOccurrences(haystack, needle) {
624
+ return needle === "" ? 0 : haystack.split(needle).length - 1;
625
+ }
626
+
627
+ /**
628
+ * Tally every marker across a run's debug artifacts, per flow.
629
+ * @param {readonly {path: string, text: string}[]} artifacts - Debug artifacts
630
+ * @param {readonly {flow: string, keys: readonly string[]}[]} flowKeys - Flows in the report
631
+ * @param {readonly string[]} markers - Markers to count
632
+ * @returns {{perFlow: Map<string, object>, unattributed: object}} Tallies
633
+ */
634
+ export function tallyDeviceMarkers(artifacts, flowKeys, markers) {
635
+ const perFlow = new Map(flowKeys.map(entry => [entry.flow, {}]));
636
+ const unattributed = {};
637
+ for (const artifact of artifacts) {
638
+ // Enforced HERE and not only at read time. `readDebugArtifacts` skips these
639
+ // to avoid loading megabytes of PNG, which is an I/O saving; this is the
640
+ // correctness one, and it holds for any caller that assembles the artifact
641
+ // list some other way.
642
+ if (isOpaque(artifact.path)) continue;
643
+ const flow = attributeArtifact(artifact.path, flowKeys);
644
+ const bucket = flow === null ? unattributed : (perFlow.get(flow) ?? {});
645
+ for (const marker of markers) {
646
+ const count = countOccurrences(artifact.text, marker);
647
+ if (count === 0) continue;
648
+ const seen = bucket[marker] ?? {
649
+ count: 0,
650
+ artifact: path.basename(artifact.path),
651
+ };
652
+ bucket[marker] = { count: seen.count + count, artifact: seen.artifact };
653
+ }
654
+ }
655
+ return { perFlow, unattributed };
656
+ }
657
+
658
+ /**
659
+ * Median of a list of counts, which is 0 for an empty one.
660
+ * @param {readonly number[]} values - Counts
661
+ * @returns {number} Median
662
+ */
663
+ function median(values) {
664
+ if (values.length === 0) return 0;
665
+ const sorted = [...values].sort((left, right) => left - right);
666
+ const middle = Math.floor(sorted.length / 2);
667
+ return sorted.length % 2 === 1
668
+ ? sorted[middle]
669
+ : (sorted[middle - 1] + sorted[middle]) / 2;
670
+ }
671
+
672
+ /**
673
+ * Decide whether one flow's tally amounts to a device fault.
674
+ *
675
+ * A fault marker is decided by PRESENCE — nothing a product bug does raises
676
+ * `DeviceServerDiedException`. An instability marker is decided by COUNT
677
+ * against the run's own median flow, and must clear BOTH a floor and a
678
+ * multiple. Each threshold rules out a mistake the other cannot:
679
+ *
680
+ * - the floor rules out a run whose median is 0, where a single stray event
681
+ * sits infinitely above baseline and means nothing;
682
+ * - the multiple rules out a uniformly degraded run, where every flow clears
683
+ * the floor and a floor-only test would empty the product column.
684
+ *
685
+ * With the measured IME case — 25 events on the affected flows against 0-1
686
+ * elsewhere — the median is 1 and both tests pass by a wide margin.
687
+ * @param {object} tallies - This flow's marker tallies
688
+ * @param {Record<string, number>} baselines - Median count per instability marker
689
+ * @param {{faultMarkers: readonly string[], instabilityMarkers: readonly string[]}} markers - Marker sets
690
+ * @returns {object | null} The device signal, or null
691
+ */
692
+ export function deviceVerdict(tallies, baselines, markers) {
693
+ for (const marker of markers.faultMarkers) {
694
+ const seen = tallies[marker];
695
+ if (seen)
696
+ return {
697
+ signal: "fault-marker",
698
+ marker,
699
+ count: seen.count,
700
+ baseline: null,
701
+ artifact: seen.artifact,
702
+ };
703
+ }
704
+ for (const marker of markers.instabilityMarkers) {
705
+ const seen = tallies[marker];
706
+ if (!seen || seen.count < DEVICE_INSTABILITY_FLOOR) continue;
707
+ const baseline = Math.max(1, baselines[marker] ?? 0);
708
+ if (seen.count < baseline * DEVICE_INSTABILITY_MULTIPLE) continue;
709
+ return {
710
+ signal: "instability",
711
+ marker,
712
+ count: seen.count,
713
+ baseline,
714
+ artifact: seen.artifact,
715
+ };
716
+ }
717
+ return null;
718
+ }
719
+
720
+ /**
721
+ * Read every TEXT artifact under a run's `--debug-output` tree.
722
+ *
723
+ * Absence is normal and silent: a run that crashed before Maestro started, or a
724
+ * caller that has not wired the flag, simply yields no evidence — and with no
725
+ * evidence nothing is ever a device fault.
726
+ * @param {string | null} debugRoot - Absolute path of the debug-output directory
727
+ * @param {{listFiles: Function, readFile: Function}} io - Injected readers
728
+ * @returns {{path: string, text: string}[]} Artifacts
729
+ */
730
+ export function readDebugArtifacts(debugRoot, { listFiles, readFile }) {
731
+ if (!debugRoot) return [];
732
+ const artifacts = [];
733
+ for (const file of listFiles(debugRoot) ?? []) {
734
+ if (isOpaque(file)) continue;
735
+ const text = readFile(file);
736
+ if (text === null) continue;
737
+ artifacts.push({ path: file, text });
738
+ }
739
+ return artifacts;
740
+ }
741
+
433
742
  /**
434
743
  * Reject a registry entry that cannot support the claim it makes.
435
744
  * @param {unknown} entry - Candidate registry entry
@@ -547,7 +856,7 @@ function resolveFlowPath(reported, { projectRoot, maestroRoot, readFile }) {
547
856
  }
548
857
 
549
858
  /**
550
- * Classify every failure in a report.
859
+ * Classify one report's failures, plus whatever the run said about the device.
551
860
  *
552
861
  * `readFile` returns a flow's source or `null` when it is not on disk — a
553
862
  * report may name a flow deleted since the run, and that must degrade to
@@ -560,9 +869,12 @@ function resolveFlowPath(reported, { projectRoot, maestroRoot, readFile }) {
560
869
  * @param {readonly string[]} [options.signInMarkers] - Project sign-in markers
561
870
  * @param {readonly unknown[]} [options.knownIntermittent] - Raw registry entries
562
871
  * @param {string} [options.platform] - Arm the report came from
563
- * @returns {object[]} One record per failing flow
872
+ * @param {readonly {path: string, text: string}[]} [options.debugArtifacts] - Run observation
873
+ * @param {readonly string[]} [options.deviceFaultMarkers] - Presence-decided device faults
874
+ * @param {readonly string[]} [options.deviceInstabilityMarkers] - Count-decided device faults
875
+ * @returns {{failures: object[], deviceRunEvidence: object[]}} The report's verdict
564
876
  */
565
- export function classify(reportXml, options) {
877
+ export function classifyRun(reportXml, options) {
566
878
  const {
567
879
  maestroRoot,
568
880
  readFile,
@@ -570,26 +882,63 @@ export function classify(reportXml, options) {
570
882
  signInMarkers = DEFAULT_SIGN_IN_MARKERS,
571
883
  knownIntermittent = [],
572
884
  platform = null,
885
+ debugArtifacts = [],
886
+ deviceFaultMarkers = DEFAULT_DEVICE_FAULT_MARKERS,
887
+ deviceInstabilityMarkers = DEFAULT_DEVICE_INSTABILITY_MARKERS,
573
888
  } = options;
574
889
  const registry = validateIntermittentRegistry(knownIntermittent).entries;
575
- const results = [];
576
- for (const testCase of parseReport(reportXml)) {
577
- if (!testCase.message) continue;
578
- const flowPath = resolveFlowPath(testCase.file, {
579
- projectRoot,
580
- maestroRoot,
581
- readFile,
582
- });
583
- const matched = matchPreambleGate(flowPath, testCase, {
584
- readFile,
585
- signInMarkers,
586
- });
890
+ const rows = parseReport(reportXml);
891
+ const paths = new Map(
892
+ rows.map(row => [
893
+ row.file,
894
+ resolveFlowPath(row.file, { projectRoot, maestroRoot, readFile }),
895
+ ])
896
+ );
897
+ // Every row, not just the failing ones: the instability baseline is the run's
898
+ // own healthy flows, and a baseline drawn from the failures alone would be
899
+ // the very population it is supposed to be measured against.
900
+ const flowKeys = rows.map(row => ({
901
+ flow: row.file,
902
+ keys: flowArtifactKeys(row.file, readFile(paths.get(row.file))),
903
+ }));
904
+ const markers = {
905
+ faultMarkers: deviceFaultMarkers,
906
+ instabilityMarkers: deviceInstabilityMarkers,
907
+ };
908
+ const tally = tallyDeviceMarkers(debugArtifacts, flowKeys, [
909
+ ...deviceFaultMarkers,
910
+ ...deviceInstabilityMarkers,
911
+ ]);
912
+ const baselines = {};
913
+ for (const marker of deviceInstabilityMarkers)
914
+ baselines[marker] = median(
915
+ [...tally.perFlow.values()].map(bucket => bucket[marker]?.count ?? 0)
916
+ );
917
+ const failures = [];
918
+ for (const testCase of rows) {
919
+ if (!testCase.failed) continue;
920
+ const device = deviceVerdict(
921
+ tally.perFlow.get(testCase.file) ?? {},
922
+ baselines,
923
+ markers
924
+ );
925
+ // A device death short-circuits the preamble/product split rather than
926
+ // annotating it: the flow did not reach a verdict about the product at all,
927
+ // so which gate it happened to be standing on when the device went is not a
928
+ // finding about the app.
929
+ const matched = device
930
+ ? null
931
+ : matchPreambleGate(paths.get(testCase.file), testCase, {
932
+ readFile,
933
+ signInMarkers,
934
+ });
587
935
  const flow = path.basename(testCase.file);
588
- results.push({
936
+ failures.push({
589
937
  flow,
590
938
  durationSec: testCase.durationSec,
591
939
  message: testCase.message,
592
- kind: matched ? "preamble" : "product",
940
+ kind: device ? "device" : matched ? "preamble" : "product",
941
+ device,
593
942
  gate: matched ? matched.selector : null,
594
943
  subflow: matched ? matched.subflow : null,
595
944
  gateCeilingSec:
@@ -601,7 +950,29 @@ export function classify(reportXml, options) {
601
950
  intermittent: intermittentFor(flow, platform, registry),
602
951
  });
603
952
  }
604
- return results;
953
+ return {
954
+ failures,
955
+ deviceRunEvidence: Object.entries(tally.unattributed).map(
956
+ ([marker, seen]) => ({
957
+ marker,
958
+ count: seen.count,
959
+ artifact: seen.artifact,
960
+ })
961
+ ),
962
+ };
963
+ }
964
+
965
+ /**
966
+ * Classify every failure in a report.
967
+ *
968
+ * The per-failure half of {@link classifyRun}, kept as its own export because
969
+ * that is the shape every caller but the renderer wants.
970
+ * @param {string} reportXml - JUnit report source
971
+ * @param {object} options - Classification context, as {@link classifyRun} takes it
972
+ * @returns {object[]} One record per failing flow
973
+ */
974
+ export function classify(reportXml, options) {
975
+ return classifyRun(reportXml, options).failures;
605
976
  }
606
977
 
607
978
  /**
@@ -660,6 +1031,41 @@ function readFileOrNull(target) {
660
1031
  }
661
1032
  }
662
1033
 
1034
+ /**
1035
+ * Every FILE under `root`, recursively, or null when `root` is not a directory.
1036
+ *
1037
+ * `withFileTypes` reports a symlink as a symlink rather than as the thing it
1038
+ * points at, so a link back up the tree is neither followed nor recursed into
1039
+ * and this cannot loop.
1040
+ * @param {string} root - Absolute directory path
1041
+ * @returns {string[] | null} Absolute file paths, or null
1042
+ */
1043
+ function listFilesRecursive(root) {
1044
+ let entries;
1045
+ try {
1046
+ entries = fs.readdirSync(root, { withFileTypes: true });
1047
+ } catch {
1048
+ return null;
1049
+ }
1050
+ const files = [];
1051
+ for (const entry of entries) {
1052
+ const full = path.join(root, entry.name);
1053
+ if (entry.isDirectory()) files.push(...(listFilesRecursive(full) ?? []));
1054
+ else if (entry.isFile()) files.push(full);
1055
+ }
1056
+ return files;
1057
+ }
1058
+
1059
+ /**
1060
+ * A config array of strings, or the shipped default when it is absent.
1061
+ * @param {unknown} value - Raw config value
1062
+ * @param {readonly string[]} fallback - Shipped default
1063
+ * @returns {readonly string[]} The markers to use
1064
+ */
1065
+ function markerList(value, fallback) {
1066
+ return Array.isArray(value) ? value.map(String) : fallback;
1067
+ }
1068
+
663
1069
  /**
664
1070
  * Load the project's classification config, tolerating absence and damage.
665
1071
  *
@@ -667,31 +1073,38 @@ function readFileOrNull(target) {
667
1073
  * throwing: this tool runs beside a failing test suite, and a diagnostic that
668
1074
  * dies on a typo is a diagnostic nobody consults on the night they need it.
669
1075
  * @param {string} projectRoot - Absolute project root
670
- * @returns {{signInMarkers: string[], knownIntermittent: unknown[], defects: object[]}} Config
1076
+ * @returns {{signInMarkers: readonly string[], knownIntermittent: unknown[], deviceFaultMarkers: readonly string[], deviceInstabilityMarkers: readonly string[], defects: object[]}} Config
671
1077
  */
672
1078
  export function loadConfig(projectRoot) {
1079
+ const defaults = {
1080
+ signInMarkers: DEFAULT_SIGN_IN_MARKERS,
1081
+ knownIntermittent: [],
1082
+ deviceFaultMarkers: DEFAULT_DEVICE_FAULT_MARKERS,
1083
+ deviceInstabilityMarkers: DEFAULT_DEVICE_INSTABILITY_MARKERS,
1084
+ defects: [],
1085
+ };
673
1086
  const raw = readFileOrNull(path.join(projectRoot, CONFIG_REL_PATH));
674
- if (raw === null)
675
- return {
676
- signInMarkers: DEFAULT_SIGN_IN_MARKERS,
677
- knownIntermittent: [],
678
- defects: [],
679
- };
1087
+ if (raw === null) return defaults;
680
1088
  try {
681
1089
  const parsed = JSON.parse(raw);
682
1090
  return {
683
- signInMarkers: Array.isArray(parsed.signInMarkers)
684
- ? parsed.signInMarkers.map(String)
685
- : DEFAULT_SIGN_IN_MARKERS,
1091
+ ...defaults,
1092
+ signInMarkers: markerList(parsed.signInMarkers, DEFAULT_SIGN_IN_MARKERS),
686
1093
  knownIntermittent: Array.isArray(parsed.knownIntermittent)
687
1094
  ? parsed.knownIntermittent
688
1095
  : [],
689
- defects: [],
1096
+ deviceFaultMarkers: markerList(
1097
+ parsed.deviceFaultMarkers,
1098
+ DEFAULT_DEVICE_FAULT_MARKERS
1099
+ ),
1100
+ deviceInstabilityMarkers: markerList(
1101
+ parsed.deviceInstabilityMarkers,
1102
+ DEFAULT_DEVICE_INSTABILITY_MARKERS
1103
+ ),
690
1104
  };
691
1105
  } catch (error) {
692
1106
  return {
693
- signInMarkers: DEFAULT_SIGN_IN_MARKERS,
694
- knownIntermittent: [],
1107
+ ...defaults,
695
1108
  defects: [
696
1109
  { flow: CONFIG_REL_PATH, reason: `unreadable JSON: ${error.message}` },
697
1110
  ],
@@ -701,45 +1114,101 @@ export function loadConfig(projectRoot) {
701
1114
 
702
1115
  /**
703
1116
  * Classify every named report against one project checkout.
1117
+ *
1118
+ * The debug-output tree is read ONCE and shared across the named reports: it is
1119
+ * the observation of a single run, and re-walking it per report would only cost
1120
+ * time. A retry arm writes into the same tree, which is correct — retries only
1121
+ * re-run flows that already failed, so its evidence is about those same flows.
704
1122
  * @param {readonly string[]} reportPaths - Report paths
705
- * @param {{projectRoot: string, platform: string | null}} context - Run context
706
- * @returns {{report: string, failures: object[], defects: object[]}[]} Results
1123
+ * @param {{projectRoot: string, platform: string | null, debugRoot?: string | null}} context - Run context
1124
+ * @returns {{report: string, failures: object[], defects: object[], deviceRunEvidence: object[]}[]} Results
707
1125
  */
708
- export function run(reportPaths, { projectRoot, platform }) {
1126
+ export function run(reportPaths, { projectRoot, platform, debugRoot = null }) {
709
1127
  const maestroRoot = path.join(projectRoot, ".maestro");
710
1128
  const config = loadConfig(projectRoot);
711
1129
  const registry = validateIntermittentRegistry(config.knownIntermittent);
712
1130
  const defects = [...config.defects, ...registry.defects];
1131
+ const debugArtifacts = readDebugArtifacts(
1132
+ debugRoot ? path.resolve(projectRoot, debugRoot) : null,
1133
+ { listFiles: listFilesRecursive, readFile: readFileOrNull }
1134
+ );
713
1135
  return reportPaths.map(reportPath => ({
714
1136
  report: path.basename(reportPath),
715
1137
  defects,
716
- failures: classify(readFileOrNull(reportPath) ?? "", {
1138
+ ...classifyRun(readFileOrNull(reportPath) ?? "", {
717
1139
  maestroRoot,
718
1140
  projectRoot,
719
1141
  readFile: readFileOrNull,
720
1142
  signInMarkers: config.signInMarkers,
721
1143
  knownIntermittent: config.knownIntermittent,
1144
+ deviceFaultMarkers: config.deviceFaultMarkers,
1145
+ deviceInstabilityMarkers: config.deviceInstabilityMarkers,
1146
+ debugArtifacts,
722
1147
  platform,
723
1148
  }),
724
1149
  }));
725
1150
  }
726
1151
 
1152
+ /**
1153
+ * The failure text, or a plain statement that there was none.
1154
+ *
1155
+ * A blank cell reads as a rendering bug. "No text" is itself the finding on the
1156
+ * measured device deaths, so it is written out.
1157
+ * @param {string | null} message - Failure text from the report
1158
+ * @returns {string} Table-safe text
1159
+ */
1160
+ function failureText(message) {
1161
+ return message ? cell(message) : "_(no failure text)_";
1162
+ }
1163
+
1164
+ /**
1165
+ * How a device signal was arrived at, in one reader-facing phrase.
1166
+ * @param {object} device - The device signal
1167
+ * @returns {string} Evidence summary
1168
+ */
1169
+ function deviceEvidence(device) {
1170
+ return device.signal === "fault-marker"
1171
+ ? `raised in \`${device.artifact}\``
1172
+ : `${device.count} events in \`${device.artifact}\` vs a baseline of ${device.baseline}`;
1173
+ }
1174
+
727
1175
  /**
728
1176
  * Render one report's classification as GitHub step-summary markdown.
729
- * @param {{report: string, failures: object[], defects: object[]}} result - One report's result
1177
+ * @param {{report: string, failures: object[], defects: object[], deviceRunEvidence?: object[]}} result - One report's result
730
1178
  * @returns {string} Markdown block
731
1179
  */
732
- export function renderMarkdown({ report, failures, defects }) {
1180
+ export function renderMarkdown({
1181
+ report,
1182
+ failures,
1183
+ defects,
1184
+ deviceRunEvidence = [],
1185
+ }) {
733
1186
  const preamble = failures.filter(failure => failure.kind === "preamble");
734
1187
  const product = failures.filter(failure => failure.kind === "product");
1188
+ const device = failures.filter(failure => failure.kind === "device");
735
1189
  const lines = [
736
1190
  `### 🔍 Flake classification — \`${report}\``,
737
1191
  "",
738
- `**${product.length} product** · **${preamble.length} preamble** (tested nothing) · ${failures.length} failing flow(s)`,
1192
+ `**${product.length} product** · **${device.length} device** (never exercised the product) · **${preamble.length} preamble** (tested nothing) · ${failures.length} failing flow(s)`,
739
1193
  "",
740
1194
  "_Diagnostic only — this never changes the result of any gate._",
741
1195
  "",
742
1196
  ];
1197
+ if (device.length > 0) {
1198
+ lines.push(
1199
+ "| flow | device signal | evidence | failure text |",
1200
+ "| --- | --- | --- | --- |"
1201
+ );
1202
+ for (const failure of device)
1203
+ lines.push(
1204
+ `| \`${failure.flow}\` | \`${failure.device.marker}\` (${failure.device.signal}) | ${deviceEvidence(failure.device)} | ${failureText(failure.message)} |`
1205
+ );
1206
+ lines.push(
1207
+ "",
1208
+ "_Read off the run's `--debug-output`, never off the failure text above — the measured device deaths carried none._",
1209
+ ""
1210
+ );
1211
+ }
743
1212
  if (product.length > 0) {
744
1213
  lines.push(
745
1214
  "| flow | failure | known intermittent |",
@@ -750,7 +1219,7 @@ export function renderMarkdown({ report, failures, defects }) {
750
1219
  ? `${failure.intermittent.ratePercent}% (${failure.intermittent.failures}/${failure.intermittent.runs}, measured ${failure.intermittent.measuredAt})`
751
1220
  : "—";
752
1221
  lines.push(
753
- `| \`${failure.flow}\` | ${cell(failure.message)} | ${known} |`
1222
+ `| \`${failure.flow}\` | ${failureText(failure.message)} | ${known} |`
754
1223
  );
755
1224
  }
756
1225
  lines.push("");
@@ -771,6 +1240,11 @@ export function renderMarkdown({ report, failures, defects }) {
771
1240
  }
772
1241
  lines.push("");
773
1242
  }
1243
+ for (const evidence of deviceRunEvidence) {
1244
+ lines.push(
1245
+ `> 🩺 device signal \`${evidence.marker}\` ×${evidence.count} in \`${evidence.artifact}\`, which names no single flow. Reported only — it reclassifies nothing.`
1246
+ );
1247
+ }
774
1248
  for (const defect of defects) {
775
1249
  lines.push(
776
1250
  `> ⚠️ known-intermittent entry \`${defect.flow}\` was IGNORED: ${defect.reason}`
@@ -781,17 +1255,23 @@ export function renderMarkdown({ report, failures, defects }) {
781
1255
 
782
1256
  /**
783
1257
  * Render one report's classification as plain text.
784
- * @param {{report: string, failures: object[], defects: object[]}} result - One report's result
1258
+ * @param {{report: string, failures: object[], defects: object[], deviceRunEvidence?: object[]}} result - One report's result
785
1259
  * @returns {string} Text block
786
1260
  */
787
- function renderText({ report, failures, defects }) {
1261
+ function renderText({ report, failures, defects, deviceRunEvidence = [] }) {
788
1262
  const preamble = failures.filter(failure => failure.kind === "preamble");
789
1263
  const product = failures.filter(failure => failure.kind === "product");
1264
+ const device = failures.filter(failure => failure.kind === "device");
790
1265
  const lines = [
791
1266
  "",
792
1267
  `${report}: ${failures.length} failures`,
793
- ` ${product.length} product · ${preamble.length} preamble (tested nothing)`,
1268
+ ` ${product.length} product · ${device.length} device (never exercised the product) · ${preamble.length} preamble (tested nothing)`,
794
1269
  ];
1270
+ for (const failure of device) {
1271
+ lines.push(
1272
+ ` [device ] ${failure.flow}: ${failure.device.marker} — ${deviceEvidence(failure.device).replace(/`/g, "")}`
1273
+ );
1274
+ }
795
1275
  for (const failure of preamble) {
796
1276
  const reach =
797
1277
  failure.elapsedAtGateSec === null
@@ -803,7 +1283,13 @@ function renderText({ report, failures, defects }) {
803
1283
  const known = failure.intermittent
804
1284
  ? ` [known intermittent ${failure.intermittent.ratePercent}% — ${failure.intermittent.failures}/${failure.intermittent.runs} measured ${failure.intermittent.measuredAt}]`
805
1285
  : "";
806
- lines.push(` [product ] ${failure.flow}: ${failure.message}${known}`);
1286
+ const text = failure.message || "(no failure text)";
1287
+ lines.push(` [product ] ${failure.flow}: ${text}${known}`);
1288
+ }
1289
+ for (const evidence of deviceRunEvidence) {
1290
+ lines.push(
1291
+ ` [device? ] ${evidence.marker} ×${evidence.count} in ${evidence.artifact} — names no single flow, reclassifies nothing`
1292
+ );
807
1293
  }
808
1294
  for (const defect of defects) {
809
1295
  lines.push(
@@ -822,10 +1308,11 @@ function main(argv) {
822
1308
  const asJson = argv.includes("--json");
823
1309
  const asMarkdown = argv.includes("--markdown");
824
1310
  const platformArg = argv.find(arg => arg.startsWith("--platform="));
1311
+ const debugArg = argv.find(arg => arg.startsWith("--debug-output="));
825
1312
  const reports = argv.filter(arg => !arg.startsWith("--"));
826
1313
  if (reports.length === 0) {
827
1314
  console.error(
828
- "usage: node scripts/classify-maestro-failures.mjs [--json|--markdown] [--platform=android] <report.xml> [...]"
1315
+ "usage: node scripts/classify-maestro-failures.mjs [--json|--markdown] [--platform=android] [--debug-output=maestro-debug] <report.xml> [...]"
829
1316
  );
830
1317
  process.exitCode = 1;
831
1318
  return;
@@ -834,6 +1321,7 @@ function main(argv) {
834
1321
  const results = run(reports, {
835
1322
  projectRoot,
836
1323
  platform: platformArg ? platformArg.slice("--platform=".length) : null,
1324
+ debugRoot: debugArg ? debugArg.slice("--debug-output=".length) : null,
837
1325
  });
838
1326
  if (asJson) {
839
1327
  console.log(JSON.stringify(results, null, 2));