Skip to content

Commit 11665ef

Browse files
mnm-matinclaude
andcommitted
Read the reference panel's component names past inline fallbacks
The reference panel now destructures the SDK component kit with default implementations, so the hygiene test that checks every name it binds is exported by the v2 SDK has to read the multi-line destructure instead of the one-line form. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q7Xrrx3fhVzCCSZSBGjEDa
1 parent d897ea0 commit 11665ef

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎tests/test_panel_contract_hygiene.py‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
ROOT = Path(__file__).resolve().parents[1]
1212
PANEL_SDK_SOURCE = ROOT / "frontend" / "src" / "panel-sdk" / "index.tsx"
13-
REFERENCE_PANEL_SOURCE = ROOT / "src" / "hyperview" / "shipped_extensions" / "reference" / "panel.jsx"
13+
REFERENCE_PANEL_SOURCE = (
14+
ROOT / "src" / "hyperview" / "shipped_extensions" / "reference" / "panel.jsx"
15+
)
1416

1517

1618
def test_v2_sdk_exposes_generic_similarity_hook_to_extensions() -> None:
@@ -42,9 +44,7 @@ def test_custom_panel_snapshot_carries_state_only_in_panel_state_map() -> None:
4244

4345

4446
def test_custom_panel_kind_is_normalized_and_unknown_values_fail_clearly() -> None:
45-
scatter = CustomPanelSpec.from_dict(
46-
{"id": "map", "title": "Map", "kind": "scatter"}
47-
)
47+
scatter = CustomPanelSpec.from_dict({"id": "map", "title": "Map", "kind": "scatter"})
4848
extension = CustomPanelSpec.from_dict(
4949
{"id": "summary", "title": "Summary", "kind": "extension"}
5050
)
@@ -59,9 +59,7 @@ def test_custom_panel_kind_is_normalized_and_unknown_values_fail_clearly() -> No
5959
ValueError,
6060
match="Unsupported panel kind 'iframe'; expected 'builtin' or 'module'",
6161
):
62-
CustomPanelSpec.from_dict(
63-
{"id": "legacy", "title": "Legacy", "kind": "iframe"}
64-
)
62+
CustomPanelSpec.from_dict({"id": "legacy", "title": "Legacy", "kind": "iframe"})
6563

6664

6765
def test_extension_panel_definitions_do_not_publish_lifecycle(tmp_path: Path) -> None:
@@ -128,10 +126,20 @@ def test_shipped_reference_panel_uses_only_components_exported_by_v2_sdk() -> No
128126
panel_source = REFERENCE_PANEL_SOURCE.read_text(encoding="utf-8")
129127
sdk_source = PANEL_SDK_SOURCE.read_text(encoding="utf-8")
130128

131-
component_match = re.search(r"const \{ ([^}]+) \} = components;", panel_source)
129+
component_match = re.search(
130+
r"(?m)^const \{((?:(?!^const \{)[\s\S])*?)\} = components;", panel_source
131+
)
132132
assert component_match is not None, "the reference panel should demonstrate the component kit"
133+
# The destructure may carry inline fallbacks (``Panel = (...) => ...``); the
134+
# names it binds are the identifiers that open each entry.
135+
body = component_match.group(1)
136+
if "\n" in body:
137+
used_components = re.findall(r"(?m)^\s*([A-Za-z_]\w*)\s*(?:=|,|$)", body)
138+
else:
139+
used_components = [name.strip() for name in body.split(",") if name.strip()]
140+
assert used_components, "the reference panel should demonstrate the component kit"
133141

134142
declaration = re.search(r"components:\s*\{([\s\S]*?)\};", sdk_source)
135143
assert declaration is not None
136-
for component in (name.strip() for name in component_match.group(1).split(",")):
137-
assert f"{component}: typeof {component};" in declaration.group(1)
144+
for component in used_components:
145+
assert f"{component}: typeof {component};" in declaration.group(1), component

0 commit comments

Comments
 (0)