Skip to content

refactor(core): move shared helpers out of web_fetch and add layering checks - #344

Merged
lanyue-llk merged 3 commits into
mainfrom
refactor/core-checks
Nov 24, 2026
Merged

lanyue-llk merged 3 commits into
mainfrom
refactor/core-checks

Conversation

@lanyue-llk

Copy link
Copy Markdown
Contributor

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 on web_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 --> S
Loading

What moved

From To
harness/web_fetch/safety.py harness/safety.py (bytes unchanged)
harness/web_fetch/artifact_auth.py harness/artifact_auth.py (bytes unchanged)
load_runtime_env, repository_env, load_env_file, expand_env in harness/web_fetch/config.py harness/runtime_env.py. env_file.py stays parse-only, as its docstring says.
Root dispatch in harness/web_fetch/cli.py (OWNER_COMMANDS entries for other tracks) harness/cli.py TRACKS and SHARED_COMMANDS; [project.scripts] webstone = "harness.cli:main"
harness/reporting/certified_cli.py (if/else over track names) harness.cli.certified_main, which reads the same TRACKS registry; scripts/run_certified_benchmark.py calls it. web_search.runner.certified_main is the Web Search entry.
reporting/versions.py importing harness.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 webstone command keeps its name and behaviour, and webstone --help still lists all of them. python -m harness.web_fetch now 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 only web-search worked).

Hash bindings: safety.py and artifact_auth.py moved without byte changes. browser_observations.capture_source_identity keeps the key safety.py, so capture checkpoints keep the same identity. The WebMainBench TEDS correction now records the source as harness/safety.py. web_search/runner.py, reporting/visual.py and webmainbench_latency_diagnostic.py have 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: an ast scan of src/harness/. Shared modules (reporting, results, benchmarks, environments and top-level harness/*.py) import no track, and a track imports no other track. harness/cli.py is 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 from PROVIDER_TYPES, configs/providers.example.json, Web Search ADAPTERS, Web Extract METHODS and replay BROWSER_ADAPTERS. fixture and http are excluded as ordinary words.
  • Allowlists live in tests/architecture/. Each test fails on a new occurrence and on an allowlist entry that no longer occurs. Regenerate them with uv run --frozen python tests/architecture/scan.py.

Allowlist counts after the move:

  • Layering: 9 entries. Before the move the scan found 53. Remaining: 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.
  • Instance literals: 3 entries (environments.browser: chromium, moli; reporting.visual: chromium).

benchmarks/publication.py → web_search.revisions stays allowlisted. It sits inside a simpleqa-verified branch of shared code, so removing it needs a benchmark adapter hook, which a small change cannot add.

Verification

  • make lint-check: passed
  • make track-naming-check: passed
  • uv run --frozen --extra test python -m pytest tests/test_architecture_layering.py tests/test_architecture_instance_literals.py -q: 5 passed
  • make test-python BROWSER_TESTS=exclude PYTEST_ARGS='-n 8 --dist worksteal': 23810 passed, 31 failed. After this was found, examples/trajectory_replay/run.sh was fixed, and its 7 test_run_entry failures now pass. The other 24 node IDs were rerun on this branch and on base 997a228ed: the same 15 fail on both, for local environment reasons (no node_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 hand

Closes #314
Closes #315

…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.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review complete · 74e463c

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 (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · medium
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test · medium
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.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Addressed both OCR findings:

  • Allowlist growth: tests/architecture/scan.py now refuses to write an allowlist that would gain entries and exits with the new findings (8799126). Regeneration can only shrink the lists.
  • Relative imports: the repository bans them (pyproject.toml ban-relative-imports = "all", enforced by make lint-check with TID252), so an import such as from ..web_fetch import config fails lint before the layering check sees it. No change.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Re-review complete · 8799126

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +56 to +57
elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module and (
node.module == "harness" or node.module.startswith("harness.")):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · medium
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.

@lanyue-llk
lanyue-llk merged commit a0b5b56 into main Nov 24, 2026
7 of 8 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/core-checks branch November 24, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add layering and instance-literal checks with shrinking allowlists Move shared helpers and the root command out of web_fetch

1 participant