Skip to content

refactor: share authored payload contracts (#367) - #367

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

Sinity merged 1 commit into
masterfrom
feature/refactor/authored-surface-contracts

Conversation

@Sinity

@Sinity Sinity commented Apr 22, 2026 •

Copy link
Copy Markdown
Owner

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)

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.

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
@Sinity Sinity changed the title refactor: share authored payload contracts refactor: share authored payload contracts (#367) Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR consolidates payload utilities and type definitions scattered across polylogue/scenarios and polylogue/showcase into a centralized polylogue/authored_payloads module. It introduces stricter validation helpers (require_payload_mapping, payload_count_mapping, payload_records), a PayloadSerializable protocol, and updates import statements across 15+ modules to reference the new shared location while removing local payload-related re-exports.

Changes

Cohort / File(s) Summary
Core Payload Consolidation
polylogue/authored_payloads.py, polylogue/scenarios/__init__.py
Introduces new PayloadSerializable protocol and helpers (payload_count, require_payload_mapping, payload_count_mapping, payload_records); removes payload utilities re-export from scenarios module to consolidate in authored_payloads.
Scenarios Module Import Updates
polylogue/scenarios/assertions.py, polylogue/scenarios/cli_surfaces.py, polylogue/scenarios/corpus.py, polylogue/scenarios/executable.py, polylogue/scenarios/execution.py, polylogue/scenarios/metadata.py, polylogue/scenarios/projections.py, polylogue/scenarios/specs.py
Redirect payload-related imports from relative .payloads to polylogue.authored_payloads; no logic or signature changes.
Showcase Module Consolidation
polylogue/showcase/catalog_loader.py, polylogue/showcase/qa_session_payload.py, polylogue/showcase/showcase_report_payloads.py, polylogue/showcase/showcase_runner_support.py
Update payload imports to use polylogue.authored_payloads instead of polylogue.scenarios; import reordering only.
Showcase Helper Replacement
polylogue/showcase/qa_markdown.py, polylogue/showcase/qa_summary.py
Replace local payload validators (_payload_mapping, _count_value) with centralized require_payload_mapping and payload_count_mapping; use explicit context strings for validation.
Showcase Serialization Simplification
polylogue/showcase/report_models.py
Replace explicit to_payload() list comprehensions with centralized payload_records() helper for record tuple serialization.
Site Model Typing Updates
polylogue/site/models.py
Update return type annotations on SiteConfig.to_payload() and ConversationPageBuildStats.to_payload() to use PayloadDict for explicit payload interface typing.
Test Coverage
tests/unit/scenarios/test_authored_payloads.py, tests/unit/showcase/test_report.py
Add comprehensive unit tests for new payload utilities; replace local test helper with shared require_payload_mapping.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • PR #228: Directly modifies the same payload helper/types surface (PayloadDict/PayloadMap, payload_* helpers, canonical_payload_json) across overlapping files.
  • PR #282: Related refactor of payload/typing and registry contracts with overlapping changes in showcase and scenarios modules.

Suggested labels

type:refactor, area:site, area:qa, area:schema, type:test

Poem

🐰 We gathered scattered helpers into one bright warren,
Where PayloadSerializable hops through the code with care,
No more duplication, just validation that's fair,
Centralized wisdom in authored_payloads we won't spare!
A tidy refactor, from whiskers to tail. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% 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 'refactor: share authored payload contracts' clearly and concisely describes the main change—consolidating payload helpers into a shared contract layer.
Description check ✅ Passed The description follows the template with complete Summary, Problem, Solution, Verification, and Risks sections that explain the refactoring's goals, implementation, and validation thoroughly.
Linked Issues check ✅ Passed The PR fully addresses #317's requirements: introduces a shared typed payload contract layer, eliminates duplicated coercion helpers, updates scenario/showcase/site modules to use it directly, and provides comprehensive verification (ruff, mypy, pytest, devtools checks).
Out of Scope Changes check ✅ Passed All changes are in-scope for #317: moving and sharing payload helpers, updating imports across scenario/showcase/site modules, adding new validators and typed helpers, and removing re-exports from polylogue.scenarios.

✏️ 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/authored-surface-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 a147009 into master Apr 22, 2026
10 of 15 checks passed
@Sinity
Sinity deleted the feature/refactor/authored-surface-contracts branch April 22, 2026 22:45
@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. Swish!

ℹ️ 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 a review from Copilot May 1, 2026 01:53

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sinity added a commit that referenced this pull request May 7, 2026
## 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 -->
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 authored scenario and showcase surfaces

2 participants