extract the map workspace's domain layer out of the component
MapWorkspace.tsx opened with ~590 lines of theme catalogue, dataset matching and label formatting above a 3.200-line component. None of it is React, all of it is independently testable, and both render paths read from it, so it belongs beside the pure helpers that already live in mapWorkspaceUtils. The contract tests that read MapWorkspace.tsx would have gone red for a move that changes no behaviour at all — 24 of them. That is the brittleness the frontend_contract helper exists to remove, so it gains read_map_workspace(): the workspace is one feature spread over several modules, and a contract belongs to the feature rather than to whichever file currently holds it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,12 +22,46 @@ ROOT = Path(__file__).resolve().parents[2]
|
||||
FRONTEND_SRC = ROOT / "frontend" / "src"
|
||||
|
||||
|
||||
# The map workspace is one feature split across several modules: the container
|
||||
# component, its domain layer and its pure helpers. A contract belongs to the
|
||||
# feature, not to whichever file currently holds it, so splitting a 4.000-line
|
||||
# component must not red the suite.
|
||||
MAP_WORKSPACE_SOURCES = (
|
||||
"components/map/MapWorkspace.tsx",
|
||||
"components/map/mapWorkspaceThemes.ts",
|
||||
"components/map/mapWorkspaceUtils.ts",
|
||||
"components/map/MapExplorerView.tsx",
|
||||
"components/map/MapAdvancedWorkbench.tsx",
|
||||
)
|
||||
|
||||
|
||||
def read_frontend(relative_path: str) -> str:
|
||||
"""Read one frontend source file relative to ``frontend/src``."""
|
||||
|
||||
return (FRONTEND_SRC / relative_path).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def read_frontend_area(*relative_paths: str) -> str:
|
||||
"""Read several related sources as one body of code.
|
||||
|
||||
Files that do not exist are skipped, so this survives a module being split
|
||||
further or merged back.
|
||||
"""
|
||||
|
||||
parts: list[str] = []
|
||||
for relative_path in relative_paths:
|
||||
path = FRONTEND_SRC / relative_path
|
||||
if path.is_file():
|
||||
parts.append(path.read_text(encoding="utf-8"))
|
||||
return chr(10).join(parts)
|
||||
|
||||
|
||||
def read_map_workspace() -> str:
|
||||
"""The whole map workspace feature, whichever modules it is split into."""
|
||||
|
||||
return read_frontend_area(*MAP_WORKSPACE_SOURCES)
|
||||
|
||||
|
||||
def assert_wired(source: str, *identifiers: str, context: str = "frontend source") -> None:
|
||||
"""Every identifier must appear in ``source``.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user