test: register a gate module before executing it - #389
Merged
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013sYZswUQ3HEnUEdVWrUbvq Change-Id: I8b93e3c486069b3c04e42b40193f35a17a15a3d6
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_09d014d1-3d39-45ec-9776-ab1cca613b04) |
5 tasks
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
Owner
Author
|
@Mergifyio queue |
Contributor
Merge Queue Status
This pull request spent 5 minutes 30 seconds in the queue, including 4 minutes 23 seconds running CI. Required conditions to merge
|
5 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.
Summary
_loadin the gate-docstring test builds a module withmodule_from_specbut never registers it insys.modules. On Python 3.12+,@dataclassresolves its own module throughsys.modules[cls.__module__].__dict__when annotations are strings, so that lookup returnsNoneand the decorator raisesAttributeErrorbefore any assertion runs. CI pins Python 3.9, where the lookup takes a different path, so CI cannot see this.Before and After
The same probe gate (
from __future__ import annotationsplus one@dataclass) loaded through this test file's_loadon Python 3.12.3, withpython3 -c 'from pathlib import Path; from tests.test_check_docstrings_match_regexes import _load; m = _load(Path("/tmp/pr389/check_dataclass_probe.py")); print("loaded:", m.Promise("x"))', run once on base28f750aand once on head9b18d47:Review Claim
A gate module that uses
@dataclassunder postponed annotations loads successfully in this test's loader.Review Lane
behavior
Review Unit
engine-runtime
Safety Invariant
Registering the module under its spec name is the documented importlib recipe and does not change which gates are collected or what they assert. No gate currently on main uses
@dataclass, so no existing result changes — the fix is for the next one that does.Slice Rationale
One line in
_loadplus the test that proves it. No gate is edited.Non-goals
Test Plan
New
TestGateLoader.test_a_gate_using_dataclass_loadswrites a probe gate that usesfrom __future__ import annotationsplus@dataclass— the shape that triggers the failure — and loads it.Without
sys.modules[spec.name] = module:With it:
The probe needs the postponed-annotations import: a first version without it passed with and without the fix, proving nothing, and was corrected.
Whole file, on this branch (Python 3.14.7 locally):
Found while rebasing #371, whose new
scripts/check_detector_backtested.pyuses@dataclassthree times and crashed this test'ssetUpClasslocally while CI reported green.Revert Plan
git revertthis commit. The loader stops registering the module and any gate using@dataclasscrashes the test again on Python 3.12+; none does on main today.🤖 Generated with Claude Code
https://claude.ai/code/session_013sYZswUQ3HEnUEdVWrUbvq
Note
Low Risk
Test-only loader change with no production or CI Python pin changes; behavior for current gates on main is unchanged.
Overview
Fixes dynamic gate loading in
tests/test_check_docstrings_match_regexes.pyso it matches the documented importlib pattern and works on Python 3.12+._loadnow assignssys.modules[spec.name] = modulebeforeexec_module. Without that registration, a gate usingfrom __future__ import annotationsand@dataclasscan fail during import because the decorator looks up the module insys.modulesand getsNone—a failure CI on Python 3.9 would not hit.Adds
TestGateLoader.test_a_gate_using_dataclass_loads, which writes a minimal probe gate with postponed annotations and@dataclass, loads it via_load, and assertsflags_exemplarbehavior. Existing promise checks are unchanged; no production gates are modified.Reviewed by Cursor Bugbot for commit 9b18d47. Bugbot is set up for automated code reviews on this repo. Configure here.