Skip to content

refactor(test): harden verification fixture contracts (#374) - #374

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

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

Conversation

@Sinity

@Sinity Sinity commented Apr 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Tighten the shared verification substrate so authored scenarios and storage-record helpers use explicit typed contracts instead of legacy loose payload shapes.

Problem

Issue #267 identified that renewed source/schema/storage semantics could still drift because tests and verification helpers preserved older dictionary-shaped shortcuts. Before implementation, the issue was strengthened with a concrete fixture-boundary target: storage helpers conflated JSON metadata with internal Pydantic model payloads, and archive scenarios still accepted raw content-block dictionaries.

Closes #267

Solution

  • Added typed ScenarioContentBlock fixtures for authored archive scenarios and made raw dictionary content blocks fail at scenario seed time.
  • Split storage helper JSON validation from internal RecordPayload construction while preserving existing low-level builder convenience.
  • Validated provider metadata, attachment metadata, content-block tool input, and content-block metadata as JSON-compatible at the shared helper boundary.
  • Added focused infra tests for invalid legacy shapes and valid JSON content-block preservation.
  • Added a verification-substrate-contracts validation lane plus declared operation metadata for fixture seeding/building, then regenerated quality and verification catalogs.

Verification

  • pytest -q tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py tests/infra/test_json_contracts.py tests/unit/devtools/test_validation_lanes.py -> 154 passed initially, then 160 passed after fixes and projection coverage
  • devtools run-validation-lanes --lane verification-substrate-contracts -> 13 passed
  • ruff check tests/infra/storage_records.py tests/infra/archive_scenarios.py tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py devtools/validation_lane_catalog_contracts.py tests/unit/devtools/test_validation_lanes.py polylogue/operations/specs.py tests/unit/storage/test_repository_lifecycle_laws.py -> passed
  • mypy tests/infra/storage_records.py tests/infra/archive_scenarios.py tests/unit/ui/test_ui_visual.py tests/unit/core/conftest.py tests/unit/storage/test_store_ops.py polylogue/operations/specs.py -> no issues
  • pytest -q tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py tests/infra/test_json_contracts.py tests/unit/devtools/test_validation_lanes.py tests/unit/devtools/test_scenario_projections.py tests/unit/storage/test_scale.py::TestPerformanceBudget::test_has_tool_use_filter_budget -> 160 passed
  • devtools render-all --check -> generated surfaces in sync
  • devtools verify -> all checks passed
  • git push -u origin feature/refactor/verification-substrate-contracts -> pre-push quick verification passed

Summary by CodeRabbit

  • New Features

    • Introduced new verification workflow for enhanced test infrastructure validation
  • Improvements

    • Strengthened type safety in test fixtures with enhanced validation
    • Expanded validation registry metrics and operation targets
  • Tests

    • Added comprehensive tests for new verification operations
    • Enhanced content and data serialization validation test coverage
    • Improved type checking in fixture seeding operations

Problem: shared verification helpers still allowed loose payload shapes after the semantic-precision renewal. Storage test helpers used the same dictionary alias for JSON metadata and internal model-construction payloads, and archive scenarios could still smuggle raw content-block dictionaries into cross-surface fixtures.

What changed: split storage helper JSON validation from record payload construction, reject non-JSON metadata and content-block fragments at helper boundaries, add typed ScenarioContentBlock fixtures for authored archive scenarios, and register a focused validation lane for the renewed fixture contracts. Generated quality and verification catalogs were refreshed from the updated lane and operation metadata.

Verification: devtools run-validation-lanes --lane verification-substrate-contracts passed; targeted infra/devtools tests passed; targeted mypy and ruff checks passed; devtools render-all --check passed; devtools verify passed.

Closes #267
@Sinity Sinity changed the title refactor(test): harden verification fixture contracts refactor(test): harden verification fixture contracts (#374) Apr 23, 2026
@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Introduces a new validation lane verification-substrate-contracts with two control-plane operations (seed-archive-scenarios, build-storage-record-fixtures) to verify test fixtures and helpers. Refactors test infrastructure to enforce typed ScenarioContentBlock fixtures, stricter JSON metadata validation, and rejects raw dictionary shapes in storage builders and archive scenarios.

Changes

Cohort / File(s) Summary
Validation Lane & Operations
devtools/validation_lane_catalog_contracts.py, polylogue/operations/specs.py
Adds verification-substrate-contracts lane with pytest execution constrained via -q/-n 0, wired to dedicated path/artifact/operation targets. Registers two new previewable control-plane projection operations: seed-archive-scenarios and build-storage-record-fixtures for tests and validation-lane surfaces.
Test Infrastructure Refactoring
tests/infra/archive_scenarios.py, tests/infra/storage_records.py
Introduces typed ScenarioContentBlock dataclass with to_payload() method and classmethods (text_block, tool_use, tool_result, thinking) replacing raw dictionaries. Updates ScenarioMessage.content_blocks type from Sequence[JSONRecord] to Sequence[ScenarioContentBlock]. Tightens storage helpers with stricter JSON validation, replaces _optional_dict with _optional_json_document, and enforces non-string-key rejection in content blocks via TypeError.
Test Updates
tests/infra/test_archive_scenarios.py, tests/infra/test_storage_records.py, tests/unit/storage/test_repository_lifecycle_laws.py, tests/unit/devtools/test_validation_lanes.py
Updates test seeding to use typed ScenarioContentBlock.tool_use(...) API. Adds validation tests proving legacy raw dictionary blocks and non-JSON-serializable inputs (e.g., Path objects) in metadata/content blocks raise TypeError with actionable messages. Adds unit tests for the new verification-substrate-contracts lane metadata and command construction.
Documentation
docs/test-quality-workflows.md, docs/verification-catalog.md
Updates generated registry metrics: contract lanes +1, scenario projections +1, validation-lane +1; runtime coverage increases from 41 to 43 declared operation targets. Snapshot subjects increased from 9034 to 9036 and proof obligations from 9115 to 9117.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

type:refactor, type:test, area:qa, area:storage, tool:claude

Poem

🐰 With whiskers twitching, we type our blocks,
No loose dicts here—just structured locks!
Archive scenarios, neat and tight,
JSON validation done just right,
A validation lane hops into place,
Semantic precision wins the race! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.71% 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
Title check ✅ Passed The title clearly and specifically identifies the main change: refactoring tests to harden verification fixture contracts, which is the primary objective of this PR.
Description check ✅ Passed The PR description closely follows the template structure with Summary, Problem, Solution, and Verification sections; all required content is present and substantive.
Linked Issues check ✅ Passed The PR directly implements the specific technical requirements from issue #267, including typed ScenarioContentBlock fixtures, JSON validation in storage helpers, and a validation lane for verification contracts.
Out of Scope Changes check ✅ Passed All changes directly support the core objective of hardening verification fixture contracts; documentation updates and catalog regeneration are natural consequences of the implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/refactor/verification-substrate-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 merged commit 1856ad0 into master Apr 23, 2026
10 of 14 checks passed
@Sinity
Sinity deleted the feature/refactor/verification-substrate-contracts branch April 23, 2026 03:08
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ 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
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 01:54
Sinity added a commit that referenced this pull request May 7, 2026
## Summary

Tighten the shared verification substrate so authored scenarios and storage-record helpers use explicit typed contracts instead of legacy loose payload shapes.

## Problem

Issue #267 identified that renewed source/schema/storage semantics could still drift because tests and verification helpers preserved older dictionary-shaped shortcuts. Before implementation, the issue was strengthened with a concrete fixture-boundary target: storage helpers conflated JSON metadata with internal Pydantic model payloads, and archive scenarios still accepted raw content-block dictionaries.

Closes #267

## Solution

- Added typed `ScenarioContentBlock` fixtures for authored archive scenarios and made raw dictionary content blocks fail at scenario seed time.
- Split storage helper JSON validation from internal `RecordPayload` construction while preserving existing low-level builder convenience.
- Validated provider metadata, attachment metadata, content-block tool input, and content-block metadata as JSON-compatible at the shared helper boundary.
- Added focused infra tests for invalid legacy shapes and valid JSON content-block preservation.
- Added a `verification-substrate-contracts` validation lane plus declared operation metadata for fixture seeding/building, then regenerated quality and verification catalogs.

## Verification

- `pytest -q tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py tests/infra/test_json_contracts.py tests/unit/devtools/test_validation_lanes.py` -> 154 passed initially, then 160 passed after fixes and projection coverage
- `devtools run-validation-lanes --lane verification-substrate-contracts` -> 13 passed
- `ruff check tests/infra/storage_records.py tests/infra/archive_scenarios.py tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py devtools/validation_lane_catalog_contracts.py tests/unit/devtools/test_validation_lanes.py polylogue/operations/specs.py tests/unit/storage/test_repository_lifecycle_laws.py` -> passed
- `mypy tests/infra/storage_records.py tests/infra/archive_scenarios.py tests/unit/ui/test_ui_visual.py tests/unit/core/conftest.py tests/unit/storage/test_store_ops.py polylogue/operations/specs.py` -> no issues
- `pytest -q tests/infra/test_storage_records.py tests/infra/test_archive_scenarios.py tests/infra/test_json_contracts.py tests/unit/devtools/test_validation_lanes.py tests/unit/devtools/test_scenario_projections.py tests/unit/storage/test_scale.py::TestPerformanceBudget::test_has_tool_use_filter_budget` -> 160 passed
- `devtools render-all --check` -> generated surfaces in sync
- `devtools verify` -> all checks passed
- `git push -u origin feature/refactor/verification-substrate-contracts` -> pre-push quick verification 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 tests and verification over semantic-precision substrate

1 participant