Repository navigation
refactor(test): centralize JSON verification helpers (#366) - #366
Conversation
Problem: CLI/product/devtools tests kept local JSON envelope and result parsers from older surface-contract seams, and the generated quality reference did not point readers at the shared verification substrate. What changed: add tests/infra/json_contracts.py for typed JSON assertions, migrate repeated CLI JSON helpers to it, document shared test infrastructure in the generated quality reference, and add a validation-lane guard against duplicate explicit pytest targets. Verification: ruff check and mypy passed on touched files; focused pytest group reported 293 passed; devtools render-all --check passed; devtools verify reported all checks passed. Closes #274
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 15 minutes and 26 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a7a12ed2a
ℹ️ 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".
| if payload.get("status") == "ok" and "result" in payload: | ||
| return envelope_result(payload, context=context) | ||
| return payload |
There was a problem hiding this comment.
Reject malformed success envelopes when unwrapping result
unwrap_success_result silently falls back to returning the original payload when status is "ok" but result is absent. Because extract_json_result is now used by suites like tests/unit/cli/test_check.py and tests/unit/cli/test_products.py, outputs such as {"status":"ok","count":2} can now satisfy downstream assertions even though they violate the success-envelope contract; before this refactor those tests would fail on missing result. Treating status == "ok" without result as an assertion failure would preserve the contract checks these tests are meant to provide.
Useful? React with 👍 / 👎.
## Summary Adds a shared typed JSON assertion helper for verification tests, migrates repeated CLI JSON helper code into it, and updates the generated quality reference so verification helper contracts are visible from the devtools docs. ## Problem Issue #274 asks for the verification/test/devtools layer to reflect the renewed substrate and surface contracts. Several CLI test suites still carried local JSON object/envelope/result parsers from older surface ambiguity, which meant the same contract was reimplemented slightly differently across check, machine main, deterministic output, products, and JSON envelope tests. The generated quality reference also listed lanes and campaigns but did not point readers at the shared `tests/infra` verification substrate. ## Solution - Added `tests/infra/json_contracts.py` with typed helpers for JSON object extraction, success-envelope unwrapping, object/list narrowing, and numeric assertions. - Added `tests/infra/test_json_contracts.py` to lock down the shared helper behavior. - Migrated repeated local JSON helper functions in CLI check, machine, JSON envelope, deterministic-output, and product tests to the shared helper. - Added a validation-lane test that rejects duplicate explicit pytest targets in authored lanes. - Updated `devtools/render_quality_reference.py` and regenerated `docs/test-quality-workflows.md` with a “Test Infrastructure Contracts” section covering the shared helper surfaces. Closes #274. ## Verification - `pytest -q tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py` -> `293 passed in 9.84s` - `ruff check devtools/render_quality_reference.py tests/infra/json_contracts.py tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py` -> passed - `mypy devtools/render_quality_reference.py tests/infra/json_contracts.py tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py` -> passed - `devtools render-all --check` -> passed - `devtools verify` -> `verify: all checks passed` - `git push -u origin feature/refactor/verification-contracts` pre-push hook ran `devtools verify --quick` -> `verify: all checks passed`
Summary
Adds a shared typed JSON assertion helper for verification tests, migrates repeated CLI JSON helper code into it, and updates the generated quality reference so verification helper contracts are visible from the devtools docs.
Problem
Issue #274 asks for the verification/test/devtools layer to reflect the renewed substrate and surface contracts. Several CLI test suites still carried local JSON object/envelope/result parsers from older surface ambiguity, which meant the same contract was reimplemented slightly differently across check, machine main, deterministic output, products, and JSON envelope tests. The generated quality reference also listed lanes and campaigns but did not point readers at the shared
tests/infraverification substrate.Solution
tests/infra/json_contracts.pywith typed helpers for JSON object extraction, success-envelope unwrapping, object/list narrowing, and numeric assertions.tests/infra/test_json_contracts.pyto lock down the shared helper behavior.devtools/render_quality_reference.pyand regenerateddocs/test-quality-workflows.mdwith a “Test Infrastructure Contracts” section covering the shared helper surfaces.Closes #274.
Verification
pytest -q tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py->293 passed in 9.84sruff check devtools/render_quality_reference.py tests/infra/json_contracts.py tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py-> passedmypy devtools/render_quality_reference.py tests/infra/json_contracts.py tests/infra/test_json_contracts.py tests/unit/cli/test_check.py tests/unit/cli/test_click_app_main.py tests/unit/cli/test_deterministic_output.py tests/unit/cli/test_json_envelope_contract.py tests/unit/cli/test_machine_main.py tests/unit/cli/test_products.py tests/unit/devtools/test_validation_lanes.py-> passeddevtools render-all --check-> passeddevtools verify->verify: all checks passedgit push -u origin feature/refactor/verification-contractspre-push hook randevtools verify --quick->verify: all checks passed