Repository navigation
refactor(core): move shared helpers out of web_fetch and add layering checks - #344
Conversation
…etch Move safety.py and artifact_auth.py to harness/, and the environment loading helpers of web_fetch/config.py to harness/runtime_env.py. Build the root webstone command and the certified runner from one track registry in harness/cli.py, replacing the dispatch in web_fetch/cli.py and reporting/certified_cli.py. Migrate every caller; no aliases remain.
…ng allowlists Shared packages import no track and a track imports no other track; shared modules name no registered method, provider or browser. Allowlists generated from the tree hold the remaining occurrences and may only shrink.
There was a problem hiding this comment.
This review found 2 issue(s), including 2 blocking issue(s).
| for node in ast.walk(ast.parse(path.read_bytes(), filename=str(path))): | ||
| if isinstance(node, ast.Import): | ||
| imported.update(alias.name for alias in node.names if alias.name.startswith("harness.")) | ||
| elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module and ( |
There was a problem hiding this comment.
Relative imports are silently excluded from the layering check. For example, from ..web_fetch import config in harness.web_search.runner introduces a cross-track dependency but produces no finding. Although current source imports are absolute, the guard will accept this future violation. Resolve relative ImportFrom nodes against the importing module/package (including init.py), and add a relative-import regression test.
|
|
||
|
|
||
| def write_allowlist(path: Path, found: dict[str, list[str]]) -> None: | ||
| path.write_text(json.dumps(dict(sorted(found.items())), indent=2) + "\n", encoding="utf-8") |
There was a problem hiding this comment.
The documented regeneration command can grow either supposedly shrink-only allowlist: adding a violation and running this function records it as allowed, after which both drift tests pass. Those tests compare only against the newly written baseline, and there is no separate baseline-growth check. For existing allowlists, reject findings outside the previous entries before writing, or enforce the subset constraint against the base revision in CI.
|
Addressed both OCR findings:
|
There was a problem hiding this comment.
This review found 1 issue(s), including 1 blocking issue(s).
| elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module and ( | ||
| node.module == "harness" or node.module.startswith("harness.")): |
There was a problem hiding this comment.
The node.level == 0 condition silently skips all relative imports. For example, from ..web_fetch import config in harness.reporting or harness.web_search introduces a forbidden dependency but produces no layering violation. Although current sources use absolute imports, this leaves the new regression check unable to enforce the rule for valid relative-import syntax. Resolve relative imports against the importing package (including __init__.py) before classifying targets, and add regression coverage for these cases.
Purpose
Make the first two architecture rules in the repository specification (
docs/spec.md, rules 1 and 2) hold, and check them mechanically. Shared code stops depending onweb_fetch. The root command and the certified runner get their tracks from one registry. Two tests with allowlists that can only shrink hold the remaining violations.flowchart LR subgraph root["Root (harness/cli.py)"] R["TRACKS registry<br/>webstone main · certified_main"] end subgraph tracks["Tracks"] WF[web_fetch] WS[web_search] WE[web_extract] TR[trajectory_replay] BU[browser_use] end subgraph shared["Shared"] S["harness/*.py<br/>safety · artifact_auth · runtime_env · env_file ..."] P["reporting · results · benchmarks · environments"] end R -. "lazy import of the selected owner" .-> tracks tracks --> shared P --> SWhat moved
harness/web_fetch/safety.pyharness/safety.py(bytes unchanged)harness/web_fetch/artifact_auth.pyharness/artifact_auth.py(bytes unchanged)load_runtime_env,repository_env,load_env_file,expand_envinharness/web_fetch/config.pyharness/runtime_env.py.env_file.pystays parse-only, as its docstring says.harness/web_fetch/cli.py(OWNER_COMMANDSentries for other tracks)harness/cli.pyTRACKSandSHARED_COMMANDS;[project.scripts] webstone = "harness.cli:main"harness/reporting/certified_cli.py(if/else over track names)harness.cli.certified_main, which reads the sameTRACKSregistry;scripts/run_certified_benchmark.pycalls it.web_search.runner.certified_mainis the Web Search entry.reporting/versions.pyimportingharness.web_fetch.__version__importlib.metadata.version("webstone")Every caller moved in the same change (src, tests, scripts), with no alias left at the old paths. Web Search and Web Search publication take the repository root from
harness.distribution.Every
webstonecommand keeps its name and behaviour, andwebstone --helpstill lists all of them.python -m harness.web_fetchnow lists only Web Fetch stages, and no documentation or caller used it for another track. The certified runner now accepts any registered certified track as the first positional argument (before this change onlyweb-searchworked).Hash bindings:
safety.pyandartifact_auth.pymoved without byte changes.browser_observations.capture_source_identitykeeps the keysafety.py, so capture checkpoints keep the same identity. The WebMainBench TEDS correction now records the source asharness/safety.py.web_search/runner.py,reporting/visual.pyandwebmainbench_latency_diagnostic.pyhave import-only edits. Their hashes are checked only against live state (a resume contract or a regenerated visual receipt), and no committed frozen record binds them. So an in-progress Web Search cohort cannot resume across this change, and visual receipts must be regenerated before the next release, as after any edit to these files.Checks (#315)
tests/test_architecture_layering.py: anastscan ofsrc/harness/. Shared modules (reporting,results,benchmarks,environmentsand top-levelharness/*.py) import no track, and a track imports no other track.harness/cli.pyis exempt because it is the registry.tests/test_architecture_instance_literals.py: shared modules must not contain a string literal equal to a registered name. Names come fromPROVIDER_TYPES,configs/providers.example.json, Web SearchADAPTERS, Web ExtractMETHODSand replayBROWSER_ADAPTERS.fixtureandhttpare excluded as ordinary words.tests/architecture/. Each test fails on a new occurrence and on an allowlist entry that no longer occurs. Regenerate them withuv run --frozen python tests/architecture/scan.py.Allowlist counts after the move:
web_extract→web_fetch.providers.http_client(4),web_extract/web_search→web_fetch.publication_privacy(2),browser_use→web_fetch.report_style,web_fetch.certification→web_search.runner,benchmarks.publication→web_search.revisions.environments.browser:chromium,moli;reporting.visual:chromium).benchmarks/publication.py→web_search.revisionsstays allowlisted. It sits inside asimpleqa-verifiedbranch of shared code, so removing it needs a benchmark adapter hook, which a small change cannot add.Verification
make lint-check: passedmake track-naming-check: passeduv run --frozen --extra test python -m pytest tests/test_architecture_layering.py tests/test_architecture_instance_literals.py -q: 5 passedmake test-python BROWSER_TESTS=exclude PYTEST_ARGS='-n 8 --dist worksteal': 23810 passed, 31 failed. After this was found,examples/trajectory_replay/run.shwas fixed, and its 7test_run_entryfailures now pass. The other 24 node IDs were rerun on this branch and on base997a228ed: the same 15 fail on both, for local environment reasons (nonode_modules, no installed Web Search benchmark data, the Node CI-expression evaluator), and the rest pass on both.webstone --help,webstone web-search --help,python scripts/run_certified_benchmark.py --track <unknown>: checked by handCloses #314
Closes #315