Skip to content

refactor(test): centralize JSON verification helpers (#366) - #366

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/verification-contracts
Apr 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/verification-contracts

Conversation

@Sinity

@Sinity Sinity commented Apr 22, 2026

Copy link
Copy Markdown
Owner

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

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
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 26 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1debe7ce-681e-4311-9b96-fb008bf090a0

📥 Commits

Reviewing files that changed from the base of the PR and between d458ad1 and 1a7a12e.

📒 Files selected for processing (11)
  • devtools/render_quality_reference.py
  • docs/test-quality-workflows.md
  • 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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/verification-contracts

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 and usage tips.

@Sinity Sinity changed the title refactor(test): centralize JSON verification helpers refactor(test): centralize JSON verification helpers (#366) Apr 22, 2026
@Sinity
Sinity merged commit e85a0d2 into master Apr 22, 2026
11 of 14 checks passed
@Sinity
Sinity deleted the feature/refactor/verification-contracts branch April 22, 2026 19:44

@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: 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".

Comment on lines +85 to +87
if payload.get("status") == "ok" and "result" in payload:
return envelope_result(payload, context=context)
return payload

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Sinity

Sinity commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

🤖 Post-hoc audit note: this PR received bot review feedback verified against current HEAD as part of #544. 1 finding(s) confirmed still present → tracked in #550.

@Sinity
Sinity requested a review from Copilot May 1, 2026 00:44
@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 01:05
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:15
Sinity added a commit that referenced this pull request May 7, 2026
## 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`
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.

refactor: renew verification, test helpers, and quality tooling contracts

1 participant