Repository navigation
feat(devtools): enforce pytest timeout override policy - #2721
Conversation
Problem: explicit pytest timeout exceptions could disable or exceed the repository-wide 300-second guard without a static review boundary. What changed: add an AST-based verifier for pytest decorators and devtools-managed pytest commands, with a reconciled path/value/rationale manifest for longer exceptions. Register it in the normal devtools catalog and quick verification tier, and cover each rejection rule through the registered production command. Compatibility: normal positive overrides at or below the configured default remain unchanged; the sole current 600-second coverage exception is explicitly inventoried. Co-Authored-By: Codex <[email protected]>
Problem: the initial policy command missed timeout-shaped dynamic strings and managed pytest commands below the devtools root. What changed: reject f-string and concatenated timeout option expressions, recurse through devtools Python modules, and add catalog-resolved mutation tests for both bypasses. Co-Authored-By: Codex <[email protected]>
Problem: timeout policy scanning missed pytest import aliases and valid marker option forms, while compound managed command expressions could hide overrides. What changed: resolve pytest and mark import aliases structurally, accept the plugin's static timeout/method/func_only marker syntax, reject bare and dynamic timeout forms, and flatten static command composition while preserving dynamic-timeout rejection. Co-Authored-By: Codex <[email protected]>
Problem: the timeout policy covered function decorators but missed class-level marks and pytest's module-level pytestmark declaration. What changed: scan timeout markers on classes and structural top-level pytestmark assignments, including static marker lists, with catalog-resolved regressions for unbounded declarations. Co-Authored-By: Codex <[email protected]>
📝 WalkthroughWalkthroughAdds an AST-based verifier for pytest timeout overrides, validates exceptions against a TOML manifest, integrates the check into default developer verification, documents the command, and adds end-to-end unit coverage. ChangesPytest timeout verification
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Developer
participant devtools_verify
participant TimeoutVerifier
participant Repository
Developer->>devtools_verify: run verify pytest-timeout-overrides
devtools_verify->>TimeoutVerifier: invoke verifier
TimeoutVerifier->>Repository: read pyproject, manifest, and Python files
Repository-->>TimeoutVerifier: timeout defaults, exceptions, and AST inputs
TimeoutVerifier-->>devtools_verify: return validation errors or success
devtools_verify-->>Developer: print human-readable or JSON result
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem: module-level pytestmark could add an unbounded timeout through a static += declaration after its initial assignment. What changed: scan top-level AugAssign pytestmark values using the same structural marker parser and add a catalog-resolved regression. Co-Authored-By: Codex <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20b62d8fee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Problem: pytest.param marks create generated test items, so timeout overrides there bypassed decorator and module-mark scanning. What changed: structurally inspect marks on pytest.param calls, including imported and aliased param/mark forms plus static mark lists, with registered-command tests for valid, dynamic, and unbounded timeout marks. Co-Authored-By: Codex <[email protected]>
Problem: static aliases could hide timeout marks from pytestmark declarations and pytest.param marks. What changed: recursively flatten safe list and tuple aliases for marker expressions, reject unresolved or cyclic aliases, and cover module, incremental, parameter, bounded, and cycle cases through the registered verifier. Co-Authored-By: Codex <[email protected]>
Problem: resolving only a module's final binding let later harmless assignments hide timeout marks that pytest consumed earlier. What changed: preserve only single-assignment marker aliases; rebound, unresolved, imported, and cyclic aliases fail closed. Add source-order regressions for module, incremental, and parameter marks plus single-assignment controls. Co-Authored-By: Codex <[email protected]>
Problem: rebound command arguments and mutable marker lists could change after the verifier captured their initial binding, letting runtime-effective unbounded timeouts evade the static gate.\n\nWhat changed: reject rebound names in managed pytest commands and fail closed for mutable list marker aliases. Immutable tuple aliases and direct marker expressions remain supported.\n\nCo-Authored-By: Codex <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Add an AST-backed policy gate for explicit pytest timeout overrides and wire it into the quick verification tier.
Problem
Tests and devtools-managed pytest commands could disable or exceed the repository's 300-second timeout floor without a reviewable exception boundary. Literal-only scanning false-greened aliases, dynamic expressions, class/module/parameter marks, source-order rebinding, and mutable marker lists.
Solution
pytestmark, andpytest.param(..., marks=...)declarations with pytest import aliases.devtools verify --quick.Adversarial review iterated over dynamic/composed expressions, marker aliases/options, class/module/parameter marks, source-order rebinding, and mutable alias mutation. The final contract deliberately supports bounded static syntax rather than pretending to solve arbitrary Python dataflow.
Ref polylogue-c3qh.
Verification
devtools test tests/unit/devtools/test_verify_pytest_timeout_overrides.py -n 0-> 50 passed.devtools verify --quick-> 14/14 steps passed, exit 0 (20260711T235725Z-quick-1886475-c0df049a).