Repository navigation
refactor(cli): derive action output docs from contracts (#1816) - #2008
Conversation
Problem: the CLI reference still depended on polylogue.cli.output_assurance, a hand-maintained registry that duplicated action-contract and output-schema metadata and kept stale command surfaces alive in docs. What changed: remove the old output_assurance module and its registry tests, render the CLI reference from ACTION_CONTRACTS plus the generated CLI schema registry, correct stale select/neighbors schema surface names, and refresh generated docs/topology surfaces. Verification: devtools test tests/unit/cli/test_cli_action_contracts.py tests/unit/devtools/test_action_contract_report.py tests/unit/devtools/test_render_cli_reference.py tests/unit/cli/test_cli_output_schemas.py tests/unit/cli/test_neighbors_command.py (52 passed); devtools release-readiness (ok); devtools verify --quick (exit_code 0). devtools verify static checks passed but pytest-testmon expanded into a write-heavy run and was stopped after ~12 minutes / ~15.5 GB writes with no result files.
📝 WalkthroughWalkthroughRemoves the 567-line hand-maintained ChangesReplace output assurance with code-generated action contract report
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/devtools/test_action_contract_report.py`:
- Around line 13-22: The assertions within the loop that iterates over
ACTION_CONTRACTS are checking if contract attributes (path, effect, input_unit,
machine_envelope, formats, guards) exist anywhere in the global rendered output,
which allows tests to pass even if a specific contract's row is malformed as
long as the tokens appear elsewhere. Extract the rendered output for each
individual contract row and bind all assertions for that contract (including the
nested loops for formats and guards) to check against that specific row's output
instead of the global rendered output, ensuring all contract attributes are
verified to appear together in the same row.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 27c328c9-a80d-4569-a8d9-29725e9d06fa
📒 Files selected for processing (15)
devtools/action_contract_report.pydevtools/generated_surfaces.pydevtools/render_cli_output_schemas.pydevtools/render_cli_reference.pydocs/cli-reference.mddocs/plans/release-readiness-gate.mddocs/plans/topology-target.yamldocs/schemas/cli-output/README.mddocs/schemas/cli-output/session-neighbor-candidate.schema.jsondocs/schemas/cli-output/session-summary.schema.jsondocs/topology-status.mdpolylogue/cli/output_assurance.pytests/unit/cli/test_cli_output_assurance_matrix.pytests/unit/devtools/test_action_contract_report.pytests/unit/devtools/test_render_cli_reference.py
💤 Files with no reviewable changes (2)
- polylogue/cli/output_assurance.py
- tests/unit/cli/test_cli_output_assurance_matrix.py
| for contract in ACTION_CONTRACTS: | ||
| path = f"`polylogue {' '.join(contract.path)}`" | ||
| assert path in rendered | ||
| assert f"`{contract.effect}`" in rendered | ||
| assert f"`{contract.input_unit}`" in rendered | ||
| assert f"`{contract.machine_envelope}`" in rendered | ||
| for output_format in contract.formats: | ||
| assert f"`{output_format}`" in rendered | ||
| for guard in contract.guards: | ||
| assert f"`{guard}`" in rendered |
There was a problem hiding this comment.
Bind attribute assertions to the same rendered table row.
These assertions are document-global, so a broken per-contract/per-schema row can still pass when tokens appear in other rows.
Proposed test hardening
def test_report_is_derived_from_action_contracts() -> None:
rendered = render_action_contract_report()
+ lines = rendered.splitlines()
assert "## Public Action Contracts" in rendered
assert "ACTION_CONTRACTS" in rendered
for contract in ACTION_CONTRACTS:
path = f"`polylogue {' '.join(contract.path)}`"
- assert path in rendered
- assert f"`{contract.effect}`" in rendered
- assert f"`{contract.input_unit}`" in rendered
- assert f"`{contract.machine_envelope}`" in rendered
+ row = next((line for line in lines if line.startswith(f"| {path} |")), "")
+ assert row, f"Missing row for {path}"
+ assert f"`{contract.effect}`" in row
+ assert f"`{contract.input_unit}`" in row
+ assert f"`{contract.machine_envelope}`" in row
for output_format in contract.formats:
- assert f"`{output_format}`" in rendered
+ assert f"`{output_format}`" in row
for guard in contract.guards:
- assert f"`{guard}`" in rendered
+ assert f"`{guard}`" in row
def test_report_is_derived_from_published_output_schemas() -> None:
rendered = render_action_contract_report()
+ lines = rendered.splitlines()
assert "## Published Machine Output Schemas" in rendered
assert "render_cli_output_schemas.SCHEMAS" in rendered
for schema in SCHEMAS:
- assert f"`{schema.name}`" in rendered
- assert f"`{schema.model.__name__}`" in rendered
+ schema_name = f"`{schema.name}`"
+ row = next((line for line in lines if line.startswith(f"| {schema_name} |")), "")
+ assert row, f"Missing row for schema {schema.name}"
+ assert f"`{schema.model.__name__}`" in row
for surface in schema.surfaces:
- assert f"`{surface}`" in rendered
+ assert f"`{surface}`" in rowAlso applies to: 30-34
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit/devtools/test_action_contract_report.py` around lines 13 - 22, The
assertions within the loop that iterates over ACTION_CONTRACTS are checking if
contract attributes (path, effect, input_unit, machine_envelope, formats,
guards) exist anywhere in the global rendered output, which allows tests to pass
even if a specific contract's row is malformed as long as the tokens appear
elsewhere. Extract the rendered output for each individual contract row and bind
all assertions for that contract (including the nested loops for formats and
guards) to check against that specific row's output instead of the global
rendered output, ensuring all contract attributes are verified to appear
together in the same row.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45f163f63a
ℹ️ 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".
| ), | ||
| model=SessionNeighborCandidatePayload, | ||
| surfaces=("polylogue neighbors --format json",), | ||
| surfaces=("polylogue read --view neighbors --format json",), |
There was a problem hiding this comment.
Scope neighbor schema to emitted array entries
For the neighbors JSON path, the CLI does not emit a SessionNeighborCandidatePayload as the top-level output; _run_read_neighbors wraps the candidates via emit_success({"neighbors": [...]}), so the actual JSON is a machine-success envelope with candidates under result.neighbors. Publishing this candidate schema against polylogue read --view neighbors --format json will make downstream validators apply it to the whole CLI output and fail; please label the surface as the nested result.neighbors[] payload or publish an envelope schema for the command.
Useful? React with 👍 / 👎.
Summary
Remove the old
polylogue.cli.output_assuranceregistry and render the CLI action/output documentation from the live action contracts plus generated CLI output schema metadata. This keeps the command-floor report coupled to executable contract tests instead of a parallel checklist.Closes #1816.
Ref #1849.
Ref #1827.
Problem
output_assurance.pywas still a 500+ line hand-maintained second registry: command families, schema flags, snapshot/plain flags, streaming flags, and a CLI-reference renderer. That duplicatedACTION_CONTRACTSand schema metadata, and it preserved stale command names after command absorption.Solution
devtools.action_contract_reportas the docs renderer overACTION_CONTRACTSandrender_cli_output_schemas.SCHEMAS.polylogue/cli/output_assurance.pyand the registry-specific test file.devtools render-cli-referenceto the contract-derived report.polylogue selectbecomes query-hit session summary metadata, and standalonepolylogue neighborsbecomesread --view neighbors.Verification
devtools test tests/unit/cli/test_cli_action_contracts.py tests/unit/devtools/test_action_contract_report.py tests/unit/devtools/test_render_cli_reference.py tests/unit/cli/test_cli_output_schemas.py tests/unit/cli/test_neighbors_command.py—52 passed in 40.37s.devtools release-readiness—release-readiness: ok.devtools verify --quick—exit_code: 0.devtools verify --quickon45f163f6—exit_code: 0.devtools verifycompleted all static/generated checks, then pytest-testmon expanded into a write-heavy run rather than a bounded affected slice. I stopped it after about 12 minutes and about 15.5 GB of writes with no junit/json result files produced; the run did not report a test failure.Summary by CodeRabbit