scope frontend contracts to the feature, not to one file

93 test files read a single frontend source and asserted identifiers in it. The
MapWorkspace split showed what that costs: 24 tests went red for a move that
changed no behaviour at all. A contract belongs to the feature — a container,
its hooks, its domain layer — not to whichever file currently holds it.

232 read sites now resolve through read_feature(). The distinction that makes
this safe is direction: a *positive* contract ("this is wired") may widen,
because the identifier must still exist somewhere in the feature; a *negative*
one ("this component performs no transport") is a statement about one file, and
widening it would quietly weaken the check. The 73 single-file reads that
remain are exactly those, and a guard now enforces the rule for new tests.

Verified rather than assumed: of the 732 migrated positive assertions, 644 still
match exactly one module — as specific as before — and the other 86 already
spanned a container and its hook by nature. Two apparent misses are an artefact
of the checking regex reading an escaped newline literally.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jens
2026-08-22 22:05:43 +02:00
co-authored by Claude Opus 5
parent a2a8775df1
commit 6572e4ad5f
95 changed files with 454 additions and 444 deletions
+84 -15
View File
@@ -22,20 +22,77 @@ 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",
"hooks/useMapImageOverlays.ts",
"hooks/useMapRectangleSelection.ts",
"hooks/useFullGisWorkflow.ts",
"components/map/MapExplorerView.tsx",
"components/map/MapAdvancedWorkbench.tsx",
)
# A feature is one behaviour spread over several modules: a container, its
# hooks, its domain layer, its pure helpers. A contract belongs to the feature,
# not to whichever file currently holds it, so moving code between siblings
# must not red the suite. Missing entries are skipped, so a group survives a
# module being split further, renamed or merged back.
#
# Use these for *positive* contracts ("this is wired"). A negative contract
# ("this component performs no transport") is a statement about one file and
# must keep reading that file, or widening it would quietly weaken the check.
FEATURE_SOURCES: dict[str, tuple[str, ...]] = {
"map_workspace": (
"components/map/MapWorkspace.tsx",
"components/map/mapWorkspaceThemes.ts",
"components/map/mapWorkspaceUtils.ts",
"components/map/MapExplorerView.tsx",
"components/map/MapAdvancedWorkbench.tsx",
"hooks/useMapImageOverlays.ts",
"hooks/useMapRectangleSelection.ts",
"hooks/useFullGisWorkflow.ts",
"hooks/useMapThemeSelectionInsights.ts",
"hooks/useMapSelectionExtract.ts",
"hooks/useMapWorkspaceState.ts",
"hooks/useMapSelectionDataset.ts",
"hooks/useMapSelectionQa.ts",
"hooks/useMapThemeSelectionInsights.ts",
"hooks/useTemporalComparison.ts",
"hooks/useCoverageResolver.ts",
"hooks/useOfficialMapProducts.ts",
),
"detection": (
"components/detection/DetectionLab.tsx",
"components/detection/DetectionModelManagement.tsx",
"components/detection/detectionProfiles.ts",
"components/models/ModelSelector.tsx",
"components/models/modelOptions.ts",
"hooks/useDetectionWorkflow.ts",
),
"segmentation": (
"components/segmentation/SegmentationLab.tsx",
"hooks/useSegmentationWorkflow.ts",
),
"quality": (
"components/quality/QualityResultsPanel.tsx",
"components/quality/DetectionReviewPanel.tsx",
"hooks/useQualityWorkflow.ts",
),
"datasets": (
"components/datasets/DatasetPanel.tsx",
"components/datasets/DatasetDetailPanel.tsx",
"components/datasets/RasterControls.tsx",
"components/datasets/VectorControls.tsx",
"components/datasets/SourceCatalogPanel.tsx",
"hooks/useDatasetWorkflow.ts",
"services/api/datasets.ts",
),
"exports": (
"components/exports/ExportCenter.tsx",
"hooks/useExportWorkflow.ts",
),
"shell": (
"App.tsx",
"components/shell/WorkbenchNavigation.tsx",
"components/shell/SecondaryDisplay.tsx",
"components/inspector/WorkbenchInspector.tsx",
"components/overview/OverviewWorkspace.tsx",
"hooks/useProjectWorkspace.ts",
"hooks/useWorkbenchBootstrap.ts",
),
}
MAP_WORKSPACE_SOURCES = FEATURE_SOURCES["map_workspace"]
def read_frontend(relative_path: str) -> str:
@@ -59,10 +116,22 @@ def read_frontend_area(*relative_paths: str) -> str:
return chr(10).join(parts)
def read_feature(name: str) -> str:
"""Every module of one feature, whichever files it is currently split into."""
try:
sources = FEATURE_SOURCES[name]
except KeyError: # pragma: no cover - a typo should fail loudly
raise AssertionError(
f"Unknown frontend feature {name!r}; known: {sorted(FEATURE_SOURCES)}"
) from None
return read_frontend_area(*sources)
def read_map_workspace() -> str:
"""The whole map workspace feature, whichever modules it is split into."""
return read_frontend_area(*MAP_WORKSPACE_SOURCES)
return read_feature("map_workspace")
def assert_wired(source: str, *identifiers: str, context: str = "frontend source") -> None: