Repository navigation
refactor: share authored payload contracts (#367) - #367
Conversation
Problem: scenario, showcase, QA, and site manifest payload contracts were owned through the scenarios package even when the callers were outside scenario execution. QA rendering also carried local mapping/count coercion that duplicated the payload helper semantics. What changed: moved the payload helpers to polylogue.authored_payloads, removed the scenarios package re-export, updated scenario/showcase/site callers to import the shared authored-surface contract directly, and added unit coverage for mapping validation, count coercion, canonical JSON, and typed record serialization. Verification: ruff check over the changed authored payload, scenario, showcase, site, and focused test paths; mypy over the same focused surface; focused pytest over scenario/showcase/site/rendering tests; devtools render-all --check; devtools lab-scenario verify-baselines; devtools verify. Closes #317
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR consolidates payload utilities and type definitions scattered across Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
## Summary Moves the authored scenario/showcase payload helpers into a shared `polylogue.authored_payloads` contract layer and updates scenario, showcase, QA, and site manifest-facing serialization to consume it directly. ## Problem Issue #317 calls for the authored scenario/showcase/rendering/site cluster to have explicit, typed surface contracts instead of ad-hoc payload handling. The existing useful helpers were owned by `polylogue.scenarios.payloads`, which made non-scenario callers import payload semantics through the scenario package. QA markdown and summary rendering also duplicated string-keyed mapping and count coercion locally. ## Solution - Renamed `polylogue/scenarios/payloads.py` to `polylogue/authored_payloads.py`. - Removed payload helper re-exports from `polylogue.scenarios` so ownership is explicit. - Updated scenario, showcase, QA report, and site manifest-facing payload methods to import the shared authored payload contract directly. - Added `PayloadSerializable`, `require_payload_mapping`, `payload_count`, `payload_count_mapping`, and `payload_records` for typed record serialization and safer mapping/count handling. - Added focused tests for mapping validation, count coercion, typed payload record serialization, and canonical JSON. Rendering already had typed rendered-message/block records, and site publication already had a Pydantic manifest, so this PR wires their manifest-facing payload methods into the shared payload contract without adding a redundant DTO layer. Closes #317 ## Verification - `ruff check polylogue/authored_payloads.py polylogue/scenarios polylogue/showcase polylogue/site tests/unit/scenarios/test_authored_payloads.py tests/unit/showcase/test_report.py tests/unit/site/test_builder.py` - `mypy polylogue/authored_payloads.py polylogue/scenarios polylogue/showcase polylogue/site tests/unit/scenarios/test_authored_payloads.py tests/unit/showcase/test_report.py tests/unit/site/test_builder.py` - `pytest -q tests/unit/scenarios/test_authored_payloads.py tests/unit/scenarios tests/unit/showcase/test_report.py tests/unit/showcase/test_exercise_catalog.py tests/unit/showcase/test_generators.py tests/unit/showcase/test_workspace.py tests/unit/showcase/test_qa_markdown.py tests/unit/site/test_builder.py tests/unit/rendering/test_rendering.py` (`149 passed`) - `devtools render-all --check` - `devtools lab-scenario verify-baselines` (`Ran 40 exercises`; all baselines match) - `devtools verify` (`all checks passed`) - pre-push `devtools verify --quick` (`all checks passed`) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added centralized payload serialization protocol with enhanced validation utilities for stricter type enforcement and field coercion. * **Bug Fixes** * Improved payload validation with explicit error context for debugging mapping and count-field issues. * **Refactor** * Reorganized payload utilities into a dedicated authored-payloads module; removed re-exports from the scenarios package (migration required if importing these utilities). * Consolidated record serialization using a unified conversion helper. * **Tests** * Added comprehensive tests for new payload validation and serialization utilities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Moves the authored scenario/showcase payload helpers into a shared
polylogue.authored_payloadscontract layer and updates scenario, showcase, QA, and site manifest-facing serialization to consume it directly.Problem
Issue #317 calls for the authored scenario/showcase/rendering/site cluster to have explicit, typed surface contracts instead of ad-hoc payload handling. The existing useful helpers were owned by
polylogue.scenarios.payloads, which made non-scenario callers import payload semantics through the scenario package. QA markdown and summary rendering also duplicated string-keyed mapping and count coercion locally.Solution
polylogue/scenarios/payloads.pytopolylogue/authored_payloads.py.polylogue.scenariosso ownership is explicit.PayloadSerializable,require_payload_mapping,payload_count,payload_count_mapping, andpayload_recordsfor typed record serialization and safer mapping/count handling.Rendering already had typed rendered-message/block records, and site publication already had a Pydantic manifest, so this PR wires their manifest-facing payload methods into the shared payload contract without adding a redundant DTO layer.
Closes #317
Verification
ruff check polylogue/authored_payloads.py polylogue/scenarios polylogue/showcase polylogue/site tests/unit/scenarios/test_authored_payloads.py tests/unit/showcase/test_report.py tests/unit/site/test_builder.pymypy polylogue/authored_payloads.py polylogue/scenarios polylogue/showcase polylogue/site tests/unit/scenarios/test_authored_payloads.py tests/unit/showcase/test_report.py tests/unit/site/test_builder.pypytest -q tests/unit/scenarios/test_authored_payloads.py tests/unit/scenarios tests/unit/showcase/test_report.py tests/unit/showcase/test_exercise_catalog.py tests/unit/showcase/test_generators.py tests/unit/showcase/test_workspace.py tests/unit/showcase/test_qa_markdown.py tests/unit/site/test_builder.py tests/unit/rendering/test_rendering.py(149 passed)devtools render-all --checkdevtools lab-scenario verify-baselines(Ran 40 exercises; all baselines match)devtools verify(all checks passed)devtools verify --quick(all checks passed)Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests