@jesdi/skills 0.0.85 → 0.0.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/implement-spec/tests/test_landing.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +2 -2
- package/skills/test-weigh-in/dashboard.html +185 -27
- package/skills/test-weigh-in/rules.toml +18 -0
- package/skills/test-weigh-in/tests/browser_driver.py +161 -0
- package/skills/test-weigh-in/tests/conftest.py +8 -1
- package/skills/test-weigh-in/tests/latency_probe.py +96 -0
- package/skills/test-weigh-in/tests/layout_page.py +37 -0
- package/skills/test-weigh-in/tests/metric_page.py +56 -0
- package/skills/test-weigh-in/tests/overlap_page.py +60 -0
- package/skills/test-weigh-in/tests/rules_fixture.py +3 -1
- package/skills/test-weigh-in/tests/sorted_map_page.py +35 -0
- package/skills/test-weigh-in/tests/test_brittleness.py +5 -0
- package/skills/test-weigh-in/tests/test_dashboard_layout.py +103 -0
- package/skills/test-weigh-in/tests/test_scoring.py +10 -0
- package/skills/test-weigh-in/weigh.py +25 -15
- package/skills/test-weigh-in/weigh_dashboard.py +9 -1
- package/skills/test-weigh-in/weigh_rules.py +3 -0
- package/skills-manifest.json +5 -5
package/package.json
CHANGED
|
@@ -192,9 +192,9 @@ def ended(proc):
|
|
|
192
192
|
|
|
193
193
|
|
|
194
194
|
def until(done, seconds=30):
|
|
195
|
-
end = time.
|
|
195
|
+
end = time.monotonic() + seconds
|
|
196
196
|
while not done():
|
|
197
|
-
assert time.
|
|
197
|
+
assert time.monotonic() < end, "the first driver did not reach its agent"
|
|
198
198
|
time.sleep(0.02)
|
|
199
199
|
|
|
200
200
|
|
|
@@ -202,8 +202,8 @@ class Rig:
|
|
|
202
202
|
proc = subprocess.Popen(["sh", str(RUN), *args], cwd=self.repo, env=self.env, text=True, stdout=o,
|
|
203
203
|
stderr=e, start_new_session=True)
|
|
204
204
|
self.snaps, self.torn = [], []
|
|
205
|
-
state, end = self.repo / ".agent/implement/state.json", time.
|
|
206
|
-
while proc.poll() is None and time.
|
|
205
|
+
state, end = self.repo / ".agent/implement/state.json", time.monotonic() + 120
|
|
206
|
+
while proc.poll() is None and time.monotonic() < end:
|
|
207
207
|
if watch:
|
|
208
208
|
try:
|
|
209
209
|
self.snaps.append(json.loads(state.read_text()))
|
|
@@ -1,18 +1,54 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en"><head><meta charset="utf-8"><title>test-weigh-in</title>
|
|
3
3
|
<style>
|
|
4
|
-
body{font:14px system-ui,sans-serif;margin:24px;color:#222}
|
|
5
|
-
#gauges{display:
|
|
6
|
-
.gauge{
|
|
4
|
+
body{font:14px system-ui,sans-serif;margin:24px;color:#222;overflow-wrap:break-word}
|
|
5
|
+
#gauges{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:0 12px;margin:16px 0}
|
|
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
|
+
.gauge>*{align-self:start}
|
|
8
|
+
.gauge-status{font-size:12px;line-height:1.3}
|
|
9
|
+
/* one row of tabs on a rule; it scrolls sideways when the row is wider than the screen */
|
|
10
|
+
.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}
|
|
12
|
+
.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}}
|
|
14
|
+
button:focus-visible{outline:3px solid #f59e0b;outline-offset:2px}
|
|
15
|
+
#details table{width:100%}
|
|
16
|
+
#details tr+tr{border-top:1px solid #e5e7eb}
|
|
7
17
|
.gauge[aria-pressed=true]{border-color:#2563eb}
|
|
8
18
|
.score{display:block;font-size:32px;font-weight:600}
|
|
9
|
-
#banner{background:#fef2f2;color:#991b1b;padding:8px 12px;border-radius:6px}
|
|
19
|
+
#banner{background:#fef2f2;color:#991b1b;padding:8px 12px;border-radius:6px;margin-bottom:0}
|
|
20
|
+
#failing{border:1px solid #fecaca;border-top:0;border-radius:0 0 6px 6px;padding:4px 12px;margin-bottom:16px}
|
|
21
|
+
#failing p{margin:4px 0}
|
|
22
|
+
#failing:empty{display:none}
|
|
23
|
+
#banner:has(+#failing:not(:empty)){border-radius:6px 6px 0 0}
|
|
10
24
|
.flag{display:block;color:#92400e}
|
|
11
25
|
table{border-collapse:collapse}td,th{padding:4px 12px;text-align:left}
|
|
26
|
+
/* a test identity: breaks after / :: . _ (see ident), anywhere only when one part is wider than the line */
|
|
27
|
+
.id{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere}
|
|
28
|
+
/* the anchors column takes the spare width, so a metric and its value stay side by side */
|
|
29
|
+
@media (min-width:601px){#details th:nth-child(-n+3),#details td:nth-child(-n+3):not([colspan]){width:1%;white-space:nowrap}}
|
|
30
|
+
td:first-child,th:first-child{padding-left:0}
|
|
31
|
+
@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}
|
|
33
|
+
.pair{display:grid;grid-template-columns:8em minmax(0,1fr);gap:4px 12px;padding:8px 0;border-bottom:1px solid #e5e7eb}
|
|
34
|
+
.pair>strong{grid-row:span 3}
|
|
35
|
+
.pair hr{width:100%;border:0;border-top:1px dashed #d1d5db;margin:0}
|
|
36
|
+
@media (max-width:600px){.pair{grid-template-columns:minmax(0,1fr)}.pair>strong{grid-row:auto}}
|
|
37
|
+
.map{display:grid;gap:16px;align-items:start}
|
|
38
|
+
.map svg{display:block;width:100%;height:auto}
|
|
39
|
+
.map-side p{margin:0 0 8px}
|
|
40
|
+
.similar{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:4px 12px}
|
|
41
|
+
.similar>div{display:grid;grid-template-columns:subgrid;grid-column:1/-1}
|
|
42
|
+
.similar>.head{font-weight:600}
|
|
43
|
+
.similar>div+div+div{border-top:1px solid #f3f4f6;padding-top:4px}
|
|
44
|
+
.similar .num{text-align:right;font-variant-numeric:tabular-nums}
|
|
45
|
+
/* wide screens: the selection sits beside the map and stays in view while the map scrolls */
|
|
46
|
+
@media (min-width:900px){.map{grid-template-columns:minmax(0,1fr) 22rem}.map-side{position:sticky;top:0;max-height:100vh;overflow-y:auto}}
|
|
12
47
|
</style></head><body>
|
|
13
48
|
<h1>test-weigh-in</h1>
|
|
14
49
|
<p data-testid="inventory" id="inventory"></p>
|
|
15
50
|
<p data-testid="banner" id="banner"></p>
|
|
51
|
+
<div data-testid="failing" id="failing"></div>
|
|
16
52
|
<div id="gauges"></div>
|
|
17
53
|
<section data-testid="details" id="details"></section>
|
|
18
54
|
<script>
|
|
@@ -20,15 +56,46 @@ const data = __DATA__;
|
|
|
20
56
|
const shown = (s) => Math.min(99, Math.max(1, Math.round(s)));
|
|
21
57
|
const el = (tag, text, parent) => { const e = document.createElement(tag); e.textContent = text; parent.appendChild(e); return e; };
|
|
22
58
|
const fmt = (n) => String(Math.round(n * 100) / 100);
|
|
59
|
+
// words that belong together stay on one line: "71.3 %", "target ≤ 60 s"
|
|
60
|
+
const nb = (...parts) => parts.filter((x) => x !== '').join('\u00a0');
|
|
61
|
+
// ident marks an element whose text is a test identity. It gets break opportunities after / :: . or _ (not inside
|
|
62
|
+
// "name.py"), at least 12 characters apart, so it wraps between its parts; overflow-wrap breaks a part only when it is
|
|
63
|
+
// wider than the line. The breaks are added just before the next paint, to the identities still on the page then:
|
|
64
|
+
// paging through thousands of pairs in one go never builds the breaks of pages nobody saw.
|
|
65
|
+
let unbroken = [];
|
|
66
|
+
const addBreaks = () => {
|
|
67
|
+
const ids = unbroken; unbroken = [];
|
|
68
|
+
ids.forEach((s) => {
|
|
69
|
+
if (!s.isConnected) return;
|
|
70
|
+
const parts = [];
|
|
71
|
+
let chunk = '';
|
|
72
|
+
for (const part of s.textContent.split(/(?<=\/|::|\.(?!py\b)|_)/)) if ((chunk += part).length >= 12) { parts.push(chunk); chunk = ''; }
|
|
73
|
+
if (chunk) parts.push(chunk);
|
|
74
|
+
s.replaceChildren();
|
|
75
|
+
parts.forEach((part, i) => { if (i) s.appendChild(document.createElement('wbr')); s.appendChild(document.createTextNode(part)); });
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const ident = (e) => {
|
|
79
|
+
e.className = 'id';
|
|
80
|
+
if (!unbroken.length) (window.requestAnimationFrame || setTimeout)(addBreaks);
|
|
81
|
+
unbroken.push(e);
|
|
82
|
+
return e;
|
|
83
|
+
};
|
|
84
|
+
// a block naming one test, optionally followed by a note such as "(skipped)" or "(Real sleep, 1.02 s)", whose numbers keep their units
|
|
85
|
+
const testLine = (tag, test, parent, note) => {
|
|
86
|
+
if (!note) return ident(el(tag, test, parent));
|
|
87
|
+
const e = el(tag, '', parent); ident(el('span', test, e));
|
|
88
|
+
e.append(' ' + note.replace(/(\d) (?=s\b|%)/g, '$1\u00a0'));
|
|
89
|
+
return e;
|
|
90
|
+
};
|
|
23
91
|
let selected = 0, tab = 'Metrics', picked = null;
|
|
24
92
|
const NS = 'http://www.w3.org/2000/svg';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// ponytail: all pairs per pass, quadratic; a spatial grid if maps of thousands of dots get slow
|
|
93
|
+
// tests with the same or nearly the same coverage land on or near one place: push apart each pair of dots that
|
|
94
|
+
// overlaps until none does, so every dot stays clickable; same data, same pushes, same map on every load.
|
|
95
|
+
// Computed once, on first opening: selecting a dot never moves one.
|
|
96
|
+
// ponytail: all pairs per pass, quadratic; a spatial grid if maps of thousands of dots get slow
|
|
97
|
+
let placed = null;
|
|
98
|
+
function place() {
|
|
32
99
|
const dots = data.map.map((d) => ({ d, cx: 20 + d.x * 360, cy: 20 + d.y * 260, r: 4 + Math.min(10, d.runtime * 4) }));
|
|
33
100
|
for (let pass = 0, moved = true; moved && pass < 200; pass++) {
|
|
34
101
|
moved = false;
|
|
@@ -42,70 +109,161 @@ function drawMap(parent) {
|
|
|
42
109
|
moved = true;
|
|
43
110
|
}));
|
|
44
111
|
}
|
|
45
|
-
// the view grows to hold every ring
|
|
112
|
+
// the view grows to hold every ring; the drawing then scales to the width it gets, dots and gaps alike
|
|
46
113
|
const x0 = Math.min(0, ...dots.map((o) => o.cx - o.r - 2)), y0 = Math.min(0, ...dots.map((o) => o.cy - o.r - 2));
|
|
47
114
|
const w = Math.max(400, ...dots.map((o) => o.cx + o.r + 2)) - x0, h = Math.max(300, ...dots.map((o) => o.cy + o.r + 2)) - y0;
|
|
48
|
-
|
|
115
|
+
return { dots, x0, y0, w, h };
|
|
116
|
+
}
|
|
117
|
+
function drawMap(parent) {
|
|
118
|
+
const { dots, x0, y0, w, h } = placed || (placed = place());
|
|
119
|
+
const legend = el('p', 'Colour shows unique lines: grey 0, amber 1–3, green 4+. Dot size shows runtime: slower tests are larger. Hover a dot for its test; click it to select.', parent);
|
|
120
|
+
legend.setAttribute('data-testid', 'map-legend');
|
|
121
|
+
const box = el('div', '', parent); box.className = 'map';
|
|
122
|
+
const svg = document.createElementNS(NS, 'svg');
|
|
123
|
+
box.appendChild(svg);
|
|
124
|
+
svg.setAttribute('viewBox', `${x0} ${y0} ${w} ${h}`);
|
|
125
|
+
const circles = new Map();
|
|
49
126
|
dots.forEach(({ d, cx, cy, r }) => {
|
|
50
127
|
const c = document.createElementNS(NS, 'circle');
|
|
51
128
|
c.setAttribute('cx', cx); c.setAttribute('cy', cy);
|
|
52
129
|
c.setAttribute('r', r);
|
|
53
130
|
c.setAttribute('fill', d.unique === 0 ? '#9ca3af' : d.unique < 4 ? '#f59e0b' : '#16a34a');
|
|
54
|
-
c.setAttribute('stroke', picked && (picked === d || near.has(d.test)) ? '#2563eb' : 'none');
|
|
55
131
|
c.setAttribute('stroke-width', '3');
|
|
56
132
|
c.setAttribute('data-testid', 'map-dot'); c.dataset.test = d.test;
|
|
57
|
-
|
|
58
|
-
|
|
133
|
+
el('title', d.test, c);
|
|
134
|
+
circles.set(d.test, c);
|
|
135
|
+
c.onclick = () => pick(d);
|
|
59
136
|
svg.appendChild(c);
|
|
60
137
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
138
|
+
const side = el('div', '', box); side.className = 'map-side';
|
|
139
|
+
const hint = el('p', 'Click a dot to see its test and the tests that cover nearly the same lines.', side);
|
|
140
|
+
const pickedName = el('p', '', side); pickedName.setAttribute('data-testid', 'map-picked');
|
|
141
|
+
const list = el('div', '', side); list.setAttribute('data-testid', 'map-similar');
|
|
142
|
+
let lit = [];
|
|
143
|
+
// selection touches only the previous and the new highlights and the neighbour list, never the placement
|
|
144
|
+
const pick = (d) => {
|
|
145
|
+
picked = d;
|
|
146
|
+
lit.forEach((c) => { c.setAttribute('stroke', 'none'); delete c.dataset.highlighted; });
|
|
147
|
+
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);
|
|
149
|
+
lit.forEach((c) => { c.setAttribute('stroke', '#2563eb'); c.dataset.highlighted = 'true'; });
|
|
150
|
+
hint.hidden = true;
|
|
151
|
+
pickedName.replaceChildren();
|
|
152
|
+
el('strong', 'Selected', pickedName); el('br', '', pickedName); ident(el('span', d.test, pickedName));
|
|
153
|
+
list.replaceChildren();
|
|
154
|
+
if (!sims.length) { el('p', 'No test covers similar lines.', list); return; }
|
|
155
|
+
el('p', sims.length + (sims.length === 1 ? ' similar test' : ' similar tests') + ', highest Jaccard similarity first; 1.00 means identical coverage', list);
|
|
156
|
+
// built off the page and attached once: one insertion instead of hundreds keeps a 148-neighbour selection fast
|
|
157
|
+
const table = document.createElement('div'); table.className = 'similar';
|
|
158
|
+
const head = el('div', '', table); head.className = 'head';
|
|
159
|
+
el('span', 'Test', head); el('span', 'Jaccard', head).className = 'num';
|
|
160
|
+
sims.forEach(([n, s]) => {
|
|
161
|
+
const row = el('div', '', table); row.setAttribute('data-testid', 'map-similar-item');
|
|
162
|
+
ident(el('span', n, row)); row.append(' '); el('span', s.toFixed(2), row).className = 'num';
|
|
163
|
+
});
|
|
164
|
+
list.appendChild(table);
|
|
165
|
+
};
|
|
166
|
+
if (picked) pick(picked);
|
|
167
|
+
}
|
|
168
|
+
const PAGE = 100;
|
|
169
|
+
// highest similarity first; ties by identities, so the order does not depend on how the pairs arrive
|
|
170
|
+
const byIdentity = (o) => o.tests.slice().sort().join('\n');
|
|
171
|
+
const ranked = data.overlaps.slice().sort((a, b) => b.jaccard - a.jaccard || (byIdentity(a) < byIdentity(b) ? -1 : byIdentity(a) > byIdentity(b) ? 1 : 0));
|
|
172
|
+
let ovQuery = '', ovPage = 0;
|
|
173
|
+
function drawOverlaps(parent) {
|
|
174
|
+
const box = el('div', '', parent);
|
|
175
|
+
const input = document.createElement('input');
|
|
176
|
+
input.type = 'search'; input.placeholder = 'Search test identities'; input.value = ovQuery; input.setAttribute('aria-label', 'Search overlapping tests');
|
|
177
|
+
input.setAttribute('data-testid', 'overlap-search');
|
|
178
|
+
box.appendChild(input);
|
|
179
|
+
const out = el('div', '', box);
|
|
180
|
+
const draw = () => {
|
|
181
|
+
out.replaceChildren();
|
|
182
|
+
const q = ovQuery.toLowerCase();
|
|
183
|
+
const hits = q ? ranked.filter((o) => o.tests.some((t) => t.toLowerCase().includes(q))) : ranked;
|
|
184
|
+
const pages = Math.max(1, Math.ceil(hits.length / PAGE));
|
|
185
|
+
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');
|
|
188
|
+
// a page is built off the page and attached once: one insertion instead of hundreds
|
|
189
|
+
const rows = document.createDocumentFragment();
|
|
190
|
+
hits.slice(ovPage * PAGE, (ovPage + 1) * PAGE).forEach((o) => {
|
|
191
|
+
const row = el('div', '', rows);
|
|
192
|
+
row.setAttribute('data-testid', 'overlap-pair'); row.className = 'pair';
|
|
193
|
+
el('strong', 'Jaccard ' + o.jaccard.toFixed(2), row);
|
|
194
|
+
// the two tests on their own lines, a dashed rule between them
|
|
195
|
+
o.tests.forEach((t, k) => { if (k) el('hr', '', row); testLine('div', t, row).setAttribute('data-testid', 'overlap-test'); });
|
|
196
|
+
});
|
|
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');
|
|
203
|
+
};
|
|
204
|
+
input.oninput = () => { ovQuery = input.value; ovPage = 0; draw(); };
|
|
205
|
+
draw();
|
|
63
206
|
}
|
|
64
207
|
function render() {
|
|
65
208
|
document.getElementById('inventory').textContent = data.inventory;
|
|
66
209
|
const banner = document.getElementById('banner');
|
|
67
210
|
if (banner) { if (data.banner) banner.textContent = data.banner; else banner.remove(); }
|
|
211
|
+
const failing = document.getElementById('failing'); failing.replaceChildren();
|
|
212
|
+
data.failing.forEach((n) => testLine('p', n, failing).setAttribute('data-testid', 'failing-test'));
|
|
68
213
|
const gauges = document.getElementById('gauges'), details = document.getElementById('details');
|
|
69
214
|
gauges.replaceChildren(); details.replaceChildren();
|
|
70
215
|
data.pillars.forEach((p, i) => {
|
|
71
216
|
const g = el('button', '', gauges);
|
|
72
217
|
g.className = 'gauge'; g.dataset.testid = 'gauge'; g.setAttribute('data-testid', 'gauge');
|
|
73
218
|
g.setAttribute('aria-pressed', i === selected);
|
|
74
|
-
el('span', p.name, g);
|
|
219
|
+
el('span', p.name, g).setAttribute('data-testid', 'gauge-title');
|
|
75
220
|
el('span', p.score === null ? '–' : shown(p.score), g).className = 'score';
|
|
76
|
-
|
|
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');
|
|
77
223
|
g.onclick = () => { selected = i; tab = 'Metrics'; picked = null; render(); };
|
|
78
224
|
});
|
|
79
225
|
const p = data.pillars[selected];
|
|
80
226
|
el('h2', p.name, details);
|
|
81
227
|
const names = ['Metrics', 'Worst tests', 'Smells', ...(p.key === 'economy' ? ['Overlaps', 'Map'] : [])];
|
|
82
|
-
|
|
228
|
+
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(); }; });
|
|
83
230
|
el('h3', tab, details);
|
|
84
231
|
if (tab === 'Metrics') {
|
|
232
|
+
if (!p.metrics.length) el('p', 'No metrics were measured for this pillar.', details);
|
|
85
233
|
const t = el('table', '', details);
|
|
234
|
+
const head = el('tr', '', t);
|
|
235
|
+
['Metric', 'Value', 'Score', 'Anchors'].forEach((h) => el('th', h, head));
|
|
86
236
|
p.metrics.forEach((m) => {
|
|
237
|
+
const u = m.unit || '', up = m.target < m.bad;
|
|
238
|
+
const r = el('tr', '', t);
|
|
239
|
+
el('td', m.name, r); el('td', nb(fmt(m.value), u), r); el('td', String(shown(m.score)), r);
|
|
240
|
+
el('td', nb('target', up ? '≤' : '≥', fmt(m.target), u) + ', ' + nb('bad', up ? '≥' : '≤', fmt(m.bad), u), r);
|
|
241
|
+
});
|
|
242
|
+
p.missing.forEach((m) => {
|
|
87
243
|
const r = el('tr', '', t);
|
|
88
|
-
|
|
244
|
+
// no value, so no score or anchors: the reason takes their place
|
|
245
|
+
el('td', m.name, r); el('td', 'unmeasured: ' + (m.reason || 'unavailable (cause not recorded)'), r).colSpan = 3;
|
|
89
246
|
});
|
|
247
|
+
el('p', 'Scores are rounded and shown as 1 to 99, not 100 or 0. A metric at its target scores 90 and at its bad anchor 10; the logistic curve between them never reaches 0 or 100.', details);
|
|
90
248
|
if (data.skipped.length) {
|
|
91
249
|
el('h3', 'Skipped tests', details);
|
|
92
|
-
data.skipped.forEach((n) =>
|
|
250
|
+
data.skipped.forEach((n) => testLine('p', n, details, '(skipped)'));
|
|
93
251
|
}
|
|
94
252
|
if (p.key === 'economy' && data.insufficient.length) {
|
|
95
253
|
el('h3', 'Insufficient evidence (fewer than 2 sampled mutants on their lines)', details);
|
|
96
|
-
data.insufficient.forEach((n) =>
|
|
254
|
+
data.insufficient.forEach((n) => testLine('p', n, details));
|
|
97
255
|
}
|
|
98
256
|
} else if (tab === 'Worst tests') {
|
|
99
|
-
p.worst.forEach((w) =>
|
|
257
|
+
p.worst.forEach((w) => testLine('p', w.test, details, '(' + w.reason + ')').setAttribute('data-testid', 'worst-test'));
|
|
100
258
|
} else if (tab === 'Smells') {
|
|
101
259
|
const smells = Object.entries(p.smells);
|
|
102
260
|
if (!smells.length) el('p', 'No test has a smell of this pillar.', details);
|
|
103
261
|
smells.forEach(([smell, tests]) => {
|
|
104
262
|
el('h4', smell + ' (' + tests.length + (tests.length === 1 ? ' test)' : ' tests)'), details).setAttribute('data-testid', 'smell');
|
|
105
|
-
tests.forEach((n) =>
|
|
263
|
+
tests.forEach((n) => testLine('p', n, details).setAttribute('data-testid', 'smell-test'));
|
|
106
264
|
});
|
|
107
265
|
} else if (tab === 'Overlaps') {
|
|
108
|
-
|
|
266
|
+
drawOverlaps(details);
|
|
109
267
|
} else if (tab === 'Map') drawMap(details);
|
|
110
268
|
}
|
|
111
269
|
render();
|
|
@@ -9,12 +9,14 @@ name = "Protection against regressions"
|
|
|
9
9
|
|
|
10
10
|
[pillars.regression.metrics.mutation_score]
|
|
11
11
|
name = "Mutation score"
|
|
12
|
+
unit = "%"
|
|
12
13
|
weight = 0.45
|
|
13
14
|
target = 80
|
|
14
15
|
bad = 40
|
|
15
16
|
|
|
16
17
|
[pillars.regression.metrics.branch_coverage]
|
|
17
18
|
name = "Branch coverage"
|
|
19
|
+
unit = "%"
|
|
18
20
|
weight = 0.25
|
|
19
21
|
target = 90
|
|
20
22
|
bad = 50
|
|
@@ -22,6 +24,7 @@ partial_weight = 0.6
|
|
|
22
24
|
|
|
23
25
|
[pillars.regression.metrics.hollow_tests]
|
|
24
26
|
name = "Hollow tests"
|
|
27
|
+
unit = "%"
|
|
25
28
|
weight = 0.2
|
|
26
29
|
target = 0
|
|
27
30
|
bad = 10
|
|
@@ -29,6 +32,7 @@ partial_weight = 0.4
|
|
|
29
32
|
|
|
30
33
|
[pillars.regression.metrics.pseudo_tested_functions]
|
|
31
34
|
name = "Pseudo-tested functions"
|
|
35
|
+
unit = "%"
|
|
32
36
|
weight = 0.1
|
|
33
37
|
target = 0
|
|
34
38
|
bad = 15
|
|
@@ -38,24 +42,28 @@ name = "Resistance to refactoring"
|
|
|
38
42
|
|
|
39
43
|
[pillars.refactoring.metrics.brittle_test_files]
|
|
40
44
|
name = "Brittle test files"
|
|
45
|
+
unit = "%"
|
|
41
46
|
weight = 0.4
|
|
42
47
|
target = 15
|
|
43
48
|
bad = 60
|
|
44
49
|
|
|
45
50
|
[pillars.refactoring.metrics.private_access]
|
|
46
51
|
name = "Tests with private access"
|
|
52
|
+
unit = "%"
|
|
47
53
|
weight = 0.25
|
|
48
54
|
target = 2
|
|
49
55
|
bad = 30
|
|
50
56
|
|
|
51
57
|
[pillars.refactoring.metrics.mock_heavy]
|
|
52
58
|
name = "Mock-heavy tests"
|
|
59
|
+
unit = "%"
|
|
53
60
|
weight = 0.2
|
|
54
61
|
target = 5
|
|
55
62
|
bad = 30
|
|
56
63
|
|
|
57
64
|
[pillars.refactoring.metrics.interaction_only]
|
|
58
65
|
name = "Interaction-only tests"
|
|
66
|
+
unit = "%"
|
|
59
67
|
weight = 0.15
|
|
60
68
|
target = 5
|
|
61
69
|
bad = 30
|
|
@@ -65,6 +73,7 @@ name = "Fast feedback"
|
|
|
65
73
|
|
|
66
74
|
[pillars.feedback.metrics.total_runtime]
|
|
67
75
|
name = "Total runtime"
|
|
76
|
+
unit = "s"
|
|
68
77
|
weight = 0.4
|
|
69
78
|
target = 60
|
|
70
79
|
bad = 600
|
|
@@ -72,6 +81,7 @@ log = true
|
|
|
72
81
|
|
|
73
82
|
[pillars.feedback.metrics.p95_duration]
|
|
74
83
|
name = "p95 test duration"
|
|
84
|
+
unit = "s"
|
|
75
85
|
weight = 0.3
|
|
76
86
|
target = 0.1
|
|
77
87
|
bad = 2
|
|
@@ -79,12 +89,14 @@ log = true
|
|
|
79
89
|
|
|
80
90
|
[pillars.feedback.metrics.slowest_decile_share]
|
|
81
91
|
name = "Runtime share of slowest 10% of tests"
|
|
92
|
+
unit = "%"
|
|
82
93
|
weight = 0.15
|
|
83
94
|
target = 40
|
|
84
95
|
bad = 90
|
|
85
96
|
|
|
86
97
|
[pillars.feedback.metrics.tests_over_10s]
|
|
87
98
|
name = "Tests over 10 s"
|
|
99
|
+
unit = "%"
|
|
88
100
|
weight = 0.15
|
|
89
101
|
target = 0
|
|
90
102
|
bad = 2
|
|
@@ -94,18 +106,21 @@ name = "Maintainability"
|
|
|
94
106
|
|
|
95
107
|
[pillars.maintainability.metrics.smelly_tests]
|
|
96
108
|
name = "Tests with a maintainability smell"
|
|
109
|
+
unit = "%"
|
|
97
110
|
weight = 0.5
|
|
98
111
|
target = 5
|
|
99
112
|
bad = 40
|
|
100
113
|
|
|
101
114
|
[pillars.maintainability.metrics.long_tests]
|
|
102
115
|
name = "Tests longer than 50 lines"
|
|
116
|
+
unit = "%"
|
|
103
117
|
weight = 0.2
|
|
104
118
|
target = 2
|
|
105
119
|
bad = 20
|
|
106
120
|
|
|
107
121
|
[pillars.maintainability.metrics.test_source_ratio]
|
|
108
122
|
name = "Test : source lines-of-code ratio"
|
|
123
|
+
unit = ""
|
|
109
124
|
weight = 0.3
|
|
110
125
|
target = 1.5
|
|
111
126
|
bad = 4.0
|
|
@@ -115,6 +130,7 @@ name = "Economy"
|
|
|
115
130
|
|
|
116
131
|
[pillars.economy.metrics.no_unique_coverage]
|
|
117
132
|
name = "Tests with no unique coverage"
|
|
133
|
+
unit = "%"
|
|
118
134
|
weight = 0.35
|
|
119
135
|
target = 10
|
|
120
136
|
bad = 50
|
|
@@ -122,12 +138,14 @@ partial_weight = 0.6
|
|
|
122
138
|
|
|
123
139
|
[pillars.economy.metrics.subsumed_in_kill_matrix]
|
|
124
140
|
name = "Tests subsumed in the kill matrix"
|
|
141
|
+
unit = "%"
|
|
125
142
|
weight = 0.4
|
|
126
143
|
target = 5
|
|
127
144
|
bad = 35
|
|
128
145
|
|
|
129
146
|
[pillars.economy.metrics.duplicate_clusters]
|
|
130
147
|
name = "Tests in a duplicate-body cluster"
|
|
148
|
+
unit = "%"
|
|
131
149
|
weight = 0.25
|
|
132
150
|
target = 2
|
|
133
151
|
bad = 20
|
|
@@ -0,0 +1,161 @@
|
|
|
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.
|
|
4
|
+
|
|
5
|
+
Page interface the acceptance tests pin, on top of the earlier tickets' markup (metric/overlap/map tabs):
|
|
6
|
+
[data-testid=gauge-title] inside every [data-testid=gauge]: the pillar title
|
|
7
|
+
[data-testid=gauge-status] inside every gauge, also a fully measured one: the measurement status text
|
|
8
|
+
[data-testid=gauge] .score the displayed score (existing)
|
|
9
|
+
the tabs are the <button>s inside [data-testid=details]; the selected one must look different from the others.
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from urllib.parse import quote
|
|
15
|
+
|
|
16
|
+
from playwright.sync_api import sync_playwright
|
|
17
|
+
|
|
18
|
+
URL = "file://" + quote(str(Path(sys.argv[1]).resolve()))
|
|
19
|
+
UNIQUE = "test_only_left_xylophone"
|
|
20
|
+
GAUGE = "[data-testid=gauge]"
|
|
21
|
+
TABS = "[data-testid=details] button"
|
|
22
|
+
|
|
23
|
+
GAUGES = """() => [...document.querySelectorAll('[data-testid=gauge]')].map((g) => {
|
|
24
|
+
const box = (e) => { if (!e) return null; const r = e.getBoundingClientRect(), s = getComputedStyle(e);
|
|
25
|
+
return {top: Math.round(r.top), left: Math.round(r.left), width: Math.round(r.width), height: Math.round(r.height),
|
|
26
|
+
lines: Math.round(r.height / (parseFloat(s.lineHeight) || 1.2 * parseFloat(s.fontSize))), font: parseFloat(s.fontSize),
|
|
27
|
+
clipped: e.scrollWidth > e.clientWidth + 1 || e.scrollHeight > e.clientHeight + 1, text: e.textContent.trim()}; };
|
|
28
|
+
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]'))};
|
|
30
|
+
})"""
|
|
31
|
+
|
|
32
|
+
SIG = """(el) => { const s = getComputedStyle(el);
|
|
33
|
+
return [s.backgroundColor, s.color, s.fontWeight, s.borderTopColor, s.borderBottomColor, s.borderBottomWidth, s.textDecorationLine,
|
|
34
|
+
s.boxShadow].join('|'); }"""
|
|
35
|
+
FOCUS = """() => { const el = document.activeElement, s = getComputedStyle(el);
|
|
36
|
+
return {text: el.textContent.trim(), outline: s.outlineStyle + ' ' + s.outlineWidth + ' ' + s.outlineColor, shadow: s.boxShadow}; }"""
|
|
37
|
+
TAB_STATE = """() => { const tabs = [...document.querySelectorAll('[data-testid=details] button')];
|
|
38
|
+
return tabs.filter((b) => ['Metrics', 'Worst tests', 'Smells', 'Overlaps', 'Map'].includes(b.textContent.trim())).map((b) => ({text: b.textContent.trim(), sig: window.sigOf(b)})); }"""
|
|
39
|
+
OVERFLOW = """() => ({viewport: document.documentElement.clientWidth, scroll_width: document.documentElement.scrollWidth,
|
|
40
|
+
details_right: Math.round(Math.max(...[...document.querySelectorAll('[data-testid=details] > *')].map((e) => e.getBoundingClientRect().right))),
|
|
41
|
+
details_width: Math.round(document.querySelector('[data-testid=details]').getBoundingClientRect().width)})"""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def click_gauge(page, label):
|
|
45
|
+
page.locator(GAUGE).filter(has_text=label).first.click()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def click_tab(page, label):
|
|
49
|
+
page.locator(TABS).filter(has_text=label).first.click()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def tabs(page):
|
|
53
|
+
return page.evaluate(TAB_STATE)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def table_share(page):
|
|
57
|
+
return page.evaluate("""() => { const t = document.querySelector('[data-testid=details] table'), d = document.querySelector('[data-testid=details]');
|
|
58
|
+
return t ? t.getBoundingClientRect().width / d.getBoundingClientRect().width : null; }""")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def layout(browser, width, height):
|
|
62
|
+
page = browser.new_page(viewport={"width": width, "height": height})
|
|
63
|
+
page.goto(URL)
|
|
64
|
+
page.wait_for_selector(GAUGE)
|
|
65
|
+
out = {"gauges": page.evaluate(GAUGES), "overview": page.evaluate(OVERFLOW)}
|
|
66
|
+
click_gauge(page, "Fast feedback")
|
|
67
|
+
out["feedback_table_share"] = table_share(page)
|
|
68
|
+
out["feedback_details"] = page.evaluate(OVERFLOW)
|
|
69
|
+
click_gauge(page, "Resistance to refactoring")
|
|
70
|
+
out["refactoring_details"] = page.evaluate(OVERFLOW)
|
|
71
|
+
click_gauge(page, "Economy")
|
|
72
|
+
click_tab(page, "Overlaps")
|
|
73
|
+
out["overlaps"] = page.evaluate(OVERFLOW)
|
|
74
|
+
out["overlap_ids"] = page.evaluate("""() => [...document.querySelectorAll('[data-testid=overlap-test]')].map((e) => {
|
|
75
|
+
const r = e.getBoundingClientRect(), s = getComputedStyle(e);
|
|
76
|
+
return {text: e.textContent, right: Math.round(r.right), clipped: e.scrollWidth > e.clientWidth + 1 && s.overflowX !== 'visible',
|
|
77
|
+
ellipsis: s.textOverflow === 'ellipsis', title: e.getAttribute('title')}; })""")
|
|
78
|
+
click_tab(page, "Map")
|
|
79
|
+
out["map"] = page.evaluate(OVERFLOW)
|
|
80
|
+
page.close()
|
|
81
|
+
return out
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def tab_styles(browser):
|
|
85
|
+
page = browser.new_page(viewport={"width": 1440, "height": 900})
|
|
86
|
+
page.goto(URL)
|
|
87
|
+
page.wait_for_selector(GAUGE)
|
|
88
|
+
page.evaluate("() => { window.sigOf = " + SIG + "; }")
|
|
89
|
+
click_gauge(page, "Economy")
|
|
90
|
+
steps = {}
|
|
91
|
+
for label in ("Metrics", "Overlaps", "Map"):
|
|
92
|
+
click_tab(page, label)
|
|
93
|
+
steps[label] = tabs(page)
|
|
94
|
+
# keyboard focus: from the active Map tab, Shift+Tab lands on a neighbouring tab
|
|
95
|
+
before = {t["text"]: t["sig"] for t in tabs(page)}
|
|
96
|
+
page.keyboard.press("Shift+Tab")
|
|
97
|
+
focus = page.evaluate(FOCUS)
|
|
98
|
+
focus["sig_unfocused"] = before.get(focus["text"])
|
|
99
|
+
focus["sig_focused"] = page.evaluate("() => window.sigOf(document.activeElement)")
|
|
100
|
+
page.close()
|
|
101
|
+
return {"steps": steps, "focus": focus}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def journey(browser):
|
|
105
|
+
context = browser.new_context(viewport={"width": 1440, "height": 900}, offline=True)
|
|
106
|
+
requests = []
|
|
107
|
+
context.on("request", lambda r: requests.append(r.url))
|
|
108
|
+
failures = []
|
|
109
|
+
context.on("requestfailed", lambda r: failures.append(r.url))
|
|
110
|
+
page = context.new_page()
|
|
111
|
+
errors = []
|
|
112
|
+
page.on("pageerror", lambda e: errors.append(str(e)))
|
|
113
|
+
page.goto(URL)
|
|
114
|
+
page.wait_for_selector(GAUGE)
|
|
115
|
+
page.evaluate("() => { window.sigOf = " + SIG + "; }")
|
|
116
|
+
log = {}
|
|
117
|
+
count = lambda: (page.locator("[data-testid=overlap-count]").first.text_content() or "")
|
|
118
|
+
click_gauge(page, "Fast feedback")
|
|
119
|
+
log["feedback_text"] = page.inner_text("[data-testid=details]")
|
|
120
|
+
click_gauge(page, "Resistance to refactoring")
|
|
121
|
+
log["refactoring_text"] = page.inner_text("[data-testid=details]")
|
|
122
|
+
click_gauge(page, "Economy")
|
|
123
|
+
click_tab(page, "Overlaps")
|
|
124
|
+
log["active_overlaps"] = tabs(page)
|
|
125
|
+
log["count_all"] = count()
|
|
126
|
+
log["first_row_page_1"] = page.locator("[data-testid=overlap-pair]").first.text_content()
|
|
127
|
+
page.locator("[data-testid=overlap-next]").click()
|
|
128
|
+
log["first_row_page_2"] = page.locator("[data-testid=overlap-pair]").first.text_content()
|
|
129
|
+
page.locator("[data-testid=overlap-search]").fill(UNIQUE)
|
|
130
|
+
page.wait_for_timeout(300)
|
|
131
|
+
log["count_search"] = count()
|
|
132
|
+
log["rows_search"] = page.locator("[data-testid=overlap-pair]").count()
|
|
133
|
+
page.locator("[data-testid=overlap-search]").fill("")
|
|
134
|
+
page.wait_for_timeout(300)
|
|
135
|
+
log["count_cleared"] = count()
|
|
136
|
+
click_tab(page, "Map")
|
|
137
|
+
log["active_map"] = tabs(page)
|
|
138
|
+
dot = page.locator("[data-testid=map-dot]").nth(10)
|
|
139
|
+
log["dots"] = page.locator("[data-testid=map-dot]").count()
|
|
140
|
+
dot.dispatch_event("click")
|
|
141
|
+
page.wait_for_timeout(300)
|
|
142
|
+
log["picked"] = (page.locator("[data-testid=map-picked]").first.text_content() or "")
|
|
143
|
+
log["similar_items"] = page.locator("[data-testid=map-similar-item]").count()
|
|
144
|
+
click_tab(page, "Metrics")
|
|
145
|
+
log["active_metrics"] = tabs(page)
|
|
146
|
+
log["metrics_text"] = page.inner_text("[data-testid=details]")
|
|
147
|
+
log["requests"] = [u for u in requests if not u.startswith("file:")]
|
|
148
|
+
log["failed_requests"] = failures
|
|
149
|
+
log["page_errors"] = errors
|
|
150
|
+
context.close()
|
|
151
|
+
return log
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
with sync_playwright() as p:
|
|
155
|
+
try:
|
|
156
|
+
browser = p.chromium.launch(channel="chrome")
|
|
157
|
+
except Exception:
|
|
158
|
+
browser = p.chromium.launch()
|
|
159
|
+
result = {"desktop": layout(browser, 1440, 900), "narrow": layout(browser, 390, 844), "tabs": tab_styles(browser), "journey": journey(browser)}
|
|
160
|
+
browser.close()
|
|
161
|
+
print(json.dumps(result))
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
# The engine's modules sit one folder up. Set the path here, before any test module is collected, so a test file
|
|
5
|
+
# needs no sys.path line of its own and collection order cannot hide a missing one.
|
|
6
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
7
|
+
|
|
1
8
|
collect_ignore_glob = ["testdata/*"]
|
|
2
9
|
|
|
3
|
-
import pytest
|
|
10
|
+
import pytest # noqa: E402
|
|
4
11
|
|
|
5
12
|
from fixture_repo import build_repo, weigh
|
|
6
13
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Ticket 03 latency evidence (R3, design.md "Latency evidence"): `uv run --with playwright python latency_probe.py <out-dir>`.
|
|
2
|
+
|
|
3
|
+
Writes a 2,172-dot map (test_hub has 148 neighbours) through weigh_dashboard.write_dashboard, opens it from disk in Chrome
|
|
4
|
+
with no CPU throttling, and prints one JSON document: machine, OS, browser version, fixture, the cold map opening (Map tab
|
|
5
|
+
click to the first frame painted with every dot) and 20 alternating selections (dot click to the first frame painted with
|
|
6
|
+
the new name, highlights and neighbours). It asserts nothing: the 200 ms claim needs the benchmark machine the operator agrees.
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import platform
|
|
10
|
+
import random
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from urllib.parse import quote
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
17
|
+
|
|
18
|
+
import map_fixture
|
|
19
|
+
from playwright.sync_api import sync_playwright
|
|
20
|
+
|
|
21
|
+
N, NEAR = 2172, 148
|
|
22
|
+
HUB, OTHER = "tests/hub/test_hub.py::test_hub", "tests/scale/test_module_0005.py::test_case_0005"
|
|
23
|
+
FIXTURE = f"{N} dots, {HUB} with {NEAR} neighbours, alternating with {OTHER}"
|
|
24
|
+
|
|
25
|
+
FRAME = "() => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)))"
|
|
26
|
+
COLD = """async () => {
|
|
27
|
+
const t0 = performance.now();
|
|
28
|
+
[...document.querySelectorAll('[data-testid=details] button')].find((b) => b.textContent.trim() === 'Map').click();
|
|
29
|
+
await new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)));
|
|
30
|
+
return {ms: performance.now() - t0, dots: document.querySelectorAll('[data-testid=map-dot]').length};
|
|
31
|
+
}"""
|
|
32
|
+
SELECT = """async ([hub, other]) => {
|
|
33
|
+
const out = [];
|
|
34
|
+
for (let i = 0; i < 20; i++) {
|
|
35
|
+
const target = i % 2 === 0 ? hub : other;
|
|
36
|
+
const dot = document.querySelector(`[data-testid=map-dot][data-test="${target}"]`);
|
|
37
|
+
const t0 = performance.now();
|
|
38
|
+
dot.dispatchEvent(new MouseEvent('click', {bubbles: true}));
|
|
39
|
+
await new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)));
|
|
40
|
+
const ms = performance.now() - t0;
|
|
41
|
+
const shown = document.querySelector('[data-testid=map-picked]').textContent.endsWith(target);
|
|
42
|
+
out.push({target, ms, shown, neighbours: document.querySelectorAll('[data-testid=map-similar-item]').length});
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}"""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def page(out):
|
|
49
|
+
map_fixture.build(out) # a write_dashboard page whose map is replaced by the scaled one
|
|
50
|
+
html = out / "dashboard.html"
|
|
51
|
+
text = html.read_text()
|
|
52
|
+
head, rest = text.split("const data = ", 1)
|
|
53
|
+
end = rest.index(";\n")
|
|
54
|
+
data = json.loads(rest[:end])
|
|
55
|
+
names = [HUB] + [f"tests/scale/test_module_{i:04d}.py::test_case_{i:04d}" for i in range(1, N)]
|
|
56
|
+
similar = {n: [] for n in names}
|
|
57
|
+
for k in range(1, NEAR + 1):
|
|
58
|
+
s = 0.7 + (k * 7 % 19) / 100
|
|
59
|
+
similar[HUB].append([names[k], s])
|
|
60
|
+
similar[names[k]].append([HUB, s])
|
|
61
|
+
rnd = random.Random(7)
|
|
62
|
+
data["map"] = [{"test": n, "x": rnd.random(), "y": rnd.random(), "runtime": 0.01, "unique": 0, "similar": similar[n]} for n in names]
|
|
63
|
+
html.write_text(head + "const data = " + json.dumps(data).replace("</", "<\\/") + rest[end:])
|
|
64
|
+
return html
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def machine():
|
|
68
|
+
if sys.platform == "darwin":
|
|
69
|
+
return subprocess.run(["sysctl", "-n", "machdep.cpu.brand_string"], capture_output=True, text=True).stdout.strip()
|
|
70
|
+
return platform.processor() or platform.machine()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def main(out):
|
|
74
|
+
html = page(out)
|
|
75
|
+
with sync_playwright() as p:
|
|
76
|
+
try:
|
|
77
|
+
browser = p.chromium.launch(channel="chrome")
|
|
78
|
+
except Exception:
|
|
79
|
+
browser = p.chromium.launch()
|
|
80
|
+
tab = browser.new_page(viewport={"width": 1440, "height": 900})
|
|
81
|
+
tab.goto("file://" + quote(str(html.resolve())))
|
|
82
|
+
tab.locator("[data-testid=gauge]").filter(has_text="Economy").first.click()
|
|
83
|
+
tab.evaluate(FRAME)
|
|
84
|
+
cold = tab.evaluate(COLD)
|
|
85
|
+
selections = tab.evaluate(SELECT, [HUB, OTHER])
|
|
86
|
+
result = {"machine": machine(), "os": platform.platform(), "browser": f"{browser.browser_type.name} {browser.version}",
|
|
87
|
+
"fixture": FIXTURE, "cold_map_opening_ms": round(cold["ms"]), "dots": cold["dots"],
|
|
88
|
+
"selections_ms": [round(s["ms"], 1) for s in selections], "max_selection_ms": round(max(s["ms"] for s in selections), 1),
|
|
89
|
+
"all_shown": all(s["shown"] for s in selections),
|
|
90
|
+
"neighbours": sorted({s["neighbours"] for s in selections})}
|
|
91
|
+
browser.close()
|
|
92
|
+
print(json.dumps(result, indent=1))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main(Path(sys.argv[1]))
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Ticket 04 fixture, no repo run: `layout_page.py <out-dir>` writes <out-dir>/dashboard.html through
|
|
2
|
+
weigh_dashboard.write_dashboard and prints its path. The real-suite shape of the spec: 2,172 tests (all drawn on the
|
|
3
|
+
Map), 3,196 cases, 6,757 overlap pairs with 200-character ids.
|
|
4
|
+
Fast feedback is fully measured, Resistance to refactoring has 0 of its 4 metrics measured (reasons recorded).
|
|
5
|
+
"""
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
10
|
+
|
|
11
|
+
import overlap_page
|
|
12
|
+
from weigh_dashboard import write_dashboard
|
|
13
|
+
from weigh_rules import load
|
|
14
|
+
from weigh_score import feedback_values, score
|
|
15
|
+
|
|
16
|
+
FIXTURE = "2172 tests, 3196 cases, 6757 pairs"
|
|
17
|
+
NOT_MEASURED = ("brittle_test_files", "private_access", "mock_heavy", "interaction_only")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def build(out):
|
|
21
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
rules = load()
|
|
23
|
+
tests = {}
|
|
24
|
+
for i in range(overlap_page.N_TESTS):
|
|
25
|
+
lo = (i % 300) * 10 + 1
|
|
26
|
+
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
|
+
"unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}
|
|
28
|
+
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)
|
|
30
|
+
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
|
+
"metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": overlap_page.pairs(),
|
|
32
|
+
"unmeasured": {m: "no git history" for m in NOT_MEASURED}}
|
|
33
|
+
return write_dashboard(out, data, rules)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
print(build(Path(sys.argv[1])))
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Ticket 01 fixtures, no repo run: `metric_page.py <out-dir> <scenario>` writes <out-dir>/dashboard.html through
|
|
2
|
+
weigh_dashboard.write_dashboard and prints its path.
|
|
3
|
+
|
|
4
|
+
Interface the acceptance tests pin (the spec leaves the snapshot key open): snapshot["unmeasured"] = {metric id: reason}
|
|
5
|
+
records why a metric was not measured; a snapshot without it (older data) or without the metric's entry has no recorded cause.
|
|
6
|
+
Scenarios:
|
|
7
|
+
values total_runtime 64.16 and branch_coverage 94.84, rules with non-default total_runtime anchors (30 / 300)
|
|
8
|
+
zero refactoring has 0 of 4 metrics measured (all four have reasons); feedback has tests_over_10s measured at 0 and
|
|
9
|
+
p95_duration missing with no recorded cause
|
|
10
|
+
scores metric scores 0.2, 100 and (zero tests over 10 s) 90
|
|
11
|
+
default the default-run shape: regression lacks mutation_score and pseudo_tested_functions, with the recorded reason
|
|
12
|
+
"""
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
18
|
+
|
|
19
|
+
import rules_fixture
|
|
20
|
+
from weigh_dashboard import write_dashboard
|
|
21
|
+
from weigh_rules import load
|
|
22
|
+
from weigh_score import score
|
|
23
|
+
|
|
24
|
+
TIER = "the mutation tier did not run"
|
|
25
|
+
VALUES = {
|
|
26
|
+
"values": {"total_runtime": 64.16, "branch_coverage": 94.84},
|
|
27
|
+
"zero": {"tests_over_10s": 0, "total_runtime": 5.0, "slowest_decile_share": 50.0},
|
|
28
|
+
"scores": {"smelly_tests": 20.0, "long_tests": 1.0, "tests_over_10s": 0},
|
|
29
|
+
"default": {"branch_coverage": 80.0, "hollow_tests": 1.0},
|
|
30
|
+
}
|
|
31
|
+
UNMEASURED = {
|
|
32
|
+
"zero": {"brittle_test_files": "no git history", "private_access": "no ruff", "mock_heavy": "no ruff", "interaction_only": "no ruff"},
|
|
33
|
+
"default": {"mutation_score": TIER, "pseudo_tested_functions": TIER},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def build(out, scenario):
|
|
38
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
rules_path = rules_fixture.write_rules(out / "rules.toml", **({"total_runtime": dict(target=30, bad=300)} if scenario == "values" else {}))
|
|
40
|
+
import os
|
|
41
|
+
os.environ["TEST_WEIGH_IN_RULES"] = str(rules_path)
|
|
42
|
+
rules = load()
|
|
43
|
+
metrics, pillars = score(rules, VALUES[scenario])
|
|
44
|
+
if scenario == "scores":
|
|
45
|
+
metrics["smelly_tests"]["score"], metrics["long_tests"]["score"] = 0.2, 100.0
|
|
46
|
+
pillars["maintainability"]["score"] = 100.0
|
|
47
|
+
tests = {"tests/test_a.py::test_a": {"outcome": "passed", "duration": 0.1, "coverage": {}, "unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}}
|
|
48
|
+
data = {"commit": "abc1234", "dirty": False, "inventory": {"tests": 1, "cases": 1, "test_files": 1, "test_lines": 2, "source_lines": 2, "runtime_seconds": 0.1},
|
|
49
|
+
"metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": []}
|
|
50
|
+
if scenario in UNMEASURED:
|
|
51
|
+
data["unmeasured"] = UNMEASURED[scenario]
|
|
52
|
+
return write_dashboard(out, data, rules)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
print(build(Path(sys.argv[1]), sys.argv[2]))
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Ticket 02 fixture, no repo run: `overlap_page.py <out-dir> [reversed]` writes <out-dir>/dashboard.html through
|
|
2
|
+
weigh_dashboard.write_dashboard and <out-dir>/pairs.json (the pairs as fed, same order unless "reversed").
|
|
3
|
+
|
|
4
|
+
6,757 overlap pairs over 2,172 tests with 200-character ids, Jaccard values on a 0.90..1.00 grid (many ties).
|
|
5
|
+
One pair holds ids that occur nowhere else (UNIQUE_LEFT / UNIQUE_RIGHT), one pair holds markup in its ids (HOSTILE).
|
|
6
|
+
Interface the acceptance tests pin (the spec leaves the markup open), inside the Overlaps tab of the Economy pillar:
|
|
7
|
+
[data-testid=overlap-search] the search input (an `input` event applies the query)
|
|
8
|
+
[data-testid=overlap-count] the result count: contains the number of matching pairs
|
|
9
|
+
[data-testid=overlap-pair] one row per pair on the current page, at most 100 rows; holds two
|
|
10
|
+
[data-testid=overlap-test] identities and a label naming "Jaccard" with the value
|
|
11
|
+
[data-testid=overlap-empty] shown only when no pair matches, with an explanation
|
|
12
|
+
[data-testid=overlap-next] pages forward; disabled on the last page
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
19
|
+
|
|
20
|
+
from weigh_dashboard import write_dashboard
|
|
21
|
+
from weigh_rules import load
|
|
22
|
+
from weigh_score import feedback_values, score
|
|
23
|
+
|
|
24
|
+
N_TESTS, N_PAIRS = 2172, 6757
|
|
25
|
+
UNIQUE_LEFT = "tests/unique/test_alpha_only.py::test_only_left_xylophone"
|
|
26
|
+
UNIQUE_RIGHT = "tests/unique/test_omega_only.py::test_only_right_zeppelin"
|
|
27
|
+
HOSTILE = ['tests/<b id="pwn">x<img src=x onerror="pwned=1">/test_</script><script>window.pwned=1</script>.py::test_hostile',
|
|
28
|
+
"tests/test_ok_partner.py::test_partner"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def name(i):
|
|
32
|
+
return f"tests/{'sub_package_' * 12}{i // 50:03d}/test_module_{i:04d}.py::TestClass{i % 7}::test_case_{i:04d}_{'x' * 40}"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def pairs():
|
|
36
|
+
out = []
|
|
37
|
+
for k in range(N_PAIRS):
|
|
38
|
+
a = k % N_TESTS
|
|
39
|
+
b = (a + 1 + k // N_TESTS) % N_TESTS
|
|
40
|
+
out.append({"tests": [name(a), name(b)], "jaccard": round(0.90 + (k * 7919 % 11) / 100, 2)})
|
|
41
|
+
out[1234] = {"tests": [UNIQUE_LEFT, UNIQUE_RIGHT], "jaccard": 0.93}
|
|
42
|
+
out[4321] = {"tests": HOSTILE, "jaccard": 0.91}
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def build(out, order="forward"):
|
|
47
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
48
|
+
rules = load()
|
|
49
|
+
tests = {name(i): {"outcome": "passed", "duration": 0.01, "coverage": {}, "unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}
|
|
50
|
+
for i in range(N_TESTS)}
|
|
51
|
+
metrics, pillars = score(rules, {**feedback_values(tests, 1.0), "no_unique_coverage": 100.0})
|
|
52
|
+
fed = pairs()[::-1] if order == "reversed" else pairs()
|
|
53
|
+
data = {"commit": "abc1234", "dirty": False, "inventory": {"tests": N_TESTS, "cases": 3196, "test_files": 44, "test_lines": 9000, "source_lines": 9000, "runtime_seconds": 64.2},
|
|
54
|
+
"metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": fed}
|
|
55
|
+
(out / "pairs.json").write_text(json.dumps(fed))
|
|
56
|
+
return write_dashboard(out, data, rules)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
print(build(Path(sys.argv[1]), *sys.argv[2:3]))
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Interface the tests pin (the spec leaves the TOML keys and the snapshot JSON keys open):
|
|
4
4
|
rules.toml: version = 1; [pillars.<key>] name = "..."; [pillars.<key>.metrics.<id>] name, weight,
|
|
5
|
+
unit ("%", "s" or ""),
|
|
5
6
|
optional partial_weight, target, bad, optional log = true. Percentages are 0-100,
|
|
6
7
|
durations are seconds. Pillar keys: regression, refactoring, feedback,
|
|
7
8
|
maintainability, economy.
|
|
@@ -50,7 +51,8 @@ def write_rules(path, **overrides):
|
|
|
50
51
|
lines += [f"[pillars.{key}]", f'name = "{name}"', ""]
|
|
51
52
|
for mid, mname, weight, partial, target, bad, log in metrics:
|
|
52
53
|
m = {**dict(weight=weight, target=target, bad=bad), **overrides.get(mid, {})}
|
|
53
|
-
|
|
54
|
+
unit = "s" if mid in ("total_runtime", "p95_duration") else "" if mid == "test_source_ratio" else "%"
|
|
55
|
+
lines += [f"[pillars.{key}.metrics.{mid}]", f'name = "{mname}"', f'unit = "{unit}"']
|
|
54
56
|
lines += [f"{k} = {v!r}" for k, v in m.items()]
|
|
55
57
|
if partial is not None:
|
|
56
58
|
lines.append(f"partial_weight = {partial!r}")
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Ticket 03 fixture, no repo run: `sorted_map_page.py <out-dir>` writes <out-dir>/dashboard.html through weigh_dashboard.write_dashboard.
|
|
2
|
+
|
|
3
|
+
PICKED covers lines 1-100. Its neighbours are fed in the order SIM_091 (0.91), SIM_100 (1.00), SIM_095 (0.95).
|
|
4
|
+
BELOW covers lines 1-50 (0.50 with PICKED, not eligible); LONELY covers lines 200-210 (similar to nothing).
|
|
5
|
+
"""
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
10
|
+
|
|
11
|
+
from weigh_dashboard import write_dashboard
|
|
12
|
+
from weigh_rules import load
|
|
13
|
+
from weigh_score import feedback_values, score
|
|
14
|
+
|
|
15
|
+
PICKED = "tests/test_pick.py::test_picked"
|
|
16
|
+
SIM_091, SIM_100, SIM_095 = (f"tests/test_pick.py::test_sim_{n}" for n in ("091", "100", "095"))
|
|
17
|
+
BELOW = "tests/test_pick.py::test_below"
|
|
18
|
+
LONELY = "tests/test_pick.py::test_lonely"
|
|
19
|
+
COVERAGE = {PICKED: range(1, 101), SIM_091: range(1, 92), SIM_100: range(1, 101), SIM_095: range(1, 96),
|
|
20
|
+
BELOW: range(1, 51), LONELY: range(200, 211)}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build(out):
|
|
24
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
25
|
+
rules = load()
|
|
26
|
+
tests = {n: {"outcome": "passed", "duration": 0.05, "coverage": {"demo/a.py": list(lines)}, "unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}
|
|
27
|
+
for n, lines in COVERAGE.items()}
|
|
28
|
+
metrics, pillars = score(rules, {**feedback_values(tests, 1.0), "no_unique_coverage": 100.0})
|
|
29
|
+
data = {"commit": "abc1234", "dirty": False, "inventory": {"tests": 6, "cases": 6, "test_files": 1, "test_lines": 12, "source_lines": 210, "runtime_seconds": 1.0},
|
|
30
|
+
"metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": []}
|
|
31
|
+
return write_dashboard(out, data, rules)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
print(build(Path(sys.argv[1])))
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Interface: see brittle_repo.py."""
|
|
3
3
|
from brittle_repo import CLAIMS, TEST, board_repo, claims_repo, commit, history, without_git
|
|
4
4
|
from fixture_repo import build_repo, load, snapshots, weigh
|
|
5
|
+
from weigh_rules import load as load_rules
|
|
5
6
|
|
|
6
7
|
KEY = "github.com/jesdi/demo"
|
|
7
8
|
|
|
@@ -53,6 +54,10 @@ def test_a_target_that_is_not_a_git_repository_leaves_brittleness_unmeasured(tmp
|
|
|
53
54
|
assert data["test_files"][TEST]["brittle"] is None
|
|
54
55
|
assert "brittle_test_files" not in data["metrics"]
|
|
55
56
|
assert data["pillars"]["refactoring"]["partial"] is True
|
|
57
|
+
assert data["unmeasured"]["brittle_test_files"] == "no git history"
|
|
58
|
+
# every metric is either measured or has the reason it is not, never both (hollow_tests is measured without mutation)
|
|
59
|
+
assert not data["unmeasured"].keys() & data["metrics"].keys()
|
|
60
|
+
assert data["unmeasured"].keys() | data["metrics"].keys() == {m for p in load_rules()["pillars"].values() for m in p["metrics"]}
|
|
56
61
|
|
|
57
62
|
|
|
58
63
|
def test_two_runs_of_the_default_repo_are_equal_apart_from_durations(tmp_path, home, cache):
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Ticket 04 of specs/test-weigh-in-dashboard-polish: readable layout, visible tabs and the offline report (R8, R9, R11, R12).
|
|
2
|
+
|
|
3
|
+
Seam: weigh_dashboard.write_dashboard (via layout_page.py, the real-suite fixture: 2,172 tests, 3,196 cases, 6,757 pairs).
|
|
4
|
+
The returned standalone HTML is opened from disk in Chrome with the network off (browser_driver.py, run by `uv run
|
|
5
|
+
--with playwright`, needs Chrome or a Playwright chromium) and its visible controls are driven. Latency is not asserted:
|
|
6
|
+
the 200 ms claim needs the benchmark machine the operator agrees (design.md).
|
|
7
|
+
"""
|
|
8
|
+
import json
|
|
9
|
+
import re
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
from fixture_repo import uv
|
|
17
|
+
|
|
18
|
+
HERE = Path(__file__).resolve().parent
|
|
19
|
+
SPEC = HERE.parents[2] / "specs" / "test-weigh-in-dashboard-polish"
|
|
20
|
+
TABS = ["Metrics", "Overlaps", "Map"]
|
|
21
|
+
|
|
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)
|
|
27
|
+
assert built.returncode == 0, built.stderr
|
|
28
|
+
html = Path(built.stdout.strip())
|
|
29
|
+
drove = subprocess.run([uv(), "run", "--with", "playwright", "python", str(HERE / "browser_driver.py"), str(html)],
|
|
30
|
+
capture_output=True, text=True, timeout=600)
|
|
31
|
+
assert drove.returncode == 0, drove.stderr[-3000:]
|
|
32
|
+
return {"bytes": html.stat().st_size, **json.loads(drove.stdout)}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def only_active(tabs, label):
|
|
36
|
+
"""Exactly one tab looks different from the rest, and it is `label`."""
|
|
37
|
+
sigs = [t["sig"] for t in tabs]
|
|
38
|
+
odd = [t["text"] for t in tabs if sigs.count(t["sig"]) == 1]
|
|
39
|
+
assert odd == [label], f"visibly active tabs: {odd}, selected {label}"
|
|
40
|
+
assert len({t["sig"] for t in tabs if t["text"] != label}) == 1, "the inactive tabs do not look alike"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_the_active_tab_follows_selection_and_keyboard_focus_shows(report):
|
|
44
|
+
for label in TABS:
|
|
45
|
+
only_active(report["tabs"]["steps"][label], label)
|
|
46
|
+
focus = report["tabs"]["focus"]
|
|
47
|
+
ring = not focus["outline"].startswith("none") and not focus["outline"].split()[1] == "0px"
|
|
48
|
+
assert ring or focus["sig_focused"] != focus["sig_unfocused"], f"no visible focus state: {focus}"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.mark.parametrize("view", ["desktop", "narrow"])
|
|
52
|
+
def test_gauges_align_and_partial_status_stays_readable(report, view):
|
|
53
|
+
gauges = report[view]["gauges"]
|
|
54
|
+
assert len(gauges) == 5
|
|
55
|
+
for g in gauges:
|
|
56
|
+
assert g["title"] and g["status"], "every gauge has a gauge-title and a gauge-status, a fully measured one too"
|
|
57
|
+
assert g["status"]["text"], "a fully measured pillar still states its measurement status"
|
|
58
|
+
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']}"
|
|
60
|
+
rows = {}
|
|
61
|
+
for g in gauges:
|
|
62
|
+
rows.setdefault(g["card"]["top"], []).append(g)
|
|
63
|
+
for row in rows.values():
|
|
64
|
+
for part in ("title", "score", "status"):
|
|
65
|
+
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
|
+
refactoring = next(g for g in gauges if "refactoring" in g["title"]["text"].lower())
|
|
67
|
+
assert "0 of 4" in refactoring["status"]["text"]
|
|
68
|
+
assert report[view]["overview"]["scroll_width"] <= report[view]["overview"]["viewport"], "the page overflows sideways"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize("view", ["desktop", "narrow"])
|
|
72
|
+
def test_details_use_the_available_width_and_keep_full_identities(report, view):
|
|
73
|
+
r = report[view]
|
|
74
|
+
for key in ("feedback_details", "refactoring_details", "overlaps", "map"):
|
|
75
|
+
assert r[key]["scroll_width"] <= r[key]["viewport"], f"{key} overflows the viewport"
|
|
76
|
+
assert r[key]["details_right"] <= r[key]["viewport"]
|
|
77
|
+
assert r["feedback_table_share"] >= 0.85, "the metrics table leaves the right-hand region unused"
|
|
78
|
+
assert r["overlap_ids"]
|
|
79
|
+
for ident in r["overlap_ids"]:
|
|
80
|
+
assert ident["text"].endswith("x" * 40), "identity is not shown in full"
|
|
81
|
+
assert ident["right"] <= r["overlaps"]["viewport"] and not ident["clipped"] and not ident["ellipsis"]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_offline_from_disk_keeps_the_evidence(report):
|
|
85
|
+
j = report["journey"]
|
|
86
|
+
assert j["requests"] == [] and j["failed_requests"] == [] and j["page_errors"] == []
|
|
87
|
+
assert "No metrics were measured" in j["refactoring_text"] and "Total runtime" in j["feedback_text"]
|
|
88
|
+
assert "6,757" in j["count_all"] and j["first_row_page_1"] != j["first_row_page_2"]
|
|
89
|
+
assert re.search(r"\b1\b", j["count_search"]) and j["rows_search"] == 1 and "6,757" in j["count_cleared"]
|
|
90
|
+
assert j["dots"] == 2172 and "test_module_0010" in j["picked"] and j["similar_items"] > 0
|
|
91
|
+
assert "Anchors" in j["metrics_text"]
|
|
92
|
+
only_active(j["active_overlaps"], "Overlaps")
|
|
93
|
+
only_active(j["active_map"], "Map")
|
|
94
|
+
only_active(j["active_metrics"], "Metrics")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_the_size_of_the_real_suite_report_is_recorded_without_truncating_it(report):
|
|
98
|
+
record = (SPEC / "validation.md").read_text()
|
|
99
|
+
assert "2172 tests, 3196 cases, 6757 pairs" in record
|
|
100
|
+
recorded = int(re.search(r"html-bytes:\s*([\d,]+)", record).group(1).replace(",", ""))
|
|
101
|
+
assert report["bytes"] / 2 <= recorded <= report["bytes"] * 2, f"recorded {recorded}, this fixture renders {report['bytes']}"
|
|
102
|
+
assert report["bytes"] > 1_000_000
|
|
103
|
+
assert "6,757" in report["journey"]["count_all"] and report["journey"]["dots"] == 2172
|
|
@@ -101,6 +101,16 @@ def test_equal_anchors_stop_the_run_naming_the_metric(tmp_path, home, cache):
|
|
|
101
101
|
assert snapshots(home, KEY) == []
|
|
102
102
|
|
|
103
103
|
|
|
104
|
+
def test_a_metric_with_an_unknown_unit_stops_the_run_naming_the_metric(tmp_path, home, cache):
|
|
105
|
+
repo = build_repo(tmp_path / "demo")
|
|
106
|
+
rules = write_rules(tmp_path / "rules.toml")
|
|
107
|
+
rules.write_text(rules.read_text().replace('unit = "s"', 'unit = "min"', 1)) # the first "s" metric is total_runtime
|
|
108
|
+
result = weigh(repo, home, cache=cache, rules=rules)
|
|
109
|
+
assert result.returncode == 2
|
|
110
|
+
assert "total runtime needs a unit" in (result.stdout + result.stderr).lower()
|
|
111
|
+
assert snapshots(home, KEY) == []
|
|
112
|
+
|
|
113
|
+
|
|
104
114
|
def test_edited_rules_keep_the_version_and_change_the_hash(tmp_path, home, cache):
|
|
105
115
|
repo = build_repo(tmp_path / "demo")
|
|
106
116
|
before = write_rules(tmp_path / "before.toml", branch_coverage=dict(bad=50))
|
|
@@ -65,14 +65,23 @@ def main(argv=None):
|
|
|
65
65
|
"runtime_seconds": max(run["runtime_seconds"], sum(c["duration"] for c in run["cases"].values())),
|
|
66
66
|
}
|
|
67
67
|
values = feedback_values(tests, inventory["runtime_seconds"])
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
unmeasured = {}
|
|
69
|
+
|
|
70
|
+
def measure(mid, value, reason):
|
|
71
|
+
"""An optional metric records its value, or the reason it has none, here and only here."""
|
|
72
|
+
if value is None:
|
|
73
|
+
unmeasured[mid] = reason
|
|
74
|
+
else:
|
|
75
|
+
values[mid] = value
|
|
76
|
+
|
|
77
|
+
tier = "the mutation tier did not run"
|
|
78
|
+
measure("mutation_score", None if mutation is None else mutation["score"], tier)
|
|
79
|
+
measure("pseudo_tested_functions", None if mutation is None else mutation["pseudo_tested"], tier)
|
|
71
80
|
found, clusters = find_smells(repo, tests, violations(repo, rules.get("ruff", {}).get("pt", [])))
|
|
72
81
|
for node, info in found.items():
|
|
73
82
|
tests[node].update(info)
|
|
74
|
-
if inventory["source_lines"]
|
|
75
|
-
|
|
83
|
+
measure("test_source_ratio", inventory["test_lines"] / inventory["source_lines"] if inventory["source_lines"] else None,
|
|
84
|
+
"no source lines found")
|
|
76
85
|
# failing, erroring and skipped tests cost (runtime, lines, smells) but give no value: no coverage, overlap or uniqueness
|
|
77
86
|
covered = per_test(cov["report"], cov["arcs"], repo)
|
|
78
87
|
cov_tests = aggregate(cov["cases"])
|
|
@@ -84,18 +93,18 @@ def main(argv=None):
|
|
|
84
93
|
unique = unique_coverage(passing)
|
|
85
94
|
for node, test in tests.items():
|
|
86
95
|
test["unique_coverage"] = unique.get(node, 0)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if mutation is
|
|
90
|
-
values.update(kill_matrix(tests, passing, mutation))
|
|
96
|
+
measure("branch_coverage", branch_percent(cov["value_report"]), "no branch data in the coverage report")
|
|
97
|
+
# flags tests before the metrics they change are computed
|
|
98
|
+
measure("subsumed_in_kill_matrix", None if mutation is None else kill_matrix(tests, passing, mutation)["subsumed_in_kill_matrix"], tier)
|
|
91
99
|
values.update(smell_values(tests))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
# a count-based metric is a percentage of all tests (req 17); only valued tests can lack unique coverage, and an
|
|
101
|
+
# insufficient-evidence test counts in no Economy metric
|
|
102
|
+
measure("no_unique_coverage",
|
|
103
|
+
100 * sum(not u and not tests[n].get("insufficient_evidence") for n, u in unique.items()) / len(tests) if passing else None,
|
|
104
|
+
"no test passed")
|
|
96
105
|
test_files = brittleness(repo, test_file_sources(tests))
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
measure("brittle_test_files", brittle_percent(test_files),
|
|
107
|
+
"no source file maps to a test file" if is_repo(repo) else "no git history")
|
|
99
108
|
metrics, pillars = score(rules, values, red=len(passing) < len(tests))
|
|
100
109
|
data = {
|
|
101
110
|
"commit": commit,
|
|
@@ -106,6 +115,7 @@ def main(argv=None):
|
|
|
106
115
|
"rules": {"version": rules["version"], "sha256": rules["sha256"]},
|
|
107
116
|
"inventory": inventory,
|
|
108
117
|
"metrics": metrics,
|
|
118
|
+
"unmeasured": unmeasured,
|
|
109
119
|
"pillars": pillars,
|
|
110
120
|
"mutation_settings": {"mutation": args.mutation, "matrix_per_function": "all" if args.matrix_per_function is None else args.matrix_per_function},
|
|
111
121
|
**({"mutation": {k: mutation[k] for k in ("sampled", "mutants", "matrix")}} if mutation is not None else {}),
|
|
@@ -18,6 +18,10 @@ def _failing(tests):
|
|
|
18
18
|
return sum(t["outcome"] == "failed" for t in tests.values())
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
def _failing_names(tests):
|
|
22
|
+
return [n for n, t in tests.items() if t["outcome"] == "failed"]
|
|
23
|
+
|
|
24
|
+
|
|
21
25
|
def _flaky(tests):
|
|
22
26
|
return sum(t.get("flaky", False) for t in tests.values())
|
|
23
27
|
|
|
@@ -31,6 +35,7 @@ def write_dashboard(home, data, rules):
|
|
|
31
35
|
failing = _failing(data["tests"])
|
|
32
36
|
page = {
|
|
33
37
|
"banner": f"{failing} tests are failing" if failing > 1 else "1 test is failing" if failing else None,
|
|
38
|
+
"failing": _failing_names(data["tests"]),
|
|
34
39
|
"skipped": [n for n, t in data["tests"].items() if t["outcome"] == "skipped"],
|
|
35
40
|
"insufficient": [n for n, t in data["tests"].items() if t.get("insufficient_evidence")],
|
|
36
41
|
"overlaps": data.get("overlaps", []),
|
|
@@ -39,7 +44,10 @@ def write_dashboard(home, data, rules):
|
|
|
39
44
|
"inventory": inventory_line(data["inventory"]),
|
|
40
45
|
"pillars": [
|
|
41
46
|
{"key": k, "name": p["name"], **data["pillars"][k],
|
|
42
|
-
"metrics": [{"name": m["name"],
|
|
47
|
+
"metrics": [{"name": m["name"], "unit": m["unit"], "target": m["target"], "bad": m["bad"], **data["metrics"][i]}
|
|
48
|
+
for i, m in p["metrics"].items() if i in data["metrics"]],
|
|
49
|
+
# an entry the snapshot does not record (older data) has no known cause
|
|
50
|
+
"missing": [{"name": m["name"], "reason": data.get("unmeasured", {}).get(i)} for i, m in p["metrics"].items() if i not in data["metrics"]],
|
|
43
51
|
"total": len(p["metrics"]),
|
|
44
52
|
"worst": worst_tests(data["tests"], k, _slow(rules)),
|
|
45
53
|
"smells": pillar_smells(data["tests"], PILLAR_SMELLS.get(k, ()))}
|
|
@@ -9,6 +9,7 @@ from weigh_env import SetupError
|
|
|
9
9
|
|
|
10
10
|
DEFAULT = Path(__file__).resolve().parent / "rules.toml"
|
|
11
11
|
TABLE = re.compile(r"^\[([A-Za-z0-9_.]+)\]$")
|
|
12
|
+
UNITS = ("%", "s", "") # percent of all tests, seconds, plain ratio
|
|
12
13
|
PILLARS = ("regression", "refactoring", "feedback", "maintainability", "economy")
|
|
13
14
|
|
|
14
15
|
|
|
@@ -58,6 +59,8 @@ def validate(rules):
|
|
|
58
59
|
if not pillar or not pillar.get("metrics"):
|
|
59
60
|
raise RulesError(f"rules.toml: pillar {key} is missing or has no metrics")
|
|
60
61
|
for mid, m in pillar["metrics"].items():
|
|
62
|
+
if m.get("unit") not in UNITS:
|
|
63
|
+
raise RulesError(f"rules.toml: {pillar['name']}: {m['name']} needs a unit, one of {', '.join(map(repr, UNITS))}")
|
|
61
64
|
if m["target"] == m["bad"]:
|
|
62
65
|
raise RulesError(f"rules.toml: {pillar['name']}: {m['name']} has target and bad anchors both {m['target']}")
|
|
63
66
|
total = sum(m["weight"] for m in pillar["metrics"].values())
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-05T12:22:43.116Z",
|
|
4
4
|
"skills": [
|
|
5
5
|
{
|
|
6
6
|
"name": "agents-wayfinder",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"name": "implement-spec",
|
|
61
|
-
"version": "0.1.
|
|
62
|
-
"hash": "sha256-
|
|
61
|
+
"version": "0.1.50",
|
|
62
|
+
"hash": "sha256-2b88ad4bcc572280fd6d023ad925e7644fae72483c4827c032362724d14cfa3d",
|
|
63
63
|
"description": "Implement a specification in code."
|
|
64
64
|
},
|
|
65
65
|
{
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
108
|
"name": "test-weigh-in",
|
|
109
|
-
"version": "0.1.
|
|
110
|
-
"hash": "sha256-
|
|
109
|
+
"version": "0.1.3",
|
|
110
|
+
"hash": "sha256-aecabdc7fd3d511440930bdc3274960106fe37959227ae3be7428dd634f8d4eb",
|
|
111
111
|
"description": "Measure a Python/pytest suite and score it on five pillars (Protection against regressions, Resistance to refactoring, Fast feedback, Maintainability, Economy), writing a JSON snapshot and a static HTML dashboard. Read-only. Use when the user asks to weigh, measure or score their test suite."
|
|
112
112
|
},
|
|
113
113
|
{
|