claude-dev-env 8.123.0 → 8.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ever-registered-hooks.mjs +2 -0
- package/bin/ever-registered-hooks.test.mjs +5 -0
- package/bin/profile-stop-gate.mjs +5 -7
- package/bin/profile-stop-gate.test.mjs +29 -1
- package/docs/agents-guidance/asks.md +1 -1
- package/docs/rule-guides/question-presentation.md +1 -1
- package/docs/templates/artifact-page/README.md +14 -1
- package/docs/templates/artifact-page/review-rounds.md +1 -1
- package/docs/templates/artifact-page/template.html +26 -18
- package/docs/templates/html-plan/README.md +4 -0
- package/hooks/blocking/artifact_current_page_fixtures/piled_review_page.html +399 -0
- package/hooks/blocking/artifact_current_page_fixtures/rebuilt_review_page.html +403 -0
- package/hooks/blocking/artifact_current_page_gate.py +418 -0
- package/hooks/blocking/artifact_repeated_item_render.cjs +112 -0
- package/hooks/blocking/closing_reply_judge.py +332 -0
- package/hooks/blocking/closing_reply_shapes.py +365 -0
- package/hooks/blocking/conftest.py +84 -0
- package/hooks/blocking/open_tasks_stop_gate.py +259 -11
- package/hooks/blocking/open_tasks_transcript.py +55 -2
- package/hooks/blocking/open_tasks_transcript_records.py +67 -1
- package/hooks/blocking/question_brief_gate.py +6 -4
- package/hooks/blocking/test_artifact_current_page_gate.py +415 -0
- package/hooks/blocking/test_closing_reply_judge.py +246 -0
- package/hooks/blocking/test_closing_reply_shapes.py +247 -0
- package/hooks/blocking/test_open_tasks_stop_gate.py +626 -0
- package/hooks/blocking/test_open_tasks_transcript.py +57 -0
- package/hooks/blocking/test_open_tasks_transcript_records.py +48 -0
- package/hooks/blocking/test_question_brief_gate.py +22 -0
- package/hooks/features/conduct-gates.md +10 -3
- package/hooks/hooks.json +16 -1
- package/hooks/hooks_constants/artifact_current_page_gate_constants.py +91 -0
- package/hooks/hooks_constants/artifact_dark_mode_gate_constants.py +3 -3
- package/hooks/hooks_constants/closing_reply_judge_constants.py +143 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +101 -0
- package/hooks/hooks_constants/test_artifact_current_page_gate_constants.py +53 -0
- package/hooks/hooks_constants/test_artifact_dark_mode_gate_constants.py +6 -0
- package/hooks/hooks_constants/test_hook_time_budget.py +7 -0
- package/hooks/once_per_session.py +65 -1
- package/hooks/session/artifact_link_record.py +109 -0
- package/hooks/session/test_artifact_link_record.py +101 -0
- package/hooks/test_context_budget_hooks.py +2 -0
- package/hooks/test_once_per_session.py +35 -0
- package/package.json +1 -1
- package/scripts/policy_lint/adapter_configuration.py +6 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
|
@@ -254,7 +254,8 @@ def brief_before_question(all_entries: Iterable[dict], tool_use_id: str) -> str
|
|
|
254
254
|
return None
|
|
255
255
|
|
|
256
256
|
|
|
257
|
-
def
|
|
257
|
+
def lines_outside_code_fences(brief_text: str) -> list[str]:
|
|
258
|
+
"""Return each line of the text that sits outside a code fence; the fence lines themselves are left out."""
|
|
258
259
|
all_outside_lines: list[str] = []
|
|
259
260
|
is_inside_fence = False
|
|
260
261
|
for each_line in brief_text.splitlines():
|
|
@@ -266,7 +267,8 @@ def _lines_outside_code_fences(brief_text: str) -> list[str]:
|
|
|
266
267
|
return all_outside_lines
|
|
267
268
|
|
|
268
269
|
|
|
269
|
-
def
|
|
270
|
+
def is_item_line(line: str, next_line: str) -> bool:
|
|
271
|
+
"""Return True for a bullet, a numbered line, or a table body row; a table header or separator row is no item."""
|
|
270
272
|
if LIST_ITEM_LINE_PATTERN.match(line):
|
|
271
273
|
return True
|
|
272
274
|
return bool(
|
|
@@ -288,9 +290,9 @@ def count_list_items(brief_text: str) -> int:
|
|
|
288
290
|
"| # | What |\\n|---|---|\\n| 1 | x |" -> 1
|
|
289
291
|
"```\\n- a\\n- b\\n```" -> 0
|
|
290
292
|
"""
|
|
291
|
-
all_lines =
|
|
293
|
+
all_lines = lines_outside_code_fences(brief_text)
|
|
292
294
|
return sum(
|
|
293
|
-
|
|
295
|
+
is_item_line(each_line, each_next_line)
|
|
294
296
|
for each_line, each_next_line in zip(all_lines, [*all_lines[1:], ""], strict=False)
|
|
295
297
|
)
|
|
296
298
|
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"""Behavior tests for the artifact current page publish gate."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from collections import Counter
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
16
|
+
|
|
17
|
+
from blocking.artifact_current_page_gate import (
|
|
18
|
+
format_repeat_reason,
|
|
19
|
+
full_rule_pointer,
|
|
20
|
+
is_artifact_link,
|
|
21
|
+
link_record_path,
|
|
22
|
+
page_source_after_edits,
|
|
23
|
+
page_title,
|
|
24
|
+
recorded_page_link,
|
|
25
|
+
repeated_items,
|
|
26
|
+
)
|
|
27
|
+
from hooks_constants.artifact_current_page_gate_constants import REPUBLISH_NOTE
|
|
28
|
+
from hooks_constants.artifact_dark_mode_gate_constants import ALLOW_EXIT_CODE, BLOCK_EXIT_CODE
|
|
29
|
+
|
|
30
|
+
GATE_SCRIPT_PATH = Path(__file__).resolve().parent / "artifact_current_page_gate.py"
|
|
31
|
+
FIXTURES_DIRECTORY = Path(__file__).resolve().parent / "artifact_current_page_fixtures"
|
|
32
|
+
PILED_PAGE_PATH = FIXTURES_DIRECTORY / "piled_review_page.html"
|
|
33
|
+
REBUILT_PAGE_PATH = FIXTURES_DIRECTORY / "rebuilt_review_page.html"
|
|
34
|
+
PAGE_LINK = "https://claude.ai/artifact/SamplePageLink01"
|
|
35
|
+
ITEM_IMAGE_STYLE = "<style>img{width:200px;height:300px}</style>"
|
|
36
|
+
PAGE_WITH_ONE_SCREEN = (
|
|
37
|
+
"<title>Sample Run</title>" + ITEM_IMAGE_STYLE + '<img src="screens/home.png" alt="Home">'
|
|
38
|
+
)
|
|
39
|
+
SECOND_DRAW_OF_THE_SCREEN = '<h2>Warnings</h2><img src="screens/home.png" alt="Home again">'
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _renderer_available() -> bool:
|
|
43
|
+
if shutil.which("node") is None:
|
|
44
|
+
return False
|
|
45
|
+
all_repeats, _ = repeated_items("<p>probe</p>")
|
|
46
|
+
return all_repeats is not None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
needs_renderer = pytest.mark.skipif(
|
|
50
|
+
not _renderer_available(), reason="node Playwright with Chromium is not installed"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _run_gate(tool_input: dict[str, object]) -> subprocess.CompletedProcess[str]:
|
|
55
|
+
return subprocess.run(
|
|
56
|
+
[sys.executable, str(GATE_SCRIPT_PATH)],
|
|
57
|
+
input=json.dumps({"tool_name": "Artifact", "tool_input": tool_input}),
|
|
58
|
+
capture_output=True,
|
|
59
|
+
text=True,
|
|
60
|
+
check=False,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _figure_counts_in_data_block(page_path: Path) -> tuple[int, int]:
|
|
65
|
+
data_block = re.search(
|
|
66
|
+
r'<script type="application/json" id="data">(.*?)</script>',
|
|
67
|
+
page_path.read_text(encoding="utf-8"),
|
|
68
|
+
re.DOTALL,
|
|
69
|
+
)
|
|
70
|
+
assert data_block is not None
|
|
71
|
+
page_data = json.loads(data_block.group(1))
|
|
72
|
+
all_screen_lists = [each_group["screens"] for each_group in page_data.get("groups", [])]
|
|
73
|
+
if isinstance(page_data.get("warnings"), list):
|
|
74
|
+
all_screen_lists += [each_warning["screens"] for each_warning in page_data["warnings"]]
|
|
75
|
+
all_screen_lists += [each_section["screens"] for each_section in page_data.get("sections", [])]
|
|
76
|
+
all_screen_lists.append(page_data.get("pick", {}).get("strips", []))
|
|
77
|
+
all_drawn_names = [
|
|
78
|
+
each_screen[0] for each_screen_list in all_screen_lists for each_screen in each_screen_list
|
|
79
|
+
]
|
|
80
|
+
return len(all_drawn_names), len(Counter(all_drawn_names))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_should_keep_the_incident_counts_in_the_reduced_fixtures() -> None:
|
|
84
|
+
assert _figure_counts_in_data_block(PILED_PAGE_PATH) == (33, 20)
|
|
85
|
+
assert _figure_counts_in_data_block(REBUILT_PAGE_PATH) == (20, 20)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_should_apply_an_edit_whose_old_text_occurs_once() -> None:
|
|
89
|
+
assert page_source_after_edits("<p>old</p>", [{"old_str": "old", "new_str": "new"}]) == (
|
|
90
|
+
"<p>new</p>"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_should_leave_the_page_alone_for_an_ambiguous_or_malformed_edit() -> None:
|
|
95
|
+
assert page_source_after_edits("<p>a a</p>", [{"old_str": "a", "new_str": "b"}]) == "<p>a a</p>"
|
|
96
|
+
assert page_source_after_edits("<p>a</p>", [{"old_str": "a"}, "x"]) == "<p>a</p>"
|
|
97
|
+
assert page_source_after_edits("<p>a</p>", None) == "<p>a</p>"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_should_apply_no_edit_when_one_edit_of_the_call_misses() -> None:
|
|
101
|
+
all_edits = [{"old_str": "a", "new_str": "x"}, {"old_str": "missing", "new_str": "y"}]
|
|
102
|
+
assert page_source_after_edits("<p>a b</p>", all_edits) == "<p>a b</p>"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_should_read_the_page_title() -> None:
|
|
106
|
+
assert page_title("<title> Sample Run </title><p>x</p>") == "Sample Run"
|
|
107
|
+
assert page_title("<p>no title</p>") == ""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_should_name_the_record_file_after_the_page_file() -> None:
|
|
111
|
+
assert link_record_path(Path("/work/first-look.html")) == Path(
|
|
112
|
+
"/work/first-look.html.artifact-link.json"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_should_find_no_link_for_a_page_with_no_record(tmp_path: Path) -> None:
|
|
117
|
+
assert recorded_page_link(tmp_path / "page.html", PAGE_WITH_ONE_SCREEN) == ""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_should_read_the_link_from_the_meta_tag_in_the_page(tmp_path: Path) -> None:
|
|
121
|
+
page_source = f'<meta name="artifact-link" content="{PAGE_LINK}">' + PAGE_WITH_ONE_SCREEN
|
|
122
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == PAGE_LINK
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_should_read_the_meta_tag_with_its_attributes_in_either_order(tmp_path: Path) -> None:
|
|
126
|
+
page_source = f"<meta content='{PAGE_LINK}' name='artifact-link'>" + PAGE_WITH_ONE_SCREEN
|
|
127
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == PAGE_LINK
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_should_ignore_a_meta_tag_that_holds_no_artifact_link(tmp_path: Path) -> None:
|
|
131
|
+
page_source = '<meta name="artifact-link" content="<link>">' + PAGE_WITH_ONE_SCREEN
|
|
132
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == ""
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_should_read_the_first_of_two_name_attributes_as_html_does(tmp_path: Path) -> None:
|
|
136
|
+
page_source = (
|
|
137
|
+
f'<meta name="artifact-link" name="other" content="{PAGE_LINK}">' + PAGE_WITH_ONE_SCREEN
|
|
138
|
+
)
|
|
139
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == PAGE_LINK
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_should_tell_an_artifact_link_from_other_values() -> None:
|
|
143
|
+
assert is_artifact_link(PAGE_LINK)
|
|
144
|
+
assert is_artifact_link("https://claude.ai/code/artifact/0e557edc-f0c7")
|
|
145
|
+
assert not is_artifact_link(PAGE_LINK + "/")
|
|
146
|
+
assert not is_artifact_link("<link>")
|
|
147
|
+
assert not is_artifact_link(None)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_should_read_attributes_with_no_space_before_them(tmp_path: Path) -> None:
|
|
151
|
+
for each_meta_tag in (
|
|
152
|
+
f'<meta name="artifact-link"content="{PAGE_LINK}">',
|
|
153
|
+
f'<meta/name="artifact-link" content="{PAGE_LINK}">',
|
|
154
|
+
):
|
|
155
|
+
page_source = each_meta_tag + PAGE_WITH_ONE_SCREEN
|
|
156
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == PAGE_LINK
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_should_read_the_name_attribute_beside_a_prefixed_one(tmp_path: Path) -> None:
|
|
160
|
+
page_source = (
|
|
161
|
+
f'<meta og:name="site" name="artifact-link" content="{PAGE_LINK}">' + PAGE_WITH_ONE_SCREEN
|
|
162
|
+
)
|
|
163
|
+
assert recorded_page_link(tmp_path / "page.html", page_source) == PAGE_LINK
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_should_ignore_a_record_that_holds_no_artifact_link(tmp_path: Path) -> None:
|
|
167
|
+
page_path = tmp_path / "page.html"
|
|
168
|
+
link_record_path(page_path).write_text(json.dumps({"url": "<link>", "title": "Sample Run"}))
|
|
169
|
+
assert recorded_page_link(page_path, PAGE_WITH_ONE_SCREEN) == ""
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_should_read_the_link_from_the_record_beside_the_page(tmp_path: Path) -> None:
|
|
173
|
+
page_path = tmp_path / "page.html"
|
|
174
|
+
link_record_path(page_path).write_text(json.dumps({"url": PAGE_LINK, "title": "Other"}))
|
|
175
|
+
assert recorded_page_link(page_path, PAGE_WITH_ONE_SCREEN) == PAGE_LINK
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_should_find_the_link_of_a_page_renamed_in_its_folder(tmp_path: Path) -> None:
|
|
179
|
+
link_record_path(tmp_path / "page.html").write_text(
|
|
180
|
+
json.dumps({"url": PAGE_LINK, "title": "Sample Run"})
|
|
181
|
+
)
|
|
182
|
+
assert recorded_page_link(tmp_path / "page-v2.html", PAGE_WITH_ONE_SCREEN) == PAGE_LINK
|
|
183
|
+
assert recorded_page_link(tmp_path / "other.html", "<title>Other Page</title>") == ""
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_should_leave_a_separate_page_with_the_same_title_unlinked(tmp_path: Path) -> None:
|
|
187
|
+
first_page_path = tmp_path / "team-a.html"
|
|
188
|
+
first_page_path.write_text(PAGE_WITH_ONE_SCREEN, encoding="utf-8")
|
|
189
|
+
link_record_path(first_page_path).write_text(
|
|
190
|
+
json.dumps({"url": PAGE_LINK, "title": "Sample Run"})
|
|
191
|
+
)
|
|
192
|
+
assert recorded_page_link(tmp_path / "team-b.html", PAGE_WITH_ONE_SCREEN) == ""
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def test_should_skip_an_old_name_record_whose_link_a_present_page_holds(tmp_path: Path) -> None:
|
|
196
|
+
link_record_path(tmp_path / "first-name.html").write_text(
|
|
197
|
+
json.dumps({"url": PAGE_LINK, "title": "Sample Run"})
|
|
198
|
+
)
|
|
199
|
+
renamed_page_path = tmp_path / "second-name.html"
|
|
200
|
+
renamed_page_path.write_text(PAGE_WITH_ONE_SCREEN, encoding="utf-8")
|
|
201
|
+
link_record_path(renamed_page_path).write_text(
|
|
202
|
+
json.dumps({"url": PAGE_LINK, "title": "Sample Run"})
|
|
203
|
+
)
|
|
204
|
+
assert recorded_page_link(tmp_path / "third-page.html", PAGE_WITH_ONE_SCREEN) == ""
|
|
205
|
+
assert recorded_page_link(renamed_page_path, PAGE_WITH_ONE_SCREEN) == PAGE_LINK
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def test_should_name_each_repeated_item_and_its_count() -> None:
|
|
209
|
+
block_reason = format_repeat_reason([{"kind": "image", "item": "screens/home.png", "times": 3}])
|
|
210
|
+
assert "- screens/home.png is drawn 3 times" in block_reason
|
|
211
|
+
assert "Show each item once" in block_reason
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def test_should_point_each_message_at_the_installed_rule_text() -> None:
|
|
215
|
+
rule_pointer = full_rule_pointer()
|
|
216
|
+
assert "Republish a page" in rule_pointer
|
|
217
|
+
assert "artifact-page" in rule_pointer and "README.md" in rule_pointer
|
|
218
|
+
assert format_repeat_reason([]).endswith(rule_pointer)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@needs_renderer
|
|
222
|
+
def test_should_report_the_eleven_repeated_screens_of_the_piled_page() -> None:
|
|
223
|
+
all_repeats, _ = repeated_items(PILED_PAGE_PATH.read_text(encoding="utf-8"))
|
|
224
|
+
assert all_repeats is not None
|
|
225
|
+
assert len(all_repeats) == 11
|
|
226
|
+
assert sorted(each_repeat["times"] for each_repeat in all_repeats) == [2] * 9 + [3, 3]
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@needs_renderer
|
|
230
|
+
def test_should_pass_the_rebuilt_page_that_shows_three_draws_of_one_screen() -> None:
|
|
231
|
+
assert repeated_items(REBUILT_PAGE_PATH.read_text(encoding="utf-8")) == ([], "")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
@needs_renderer
|
|
235
|
+
def test_should_refuse_the_piled_page_that_a_source_tag_count_passes() -> None:
|
|
236
|
+
piled_source = PILED_PAGE_PATH.read_text(encoding="utf-8")
|
|
237
|
+
assert piled_source.count("<img") == 1
|
|
238
|
+
denied_run = _run_gate({"file_path": str(PILED_PAGE_PATH)})
|
|
239
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
240
|
+
assert "screens/sample-theme/screen-12.png is drawn 3 times" in denied_run.stderr
|
|
241
|
+
assert _run_gate({"file_path": str(REBUILT_PAGE_PATH)}).returncode == ALLOW_EXIT_CODE
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@needs_renderer
|
|
245
|
+
def test_should_pass_a_small_icon_used_many_times() -> None:
|
|
246
|
+
icon_row = '<img src="icons/check.png" width="24" height="24" alt="Done">' * 5
|
|
247
|
+
assert repeated_items(icon_row) == ([], "")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@needs_renderer
|
|
251
|
+
def test_should_count_an_image_with_no_size_set_as_an_item() -> None:
|
|
252
|
+
page_source = '<img src="screens/home.png" alt="Home"><p>Later</p><img src="screens/home.png" alt="">'
|
|
253
|
+
all_repeats, _ = repeated_items(page_source)
|
|
254
|
+
assert all_repeats == [{"kind": "image", "item": "screens/home.png", "times": 2}]
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@needs_renderer
|
|
258
|
+
def test_should_count_two_spellings_of_one_image_file_as_one_item() -> None:
|
|
259
|
+
page_source = (
|
|
260
|
+
ITEM_IMAGE_STYLE
|
|
261
|
+
+ '<img src="screens/home.png" alt="Home">'
|
|
262
|
+
+ '<img src="./screens/home.png" alt="Home again">'
|
|
263
|
+
)
|
|
264
|
+
all_repeats, _ = repeated_items(page_source)
|
|
265
|
+
assert all_repeats == [{"kind": "image", "item": "screens/home.png", "times": 2}]
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@needs_renderer
|
|
269
|
+
def test_should_count_a_lazy_image_below_the_first_screen() -> None:
|
|
270
|
+
page_source = (
|
|
271
|
+
'<img src="screens/home.png" alt="Home">'
|
|
272
|
+
'<div style="height:4000px"></div>'
|
|
273
|
+
'<img src="screens/home.png" alt="Home" loading="lazy">'
|
|
274
|
+
)
|
|
275
|
+
all_repeats, _ = repeated_items(page_source)
|
|
276
|
+
assert all_repeats == [{"kind": "image", "item": "screens/home.png", "times": 2}]
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
@needs_renderer
|
|
280
|
+
def test_should_pass_a_thumbnail_whose_full_view_is_hidden() -> None:
|
|
281
|
+
page_source = (
|
|
282
|
+
ITEM_IMAGE_STYLE
|
|
283
|
+
+ '<img src="screens/home.png" alt="Home">'
|
|
284
|
+
+ '<dialog><img src="screens/home.png" alt="Home, full size"></dialog>'
|
|
285
|
+
+ '<details><summary>Full size</summary><img src="screens/home.png" alt="Home"></details>'
|
|
286
|
+
)
|
|
287
|
+
assert repeated_items(page_source) == ([], "")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@needs_renderer
|
|
291
|
+
def test_should_refuse_a_baseline_drawn_beside_each_variant() -> None:
|
|
292
|
+
page_source = (
|
|
293
|
+
ITEM_IMAGE_STYLE
|
|
294
|
+
+ '<img src="screens/baseline.png" alt="Baseline"><img src="screens/variant-a.png" alt="A">'
|
|
295
|
+
+ '<img src="screens/baseline.png" alt="Baseline"><img src="screens/variant-b.png" alt="B">'
|
|
296
|
+
)
|
|
297
|
+
all_repeats, _ = repeated_items(page_source)
|
|
298
|
+
assert all_repeats == [{"kind": "image", "item": "screens/baseline.png", "times": 2}]
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@needs_renderer
|
|
302
|
+
def test_should_refuse_two_drawn_elements_with_one_item_key() -> None:
|
|
303
|
+
page_source = (
|
|
304
|
+
'<article data-item="release-date">Pick a release date</article>'
|
|
305
|
+
'<article data-item="login-test">Flaky login test</article>'
|
|
306
|
+
'<article data-item="release-date">Pick a release date</article>'
|
|
307
|
+
'<article data-item="login-test" hidden>Flaky login test</article>'
|
|
308
|
+
)
|
|
309
|
+
all_repeats, _ = repeated_items(page_source)
|
|
310
|
+
assert all_repeats == [{"kind": "data-item", "item": "release-date", "times": 2}]
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@needs_renderer
|
|
314
|
+
def test_should_refuse_an_edit_that_adds_a_second_draw_of_a_screen(tmp_path: Path) -> None:
|
|
315
|
+
page_path = tmp_path / "page.html"
|
|
316
|
+
page_path.write_text(PAGE_WITH_ONE_SCREEN + "<footer>End</footer>", encoding="utf-8")
|
|
317
|
+
all_edits = [
|
|
318
|
+
{
|
|
319
|
+
"old_str": "<footer>End</footer>",
|
|
320
|
+
"new_str": SECOND_DRAW_OF_THE_SCREEN + "<footer>End</footer>",
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
assert _run_gate({"file_path": str(page_path)}).returncode == ALLOW_EXIT_CODE
|
|
324
|
+
denied_run = _run_gate({"file_path": str(page_path), "edits": all_edits})
|
|
325
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
326
|
+
assert "screens/home.png is drawn 2 times" in denied_run.stderr
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
@needs_renderer
|
|
330
|
+
def test_should_refuse_a_second_link_and_allow_the_recorded_one(tmp_path: Path) -> None:
|
|
331
|
+
page_path = tmp_path / "page.html"
|
|
332
|
+
page_path.write_text(PAGE_WITH_ONE_SCREEN, encoding="utf-8")
|
|
333
|
+
first_publish = _run_gate({"file_path": str(page_path)})
|
|
334
|
+
assert first_publish.returncode == ALLOW_EXIT_CODE
|
|
335
|
+
assert first_publish.stdout == ""
|
|
336
|
+
link_record_path(page_path).write_text(json.dumps({"url": PAGE_LINK, "title": "Sample Run"}))
|
|
337
|
+
denied_run = _run_gate({"file_path": str(page_path)})
|
|
338
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
339
|
+
assert PAGE_LINK in denied_run.stderr
|
|
340
|
+
assert "When the user asks for a separate copy" in denied_run.stderr
|
|
341
|
+
assert "page.html.artifact-link.json" in denied_run.stderr
|
|
342
|
+
allowed_run = _run_gate({"file_path": str(page_path), "url": PAGE_LINK})
|
|
343
|
+
assert allowed_run.returncode == ALLOW_EXIT_CODE
|
|
344
|
+
assert (
|
|
345
|
+
REPUBLISH_NOTE in json.loads(allowed_run.stdout)["hookSpecificOutput"]["additionalContext"]
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def test_should_name_every_place_that_keeps_the_link(tmp_path: Path) -> None:
|
|
350
|
+
page_path = tmp_path / "page.html"
|
|
351
|
+
page_path.write_text(
|
|
352
|
+
f'<meta name="artifact-link" content="{PAGE_LINK}">' + PAGE_WITH_ONE_SCREEN,
|
|
353
|
+
encoding="utf-8",
|
|
354
|
+
)
|
|
355
|
+
link_record_path(page_path).write_text(json.dumps({"url": PAGE_LINK, "title": "Sample Run"}))
|
|
356
|
+
denied_run = _run_gate({"file_path": str(page_path)})
|
|
357
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
358
|
+
assert "the artifact-link meta tag from the page and " in denied_run.stderr
|
|
359
|
+
assert "page.html.artifact-link.json, then publish" in denied_run.stderr
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def test_should_name_each_old_name_record_of_a_page_renamed_twice(tmp_path: Path) -> None:
|
|
363
|
+
for each_old_name in ("first-name.html", "second-name.html"):
|
|
364
|
+
link_record_path(tmp_path / each_old_name).write_text(
|
|
365
|
+
json.dumps({"url": PAGE_LINK, "title": "Sample Run"})
|
|
366
|
+
)
|
|
367
|
+
page_path = tmp_path / "third-name.html"
|
|
368
|
+
page_path.write_text(PAGE_WITH_ONE_SCREEN, encoding="utf-8")
|
|
369
|
+
denied_run = _run_gate({"file_path": str(page_path)})
|
|
370
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
371
|
+
assert "first-name.html.artifact-link.json" in denied_run.stderr
|
|
372
|
+
assert "second-name.html.artifact-link.json" in denied_run.stderr
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def test_should_name_the_other_link_a_second_place_holds(tmp_path: Path) -> None:
|
|
376
|
+
other_link = "https://claude.ai/artifact/OtherPageLink02"
|
|
377
|
+
page_path = tmp_path / "page.html"
|
|
378
|
+
page_path.write_text(
|
|
379
|
+
f'<meta name="artifact-link" content="{PAGE_LINK}">' + PAGE_WITH_ONE_SCREEN,
|
|
380
|
+
encoding="utf-8",
|
|
381
|
+
)
|
|
382
|
+
link_record_path(page_path).write_text(json.dumps({"url": other_link, "title": "Sample Run"}))
|
|
383
|
+
denied_run = _run_gate({"file_path": str(page_path)})
|
|
384
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
385
|
+
assert f"This page already has a link: {PAGE_LINK}" in denied_run.stderr
|
|
386
|
+
assert f"page.html.artifact-link.json (it holds {other_link})" in denied_run.stderr
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def test_should_refuse_a_call_url_that_is_no_artifact_link(tmp_path: Path) -> None:
|
|
390
|
+
page_path = tmp_path / "page.html"
|
|
391
|
+
page_path.write_text(PAGE_WITH_ONE_SCREEN, encoding="utf-8")
|
|
392
|
+
link_record_path(page_path).write_text(json.dumps({"url": PAGE_LINK, "title": "Sample Run"}))
|
|
393
|
+
denied_run = _run_gate({"file_path": str(page_path), "url": PAGE_LINK + "/"})
|
|
394
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
395
|
+
assert PAGE_LINK in denied_run.stderr
|
|
396
|
+
assert f"The url {PAGE_LINK}/ in this call is not an artifact link" in denied_run.stderr
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
@needs_renderer
|
|
400
|
+
def test_should_check_a_page_saved_in_another_text_encoding(tmp_path: Path) -> None:
|
|
401
|
+
page_path = tmp_path / "page.html"
|
|
402
|
+
page_path.write_bytes(
|
|
403
|
+
(PAGE_WITH_ONE_SCREEN + "<p>Caf\u00e9</p>" + SECOND_DRAW_OF_THE_SCREEN).encode("latin-1")
|
|
404
|
+
)
|
|
405
|
+
denied_run = _run_gate({"file_path": str(page_path)})
|
|
406
|
+
assert denied_run.returncode == BLOCK_EXIT_CODE
|
|
407
|
+
assert "screens/home.png is drawn 2 times" in denied_run.stderr
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def test_should_allow_reads_assets_and_other_tools(tmp_path: Path) -> None:
|
|
411
|
+
page_path = tmp_path / "page.html"
|
|
412
|
+
page_path.write_text(PAGE_WITH_ONE_SCREEN + SECOND_DRAW_OF_THE_SCREEN, encoding="utf-8")
|
|
413
|
+
assert _run_gate({"action": "read", "url": PAGE_LINK}).returncode == ALLOW_EXIT_CODE
|
|
414
|
+
assert _run_gate({"file_path": str(page_path), "asset": True}).returncode == ALLOW_EXIT_CODE
|
|
415
|
+
assert _run_gate({"file_path": str(tmp_path / "missing.html")}).returncode == ALLOW_EXIT_CODE
|