Skip to content

test(cli): bind mutation contracts to output schemas (#1816) - #1986

Merged
Sinity merged 1 commit into
masterfrom
feature/test/action-contract-output-schema-1816
Jun 16, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/action-contract-output-schema-1816

Conversation

@Sinity

@Sinity Sinity commented Jun 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds generated CLI output schemas for the shared mutation and query-error payloads, then binds #1816 action-contract mutation metadata to those schemas with executable tests.

Problem

#1816 introduced CliActionContract.machine_envelope, and mutation actions (mark, delete, import) declare the mutation envelope. The generated docs/schemas/cli-output/ surface did not publish MutationResultPayload, and no action-contract test validated real destructive-action machine output against a generated schema. That left the mutation-envelope claim partially prose-only.

Solution

Issue slice: contract-derived machine-output/schema drift checks for mutation/error envelopes.

Files inspected: polylogue/cli/action_contracts.py, polylogue/surfaces/payloads.py, devtools/render_cli_output_schemas.py, tests/unit/cli/test_cli_action_contracts.py, tests/unit/cli/test_cli_output_schemas.py.

Files changed: devtools/render_cli_output_schemas.py, generated docs/schemas/cli-output/*, and the two focused CLI schema/contract test files.

Old surface removed or retained: retained the existing generated CLI-output schema surface; expanded it with mutation-result.schema.json and query-error.schema.json rather than adding a detached manifest.

Contracts/tests added: mutation action contracts must now have a published MutationResultPayload schema, and delete's aborted/dry-run outputs validate against it. The schema suite also validates representative MutationResultPayload and QueryErrorPayload instances.

Generated artifacts updated: regenerated docs/schemas/cli-output/README.md, mutation-result.schema.json, and query-error.schema.json with devtools render-cli-output-schemas.

Known caveats / SPEC_MISMATCH: this does not finish all #1816 remaining work; read-view item schemas and completion/help generation remain separate coherent phases.

Follow-up intentionally not included: no command-floor expansion, no new proof/catalog layer, no release-gate closure.

Verification

  • devtools test tests/unit/cli/test_cli_action_contracts.py tests/unit/cli/test_cli_output_schemas.py -> 36 passed.
  • devtools render-cli-output-schemas --check -> sync OK for docs/schemas/cli-output.
  • devtools verify --quick -> exit_code 0.
  • Pre-push devtools verify --quick -> exit_code 0.
  • Attempted devtools verify; it stopped before tests because this fresh worktree has no pytest-testmon seed (.testmondata / .cache/testmon/seed.json).

Ref #1816

Summary by CodeRabbit

  • Documentation

    • Added new JSON schemas for mutation result and query error CLI outputs with expanded schema documentation.
  • Tests

    • Added validation tests to verify mutation and query error outputs conform to their schema specifications.

Problem: #1816 action contracts declared mutation and error machine envelopes, but the generated cli-output schema surface did not publish the shared MutationResultPayload/QueryErrorPayload models and the action-contract tests did not validate real mutation outputs against a schema.

What changed: add generated schema entries for mutation-result and query-error, regenerate the cli-output schema index/artifacts, and extend action/schema tests so delete preview/aborted outputs validate against the published mutation schema.

Verification: devtools test tests/unit/cli/test_cli_action_contracts.py tests/unit/cli/test_cli_output_schemas.py -> 36 passed; devtools render-cli-output-schemas --check -> sync OK; devtools verify --quick -> exit_code 0. Default devtools verify was attempted but this fresh worktree lacks the pytest-testmon seed.

Ref #1816
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b251cf04-6739-4b68-93f2-77f4875dbc9d

📥 Commits

Reviewing files that changed from the base of the PR and between bb43e40 and b6dfa79.

📒 Files selected for processing (6)
  • devtools/render_cli_output_schemas.py
  • docs/schemas/cli-output/README.md
  • docs/schemas/cli-output/mutation-result.schema.json
  • docs/schemas/cli-output/query-error.schema.json
  • tests/unit/cli/test_cli_action_contracts.py
  • tests/unit/cli/test_cli_output_schemas.py

📝 Walkthrough

Walkthrough

Two new CLI output JSON schemas (mutation-result and query-error) are added under docs/schemas/cli-output/, registered in the devtools render_cli_output_schemas.py generator via new CliOutputSchema entries backed by MutationResultPayload and QueryErrorPayload, documented in the README, and covered by contract tests that validate both model instances and live CLI delete outputs against the schemas.

Changes

CLI Output Schema Contracts

Layer / File(s) Summary
JSON schema files and devtools registry wiring
docs/schemas/cli-output/mutation-result.schema.json, docs/schemas/cli-output/query-error.schema.json, devtools/render_cli_output_schemas.py, docs/schemas/cli-output/README.md
Defines mutation-result.schema.json (required status, optional counts/session fields, additionalProperties: false) and query-error.schema.json (required error, literal ok: false). Imports MutationResultPayload and QueryErrorPayload and registers both as CliOutputSchema entries in the devtools generator. Adds the two new schema rows to the README table.
Contract validation tests
tests/unit/cli/test_cli_action_contracts.py, tests/unit/cli/test_cli_output_schemas.py
Adds SCHEMAS_DIR constant and _load_cli_output_schema helper. Tests assert mutation-result schema exists in the registry and on disk. Model-instance tests serialize MutationResultPayload and QueryErrorPayload via model_dump and run jsonschema.validate against the published schemas. Delete CLI tests (aborted and --dry-run) also validate JSON output against the mutation-result schema.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • Sinity/polylogue#1907: Directly related — the mutation-result JSON schema and contract tests in this PR target the standardized MutationResultPayload shape and statuses that the referenced PR refactors the CLI to emit.

Poem

🐇 Hop hop, schemas in place,
mutation-result takes its space.
query-error follows too,
additionalProperties: false — it's true!
jsonschema says "all good,"
contracts work just as they should. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test(cli): bind mutation contracts to output schemas (#1816)' accurately describes the main change—adding tests that bind mutation action contracts to generated CLI output schemas.
Description check ✅ Passed The description comprehensively covers all required template sections: Summary (what changed and why), Problem (why the work was necessary), Solution (key modules and changes), Verification (exact commands and results), and includes Risks/Follow-ups noting intentionally deferred work.
Docstring Coverage ✅ Passed Docstring coverage is 84.62% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/test/action-contract-output-schema-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.

@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: b6dfa79419

ℹ️ 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".

surfaces=(
"GET /api/sessions?query=... (error path)",
"daemon query/read error responses",
"MCP query/read error responses",

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 Remove MCP from query-error schema surfaces

For MCP query/read failures, the code path I checked (server_tools.py calling hooks.error_json, implemented by _error_json) serializes MCPErrorPayload with fields like status, message, code, and is_error, not QueryErrorPayload's ok, error, detail, and field shape. Advertising this schema for MCP query/read error responses will make downstream validators reject actual MCP errors; limit this entry to the daemon HTTP shape or publish a separate MCP error schema.

Useful? React with 👍 / 👎.

@Sinity
Sinity merged commit d8605ce into master Jun 16, 2026
12 checks passed
@Sinity
Sinity deleted the feature/test/action-contract-output-schema-1816 branch June 16, 2026 06:51
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.

1 participant