Skip to content

refactor(cli): derive action output docs from contracts (#1816) - #2008

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/action-contract-output-floor-1816
Jun 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/action-contract-output-floor-1816

Conversation

@Sinity

@Sinity Sinity commented Jun 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Remove the old polylogue.cli.output_assurance registry 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.py was still a 500+ line hand-maintained second registry: command families, schema flags, snapshot/plain flags, streaming flags, and a CLI-reference renderer. That duplicated ACTION_CONTRACTS and schema metadata, and it preserved stale command names after command absorption.

Solution

  • Add devtools.action_contract_report as the docs renderer over ACTION_CONTRACTS and render_cli_output_schemas.SCHEMAS.
  • Remove polylogue/cli/output_assurance.py and the registry-specific test file.
  • Wire devtools render-cli-reference to the contract-derived report.
  • Fix stale generated schema surfaces: polylogue select becomes query-hit session summary metadata, and standalone polylogue neighbors becomes read --view neighbors.
  • Refresh generated CLI reference, schema docs, topology projection/status, and release-readiness text.

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.
  • Pre-push hook reran devtools verify --quick on 45f163f6 — exit_code: 0.

devtools verify completed 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

  • Documentation
    • Updated CLI reference documentation with a new "Public Action Contracts" section listing all public actions and their specifications (effects, input types, formats, and more).
    • Added "Published Machine Output Schemas" section documenting available output schemas and their associated CLI surfaces.
    • Updated schema documentation references to reflect current CLI commands.
    • Removed the outdated "Output Assurance Matrix" section.

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

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Removes the 567-line hand-maintained polylogue/cli/output_assurance.py registry and its 171-line test suite. Adds devtools/action_contract_report.py that generates equivalent Markdown from ACTION_CONTRACTS and SCHEMAS, wires it into build_document(), corrects two CLI surface name strings in JSON schemas, and regenerates all affected documentation.

Changes

Replace output assurance with code-generated action contract report

Layer / File(s) Summary
New action_contract_report module and tests
devtools/action_contract_report.py, tests/unit/devtools/test_action_contract_report.py
Adds render_action_contract_report() that builds a two-section Markdown string from ACTION_CONTRACTS and SCHEMAS, with two unit tests verifying output is fully derived from those registries.
Wire new report into build_document and update surface inputs
devtools/render_cli_reference.py, devtools/generated_surfaces.py, tests/unit/devtools/test_render_cli_reference.py
Swaps render_matrix_markdown for render_action_contract_report in build_document(), expands cli-reference surface inputs to track the new module plus payloads.py, and extends the render test to assert both new section headers appear.
Correct CLI surface names in schema registry and artifacts
devtools/render_cli_output_schemas.py, docs/schemas/cli-output/session-summary.schema.json, docs/schemas/cli-output/session-neighbor-candidate.schema.json, docs/schemas/cli-output/README.md
Updates session-summary surface from polylogue select --format json to polylogue --format json <query> (hits[].session) and session-neighbor-candidate from polylogue neighbors to polylogue read --view neighbors, propagated into schema files and the schema index.
Remove output_assurance module and test suite
polylogue/cli/output_assurance.py, tests/unit/cli/test_cli_output_assurance_matrix.py
Deletes output_assurance.py (567 lines: ASSURANCE_REGISTRY, OutputAssurance, ActionContractCoverage, family helpers, render_matrix_markdown()) and the 171-line companion test module.
Regenerated docs and topology metadata
docs/cli-reference.md, docs/topology-status.md, docs/plans/release-readiness-gate.md, docs/plans/topology-target.yaml
Regenerates cli-reference.md replacing "Output Assurance Matrix" with the two new generated tables, adjusts topology totals from 828 to 827, and updates release-readiness gate notes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #1816 (Replace output assurance with code-coupled action contracts): This PR directly fulfills the acceptance criteria: deletes output_assurance.py as a hand-maintained second registry, replaces render_matrix_markdown() with a contract-derived renderer over ACTION_CONTRACTS and SCHEMAS, removes the ASSURANCE_REGISTRY parallel command list, and regenerates docs from live code.

Possibly related PRs

  • Sinity/polylogue#1986: Extends the devtools.render_cli_output_schemas.SCHEMAS registry that this PR's new action_contract_report.py directly reads to generate the "Published Machine Output Schemas" section.

Suggested labels

type:refactor

🐇 The old assurance ledger, hand-kept and wide,
Has hopped away—contracts now guide!
ACTION_CONTRACTS speaks true,
The schemas shine through,
And generated docs never lied. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% 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 summarizes the main change: replacing the old output assurance registry with documentation derived from live action contracts.
Description check ✅ Passed The description covers all required sections: Summary (what changed and why), Problem (why it was necessary), Solution (what was done), and Verification (commands run and test results).
Linked Issues check ✅ Passed The PR meets all key objectives from #1816: eliminates the hand-maintained output_assurance.py registry, couples documentation to executable action contracts, removes stale command references, and includes contract-backed verification tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to eliminating the output_assurance registry and coupling docs to action contracts. Generated file updates and schema surface corrections align with the primary objective.

✏️ 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/action-contract-output-floor-1816

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.

github-actions Bot pushed a commit that referenced this pull request Jun 17, 2026

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 123c84e and 45f163f.

📒 Files selected for processing (15)
  • devtools/action_contract_report.py
  • devtools/generated_surfaces.py
  • devtools/render_cli_output_schemas.py
  • devtools/render_cli_reference.py
  • docs/cli-reference.md
  • docs/plans/release-readiness-gate.md
  • docs/plans/topology-target.yaml
  • docs/schemas/cli-output/README.md
  • docs/schemas/cli-output/session-neighbor-candidate.schema.json
  • docs/schemas/cli-output/session-summary.schema.json
  • docs/topology-status.md
  • polylogue/cli/output_assurance.py
  • tests/unit/cli/test_cli_output_assurance_matrix.py
  • tests/unit/devtools/test_action_contract_report.py
  • tests/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

Comment on lines +13 to +22
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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 row

Also 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.

@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: 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",),

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

@Sinity
Sinity merged commit f18a6b8 into master Jun 17, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/action-contract-output-floor-1816 branch June 17, 2026 00:47
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.

Replace output assurance with code-coupled action contracts

1 participant