@jesdi/skills 0.0.86 → 0.0.88

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 (42) hide show
  1. package/package.json +1 -1
  2. package/skills/implement-spec/ARCHITECTURE.md +33 -14
  3. package/skills/implement-spec/README.md +30 -15
  4. package/skills/implement-spec/SKILL.md +1 -1
  5. package/skills/implement-spec/driver.py +3 -2
  6. package/skills/implement-spec/driver_agents.py +93 -32
  7. package/skills/implement-spec/driver_decisions.py +3 -2
  8. package/skills/implement-spec/driver_dispute.py +82 -57
  9. package/skills/implement-spec/driver_fixloop.py +18 -21
  10. package/skills/implement-spec/driver_legacy.py +31 -2
  11. package/skills/implement-spec/driver_report.py +13 -3
  12. package/skills/implement-spec/driver_run.py +23 -13
  13. package/skills/implement-spec/driver_state.py +9 -8
  14. package/skills/implement-spec/driver_summary.py +8 -1
  15. package/skills/implement-spec/prompts/correction.md +1 -0
  16. package/skills/implement-spec/prompts/reviewer.md +3 -3
  17. package/skills/implement-spec/prompts/ruled.md +1 -1
  18. package/skills/implement-spec/tests/conftest.py +2 -0
  19. package/skills/implement-spec/tests/test_agents.py +56 -5
  20. package/skills/implement-spec/tests/test_arbitration.py +104 -11
  21. package/skills/implement-spec/tests/test_decisions.py +7 -5
  22. package/skills/implement-spec/tests/test_driver.py +2 -1
  23. package/skills/implement-spec/tests/test_fixloop.py +3 -3
  24. package/skills/implement-spec/tests/test_legacy.py +27 -0
  25. package/skills/implement-spec/tests/test_lenses.py +10 -5
  26. package/skills/implement-spec/tests/test_models.py +74 -0
  27. package/skills/implement-spec/tests/test_state.py +1 -1
  28. package/skills/implement-spec/tests/test_summary.py +8 -0
  29. package/skills/test-weigh-in/dashboard.html +70 -17
  30. package/skills/test-weigh-in/tests/browser_driver.py +46 -5
  31. package/skills/test-weigh-in/tests/layout_page.py +7 -3
  32. package/skills/test-weigh-in/tests/overlap_page.py +3 -0
  33. package/skills/test-weigh-in/tests/rules_fixture.py +1 -1
  34. package/skills/test-weigh-in/tests/test_coverage_run.py +5 -1
  35. package/skills/test-weigh-in/tests/test_dashboard_layout.py +50 -9
  36. package/skills/test-weigh-in/tests/test_score.py +53 -2
  37. package/skills/test-weigh-in/weigh.py +2 -2
  38. package/skills/test-weigh-in/weigh_coverage.py +22 -2
  39. package/skills/test-weigh-in/weigh_dashboard.py +51 -10
  40. package/skills/test-weigh-in/weigh_score.py +6 -3
  41. package/skills/test-weigh-in/weigh_smells.py +3 -2
  42. package/skills-manifest.json +3 -3
@@ -6,11 +6,16 @@ body{font:14px system-ui,sans-serif;margin:24px;color:#222;overflow-wrap:break-w
6
6
  .gauge{grid-row:span 3;display:grid;grid-template-rows:subgrid;row-gap:4px;align-content:start;margin-bottom:12px;border:2px solid #ccc;border-radius:8px;padding:12px;background:#fff;text-align:center;cursor:pointer;font:inherit}
7
7
  .gauge>*{align-self:start}
8
8
  .gauge-status{font-size:12px;line-height:1.3}
9
+ /* with a red suite, each short reason wraps inside only when it alone is wider than the card, so a line never splits
10
+ "172 tests not green"; a lone "0 of 4 metrics measured" flows as text */
11
+ .gauge-status.red>span{display:inline-block}
9
12
  /* one row of tabs on a rule; it scrolls sideways when the row is wider than the screen */
10
13
  .tabs{display:flex;gap:4px;overflow-x:auto;border-bottom:1px solid #ccc;scrollbar-width:thin}
11
- .tabs>button{flex:none;font:inherit;padding:4px 12px;border:1px solid #ccc;border-bottom:3px solid transparent;border-radius:6px 6px 0 0;background:#f3f4f6;color:#222;cursor:pointer;white-space:nowrap}
14
+ .tabs>button{flex:none;display:inline-flex;flex-direction:column;align-items:center;font:inherit;padding:4px 12px;border:1px solid #ccc;border-bottom:3px solid transparent;border-radius:6px 6px 0 0;background:#f3f4f6;color:#222;cursor:pointer;white-space:nowrap}
12
15
  .tabs>button[aria-pressed=true]{background:#2563eb;color:#fff;border-bottom-color:#1e40af;font-weight:600}
13
- @media (max-width:600px){.tabs{gap:2px}.tabs>button{padding:4px 7px}}
16
+ /* every tab is as wide as its bold label, so selecting one moves no other; hidden, so screen readers skip it */
17
+ .tabs>button::after{content:attr(data-label);content:attr(data-label)/"";font-weight:600;height:0;overflow:hidden;visibility:hidden;pointer-events:none}
18
+ @media (max-width:600px){.tabs{gap:2px}.tabs>button{padding:4px 6px}}
14
19
  button:focus-visible{outline:3px solid #f59e0b;outline-offset:2px}
15
20
  #details table{width:100%}
16
21
  #details tr+tr{border-top:1px solid #e5e7eb}
@@ -29,7 +34,15 @@ table{border-collapse:collapse}td,th{padding:4px 12px;text-align:left}
29
34
  @media (min-width:601px){#details th:nth-child(-n+3),#details td:nth-child(-n+3):not([colspan]){width:1%;white-space:nowrap}}
30
35
  td:first-child,th:first-child{padding-left:0}
31
36
  @media (max-width:600px){td,th{padding:4px 6px}td:last-child,th:last-child{padding-right:0}#details td:first-child{min-width:7em}}
32
- input[type=search]{font:inherit;padding:6px 10px;border:1px solid #ccc;border-radius:6px;width:100%;max-width:24rem;box-sizing:border-box}
37
+ input[type=search]{scroll-margin-top:16px;font:inherit;padding:6px 10px;border:1px solid #ccc;border-radius:6px;width:100%;max-width:24rem;box-sizing:border-box}
38
+ /* the pair count and a pager above the list, the same pager again below it; the pager keeps to the right */
39
+ .ov-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 16px;margin:12px 0}
40
+ .ov-bar>p{margin:0}
41
+ .pager{display:flex;align-items:center;gap:8px;margin-left:auto}
42
+ .pager>span{white-space:nowrap;font-variant-numeric:tabular-nums}
43
+ .pager>button{font:inherit;min-height:32px;padding:0 12px;border:1px solid #ccc;border-radius:6px;background:#f3f4f6;color:#222;cursor:pointer}
44
+ .pager>button:disabled{color:#9ca3af;cursor:default}
45
+ @media (max-width:600px){.pager>button{min-height:44px;padding:0 14px}}
33
46
  .pair{display:grid;grid-template-columns:8em minmax(0,1fr);gap:4px 12px;padding:8px 0;border-bottom:1px solid #e5e7eb}
34
47
  .pair>strong{grid-row:span 3}
35
48
  .pair hr{width:100%;border:0;border-top:1px dashed #d1d5db;margin:0}
@@ -140,13 +153,34 @@ function drawMap(parent) {
140
153
  const pickedName = el('p', '', side); pickedName.setAttribute('data-testid', 'map-picked');
141
154
  const list = el('div', '', side); list.setAttribute('data-testid', 'map-similar');
142
155
  let lit = [];
156
+ // the selected dot's own mark, unlike the blue rings of its similar dots: the dot again, then an ink ring on a white
157
+ // rim 5 px out from it (at least 18 px across on any screen), all drawn after every dot so no neighbour covers it;
158
+ // clicks pass through to the dots beneath
159
+ const mark = document.createElementNS(NS, 'g');
160
+ mark.setAttribute('data-testid', 'map-selected'); mark.setAttribute('pointer-events', 'none'); mark.setAttribute('display', 'none');
161
+ const copy = mark.appendChild(document.createElementNS(NS, 'circle'));
162
+ const rings = [['#fff', 5], ['#222', 2.5]].map(([stroke, width]) => {
163
+ const c = document.createElementNS(NS, 'circle');
164
+ c.setAttribute('fill', 'none'); c.setAttribute('stroke', stroke); c.setAttribute('stroke-width', width);
165
+ c.setAttribute('vector-effect', 'non-scaling-stroke');
166
+ return mark.appendChild(c);
167
+ });
168
+ svg.appendChild(mark);
143
169
  // selection touches only the previous and the new highlights and the neighbour list, never the placement
144
170
  const pick = (d) => {
145
171
  picked = d;
146
172
  lit.forEach((c) => { c.setAttribute('stroke', 'none'); delete c.dataset.highlighted; });
147
173
  const sims = d.similar.slice().sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
148
- lit = [d.test, ...sims.map(([n]) => n)].map((n) => circles.get(n)).filter(Boolean);
174
+ // only the similar dots get a blue ring; the selected one shows through its own mark below
175
+ lit = sims.map(([n]) => circles.get(n)).filter(Boolean);
149
176
  lit.forEach((c) => { c.setAttribute('stroke', '#2563eb'); c.dataset.highlighted = 'true'; });
177
+ // the drawing's pixels per unit; 1 where nothing is laid out
178
+ const dot = circles.get(d.test), scale = svg.getBoundingClientRect().width / w || 1;
179
+ const r = Number(dot.getAttribute('r')), ring = Math.max(r + 5 / scale, 9 / scale);
180
+ [copy, ...rings].forEach((c) => { c.setAttribute('cx', dot.getAttribute('cx')); c.setAttribute('cy', dot.getAttribute('cy')); });
181
+ copy.setAttribute('r', r); copy.setAttribute('fill', dot.getAttribute('fill'));
182
+ rings.forEach((c) => c.setAttribute('r', ring));
183
+ mark.removeAttribute('display');
150
184
  hint.hidden = true;
151
185
  pickedName.replaceChildren();
152
186
  el('strong', 'Selected', pickedName); el('br', '', pickedName); ident(el('span', d.test, pickedName));
@@ -176,15 +210,35 @@ function drawOverlaps(parent) {
176
210
  input.type = 'search'; input.placeholder = 'Search test identities'; input.value = ovQuery; input.setAttribute('aria-label', 'Search overlapping tests');
177
211
  input.setAttribute('data-testid', 'overlap-search');
178
212
  box.appendChild(input);
179
- const out = el('div', '', box);
213
+ const bar = el('div', '', box); bar.className = 'ov-bar';
214
+ const count = el('p', '', bar); count.setAttribute('data-testid', 'overlap-count');
215
+ const empty = el('p', 'No pair matches this search.', box); empty.setAttribute('data-testid', 'overlap-empty');
216
+ const list = el('div', '', box);
217
+ const foot = el('div', '', box); foot.className = 'ov-bar';
218
+ // the same pager above and below the list; after a page turn focus is on the top one, so paging from the bottom
219
+ // brings the reader back to the start of the new page instead of leaving them 100 rows down
220
+ const pager = (parent, label, suffix) => {
221
+ const nav = el('nav', '', parent); nav.className = 'pager'; nav.setAttribute('aria-label', label);
222
+ const step = (text, d, id) => { const b = el('button', text, nav); b.setAttribute('data-testid', id + suffix); b.onclick = () => turn(d, suffix !== ''); return b; };
223
+ // the counter before the buttons, so its width changing (page 9 to 10) never moves a button
224
+ const at = el('span', '', nav); at.setAttribute('data-testid', 'overlap-page' + suffix);
225
+ return { at, prev: step('Previous', -1, 'overlap-prev'), next: step('Next', 1, 'overlap-next') };
226
+ };
227
+ const top = pager(bar, 'Pages of pairs', ''), bottom = pager(foot, 'Pages of pairs, end of list', '-bottom');
228
+ top.at.setAttribute('aria-live', 'polite');
229
+ const turn = (d, fromBottom) => {
230
+ ovPage += d; draw();
231
+ if (fromBottom) input.scrollIntoView?.({ block: 'start' }); // jsdom has no scrollIntoView
232
+ const [ahead, back] = d < 0 ? [top.prev, top.next] : [top.next, top.prev];
233
+ (ahead.disabled ? back : ahead).focus({ preventScroll: true });
234
+ };
180
235
  const draw = () => {
181
- out.replaceChildren();
182
236
  const q = ovQuery.toLowerCase();
183
237
  const hits = q ? ranked.filter((o) => o.tests.some((t) => t.toLowerCase().includes(q))) : ranked;
184
238
  const pages = Math.max(1, Math.ceil(hits.length / PAGE));
185
239
  ovPage = Math.min(ovPage, pages - 1);
186
- el('p', hits.length.toLocaleString('en-US') + (hits.length === 1 ? ' pair' : ' pairs'), out).setAttribute('data-testid', 'overlap-count');
187
- if (!hits.length) el('p', 'No pair matches this search.', out).setAttribute('data-testid', 'overlap-empty');
240
+ count.textContent = hits.length.toLocaleString('en-US') + (hits.length === 1 ? ' pair' : ' pairs');
241
+ if (hits.length) empty.remove(); else bar.after(empty);
188
242
  // a page is built off the page and attached once: one insertion instead of hundreds
189
243
  const rows = document.createDocumentFragment();
190
244
  hits.slice(ovPage * PAGE, (ovPage + 1) * PAGE).forEach((o) => {
@@ -194,12 +248,8 @@ function drawOverlaps(parent) {
194
248
  // the two tests on their own lines, a dashed rule between them
195
249
  o.tests.forEach((t, k) => { if (k) el('hr', '', row); testLine('div', t, row).setAttribute('data-testid', 'overlap-test'); });
196
250
  });
197
- out.appendChild(rows);
198
- const nav = el('p', '', out);
199
- const step = (text, d, id) => { const b = el('button', text, nav); b.setAttribute('data-testid', id); b.disabled = ovPage + d < 0 || ovPage + d >= pages; b.onclick = () => { ovPage += d; draw(); }; };
200
- step('Previous', -1, 'overlap-prev');
201
- el('span', ' Page ' + (ovPage + 1) + ' of ' + pages + ' ', nav);
202
- step('Next', 1, 'overlap-next');
251
+ list.replaceChildren(rows);
252
+ [top, bottom].forEach((p) => { p.at.textContent = 'Page ' + (ovPage + 1) + ' of ' + pages; p.prev.disabled = ovPage === 0; p.next.disabled = ovPage === pages - 1; });
203
253
  };
204
254
  input.oninput = () => { ovQuery = input.value; ovPage = 0; draw(); };
205
255
  draw();
@@ -218,18 +268,21 @@ function render() {
218
268
  g.setAttribute('aria-pressed', i === selected);
219
269
  el('span', p.name, g).setAttribute('data-testid', 'gauge-title');
220
270
  el('span', p.score === null ? '–' : shown(p.score), g).className = 'score';
221
- const status = el('span', p.partial ? 'partial: ' + p.metrics.length + ' of ' + p.total + ' metrics measured' : 'all ' + p.total + ' metrics measured', g);
222
- status.className = 'gauge-status' + (p.partial ? ' flag' : ''); status.setAttribute('data-testid', 'gauge-status');
271
+ const { head, reasons } = p.status;
272
+ const status = el('span', head, g);
273
+ reasons.forEach((r, k) => { status.append(' '); el('span', r + (k < reasons.length - 1 ? ';' : ''), status); });
274
+ status.className = 'gauge-status' + (reasons.length ? ' flag' : '') + (p.red_suite ? ' red' : ''); status.setAttribute('data-testid', 'gauge-status');
223
275
  g.onclick = () => { selected = i; tab = 'Metrics'; picked = null; render(); };
224
276
  });
225
277
  const p = data.pillars[selected];
226
278
  el('h2', p.name, details);
227
279
  const names = ['Metrics', 'Worst tests', 'Smells', ...(p.key === 'economy' ? ['Overlaps', 'Map'] : [])];
228
280
  const tabs = el('div', '', details); tabs.className = 'tabs';
229
- names.forEach((n) => { const b = el('button', n, tabs); b.setAttribute('aria-pressed', n === tab); b.onclick = () => { tab = n; picked = null; render(); }; });
281
+ names.forEach((n) => { const b = el('button', n, tabs); b.dataset.label = n; b.setAttribute('aria-pressed', n === tab); b.onclick = () => { tab = n; picked = null; render(); }; });
230
282
  el('h3', tab, details);
231
283
  if (tab === 'Metrics') {
232
284
  if (!p.metrics.length) el('p', 'No metrics were measured for this pillar.', details);
285
+ if (p.status.note) el('p', p.status.note, details).setAttribute('data-testid', 'partial-reason');
233
286
  const t = el('table', '', details);
234
287
  const head = el('tr', '', t);
235
288
  ['Metric', 'Value', 'Score', 'Anchors'].forEach((h) => el('th', h, head));
@@ -1,6 +1,7 @@
1
- """Ticket 04 browser driver: `uv run --with playwright python browser_driver.py <dashboard.html>` opens the standalone
2
- report from disk in Chrome with the network switched off, drives the visible controls and prints one JSON document of
3
- measurements on stdout. It asserts nothing: test_dashboard_layout.py reads the measurements.
1
+ """Ticket 04 browser driver: `uv run --with playwright python browser_driver.py <dashboard.html> [--gauges]` opens the
2
+ standalone report from disk in Chrome with the network switched off, drives the visible controls and prints one JSON
3
+ document of measurements on stdout; with --gauges it measures only the overview gauges at both viewports. It asserts
4
+ nothing: test_dashboard_layout.py reads the measurements.
4
5
 
5
6
  Page interface the acceptance tests pin, on top of the earlier tickets' markup (metric/overlap/map tabs):
6
7
  [data-testid=gauge-title] inside every [data-testid=gauge]: the pillar title
@@ -25,8 +26,11 @@ GAUGES = """() => [...document.querySelectorAll('[data-testid=gauge]')].map((g)
25
26
  return {top: Math.round(r.top), left: Math.round(r.left), width: Math.round(r.width), height: Math.round(r.height),
26
27
  lines: Math.round(r.height / (parseFloat(s.lineHeight) || 1.2 * parseFloat(s.fontSize))), font: parseFloat(s.fontSize),
27
28
  clipped: e.scrollWidth > e.clientWidth + 1 || e.scrollHeight > e.clientHeight + 1, text: e.textContent.trim()}; };
29
+ const status = g.querySelector('[data-testid=gauge-status]'), lh = (e) => parseFloat(getComputedStyle(e).lineHeight);
30
+ // the lines each reason of the status spans: an inline one breaks into rects, an inline-block one grows taller
31
+ const reasons = status ? [...status.children].map((s) => Math.max(s.getClientRects().length, Math.round(s.getBoundingClientRect().height / lh(s)))) : [];
28
32
  return {card: box(g), title: box(g.querySelector('[data-testid=gauge-title]')), score: box(g.querySelector('.score')),
29
- status: box(g.querySelector('[data-testid=gauge-status]'))};
33
+ status: box(status), reasons};
30
34
  })"""
31
35
 
32
36
  SIG = """(el) => { const s = getComputedStyle(el);
@@ -58,6 +62,15 @@ def table_share(page):
58
62
  return t ? t.getBoundingClientRect().width / d.getBoundingClientRect().width : null; }""")
59
63
 
60
64
 
65
+ def overview(browser, width, height):
66
+ page = browser.new_page(viewport={"width": width, "height": height})
67
+ page.goto(URL)
68
+ page.wait_for_selector(GAUGE)
69
+ out = {"gauges": page.evaluate(GAUGES), "overview": page.evaluate(OVERFLOW)}
70
+ page.close()
71
+ return out
72
+
73
+
61
74
  def layout(browser, width, height):
62
75
  page = browser.new_page(viewport={"width": width, "height": height})
63
76
  page.goto(URL)
@@ -71,6 +84,8 @@ def layout(browser, width, height):
71
84
  click_gauge(page, "Economy")
72
85
  click_tab(page, "Overlaps")
73
86
  out["overlaps"] = page.evaluate(OVERFLOW)
87
+ out["pager_heights"] = page.evaluate("""() => Object.fromEntries(['overlap-next', 'overlap-next-bottom'].map((id) =>
88
+ [id, document.querySelector(`[data-testid=${id}]`).getBoundingClientRect().height]))""")
74
89
  out["overlap_ids"] = page.evaluate("""() => [...document.querySelectorAll('[data-testid=overlap-test]')].map((e) => {
75
90
  const r = e.getBoundingClientRect(), s = getComputedStyle(e);
76
91
  return {text: e.textContent, right: Math.round(r.right), clipped: e.scrollWidth > e.clientWidth + 1 && s.overflowX !== 'visible',
@@ -101,6 +116,27 @@ def tab_styles(browser):
101
116
  return {"steps": steps, "focus": focus}
102
117
 
103
118
 
119
+ TAB_BOXES = """() => { const row = document.querySelector('[data-testid=details] .tabs'), o = row.getBoundingClientRect();
120
+ return [...row.querySelectorAll('button')].map((b) => { const r = b.getBoundingClientRect();
121
+ return {text: b.textContent.trim(), left: r.left - o.left + row.scrollLeft, width: r.width}; }); }"""
122
+
123
+
124
+ def tab_boxes(browser, width, height):
125
+ """Each tab's unrounded box in its row (scroll-independent) after every tab of Economy is selected in turn."""
126
+ page = browser.new_page(viewport={"width": width, "height": height})
127
+ page.goto(URL)
128
+ page.wait_for_selector(GAUGE)
129
+ click_gauge(page, "Economy")
130
+ labels = [b["text"] for b in page.evaluate(TAB_BOXES)]
131
+ steps = {}
132
+ for label in labels:
133
+ click_tab(page, label)
134
+ steps[label] = page.evaluate(TAB_BOXES)
135
+ out = {"steps": steps, "overview": page.evaluate(OVERFLOW)}
136
+ page.close()
137
+ return out
138
+
139
+
104
140
  def journey(browser):
105
141
  context = browser.new_context(viewport={"width": 1440, "height": 900}, offline=True)
106
142
  requests = []
@@ -156,6 +192,11 @@ with sync_playwright() as p:
156
192
  browser = p.chromium.launch(channel="chrome")
157
193
  except Exception:
158
194
  browser = p.chromium.launch()
159
- result = {"desktop": layout(browser, 1440, 900), "narrow": layout(browser, 390, 844), "tabs": tab_styles(browser), "journey": journey(browser)}
195
+ if sys.argv[2:] == ["--gauges"]:
196
+ result = {"desktop": overview(browser, 1440, 900), "narrow": overview(browser, 390, 844)}
197
+ else:
198
+ result = {"desktop": layout(browser, 1440, 900), "narrow": layout(browser, 390, 844), "tabs": tab_styles(browser),
199
+ "tab_boxes": {"desktop": tab_boxes(browser, 1440, 900), "narrow": tab_boxes(browser, 390, 844)},
200
+ "journey": journey(browser)}
160
201
  browser.close()
161
202
  print(json.dumps(result))
@@ -2,6 +2,8 @@
2
2
  weigh_dashboard.write_dashboard and prints its path. The real-suite shape of the spec: 2,172 tests (all drawn on the
3
3
  Map), 3,196 cases, 6,757 overlap pairs with 200-character ids.
4
4
  Fast feedback is fully measured, Resistance to refactoring has 0 of its 4 metrics measured (reasons recorded).
5
+ `layout_page.py <out-dir> red` makes the suite red: every 50th test fails and the one after it is skipped, so Regression
6
+ and Refactoring are partial for missing metrics and for the red suite at once.
5
7
  """
6
8
  import sys
7
9
  from pathlib import Path
@@ -17,7 +19,7 @@ FIXTURE = "2172 tests, 3196 cases, 6757 pairs"
17
19
  NOT_MEASURED = ("brittle_test_files", "private_access", "mock_heavy", "interaction_only")
18
20
 
19
21
 
20
- def build(out):
22
+ def build(out, red=False):
21
23
  out.mkdir(parents=True, exist_ok=True)
22
24
  rules = load()
23
25
  tests = {}
@@ -25,8 +27,10 @@ def build(out):
25
27
  lo = (i % 300) * 10 + 1
26
28
  tests[overlap_page.name(i)] = {"outcome": "passed", "duration": 0.01 + (i % 9) / 100, "coverage": {"src/m.py": list(range(lo, lo + 6 + i % 3))},
27
29
  "unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}
30
+ if red and i % 50 < 2:
31
+ tests[overlap_page.name(i)]["outcome"] = "failed" if i % 50 == 0 else "skipped"
28
32
  values = {**feedback_values(tests, 1.0), "no_unique_coverage": 100.0, "branch_coverage": 80.0, "hollow_tests": 1.0}
29
- metrics, pillars = score(rules, values)
33
+ metrics, pillars = score(rules, values, red=red)
30
34
  data = {"commit": "abc1234", "dirty": False, "inventory": {"tests": overlap_page.N_TESTS, "cases": 3196, "test_files": 44, "test_lines": 9000, "source_lines": 9000, "runtime_seconds": 64.2},
31
35
  "metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": overlap_page.pairs(),
32
36
  "unmeasured": {m: "no git history" for m in NOT_MEASURED}}
@@ -34,4 +38,4 @@ def build(out):
34
38
 
35
39
 
36
40
  if __name__ == "__main__":
37
- print(build(Path(sys.argv[1])))
41
+ print(build(Path(sys.argv[1]), red=sys.argv[2:] == ["red"]))
@@ -10,6 +10,9 @@ Interface the acceptance tests pin (the spec leaves the markup open), inside the
10
10
  [data-testid=overlap-test] identities and a label naming "Jaccard" with the value
11
11
  [data-testid=overlap-empty] shown only when no pair matches, with an explanation
12
12
  [data-testid=overlap-next] pages forward; disabled on the last page
13
+ [data-testid=overlap-prev] pages back; disabled on the first page
14
+ [data-testid=overlap-page] "Page <n> of <pages>"; these three form the pager above the list, the same three with
15
+ a -bottom suffix (overlap-next-bottom, ...) the pager below it
13
16
  """
14
17
  import json
15
18
  import sys
@@ -6,7 +6,7 @@ Interface the tests pin (the spec leaves the TOML keys and the snapshot JSON key
6
6
  optional partial_weight, target, bad, optional log = true. Percentages are 0-100,
7
7
  durations are seconds. Pillar keys: regression, refactoring, feedback,
8
8
  maintainability, economy.
9
- snapshot: rules {version, sha256}; metrics {<id>: {value, score}}; pillars {<key>: {score, partial}}.
9
+ snapshot: rules {version, sha256}; metrics {<id>: {value, score}}; pillars {<key>: {score, partial, red_suite}}.
10
10
  Scores are unrounded floats; only the dashboard rounds and clamps.
11
11
  """
12
12
  import hashlib
@@ -7,8 +7,9 @@ Snapshot interface the tests pin (the spec leaves the JSON keys open), on top of
7
7
  tests[node].unique_coverage number of lines the test covers that no other passing test covers
8
8
  overlaps [{"tests": [node, node], "jaccard": float}] for passing pairs with jaccard >= 0.9
9
9
  metrics.branch_coverage / metrics.no_unique_coverage {value, score}; value in percent
10
- Stdout: "<n> flaky test(s)" and "<n> tests are failing" warnings.
10
+ Stdout: "<n> flaky test(s)" and "<n> tests are failing" warnings; a partial pillar's line ends "(partial: <reasons>)", its gauge status.
11
11
  """
12
+ import re
12
13
  import time
13
14
  from concurrent.futures import ThreadPoolExecutor
14
15
 
@@ -112,6 +113,9 @@ def test_a_red_suite_is_measured_without_the_failing_tests_value(tmp_path, home,
112
113
  100 * sum(not t["unique_coverage"] for t in passed) / 40)
113
114
  assert data["pillars"]["regression"]["partial"] and data["pillars"]["economy"]["partial"]
114
115
  assert "3 tests are failing" in result.stdout
116
+ # the chat summary says why each pillar is partial, the same words as its gauge
117
+ assert re.search(r"^Protection against regressions: \d+ \(partial: 2 of 4 measured; 3 tests failing\)$", result.stdout, re.M)
118
+ assert re.search(r"^Fast feedback: \d+$", result.stdout, re.M)
115
119
 
116
120
 
117
121
  def test_skipped_tests_cost_without_value(tmp_path, home, cache):
@@ -20,18 +20,28 @@ SPEC = HERE.parents[2] / "specs" / "test-weigh-in-dashboard-polish"
20
20
  TABS = ["Metrics", "Overlaps", "Map"]
21
21
 
22
22
 
23
- @pytest.fixture(scope="module")
24
- def report(tmp_path_factory):
25
- out = tmp_path_factory.mktemp("layout04")
26
- built = subprocess.run([sys.executable, str(HERE / "layout_page.py"), str(out)], capture_output=True, text=True, timeout=600)
23
+ def drive(out, page=(), driver=()):
24
+ """Build layout_page.py with `page` args into `out` and measure it with browser_driver.py and `driver` args."""
25
+ built = subprocess.run([sys.executable, str(HERE / "layout_page.py"), str(out), *page], capture_output=True, text=True, timeout=600)
27
26
  assert built.returncode == 0, built.stderr
28
27
  html = Path(built.stdout.strip())
29
- drove = subprocess.run([uv(), "run", "--with", "playwright", "python", str(HERE / "browser_driver.py"), str(html)],
28
+ drove = subprocess.run([uv(), "run", "--with", "playwright", "python", str(HERE / "browser_driver.py"), str(html), *driver],
30
29
  capture_output=True, text=True, timeout=600)
31
30
  assert drove.returncode == 0, drove.stderr[-3000:]
32
31
  return {"bytes": html.stat().st_size, **json.loads(drove.stdout)}
33
32
 
34
33
 
34
+ @pytest.fixture(scope="module")
35
+ def report(tmp_path_factory):
36
+ return drive(tmp_path_factory.mktemp("layout04"))
37
+
38
+
39
+ @pytest.fixture(scope="module")
40
+ def red_report(tmp_path_factory):
41
+ """The same suite red: failing and skipped tests, Regression and Refactoring partial for both reasons."""
42
+ return drive(tmp_path_factory.mktemp("layout04red"), page=["red"], driver=["--gauges"])
43
+
44
+
35
45
  def only_active(tabs, label):
36
46
  """Exactly one tab looks different from the rest, and it is `label`."""
37
47
  sigs = [t["sig"] for t in tabs]
@@ -49,14 +59,22 @@ def test_the_active_tab_follows_selection_and_keyboard_focus_shows(report):
49
59
 
50
60
 
51
61
  @pytest.mark.parametrize("view", ["desktop", "narrow"])
52
- def test_gauges_align_and_partial_status_stays_readable(report, view):
53
- gauges = report[view]["gauges"]
62
+ def test_selecting_a_tab_moves_no_tab(report, view):
63
+ steps = report["tab_boxes"][view]["steps"]
64
+ assert len(steps) == 5, f"Economy shows every tab: {list(steps)}"
65
+ first = next(iter(steps.values()))
66
+ for label, boxes in steps.items():
67
+ assert boxes == first, f"selecting {label} at {view} moves the tabs: {boxes} vs {first}"
68
+
69
+
70
+ def gauges_readable(r, view, max_lines=2):
71
+ gauges = r[view]["gauges"]
54
72
  assert len(gauges) == 5
55
73
  for g in gauges:
56
74
  assert g["title"] and g["status"], "every gauge has a gauge-title and a gauge-status, a fully measured one too"
57
75
  assert g["status"]["text"], "a fully measured pillar still states its measurement status"
58
76
  assert not g["title"]["clipped"] and not g["status"]["clipped"]
59
- assert g["status"]["font"] >= 11 and g["status"]["lines"] <= 2, f"partial status unreadable: {g['status']}"
77
+ assert g["status"]["font"] >= 11 and g["status"]["lines"] <= max_lines, f"partial status unreadable: {g['status']}"
60
78
  rows = {}
61
79
  for g in gauges:
62
80
  rows.setdefault(g["card"]["top"], []).append(g)
@@ -65,7 +83,30 @@ def test_gauges_align_and_partial_status_stays_readable(report, view):
65
83
  assert len({g[part]["top"] for g in row}) == 1, f"{part} not aligned across a row at {view}: {[g[part]['top'] for g in row]}"
66
84
  refactoring = next(g for g in gauges if "refactoring" in g["title"]["text"].lower())
67
85
  assert "0 of 4" in refactoring["status"]["text"]
68
- assert report[view]["overview"]["scroll_width"] <= report[view]["overview"]["viewport"], "the page overflows sideways"
86
+ assert r[view]["overview"]["scroll_width"] <= r[view]["overview"]["viewport"], "the page overflows sideways"
87
+ return refactoring
88
+
89
+
90
+ @pytest.mark.parametrize("view", ["desktop", "narrow"])
91
+ def test_gauges_align_and_partial_status_stays_readable(report, view):
92
+ gauges_readable(report, view)
93
+
94
+
95
+ @pytest.mark.parametrize("view", ["desktop", "narrow"])
96
+ def test_a_red_suite_status_naming_both_reasons_stays_readable(red_report, view):
97
+ # 3 lines at most: at 390 px "partial: 2 of 4 measured;" is a pixel or two wider than the card, so the head, the
98
+ # metric count and the tests left out take a line each; no reason may break across lines
99
+ refactoring = gauges_readable(red_report, view, max_lines=3)
100
+ assert re.fullmatch(r"partial: 0 of 4 measured; \d+ tests not green", refactoring["status"]["text"]), refactoring["status"]
101
+ # a lone "0 of 3 metrics measured" of a pillar the red suite leaves whole may flow as text
102
+ for g in (g for g in red_report[view]["gauges"] if "green" in g["status"]["text"]):
103
+ assert all(n == 1 for n in g["reasons"]), f"a reason breaks across lines at {view}: {g['status']['text']} {g['reasons']}"
104
+
105
+
106
+ @pytest.mark.parametrize("view, least", [("desktop", 32), ("narrow", 44)])
107
+ def test_the_overlap_pager_buttons_are_tall_enough_to_tap(report, view, least):
108
+ for button, height in report[view]["pager_heights"].items():
109
+ assert height >= least, f"{button} is {height} px tall at {view}, under {least}"
69
110
 
70
111
 
71
112
  @pytest.mark.parametrize("view", ["desktop", "narrow"])
@@ -6,6 +6,8 @@ import pytest
6
6
  sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
7
7
 
8
8
  from weigh_rules import load # noqa: E402
9
+ from weigh_coverage import left_out, valued, value_kind # noqa: E402
10
+ from weigh_dashboard import left_out_line, pillar_status # noqa: E402
9
11
  from weigh_score import feedback_values, score # noqa: E402
10
12
 
11
13
 
@@ -17,10 +19,59 @@ def test_tests_over_10s_is_a_percentage_of_all_tests():
17
19
  def test_without_mutation_regression_uses_the_partial_weights():
18
20
  # coverage 90 scores 90 and 10% hollow tests score 10: .60 * 90 + .40 * 10
19
21
  metrics, pillars = score(load(), {"branch_coverage": 90, "hollow_tests": 10})
20
- assert pillars["regression"] == {"score": pytest.approx(58), "partial": True}
22
+ assert pillars["regression"] == {"score": pytest.approx(58), "partial": True, "red_suite": False}
21
23
 
22
24
 
23
25
  def test_a_pillar_without_partial_weights_keeps_its_weights():
24
26
  values = {"total_runtime": 60, "p95_duration": 2, "slowest_decile_share": 40, "tests_over_10s": 2}
25
27
  _, pillars = score(load(), values)
26
- assert pillars["feedback"] == {"score": pytest.approx(.4 * 90 + .3 * 10 + .15 * 90 + .15 * 10), "partial": False}
28
+ assert pillars["feedback"] == {"score": pytest.approx(.4 * 90 + .3 * 10 + .15 * 90 + .15 * 10), "partial": False, "red_suite": False}
29
+
30
+
31
+ def test_a_red_suite_leaves_only_the_pillars_with_a_value_metric_partial_and_says_so():
32
+ values = {"total_runtime": 60, "p95_duration": 2, "slowest_decile_share": 40, "tests_over_10s": 2}
33
+ _, pillars = score(load(), values, red=True)
34
+ assert pillars["regression"]["partial"] and pillars["regression"]["red_suite"]
35
+ assert not pillars["feedback"]["partial"] and not pillars["feedback"]["red_suite"]
36
+
37
+
38
+ def t(outcome, flaky=False):
39
+ return {"outcome": outcome, "flaky": flaky}
40
+
41
+
42
+ def test_left_out_names_each_kind_of_test_that_gives_no_value():
43
+ assert left_out({"a": t("passed")}) == []
44
+ one = left_out({"a": t("skipped"), "b": t("passed")})
45
+ assert left_out_line(one) == "1 test skipped"
46
+ mixed = left_out({"a": t("failed"), "b": t("failed", flaky=True), "c": t("skipped"), "d": t("passed", flaky=True)})
47
+ assert left_out_line(mixed) == "2 tests failing, 1 skipped, 1 flaky"
48
+
49
+
50
+ @pytest.mark.parametrize("outcome", ["passed", "failed", "skipped", "error", "xfail"])
51
+ @pytest.mark.parametrize("flaky", [False, True])
52
+ def test_a_test_that_gives_no_value_is_always_named_left_out(outcome, flaky):
53
+ # a red suite (some test not valued) must have a kind to name, or a gauge would read "0 tests not green"
54
+ tests = {"ok": t("passed"), "x": t(outcome, flaky)}
55
+ kinds = left_out(tests)
56
+ assert sum(n for n, _ in kinds) == len(tests) - len(valued(tests))
57
+ assert bool(kinds) == (value_kind(tests["x"]) != "valued")
58
+
59
+
60
+ def _status(tests, measured, red):
61
+ """pillar_status of one pillar with 4 metrics, 2 of them value metrics, `measured` of them measured."""
62
+ ids = ["branch_coverage", "mutation_score", "a", "b"]
63
+ rules = {"pillars": {"p": {"metrics": {i: {"name": i.replace("_", " ").capitalize()} for i in ids}}}}
64
+ data = {"tests": tests, "metrics": {i: {} for i in ids[:measured]},
65
+ "pillars": {"p": {"partial": red or measured < 4, "red_suite": red}}}
66
+ return pillar_status(data, rules)["p"]
67
+
68
+
69
+ def test_the_status_says_why_a_pillar_is_partial():
70
+ one = {"a": t("skipped"), "b": t("passed")}
71
+ mixed = {"a": t("failed"), "b": t("failed", flaky=True), "c": t("skipped"), "d": t("passed", flaky=True)}
72
+ assert _status(one, 4, True)["reasons"] == ["1 test skipped"]
73
+ assert _status(mixed, 0, True)["reasons"] == ["0 of 4 measured", "4 tests not green"]
74
+ assert _status(mixed, 2, False) == {"head": "partial:", "reasons": ["2 of 4 metrics measured"], "note": None}
75
+ assert _status({"a": t("passed")}, 4, False) == {"head": "all 4 metrics measured", "reasons": [], "note": None}
76
+ assert _status(mixed, 4, True)["note"] == ("Partial: Branch coverage and Mutation score count only the tests that passed "
77
+ "in both the plain and the coverage run. Left out: 2 tests failing, 1 skipped, 1 flaky.")
@@ -9,7 +9,7 @@ from pathlib import Path
9
9
  sys.path.insert(0, str(Path(__file__).resolve().parent))
10
10
 
11
11
  from weigh_env import SetupError, build_overlay, check_versions, find_interpreter
12
- from weigh_coverage import branch_percent, overlaps, per_test, test_file_sources, unique_coverage, valued
12
+ from weigh_coverage import branch_percent, left_out, overlaps, per_test, test_file_sources, unique_coverage, valued
13
13
  from weigh_git import brittle_percent, brittleness, is_repo
14
14
  from weigh_dashboard import summary, write_dashboard
15
15
  from weigh_inventory import count_lines
@@ -105,7 +105,7 @@ def main(argv=None):
105
105
  test_files = brittleness(repo, test_file_sources(tests))
106
106
  measure("brittle_test_files", brittle_percent(test_files),
107
107
  "no source file maps to a test file" if is_repo(repo) else "no git history")
108
- metrics, pillars = score(rules, values, red=len(passing) < len(tests))
108
+ metrics, pillars = score(rules, values, red=bool(left_out(tests)))
109
109
  data = {
110
110
  "commit": commit,
111
111
  "dirty": dirty,
@@ -1,6 +1,7 @@
1
1
  """Read `coverage json --show-contexts` into per-test coverage, and derive unique coverage and overlaps."""
2
2
  import os
3
3
  import re
4
+ from collections import Counter
4
5
  from itertools import combinations
5
6
 
6
7
  from weigh_inventory import is_test
@@ -60,9 +61,28 @@ def branch_percent(report):
60
61
  return 100 * totals["covered_branches"] / totals["num_branches"]
61
62
 
62
63
 
64
+ # Why a test gives no value, in the order the report names them
65
+ NO_VALUE = ("failing", "skipped", "flaky")
66
+
67
+
68
+ def value_kind(test):
69
+ """"valued" when a test passed in the plain run and the same under coverage, else why it gives no value: "failing"
70
+ (flaky or not), "skipped", or "flaky" (passed, then differed under coverage). The one definition of a test's value."""
71
+ if test["outcome"] == "passed":
72
+ return "flaky" if test["flaky"] else "valued"
73
+ return "skipped" if test["outcome"] == "skipped" else "failing"
74
+
75
+
63
76
  def valued(tests):
64
- """The tests that give value: passed in the plain run and the same under coverage, so not flaky."""
65
- return {node: test for node, test in tests.items() if test["outcome"] == "passed" and not test["flaky"]}
77
+ """The tests that give value."""
78
+ return {node: test for node, test in tests.items() if value_kind(test) == "valued"}
79
+
80
+
81
+ def left_out(tests):
82
+ """Each kind of test that gives no value with its count, e.g. [(3, "failing"), (4, "skipped")]; empty exactly when
83
+ every test gives value, so a red suite always has a kind to name."""
84
+ counts = Counter(value_kind(t) for t in tests.values())
85
+ return [(counts[kind], kind) for kind in NO_VALUE if counts[kind]]
66
86
 
67
87
 
68
88
  def _items(test):