Repository navigation
Pass the Web Fetch render context explicitly instead of through a context variable - #392
Merged
Merged
Conversation
…text variable RenderContext and MethodScope stay as they are, but nothing installs them in module state any more. Every renderer helper that reads the render context takes it as ctx; the methods helpers (report_method, method_access, browser_method_label, native_browser_engine, ...) take the measured-method part as scope. Page sets build their context at their own entry: _render_model from its model and the measured scope, diagnostic and research pages and the WCXB and WebMainBench page sets from an empty one, and the saved-composition views with model_render_context(). with_measured_method_labels passes the scope it derives to the render function it wraps. Code outside a render (release checks, rescoring, storage) passes an empty RenderContext()/MethodScope(), which is what it read from the context variable before. A new architecture check keeps context variables out of track modules. Every baseline is byte-identical. Closes #389
27 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This is the last part of #389. Web Fetch render state now moves through arguments instead of a context variable, as spec rule 4 requires ("No stage passes state through globals, context variables or undeclared keys"). Before this change,
report_model._RENDER_CONTEXT(aContextVar) carried the participants, suites, banner, score audit, coverage plan, result views and measured methods. Renderer helpers inreport.pyand the method helpers inmethods.pyread it implicitly. #390 removed the other context variable in Web Fetch.New structure
flowchart TD PS["page set entry<br/>(render_report → _model_pages / _diagnostic_pages / _research_pages,<br/>WCXB render_pages, WebMainBench sample_pages)"] --> W["with_measured_method_labels<br/>derives scope: MethodScope"] W -->|scope=| RM["_render_model(..., scope)<br/>ctx = model_render_context(model, methods=scope)<br/>ctx = replace(ctx, banner=…, score_audit=…)"] RM -->|ctx=| R["report.py helpers<br/>write, hero, ranking, overall_ranking, provider_label, …"] RM -->|ctx=| X["report_explainer / interfaces / capabilities /<br/>methods pages / pricing / changes"] R -->|scope=ctx.methods| M["methods.py<br/>report_method, method_access, browser_method_label,<br/>native_browser_engine, method_version, …"] X -->|scope=ctx.methods| M O["code outside a render<br/>(release checks, rescoring, storage)"] -->|"RenderContext() / MethodScope()"| R O --> MWhat changed
report_model.py:_RENDER_CONTEXT,render_context(),set_render_context(),reset_render_context(),rendering(),method_scope()andwith_method_scope()are removed.RenderContextandMethodScopeare unchanged. The newmodel_render_context(model, *, methods, descriptive_ranks, result_views)builds the context thatrendering(model)used to install.ctx(aRenderContext) inreport.pyand the other report modules (51 functions inreport.py, 22 elsewhere), andscope(aMethodScope) inmethods.py(10 functions). An argument left out raises aTypeError; nothing falls back silently._render_modelbuilds it from the model and the measured scope and replaces the banner, score audit, coverage plan and scope presentation in place, at the same point where the context variable was set before. The diagnostic, research, WCXB and WebMainBench page sets start from an empty context, which is what they used to read._scoped_renderis removed.with_measured_method_labelspasses the scope it derives to the function it wraps asscope=. A wrapped function called inside another render receives the enclosing scope (render_explainerpassesctx.methods). A page set starts from an empty scope.RenderContext()orMethodScope(). These are the defaults it read from the context variable before.tests/architecture/scan.py::context_variable_modules()andtest_track_modules_pass_state_explicitlyfail when a track module importscontextvars. It has 0 findings and no allowlist. A negative control (adding the import to a track module) fails the test as expected.reporting/publication_privacy._STAGED_EVIDENCEis the one context variable left insrc/. It lives in a shared package and is outside the scope of #389.Allowlists
Instance-literal 0 → 0; layering 0 → 0; the new context-variable check has 0 findings and no allowlist.
Baselines
Every baseline in
tests/baselines/is byte-identical, with no refresh. Scorer hash unchanged:0fe8931734e1ba7282e1e9c8303eea958d20fdcee83d84e87cdc7e08cd08169e.Verification
uv run --frozen --all-extras python -m pytest -q -n 8 --dist worksteal tests: 21652 passed, 78 skipped, 2 xfailed. The one failure,test_playwright_backend_executes_portable_and_snapshot_ref_calls, is timing-dependent and passes on its own.make lint-check: passeduv run --frozen lexbench-webfetch version: same scoring-source hashBreaking changes
None to commands. Python API:
report_model.render_context,set_render_context,reset_render_context,rendering,method_scopeandwith_method_scopeare removed.model_render_context()is added.harness.web_fetch.reportand the other report modules take a required keywordctx. The helpers inharness.web_fetch.methodstake a required keywordscope. A function wrapped bywith_measured_method_labelsreceivesscope=.Closes #389