Skip to content

feat(devtools): enforce pytest timeout override policy - #2721

Merged
Sinity merged 9 commits into
masterfrom
feature/test/timeout-override-policy
Jul 11, 2026
Merged

Sinity merged 9 commits into
masterfrom
feature/test/timeout-override-policy

Conversation

@Sinity

@Sinity Sinity commented Jul 11, 2026 •

Copy link
Copy Markdown
Owner

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

  • Scan timeout decorators, class marks, module pytestmark, and pytest.param(..., marks=...) declarations with pytest import aliases.
  • Scan managed pytest command constructors and reject dynamic or rebound timeout-shaped expressions.
  • Resolve only conservative immutable marker aliases; mutable, cyclic, unresolved, or rebound aliases fail closed.
  • Reconcile every longer exception against an exact path/value/rationale TOML manifest.
  • Register the policy command in devtools and devtools verify --quick.
  • Execute mutation-style cases through the registered production command.

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).
  • Independent registered-command probes reject aliased, dynamic, rebound, class/module/parameter, and mutable-list unbounded timeout declarations.

Sinity and others added 4 commits July 12, 2026 01:20
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]>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Pytest timeout verification

Layer / File(s) Summary
AST override scanning
devtools/verify_pytest_timeout_overrides.py
Parses decorator and managed-command timeout overrides, resolves supported aliases and expressions, and reports invalid or dynamic values.
Policy reconciliation and CLI
devtools/verify_pytest_timeout_overrides.py, devtools/pytest_timeout_overrides.toml
Reads the repository default and manifest, validates positive finite exceptions, detects missing or stale entries, and supports human-readable or JSON output.
Verification integration and coverage
devtools/command_catalog.py, devtools/verify.py, docs/devtools.md, tests/unit/devtools/*
Registers the command, adds it to default verification, documents it, and tests invalid, valid, stale, nested, and committed-repository cases.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and clearly describes the main change: enforcing pytest timeout override policy.
Description check ✅ Passed The description covers Summary, Problem, Solution, and Verification with concrete details; only optional Changelog and Risks sections are missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/timeout-override-policy

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Sinity and others added 4 commits July 12, 2026 01:41
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]>
@Sinity
Sinity merged commit 50378f2 into master Jul 11, 2026
3 of 14 checks passed
@Sinity
Sinity deleted the feature/test/timeout-override-policy branch July 11, 2026 23:59
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

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.

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.

1 participant