@jesdi/skills 0.0.85 → 0.0.87
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/ARCHITECTURE.md +13 -6
- package/skills/implement-spec/README.md +23 -11
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver.py +3 -2
- package/skills/implement-spec/driver_agents.py +93 -32
- package/skills/implement-spec/driver_run.py +23 -13
- package/skills/implement-spec/driver_state.py +1 -1
- package/skills/implement-spec/driver_summary.py +8 -1
- package/skills/implement-spec/tests/conftest.py +2 -0
- package/skills/implement-spec/tests/test_agents.py +56 -5
- package/skills/implement-spec/tests/test_arbitration.py +3 -1
- package/skills/implement-spec/tests/test_driver.py +2 -1
- package/skills/implement-spec/tests/test_landing.py +2 -2
- package/skills/implement-spec/tests/test_lenses.py +10 -5
- package/skills/implement-spec/tests/test_models.py +74 -0
- package/skills/implement-spec/tests/test_summary.py +8 -0
- 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
|
@@ -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):
|