@jesdi/skills 0.0.87 → 0.0.89
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/babysit-pr/SKILL.md +1 -1
- package/skills/babysit-pr/babysit.py +21 -10
- package/skills/babysit-pr/fixtures/gh +2 -1
- package/skills/babysit-pr/judge-prompt.md +7 -3
- package/skills/babysit-pr/test_babysit_judge.py +16 -10
- package/skills/babysit-pr/test_babysit_judge_isolation.py +1 -1
- package/skills/babysit-pr/test_handoff_takeover.py +1 -1
- package/skills/babysit-pr/test_merge_and_handoff.py +17 -16
- package/skills/babysit-pr/test_merge_base_pin.py +1 -1
- package/skills/babysit-pr/test_merge_gate.py +49 -14
- package/skills/babysit-pr/test_merge_session_safety.py +3 -3
- package/skills/babysit-pr/test_merged_pr_labels.py +1 -1
- package/skills/babysit-pr/test_terminal_label_regressions.py +1 -1
- package/skills/babysit-pr/test_trusted_merge_risk.py +1 -1
- package/skills/implement-spec/ARCHITECTURE.md +20 -8
- package/skills/implement-spec/README.md +7 -4
- package/skills/implement-spec/driver_decisions.py +3 -2
- package/skills/implement-spec/driver_dispute.py +82 -57
- package/skills/implement-spec/driver_fixloop.py +18 -21
- package/skills/implement-spec/driver_legacy.py +31 -2
- package/skills/implement-spec/driver_report.py +13 -3
- package/skills/implement-spec/driver_state.py +8 -7
- package/skills/implement-spec/prompts/correction.md +1 -0
- package/skills/implement-spec/prompts/reviewer.md +3 -3
- package/skills/implement-spec/prompts/ruled.md +1 -1
- package/skills/implement-spec/tests/test_arbitration.py +101 -10
- package/skills/implement-spec/tests/test_decisions.py +7 -5
- package/skills/implement-spec/tests/test_final.py +1 -1
- package/skills/implement-spec/tests/test_fixloop.py +3 -3
- package/skills/implement-spec/tests/test_legacy.py +27 -0
- package/skills/implement-spec/tests/test_state.py +1 -1
- package/skills/implement-spec/tests/test_walk.py +1 -1
- package/skills/pr-risk/SKILL.md +18 -3
- package/skills/pr-risk/merge_policy.py +29 -9
- package/skills/pr-risk/merge_risk.py +57 -14
- package/skills/pr-risk/test_hooks.py +2 -2
- package/skills/pr-risk/test_merge_risk.py +2 -2
- package/skills/pr-risk/test_merge_risk_gate.py +128 -43
- package/skills/pr-risk/test_merge_risk_regressions.py +5 -5
- package/skills/pr-risk/test_merge_risk_structure.py +5 -4
- package/skills/test-weigh-in/dashboard.html +70 -17
- package/skills/test-weigh-in/tests/browser_driver.py +46 -5
- package/skills/test-weigh-in/tests/layout_page.py +7 -3
- package/skills/test-weigh-in/tests/overlap_page.py +3 -0
- package/skills/test-weigh-in/tests/rules_fixture.py +1 -1
- package/skills/test-weigh-in/tests/test_coverage_run.py +5 -1
- package/skills/test-weigh-in/tests/test_dashboard_layout.py +50 -9
- package/skills/test-weigh-in/tests/test_score.py +53 -2
- package/skills/test-weigh-in/weigh.py +2 -2
- package/skills/test-weigh-in/weigh_coverage.py +22 -2
- package/skills/test-weigh-in/weigh_dashboard.py +51 -10
- package/skills/test-weigh-in/weigh_score.py +6 -3
- package/skills/test-weigh-in/weigh_smells.py +3 -2
- package/skills-manifest.json +9 -9
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Each test builds a temp git repo: `origin/<base>` is a remote-tracking ref that holds the
|
|
4
4
|
policy, the head commit is the PR. The gate prints one JSON object on stdout:
|
|
5
|
-
`verdict` ("auto" | "human"), `reasons` (every reason that made it human),
|
|
6
|
-
`categories` (categories of the diff) and `countedLines`.
|
|
5
|
+
`verdict` ("auto" | "human"), `reasons` (every reason that made it human), `risk` (1-10),
|
|
6
|
+
`maxAutoRisk` (the limit that applied), `categories` (categories of the diff) and `countedLines`.
|
|
7
|
+
`gh` is a fake on PATH that answers `gh repo view` with $FAKE_PRIVATE ("true" | "false"); unset,
|
|
8
|
+
it fails, and the repo counts as public.
|
|
7
9
|
"""
|
|
8
10
|
import json
|
|
9
11
|
import os
|
|
@@ -53,27 +55,40 @@ def policy(**kw):
|
|
|
53
55
|
return {POLICY: json.dumps(kw)}
|
|
54
56
|
|
|
55
57
|
|
|
56
|
-
def block(door="two-way", touches="docs", rollback="revert",
|
|
58
|
+
def block(door="two-way", touches="docs", rollback="revert", risk=1, blast="isolated"):
|
|
57
59
|
return (
|
|
58
60
|
"## Summary\n\nText.\n\n## Merge Danger\n\n```merge-risk v1\n"
|
|
59
|
-
f"door: {door}\nblast_radius:
|
|
60
|
-
f"rollback: {rollback}\
|
|
61
|
+
f"door: {door}\nblast_radius: {blast}\ntouches: [{touches}]\n"
|
|
62
|
+
f"rollback: {rollback}\nrisk: {risk}\n"
|
|
61
63
|
'reasons:\n - "Small and reversible"\n```\n'
|
|
62
64
|
)
|
|
63
65
|
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
FAKE_GH = """#!/bin/sh
|
|
68
|
+
[ "$1 $2" = "repo view" ] && [ -n "$FAKE_PRIVATE" ] && echo "$FAKE_PRIVATE" && exit 0
|
|
69
|
+
exit 1
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def gate(tmp_path, repo, sha, body, base="main", private=None):
|
|
66
74
|
f = tmp_path / "body.md"
|
|
67
75
|
f.write_text(body)
|
|
76
|
+
bin_dir = tmp_path / "bin"
|
|
77
|
+
bin_dir.mkdir(exist_ok=True)
|
|
78
|
+
(bin_dir / "gh").write_text(FAKE_GH)
|
|
79
|
+
(bin_dir / "gh").chmod(0o755)
|
|
80
|
+
env = {**ENV, "PATH": f"{bin_dir}{os.pathsep}{ENV['PATH']}"}
|
|
81
|
+
if private is not None:
|
|
82
|
+
env["FAKE_PRIVATE"] = "true" if private else "false"
|
|
68
83
|
proc = subprocess.run(
|
|
69
84
|
[sys.executable, str(SCRIPT), "gate", "--body", str(f), "--base", base, "--head", sha],
|
|
70
|
-
cwd=repo, env=
|
|
85
|
+
cwd=repo, env=env, text=True, capture_output=True, timeout=60)
|
|
71
86
|
assert proc.returncode == 0, f"gate exited {proc.returncode}: {proc.stderr or proc.stdout}"
|
|
72
87
|
return json.loads(proc.stdout)
|
|
73
88
|
|
|
74
89
|
|
|
75
90
|
def test_no_block_is_human(tmp_path):
|
|
76
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
91
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3), {"docs/a.md": "x\n"})
|
|
77
92
|
out = gate(tmp_path, repo, sha, "## Summary\n\nNo block here.\n")
|
|
78
93
|
assert out["verdict"] == "human"
|
|
79
94
|
assert "no merge-risk block" in out["reasons"]
|
|
@@ -81,7 +96,7 @@ def test_no_block_is_human(tmp_path):
|
|
|
81
96
|
|
|
82
97
|
def test_repo_paths_add_to_defaults(tmp_path):
|
|
83
98
|
repo, sha = make_repo(
|
|
84
|
-
tmp_path, policy(
|
|
99
|
+
tmp_path, policy(maxAutoRisk=3, paths={"money": ["src/billing/**"]}),
|
|
85
100
|
{"src/billing/invoice.py": "x\n", "db/migrations/0042_add.sql": "x\n"})
|
|
86
101
|
out = gate(tmp_path, repo, sha, block(touches="money, schema/migration"))
|
|
87
102
|
assert sorted(out["categories"]) == ["money", "schema/migration"]
|
|
@@ -89,40 +104,50 @@ def test_repo_paths_add_to_defaults(tmp_path):
|
|
|
89
104
|
|
|
90
105
|
def test_repo_paths_extend_default_globs_of_existing_category(tmp_path):
|
|
91
106
|
repo, sha = make_repo(
|
|
92
|
-
tmp_path, policy(
|
|
107
|
+
tmp_path, policy(maxAutoRisk=3, paths={"docs": ["notes/**"]}),
|
|
93
108
|
{"docs/a.md": "x\n", "notes/b.txt": "x\n"})
|
|
94
109
|
out = gate(tmp_path, repo, sha, block(touches="docs"))
|
|
95
110
|
assert out["categories"] == ["docs"]
|
|
96
111
|
assert out["verdict"] == "auto"
|
|
97
112
|
|
|
98
113
|
|
|
99
|
-
def
|
|
100
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
114
|
+
def test_repo_category_risk_overrides_one_default(tmp_path):
|
|
115
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=8, categoryRisk={"infra": 5}),
|
|
101
116
|
{"Dockerfile": "FROM x\n"})
|
|
102
|
-
out = gate(tmp_path, repo, sha, block(touches="infra"))
|
|
117
|
+
out = gate(tmp_path, repo, sha, block(touches="infra"), private=True)
|
|
118
|
+
assert out["risk"] == 5
|
|
103
119
|
assert out["verdict"] == "auto"
|
|
104
120
|
assert out["reasons"] == []
|
|
105
121
|
|
|
106
122
|
|
|
123
|
+
def test_old_policy_keys_name_their_replacement(tmp_path):
|
|
124
|
+
repo, sha = make_repo(tmp_path, policy(agentMerge=True, alwaysHuman=["money"]),
|
|
125
|
+
{"docs/a.md": "x\n"})
|
|
126
|
+
out = gate(tmp_path, repo, sha, block())
|
|
127
|
+
assert out["verdict"] == "human"
|
|
128
|
+
assert "policy: agentMerge was replaced by maxAutoRisk" in out["reasons"]
|
|
129
|
+
assert "policy: alwaysHuman was replaced by categoryRisk" in out["reasons"]
|
|
130
|
+
|
|
131
|
+
|
|
107
132
|
def test_pr_cannot_loosen_its_own_policy(tmp_path):
|
|
108
133
|
repo, sha = make_repo(
|
|
109
|
-
tmp_path, policy(
|
|
110
|
-
{"db/migrations/0042_add.sql": "x\n", **policy(
|
|
111
|
-
out = gate(tmp_path, repo, sha, block(touches="schema/migration, config"))
|
|
134
|
+
tmp_path, policy(maxAutoRisk=3),
|
|
135
|
+
{"db/migrations/0042_add.sql": "x\n", **policy(maxAutoRisk=10)})
|
|
136
|
+
out = gate(tmp_path, repo, sha, block(touches="schema/migration, config"), private=True)
|
|
112
137
|
assert out["verdict"] == "human"
|
|
113
|
-
assert "
|
|
138
|
+
assert "risk 9 > max auto risk 3" in out["reasons"]
|
|
114
139
|
assert "config: .merge-risk.json changed" in out["reasons"]
|
|
115
140
|
|
|
116
141
|
|
|
117
142
|
def test_first_policy_file_is_not_used_by_its_own_pr(tmp_path):
|
|
118
|
-
repo, sha = make_repo(tmp_path, {"README.md": "hi\n"}, policy(
|
|
143
|
+
repo, sha = make_repo(tmp_path, {"README.md": "hi\n"}, policy(maxAutoRisk=3))
|
|
119
144
|
out = gate(tmp_path, repo, sha, block(touches="config"))
|
|
120
145
|
assert out["verdict"] == "human"
|
|
121
|
-
assert "
|
|
146
|
+
assert "policy: no .merge-risk.json on the base" in out["reasons"]
|
|
122
147
|
|
|
123
148
|
|
|
124
149
|
def test_unknown_policy_key_is_human(tmp_path):
|
|
125
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
150
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3, autoMerge=True),
|
|
126
151
|
{"docs/a.md": "x\n"})
|
|
127
152
|
out = gate(tmp_path, repo, sha, block())
|
|
128
153
|
assert out["verdict"] == "human"
|
|
@@ -130,7 +155,7 @@ def test_unknown_policy_key_is_human(tmp_path):
|
|
|
130
155
|
|
|
131
156
|
|
|
132
157
|
def test_skill_md_is_logic_not_docs(tmp_path):
|
|
133
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
158
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3),
|
|
134
159
|
{"skills/pr-risk/SKILL.md": "x\n"})
|
|
135
160
|
out = gate(tmp_path, repo, sha, block(touches="docs"))
|
|
136
161
|
assert out["verdict"] == "human"
|
|
@@ -138,7 +163,7 @@ def test_skill_md_is_logic_not_docs(tmp_path):
|
|
|
138
163
|
|
|
139
164
|
|
|
140
165
|
def test_instruction_file_under_docs_counts_as_logic_with_its_lines(tmp_path):
|
|
141
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
166
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3, judgeMaxLines=3),
|
|
142
167
|
{"docs/SKILL.md": "a\nb\nc\nd\ne\n"})
|
|
143
168
|
out = gate(tmp_path, repo, sha, block(touches="docs, logic"))
|
|
144
169
|
assert out["categories"] == ["logic"]
|
|
@@ -146,41 +171,90 @@ def test_instruction_file_under_docs_counts_as_logic_with_its_lines(tmp_path):
|
|
|
146
171
|
assert out["verdict"] == "human"
|
|
147
172
|
|
|
148
173
|
|
|
149
|
-
def
|
|
150
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
151
|
-
out = gate(tmp_path, repo, sha, block(door="one-way",
|
|
174
|
+
def test_one_way_door_is_human_at_any_risk_and_limit(tmp_path):
|
|
175
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=10), {"docs/a.md": "x\n"})
|
|
176
|
+
out = gate(tmp_path, repo, sha, block(door="one-way", risk=1), private=True)
|
|
152
177
|
assert out["verdict"] == "human"
|
|
153
|
-
assert "door one-way"
|
|
178
|
+
assert out["reasons"] == ["door one-way"]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_rollback_that_cannot_revert_is_one_way(tmp_path):
|
|
182
|
+
for rollback in ("data-fix", "impossible"):
|
|
183
|
+
sub = tmp_path / rollback
|
|
184
|
+
sub.mkdir()
|
|
185
|
+
repo, sha = make_repo(sub, policy(maxAutoRisk=10), {"docs/a.md": "x\n"})
|
|
186
|
+
out = gate(sub, repo, sha, block(rollback=rollback), private=True)
|
|
187
|
+
assert out["reasons"] == [f"rollback {rollback} is one-way"]
|
|
154
188
|
|
|
155
189
|
|
|
156
|
-
def
|
|
157
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
158
|
-
out = gate(tmp_path, repo, sha, block(
|
|
190
|
+
def test_risk_floor_adds_blast_radius_and_redeploy(tmp_path):
|
|
191
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=10), {"src/app.py": "x\n"})
|
|
192
|
+
out = gate(tmp_path, repo, sha, block(touches="logic", blast="service",
|
|
193
|
+
rollback="revert+redeploy"), private=True)
|
|
194
|
+
assert out["risk"] == 4 + 2 + 1
|
|
195
|
+
assert out["verdict"] == "auto"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_block_risk_raises_the_floor_but_never_lowers_it(tmp_path):
|
|
199
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=5), {"src/app.py": "x\n"})
|
|
200
|
+
assert gate(tmp_path, repo, sha, block(touches="logic", risk=6), private=True)["risk"] == 6
|
|
201
|
+
out = gate(tmp_path, repo, sha, block(touches="logic", risk=1), private=True)
|
|
202
|
+
assert out["risk"] == 4
|
|
203
|
+
assert out["verdict"] == "auto"
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def test_risk_above_the_repo_limit_is_human(tmp_path):
|
|
207
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3), {"src/app.py": "x\n"})
|
|
208
|
+
out = gate(tmp_path, repo, sha, block(touches="logic"), private=True)
|
|
159
209
|
assert out["verdict"] == "human"
|
|
210
|
+
assert out["reasons"] == ["risk 4 > max auto risk 3"]
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def test_public_repo_caps_the_limit_at_3(tmp_path):
|
|
214
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=8), {"src/app.py": "x\n"})
|
|
215
|
+
out = gate(tmp_path, repo, sha, block(touches="logic"), private=False)
|
|
216
|
+
assert out["maxAutoRisk"] == 3
|
|
217
|
+
assert out["reasons"] == ["risk 4 > max auto risk 3 (public repo)"]
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def test_unknown_visibility_counts_as_public(tmp_path):
|
|
221
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=8), {"src/app.py": "x\n"})
|
|
222
|
+
assert gate(tmp_path, repo, sha, block(touches="logic"))["maxAutoRisk"] == 3
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def test_limit_defaults_to_3_when_the_policy_sets_none(tmp_path):
|
|
226
|
+
repo, sha = make_repo(tmp_path, policy(), {"src/app.py": "x\n"})
|
|
227
|
+
assert gate(tmp_path, repo, sha, block(touches="logic"), private=True)["maxAutoRisk"] == 3
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_invalid_risk_is_an_invalid_block(tmp_path):
|
|
231
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3), {"docs/a.md": "x\n"})
|
|
232
|
+
out = gate(tmp_path, repo, sha, block(risk=11))
|
|
233
|
+
assert "invalid block: risk: '11' is not a whole number from 1 to 10" in out["reasons"]
|
|
234
|
+
assert out["risk"] == 10
|
|
160
235
|
|
|
161
236
|
|
|
162
237
|
def test_undeclared_migration_is_human(tmp_path):
|
|
163
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
238
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3),
|
|
164
239
|
{"src/app.py": "x\n", "tests/test_app.py": "x\n",
|
|
165
240
|
"db/migrations/0042_add.sql": "x\n"})
|
|
166
241
|
out = gate(tmp_path, repo, sha, block(touches="logic, tests"))
|
|
167
242
|
assert out["verdict"] == "human"
|
|
168
243
|
assert "diff touches schema/migration, not in touches" in out["reasons"]
|
|
169
|
-
assert "schema/migration is always human" in out["reasons"]
|
|
170
244
|
|
|
171
245
|
|
|
172
|
-
def
|
|
173
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
174
|
-
out = gate(tmp_path, repo, sha, block(touches="logic, auth/security"))
|
|
175
|
-
assert out["
|
|
176
|
-
assert "
|
|
246
|
+
def test_category_declared_only_in_body_counts_toward_risk(tmp_path):
|
|
247
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=9), {"src/app.py": "x\n"})
|
|
248
|
+
out = gate(tmp_path, repo, sha, block(touches="logic, auth/security"), private=True)
|
|
249
|
+
assert out["risk"] == 10
|
|
250
|
+
assert out["reasons"] == ["risk 10 > max auto risk 9"]
|
|
177
251
|
|
|
178
252
|
|
|
179
|
-
def
|
|
180
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
253
|
+
def test_max_auto_risk_0_is_human(tmp_path):
|
|
254
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=0), {"docs/a.md": "x\n"})
|
|
181
255
|
out = gate(tmp_path, repo, sha, block())
|
|
182
256
|
assert out["verdict"] == "human"
|
|
183
|
-
assert "
|
|
257
|
+
assert "risk 1 > max auto risk 0" in out["reasons"]
|
|
184
258
|
|
|
185
259
|
|
|
186
260
|
def counted_diff(n):
|
|
@@ -189,14 +263,14 @@ def counted_diff(n):
|
|
|
189
263
|
|
|
190
264
|
|
|
191
265
|
def test_counted_lines_at_the_limit_is_auto(tmp_path):
|
|
192
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
193
|
-
out = gate(tmp_path, repo, sha, block(touches="deps, docs, logic"))
|
|
266
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=5), counted_diff(1500))
|
|
267
|
+
out = gate(tmp_path, repo, sha, block(touches="deps, docs, logic"), private=True)
|
|
194
268
|
assert out["countedLines"] == 1500
|
|
195
269
|
assert out["verdict"] == "auto"
|
|
196
270
|
|
|
197
271
|
|
|
198
272
|
def test_counted_lines_over_the_limit_is_human(tmp_path):
|
|
199
|
-
repo, sha = make_repo(tmp_path, policy(
|
|
273
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=3), counted_diff(1501))
|
|
200
274
|
out = gate(tmp_path, repo, sha, block(touches="deps, docs, logic"))
|
|
201
275
|
assert out["verdict"] == "human"
|
|
202
276
|
assert "1501 counted lines > 1500" in out["reasons"]
|
|
@@ -208,10 +282,21 @@ def test_stacked_base_uses_origin_parent_never_main(tmp_path):
|
|
|
208
282
|
git(repo, "init", "-q", "-b", "work")
|
|
209
283
|
main_sha = commit(repo, {"README.md": "hi\n"}, "main") # main: no policy
|
|
210
284
|
git(repo, "update-ref", "refs/remotes/origin/main", main_sha)
|
|
211
|
-
parent_sha = commit(repo, {**policy(
|
|
285
|
+
parent_sha = commit(repo, {**policy(maxAutoRisk=3), "db/migrations/0001.sql": "x\n"},
|
|
212
286
|
"parent")
|
|
213
287
|
git(repo, "update-ref", "refs/remotes/origin/feat/parent", parent_sha)
|
|
214
288
|
sha = commit(repo, {"docs/a.md": "x\n"}, "head")
|
|
215
289
|
out = gate(tmp_path, repo, sha, block(), base="feat/parent")
|
|
216
290
|
assert out["categories"] == ["docs"]
|
|
217
291
|
assert out["verdict"] == "auto"
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def test_a_caller_that_predates_public_gets_the_public_cap(tmp_path):
|
|
295
|
+
"""An older babysit-pr calls gate(body, base, head): it must get the strict cap, not crash."""
|
|
296
|
+
repo, sha = make_repo(tmp_path, policy(maxAutoRisk=8), {"src/app.py": "x\n"})
|
|
297
|
+
code = (f"import sys, json; sys.path.insert(0, {str(SCRIPT.parent)!r}); import merge_risk;"
|
|
298
|
+
f"print(json.dumps(merge_risk.gate({block(touches='logic')!r}, 'main', {sha!r})))")
|
|
299
|
+
out = json.loads(subprocess.run([sys.executable, "-c", code], cwd=repo, env=ENV, text=True,
|
|
300
|
+
capture_output=True, check=True).stdout)
|
|
301
|
+
assert out["maxAutoRisk"] == 3
|
|
302
|
+
assert out["verdict"] == "human"
|
|
@@ -7,7 +7,7 @@ from test_merge_risk_gate import block, commit, gate, git, make_repo, policy, wr
|
|
|
7
7
|
@pytest.mark.parametrize("pattern", ["src/billing[12]/**", "src/billing[!3]/**"])
|
|
8
8
|
def test_unsupported_policy_glob_requires_human(tmp_path, pattern):
|
|
9
9
|
repo, sha = make_repo(
|
|
10
|
-
tmp_path, policy(
|
|
10
|
+
tmp_path, policy(maxAutoRisk=3, paths={"money": [pattern]}),
|
|
11
11
|
{"src/billing1/invoice.py": "amount = 1\n"})
|
|
12
12
|
out = gate(tmp_path, repo, sha, block(touches="logic"))
|
|
13
13
|
assert out["verdict"] == "human"
|
|
@@ -18,20 +18,20 @@ def test_unsupported_policy_glob_requires_human(tmp_path, pattern):
|
|
|
18
18
|
def test_deleted_file_uses_merge_base_marker_and_base_tip_policy(tmp_path, was_generated):
|
|
19
19
|
repo, _ = make_repo(
|
|
20
20
|
tmp_path,
|
|
21
|
-
{**policy(
|
|
21
|
+
{**policy(maxAutoRisk=0),
|
|
22
22
|
"src/app.py": ("# @generated\n" if was_generated else "") + "x\n" * 1501},
|
|
23
23
|
{"README.md": "hi\n"})
|
|
24
24
|
ancestor = git(repo, "rev-parse", "HEAD")
|
|
25
25
|
(repo / "src/app.py").unlink()
|
|
26
26
|
sha = commit(repo, {}, "PR deletes app")
|
|
27
27
|
# Build an independent base commit without moving the PR's checked-out branch.
|
|
28
|
-
write(repo, {**policy(
|
|
28
|
+
write(repo, {**policy(maxAutoRisk=4),
|
|
29
29
|
"src/app.py": ("" if was_generated else "# @generated\n") + "x\n" * 1501})
|
|
30
30
|
git(repo, "add", "-A")
|
|
31
31
|
tree = git(repo, "write-tree")
|
|
32
32
|
base_tip = git(repo, "commit-tree", tree, "-p", ancestor, "-m", "base changes marker")
|
|
33
33
|
git(repo, "update-ref", "refs/remotes/origin/main", base_tip)
|
|
34
|
-
out = gate(tmp_path, repo, sha, block(touches="logic"))
|
|
35
|
-
assert "
|
|
34
|
+
out = gate(tmp_path, repo, sha, block(touches="logic"), private=True)
|
|
35
|
+
assert out["maxAutoRisk"] == 4 # the policy of the base tip, not of the merge base
|
|
36
36
|
assert out["countedLines"] == (0 if was_generated else 1501)
|
|
37
37
|
assert out["verdict"] == ("auto" if was_generated else "human")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Structure and behavior-preservation tests for the merge_risk refactor (ticket 17).
|
|
2
2
|
|
|
3
|
-
Golden outputs were recorded from merge_risk.py before the refactor (commit 74ccb2c)
|
|
3
|
+
Golden outputs were recorded from merge_risk.py before the refactor (commit 74ccb2c), then
|
|
4
|
+
re-recorded when the block's `verdict` became `risk` and the gate began to score risk.
|
|
4
5
|
"""
|
|
5
6
|
import ast
|
|
6
7
|
import os
|
|
@@ -13,10 +14,10 @@ SCRIPT = HERE / "merge_risk.py"
|
|
|
13
14
|
BRANCHES = (ast.If, ast.For, ast.While, ast.ExceptHandler, ast.IfExp,
|
|
14
15
|
ast.comprehension)
|
|
15
16
|
|
|
16
|
-
CASES = {'valid': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\
|
|
17
|
-
GOLDEN = {'valid:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "
|
|
17
|
+
CASES = {'valid': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nrisk: 1\nreasons:\n - "Only prose"\n', 'inline': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nrisk: 1\nreasons: [a, "b, c"]\n', 'bad': 'door: sideways\ntouches: [docs, styles, ]\nrollback: revert\nrollback: x\nfoo: 1\nreasons: nope\n junk\n', 'emptyreasons': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nrisk: 1\nreasons:\n', 'badreasons': 'door: two-way\nblast_radius: isolated\ntouches: [docs, tests]\nrollback: revert\nrisk: 1\nreasons:\n - a: b\n - ""\n - [x]\n - \'q\'x\'\n'}
|
|
18
|
+
GOLDEN = {'valid:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "risk": 1, "touches": ["docs", "tests"], "reasons": ["Only prose"], "errors": []}\n'], 'valid:validate': [0, ''], 'inline:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "risk": 1, "touches": ["docs", "tests"], "reasons": ["a", "b, c"], "errors": []}\n'], 'inline:validate': [0, ''], 'bad:parse': [0, '{"door": "sideways", "blast_radius": null, "rollback": "revert", "risk": null, "touches": ["docs", "styles", ""], "reasons": [], "errors": ["touches has an empty element", "duplicate key: rollback", "unknown key: foo", "reasons must be a `- item` list or an inline list", "unsupported line: junk", "missing key: blast_radius", "missing key: risk", "door: \'sideways\' is not one of one-way | two-way", "unknown category: styles", "reasons must have at least one item"]}\n'], 'bad:validate': [1, "touches has an empty element\nduplicate key: rollback\nunknown key: foo\nreasons must be a `- item` list or an inline list\nunsupported line: junk\nmissing key: blast_radius\nmissing key: risk\ndoor: 'sideways' is not one of one-way | two-way\nunknown category: styles\nreasons must have at least one item\n"], 'emptyreasons:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "risk": 1, "touches": ["docs", "tests"], "reasons": [], "errors": ["reasons must have at least one item"]}\n'], 'emptyreasons:validate': [1, 'reasons must have at least one item\n'], 'badreasons:parse': [0, '{"door": "two-way", "blast_radius": "isolated", "rollback": "revert", "risk": 1, "touches": ["docs", "tests"], "reasons": [], "errors": ["unsupported reason form: a: b", "empty reason", "unsupported reason form: [x]", "malformed quoted reason: \'q\'x\'", "reasons must have at least one item"]}\n'], 'badreasons:validate': [1, "unsupported reason form: a: b\nempty reason\nunsupported reason form: [x]\nmalformed quoted reason: 'q'x'\nreasons must have at least one item\n"]}
|
|
18
19
|
|
|
19
|
-
GATE_GOLDEN = '{"verdict": "human", "reasons": ["diff touches logic, not in touches", "
|
|
20
|
+
GATE_GOLDEN = '{"verdict": "human", "reasons": ["policy: no .merge-risk.json on the base", "diff touches logic, not in touches", "risk 4 > max auto risk 3"], "risk": 4, "maxAutoRisk": 3, "categories": ["docs", "logic"], "countedLines": 1}\n'
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def complexity(fn):
|
|
@@ -6,11 +6,16 @@ body{font:14px system-ui,sans-serif;margin:24px;color:#222;overflow-wrap:break-w
|
|
|
6
6
|
.gauge{grid-row:span 3;display:grid;grid-template-rows:subgrid;row-gap:4px;align-content:start;margin-bottom:12px;border:2px solid #ccc;border-radius:8px;padding:12px;background:#fff;text-align:center;cursor:pointer;font:inherit}
|
|
7
7
|
.gauge>*{align-self:start}
|
|
8
8
|
.gauge-status{font-size:12px;line-height:1.3}
|
|
9
|
+
/* with a red suite, each short reason wraps inside only when it alone is wider than the card, so a line never splits
|
|
10
|
+
"172 tests not green"; a lone "0 of 4 metrics measured" flows as text */
|
|
11
|
+
.gauge-status.red>span{display:inline-block}
|
|
9
12
|
/* one row of tabs on a rule; it scrolls sideways when the row is wider than the screen */
|
|
10
13
|
.tabs{display:flex;gap:4px;overflow-x:auto;border-bottom:1px solid #ccc;scrollbar-width:thin}
|
|
11
|
-
.tabs>button{flex:none;font:inherit;padding:4px 12px;border:1px solid #ccc;border-bottom:3px solid transparent;border-radius:6px 6px 0 0;background:#f3f4f6;color:#222;cursor:pointer;white-space:nowrap}
|
|
14
|
+
.tabs>button{flex:none;display:inline-flex;flex-direction:column;align-items:center;font:inherit;padding:4px 12px;border:1px solid #ccc;border-bottom:3px solid transparent;border-radius:6px 6px 0 0;background:#f3f4f6;color:#222;cursor:pointer;white-space:nowrap}
|
|
12
15
|
.tabs>button[aria-pressed=true]{background:#2563eb;color:#fff;border-bottom-color:#1e40af;font-weight:600}
|
|
13
|
-
|
|
16
|
+
/* every tab is as wide as its bold label, so selecting one moves no other; hidden, so screen readers skip it */
|
|
17
|
+
.tabs>button::after{content:attr(data-label);content:attr(data-label)/"";font-weight:600;height:0;overflow:hidden;visibility:hidden;pointer-events:none}
|
|
18
|
+
@media (max-width:600px){.tabs{gap:2px}.tabs>button{padding:4px 6px}}
|
|
14
19
|
button:focus-visible{outline:3px solid #f59e0b;outline-offset:2px}
|
|
15
20
|
#details table{width:100%}
|
|
16
21
|
#details tr+tr{border-top:1px solid #e5e7eb}
|
|
@@ -29,7 +34,15 @@ table{border-collapse:collapse}td,th{padding:4px 12px;text-align:left}
|
|
|
29
34
|
@media (min-width:601px){#details th:nth-child(-n+3),#details td:nth-child(-n+3):not([colspan]){width:1%;white-space:nowrap}}
|
|
30
35
|
td:first-child,th:first-child{padding-left:0}
|
|
31
36
|
@media (max-width:600px){td,th{padding:4px 6px}td:last-child,th:last-child{padding-right:0}#details td:first-child{min-width:7em}}
|
|
32
|
-
input[type=search]{font:inherit;padding:6px 10px;border:1px solid #ccc;border-radius:6px;width:100%;max-width:24rem;box-sizing:border-box}
|
|
37
|
+
input[type=search]{scroll-margin-top:16px;font:inherit;padding:6px 10px;border:1px solid #ccc;border-radius:6px;width:100%;max-width:24rem;box-sizing:border-box}
|
|
38
|
+
/* the pair count and a pager above the list, the same pager again below it; the pager keeps to the right */
|
|
39
|
+
.ov-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 16px;margin:12px 0}
|
|
40
|
+
.ov-bar>p{margin:0}
|
|
41
|
+
.pager{display:flex;align-items:center;gap:8px;margin-left:auto}
|
|
42
|
+
.pager>span{white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
43
|
+
.pager>button{font:inherit;min-height:32px;padding:0 12px;border:1px solid #ccc;border-radius:6px;background:#f3f4f6;color:#222;cursor:pointer}
|
|
44
|
+
.pager>button:disabled{color:#9ca3af;cursor:default}
|
|
45
|
+
@media (max-width:600px){.pager>button{min-height:44px;padding:0 14px}}
|
|
33
46
|
.pair{display:grid;grid-template-columns:8em minmax(0,1fr);gap:4px 12px;padding:8px 0;border-bottom:1px solid #e5e7eb}
|
|
34
47
|
.pair>strong{grid-row:span 3}
|
|
35
48
|
.pair hr{width:100%;border:0;border-top:1px dashed #d1d5db;margin:0}
|
|
@@ -140,13 +153,34 @@ function drawMap(parent) {
|
|
|
140
153
|
const pickedName = el('p', '', side); pickedName.setAttribute('data-testid', 'map-picked');
|
|
141
154
|
const list = el('div', '', side); list.setAttribute('data-testid', 'map-similar');
|
|
142
155
|
let lit = [];
|
|
156
|
+
// the selected dot's own mark, unlike the blue rings of its similar dots: the dot again, then an ink ring on a white
|
|
157
|
+
// rim 5 px out from it (at least 18 px across on any screen), all drawn after every dot so no neighbour covers it;
|
|
158
|
+
// clicks pass through to the dots beneath
|
|
159
|
+
const mark = document.createElementNS(NS, 'g');
|
|
160
|
+
mark.setAttribute('data-testid', 'map-selected'); mark.setAttribute('pointer-events', 'none'); mark.setAttribute('display', 'none');
|
|
161
|
+
const copy = mark.appendChild(document.createElementNS(NS, 'circle'));
|
|
162
|
+
const rings = [['#fff', 5], ['#222', 2.5]].map(([stroke, width]) => {
|
|
163
|
+
const c = document.createElementNS(NS, 'circle');
|
|
164
|
+
c.setAttribute('fill', 'none'); c.setAttribute('stroke', stroke); c.setAttribute('stroke-width', width);
|
|
165
|
+
c.setAttribute('vector-effect', 'non-scaling-stroke');
|
|
166
|
+
return mark.appendChild(c);
|
|
167
|
+
});
|
|
168
|
+
svg.appendChild(mark);
|
|
143
169
|
// selection touches only the previous and the new highlights and the neighbour list, never the placement
|
|
144
170
|
const pick = (d) => {
|
|
145
171
|
picked = d;
|
|
146
172
|
lit.forEach((c) => { c.setAttribute('stroke', 'none'); delete c.dataset.highlighted; });
|
|
147
173
|
const sims = d.similar.slice().sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
148
|
-
|
|
174
|
+
// only the similar dots get a blue ring; the selected one shows through its own mark below
|
|
175
|
+
lit = sims.map(([n]) => circles.get(n)).filter(Boolean);
|
|
149
176
|
lit.forEach((c) => { c.setAttribute('stroke', '#2563eb'); c.dataset.highlighted = 'true'; });
|
|
177
|
+
// the drawing's pixels per unit; 1 where nothing is laid out
|
|
178
|
+
const dot = circles.get(d.test), scale = svg.getBoundingClientRect().width / w || 1;
|
|
179
|
+
const r = Number(dot.getAttribute('r')), ring = Math.max(r + 5 / scale, 9 / scale);
|
|
180
|
+
[copy, ...rings].forEach((c) => { c.setAttribute('cx', dot.getAttribute('cx')); c.setAttribute('cy', dot.getAttribute('cy')); });
|
|
181
|
+
copy.setAttribute('r', r); copy.setAttribute('fill', dot.getAttribute('fill'));
|
|
182
|
+
rings.forEach((c) => c.setAttribute('r', ring));
|
|
183
|
+
mark.removeAttribute('display');
|
|
150
184
|
hint.hidden = true;
|
|
151
185
|
pickedName.replaceChildren();
|
|
152
186
|
el('strong', 'Selected', pickedName); el('br', '', pickedName); ident(el('span', d.test, pickedName));
|
|
@@ -176,15 +210,35 @@ function drawOverlaps(parent) {
|
|
|
176
210
|
input.type = 'search'; input.placeholder = 'Search test identities'; input.value = ovQuery; input.setAttribute('aria-label', 'Search overlapping tests');
|
|
177
211
|
input.setAttribute('data-testid', 'overlap-search');
|
|
178
212
|
box.appendChild(input);
|
|
179
|
-
const
|
|
213
|
+
const bar = el('div', '', box); bar.className = 'ov-bar';
|
|
214
|
+
const count = el('p', '', bar); count.setAttribute('data-testid', 'overlap-count');
|
|
215
|
+
const empty = el('p', 'No pair matches this search.', box); empty.setAttribute('data-testid', 'overlap-empty');
|
|
216
|
+
const list = el('div', '', box);
|
|
217
|
+
const foot = el('div', '', box); foot.className = 'ov-bar';
|
|
218
|
+
// the same pager above and below the list; after a page turn focus is on the top one, so paging from the bottom
|
|
219
|
+
// brings the reader back to the start of the new page instead of leaving them 100 rows down
|
|
220
|
+
const pager = (parent, label, suffix) => {
|
|
221
|
+
const nav = el('nav', '', parent); nav.className = 'pager'; nav.setAttribute('aria-label', label);
|
|
222
|
+
const step = (text, d, id) => { const b = el('button', text, nav); b.setAttribute('data-testid', id + suffix); b.onclick = () => turn(d, suffix !== ''); return b; };
|
|
223
|
+
// the counter before the buttons, so its width changing (page 9 to 10) never moves a button
|
|
224
|
+
const at = el('span', '', nav); at.setAttribute('data-testid', 'overlap-page' + suffix);
|
|
225
|
+
return { at, prev: step('Previous', -1, 'overlap-prev'), next: step('Next', 1, 'overlap-next') };
|
|
226
|
+
};
|
|
227
|
+
const top = pager(bar, 'Pages of pairs', ''), bottom = pager(foot, 'Pages of pairs, end of list', '-bottom');
|
|
228
|
+
top.at.setAttribute('aria-live', 'polite');
|
|
229
|
+
const turn = (d, fromBottom) => {
|
|
230
|
+
ovPage += d; draw();
|
|
231
|
+
if (fromBottom) input.scrollIntoView?.({ block: 'start' }); // jsdom has no scrollIntoView
|
|
232
|
+
const [ahead, back] = d < 0 ? [top.prev, top.next] : [top.next, top.prev];
|
|
233
|
+
(ahead.disabled ? back : ahead).focus({ preventScroll: true });
|
|
234
|
+
};
|
|
180
235
|
const draw = () => {
|
|
181
|
-
out.replaceChildren();
|
|
182
236
|
const q = ovQuery.toLowerCase();
|
|
183
237
|
const hits = q ? ranked.filter((o) => o.tests.some((t) => t.toLowerCase().includes(q))) : ranked;
|
|
184
238
|
const pages = Math.max(1, Math.ceil(hits.length / PAGE));
|
|
185
239
|
ovPage = Math.min(ovPage, pages - 1);
|
|
186
|
-
|
|
187
|
-
if (
|
|
240
|
+
count.textContent = hits.length.toLocaleString('en-US') + (hits.length === 1 ? ' pair' : ' pairs');
|
|
241
|
+
if (hits.length) empty.remove(); else bar.after(empty);
|
|
188
242
|
// a page is built off the page and attached once: one insertion instead of hundreds
|
|
189
243
|
const rows = document.createDocumentFragment();
|
|
190
244
|
hits.slice(ovPage * PAGE, (ovPage + 1) * PAGE).forEach((o) => {
|
|
@@ -194,12 +248,8 @@ function drawOverlaps(parent) {
|
|
|
194
248
|
// the two tests on their own lines, a dashed rule between them
|
|
195
249
|
o.tests.forEach((t, k) => { if (k) el('hr', '', row); testLine('div', t, row).setAttribute('data-testid', 'overlap-test'); });
|
|
196
250
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const step = (text, d, id) => { const b = el('button', text, nav); b.setAttribute('data-testid', id); b.disabled = ovPage + d < 0 || ovPage + d >= pages; b.onclick = () => { ovPage += d; draw(); }; };
|
|
200
|
-
step('Previous', -1, 'overlap-prev');
|
|
201
|
-
el('span', ' Page ' + (ovPage + 1) + ' of ' + pages + ' ', nav);
|
|
202
|
-
step('Next', 1, 'overlap-next');
|
|
251
|
+
list.replaceChildren(rows);
|
|
252
|
+
[top, bottom].forEach((p) => { p.at.textContent = 'Page ' + (ovPage + 1) + ' of ' + pages; p.prev.disabled = ovPage === 0; p.next.disabled = ovPage === pages - 1; });
|
|
203
253
|
};
|
|
204
254
|
input.oninput = () => { ovQuery = input.value; ovPage = 0; draw(); };
|
|
205
255
|
draw();
|
|
@@ -218,18 +268,21 @@ function render() {
|
|
|
218
268
|
g.setAttribute('aria-pressed', i === selected);
|
|
219
269
|
el('span', p.name, g).setAttribute('data-testid', 'gauge-title');
|
|
220
270
|
el('span', p.score === null ? '–' : shown(p.score), g).className = 'score';
|
|
221
|
-
const
|
|
222
|
-
status
|
|
271
|
+
const { head, reasons } = p.status;
|
|
272
|
+
const status = el('span', head, g);
|
|
273
|
+
reasons.forEach((r, k) => { status.append(' '); el('span', r + (k < reasons.length - 1 ? ';' : ''), status); });
|
|
274
|
+
status.className = 'gauge-status' + (reasons.length ? ' flag' : '') + (p.red_suite ? ' red' : ''); status.setAttribute('data-testid', 'gauge-status');
|
|
223
275
|
g.onclick = () => { selected = i; tab = 'Metrics'; picked = null; render(); };
|
|
224
276
|
});
|
|
225
277
|
const p = data.pillars[selected];
|
|
226
278
|
el('h2', p.name, details);
|
|
227
279
|
const names = ['Metrics', 'Worst tests', 'Smells', ...(p.key === 'economy' ? ['Overlaps', 'Map'] : [])];
|
|
228
280
|
const tabs = el('div', '', details); tabs.className = 'tabs';
|
|
229
|
-
names.forEach((n) => { const b = el('button', n, tabs); b.setAttribute('aria-pressed', n === tab); b.onclick = () => { tab = n; picked = null; render(); }; });
|
|
281
|
+
names.forEach((n) => { const b = el('button', n, tabs); b.dataset.label = n; b.setAttribute('aria-pressed', n === tab); b.onclick = () => { tab = n; picked = null; render(); }; });
|
|
230
282
|
el('h3', tab, details);
|
|
231
283
|
if (tab === 'Metrics') {
|
|
232
284
|
if (!p.metrics.length) el('p', 'No metrics were measured for this pillar.', details);
|
|
285
|
+
if (p.status.note) el('p', p.status.note, details).setAttribute('data-testid', 'partial-reason');
|
|
233
286
|
const t = el('table', '', details);
|
|
234
287
|
const head = el('tr', '', t);
|
|
235
288
|
['Metric', 'Value', 'Score', 'Anchors'].forEach((h) => el('th', h, head));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"""Ticket 04 browser driver: `uv run --with playwright python browser_driver.py <dashboard.html
|
|
2
|
-
report from disk in Chrome with the network switched off, drives the visible controls and prints one JSON
|
|
3
|
-
measurements on stdout
|
|
1
|
+
"""Ticket 04 browser driver: `uv run --with playwright python browser_driver.py <dashboard.html> [--gauges]` opens the
|
|
2
|
+
standalone report from disk in Chrome with the network switched off, drives the visible controls and prints one JSON
|
|
3
|
+
document of measurements on stdout; with --gauges it measures only the overview gauges at both viewports. It asserts
|
|
4
|
+
nothing: test_dashboard_layout.py reads the measurements.
|
|
4
5
|
|
|
5
6
|
Page interface the acceptance tests pin, on top of the earlier tickets' markup (metric/overlap/map tabs):
|
|
6
7
|
[data-testid=gauge-title] inside every [data-testid=gauge]: the pillar title
|
|
@@ -25,8 +26,11 @@ GAUGES = """() => [...document.querySelectorAll('[data-testid=gauge]')].map((g)
|
|
|
25
26
|
return {top: Math.round(r.top), left: Math.round(r.left), width: Math.round(r.width), height: Math.round(r.height),
|
|
26
27
|
lines: Math.round(r.height / (parseFloat(s.lineHeight) || 1.2 * parseFloat(s.fontSize))), font: parseFloat(s.fontSize),
|
|
27
28
|
clipped: e.scrollWidth > e.clientWidth + 1 || e.scrollHeight > e.clientHeight + 1, text: e.textContent.trim()}; };
|
|
29
|
+
const status = g.querySelector('[data-testid=gauge-status]'), lh = (e) => parseFloat(getComputedStyle(e).lineHeight);
|
|
30
|
+
// the lines each reason of the status spans: an inline one breaks into rects, an inline-block one grows taller
|
|
31
|
+
const reasons = status ? [...status.children].map((s) => Math.max(s.getClientRects().length, Math.round(s.getBoundingClientRect().height / lh(s)))) : [];
|
|
28
32
|
return {card: box(g), title: box(g.querySelector('[data-testid=gauge-title]')), score: box(g.querySelector('.score')),
|
|
29
|
-
status: box(
|
|
33
|
+
status: box(status), reasons};
|
|
30
34
|
})"""
|
|
31
35
|
|
|
32
36
|
SIG = """(el) => { const s = getComputedStyle(el);
|
|
@@ -58,6 +62,15 @@ def table_share(page):
|
|
|
58
62
|
return t ? t.getBoundingClientRect().width / d.getBoundingClientRect().width : null; }""")
|
|
59
63
|
|
|
60
64
|
|
|
65
|
+
def overview(browser, width, height):
|
|
66
|
+
page = browser.new_page(viewport={"width": width, "height": height})
|
|
67
|
+
page.goto(URL)
|
|
68
|
+
page.wait_for_selector(GAUGE)
|
|
69
|
+
out = {"gauges": page.evaluate(GAUGES), "overview": page.evaluate(OVERFLOW)}
|
|
70
|
+
page.close()
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
|
|
61
74
|
def layout(browser, width, height):
|
|
62
75
|
page = browser.new_page(viewport={"width": width, "height": height})
|
|
63
76
|
page.goto(URL)
|
|
@@ -71,6 +84,8 @@ def layout(browser, width, height):
|
|
|
71
84
|
click_gauge(page, "Economy")
|
|
72
85
|
click_tab(page, "Overlaps")
|
|
73
86
|
out["overlaps"] = page.evaluate(OVERFLOW)
|
|
87
|
+
out["pager_heights"] = page.evaluate("""() => Object.fromEntries(['overlap-next', 'overlap-next-bottom'].map((id) =>
|
|
88
|
+
[id, document.querySelector(`[data-testid=${id}]`).getBoundingClientRect().height]))""")
|
|
74
89
|
out["overlap_ids"] = page.evaluate("""() => [...document.querySelectorAll('[data-testid=overlap-test]')].map((e) => {
|
|
75
90
|
const r = e.getBoundingClientRect(), s = getComputedStyle(e);
|
|
76
91
|
return {text: e.textContent, right: Math.round(r.right), clipped: e.scrollWidth > e.clientWidth + 1 && s.overflowX !== 'visible',
|
|
@@ -101,6 +116,27 @@ def tab_styles(browser):
|
|
|
101
116
|
return {"steps": steps, "focus": focus}
|
|
102
117
|
|
|
103
118
|
|
|
119
|
+
TAB_BOXES = """() => { const row = document.querySelector('[data-testid=details] .tabs'), o = row.getBoundingClientRect();
|
|
120
|
+
return [...row.querySelectorAll('button')].map((b) => { const r = b.getBoundingClientRect();
|
|
121
|
+
return {text: b.textContent.trim(), left: r.left - o.left + row.scrollLeft, width: r.width}; }); }"""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def tab_boxes(browser, width, height):
|
|
125
|
+
"""Each tab's unrounded box in its row (scroll-independent) after every tab of Economy is selected in turn."""
|
|
126
|
+
page = browser.new_page(viewport={"width": width, "height": height})
|
|
127
|
+
page.goto(URL)
|
|
128
|
+
page.wait_for_selector(GAUGE)
|
|
129
|
+
click_gauge(page, "Economy")
|
|
130
|
+
labels = [b["text"] for b in page.evaluate(TAB_BOXES)]
|
|
131
|
+
steps = {}
|
|
132
|
+
for label in labels:
|
|
133
|
+
click_tab(page, label)
|
|
134
|
+
steps[label] = page.evaluate(TAB_BOXES)
|
|
135
|
+
out = {"steps": steps, "overview": page.evaluate(OVERFLOW)}
|
|
136
|
+
page.close()
|
|
137
|
+
return out
|
|
138
|
+
|
|
139
|
+
|
|
104
140
|
def journey(browser):
|
|
105
141
|
context = browser.new_context(viewport={"width": 1440, "height": 900}, offline=True)
|
|
106
142
|
requests = []
|
|
@@ -156,6 +192,11 @@ with sync_playwright() as p:
|
|
|
156
192
|
browser = p.chromium.launch(channel="chrome")
|
|
157
193
|
except Exception:
|
|
158
194
|
browser = p.chromium.launch()
|
|
159
|
-
|
|
195
|
+
if sys.argv[2:] == ["--gauges"]:
|
|
196
|
+
result = {"desktop": overview(browser, 1440, 900), "narrow": overview(browser, 390, 844)}
|
|
197
|
+
else:
|
|
198
|
+
result = {"desktop": layout(browser, 1440, 900), "narrow": layout(browser, 390, 844), "tabs": tab_styles(browser),
|
|
199
|
+
"tab_boxes": {"desktop": tab_boxes(browser, 1440, 900), "narrow": tab_boxes(browser, 390, 844)},
|
|
200
|
+
"journey": journey(browser)}
|
|
160
201
|
browser.close()
|
|
161
202
|
print(json.dumps(result))
|