Repository navigation
fix(tests): green master CI — TypedDict, MCP mutation contracts, drift - #505
Conversation
Master CI has been red since 6b5c392 (#489) due to 14 unrelated test failures. This PR fixes them all in one mechanical pass. Changes ------- 1. **Python 3.11 TypedDict / pydantic compatibility.** pydantic 2.12+ refuses ``typing.TypedDict`` on Py<3.12 with PydanticUserError. Switch the 19 modules that declare TypedDict subclasses to import from ``typing_extensions`` instead. Add ``typing-extensions>=4.7`` to ``pyproject.toml`` so the import resolves on every supported Python. 2. **MCP mutation tests — query_store.resolve_id pre-check.** The mutation tools (``add_tag``, ``remove_tag``, ``set_metadata``, ``delete_metadata``, ``delete_conversation``) now resolve the conversation_id via the query store before mutating; tests that mocked only ``_get_tag_store`` saw the pre-check fail with "conversation not found". Add a ``resolved_id`` parameter to ``make_query_store_mock`` and patch ``_get_query_store`` in each affected test. 3. **Bulk tag — bulk_add_tags delegation.** ``bulk_tag_conversations`` now calls ``tag_store.bulk_add_tags(ids, tags)`` once instead of fan-out N×M ``add_tag`` awaits. Update the test to mock ``bulk_add_tags`` and assert on it. 4. **Clamp limit — 1000 cap.** ``_clamp_limit`` caps inputs at 1000; the test still expected unbounded inputs to echo. Update the parametrized expectations: 5000/10001/99999 → 1000. 5. **Logging test under POLYLOGUE_FORCE_PLAIN=1.** ``configure_logging`` reads ``POLYLOGUE_FORCE_PLAIN`` and forces ``ConsoleRenderer(colors=False)`` when set. CI sets that env, so the test that asserted ``colors=True`` failed. Add ``patch.dict("os.environ")`` plus ``env.pop("POLYLOGUE_FORCE_PLAIN")`` so the colored-output branch exercises its own contract regardless of ambient env. 6. **MCP tool wire schema witness regen.** ``get_stats_by`` gained an ``enum`` field on the ``group_by`` parameter; the committed witness was stale. Regenerated. 7. **Terminal snapshot regen.** ``test_help_at_*_width`` and ``test_help_output_snapshot`` baselines drifted after the show/export help-text fixes (#482/#483). Same regen as #503; included here so the unit suite is green standalone. Verification ------------ POLYLOGUE_FORCE_PLAIN=1 pytest tests/unit/mcp/ tests/unit/test_logging_runtime.py \ tests/unit/cli/test_terminal_snapshots.py --no-cov → all pass Out of scope ------------ The following test failures from the same CI run are **not** addressed here because they are pre-existing or in another contributor's lane: - ``test_cli_tail_list_json_exposes_tail_provenance`` — TOCTOU warning from a parallel BlobStore fix; tracked separately. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThe PR migrates Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
Bundles the .txt baseline drift fix from #503 so the showcase-verify job passes on this branch standalone. Without these the unit suite is green but showcase-verify still fails. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/unit/mcp/test_tool_contracts.py (2)
989-1005: 🧹 Nitpick | 🔵 TrivialPrefer
assert_awaited_once_withfor the AsyncMock assertion.
bulk_add_tagsis now anAsyncMock, so useassert_awaited_once_withto assert the await happened (not just the call object construction). Functionallyassert_called_once_withalso works on AsyncMock, but the awaited variant better expresses intent and would catch a future regression where the coroutine is created but never awaited.Proposed nit
- mock_tag_store.bulk_add_tags.assert_called_once_with(["conv-1", "conv-2"], ["review", "important"]) + mock_tag_store.bulk_add_tags.assert_awaited_once_with(["conv-1", "conv-2"], ["review", "important"])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/mcp/test_tool_contracts.py` around lines 989 - 1005, The test uses mock_tag_store.bulk_add_tags (an AsyncMock) but asserts with mock_tag_store.bulk_add_tags.assert_called_once_with; change this to use mock_tag_store.bulk_add_tags.assert_awaited_once_with(["conv-1", "conv-2"], ["review", "important"]) so the test verifies the coroutine was actually awaited; update the assertion in tests/unit/mcp/test_tool_contracts.py next to the existing invocation of mcp_server._tool_manager._tools["bulk_tag_conversations"].fn.
1108-1121: 🧹 Nitpick | 🔵 TrivialAdd explicit assertion for
resolve_idordering in confirm check.The implementation correctly validates
confirmbefore callingresolve_id(lines 138-146 inserver_mutation_tools.py). The test should explicitly assertmock_query_store.resolve_id.assert_not_called()alongside the existingdelete_conversationassertion to lock in this ordering constraint. This prevents accidental reordering of the safety check if the implementation is refactored.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/mcp/test_tool_contracts.py` around lines 1108 - 1121, Add an explicit assertion that mock_query_store.resolve_id was not called in test_delete_requires_confirm to lock in the ordering check for confirm handling; in the test_delete_requires_confirm function, after parsing the result and before/alongside mock_query_store.delete_conversation.assert_not_called(), add mock_query_store.resolve_id.assert_not_called() to ensure resolve_id is not invoked when confirm=False on the delete_conversation tool.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/unit/mcp/test_tool_contracts.py`:
- Around line 989-1005: The test uses mock_tag_store.bulk_add_tags (an
AsyncMock) but asserts with
mock_tag_store.bulk_add_tags.assert_called_once_with; change this to use
mock_tag_store.bulk_add_tags.assert_awaited_once_with(["conv-1", "conv-2"],
["review", "important"]) so the test verifies the coroutine was actually
awaited; update the assertion in tests/unit/mcp/test_tool_contracts.py next to
the existing invocation of
mcp_server._tool_manager._tools["bulk_tag_conversations"].fn.
- Around line 1108-1121: Add an explicit assertion that
mock_query_store.resolve_id was not called in test_delete_requires_confirm to
lock in the ordering check for confirm handling; in the
test_delete_requires_confirm function, after parsing the result and
before/alongside mock_query_store.delete_conversation.assert_not_called(), add
mock_query_store.resolve_id.assert_not_called() to ensure resolve_id is not
invoked when confirm=False on the delete_conversation tool.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4aa19c02-15aa-4673-9a10-c02113683cb4
📒 Files selected for processing (29)
polylogue/lib/embeddings/stats.pypolylogue/lib/session_payload_documents.pypolylogue/mcp/payloads.pypolylogue/mcp/server_prompts.pypolylogue/pipeline/payload_types.pypolylogue/pipeline/run_finalization.pypolylogue/pipeline/semantic_capture.pypolylogue/pipeline/services/acquisition_records.pypolylogue/pipeline/services/indexing.pypolylogue/pipeline/services/ingest_worker.pypolylogue/schemas/verification_models.pypolylogue/sources/assembly.pypolylogue/sources/drive_gateway.pypolylogue/storage/backends/queries/stats.pypolylogue/storage/cursor_state.pypolylogue/storage/query_models.pypolylogue/storage/run_state.pypolylogue/storage/session_product_runtime.pypolylogue/surface_payloads.pypyproject.tomltests/baselines/showcase/help-export.txttests/baselines/showcase/help-main.txttests/baselines/showcase/help-show.txttests/data/witnesses/mcp-tool-schemas.jsontests/infra/mcp.pytests/unit/cli/__snapshots__/test_terminal_snapshots.ambrtests/unit/mcp/test_server_surfaces.pytests/unit/mcp/test_tool_contracts.pytests/unit/test_logging_runtime.py
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ 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". |
#505) ## Summary Master CI has been red since ddf212f (#489) due to 14 unrelated test failures. This PR fixes them all in one mechanical pass so the architecture-series PRs (#502 and follow-ups) can land. ## Problem Failures span four root causes: 1. **Python 3.11 / pydantic TypedDict.** Pydantic 2.12+ refuses `typing.TypedDict` on Python < 3.12. 19 modules declare TypedDict subclasses; they all need to import from `typing_extensions`. 2. **MCP mutation tests don't mock the new resolve_id pre-check.** Mutation tools resolve the conversation_id via the query store before mutating; tests only patched `_get_tag_store`, so resolve_id returned None and the tools short-circuited with "conversation not found". 3. **Schema/contract drift.** `_clamp_limit` caps at 1000 but tests still echo unbounded inputs. `get_stats_by` gained an enum on `group_by` but the witness wasn't regenerated. `bulk_tag_conversations` switched to `bulk_add_tags(ids, tags)` but the test still asserts N×M `add_tag` awaits. 4. **Env-sensitive logging test.** `configure_logging` honors `POLYLOGUE_FORCE_PLAIN`; CI sets that env to `1`, so `ConsoleRenderer(colors=True)` is unreachable from inside CI. ## Solution Six targeted fixes: 1. Switch 19 files from `typing.TypedDict` to `typing_extensions.TypedDict`. Add `typing-extensions>=4.7` to `pyproject.toml` (works on all supported Pythons). 2. Add `resolved_id` parameter to `make_query_store_mock` and patch `_get_query_store` in affected mutation tests (`add_tag`, `remove_tag`, `set_metadata`, `delete_metadata`, `delete_conversation`). 3. Update `_clamp_limit` parametrized cases (5000/10001/99999 → 1000); regen `tests/data/witnesses/mcp-tool-schemas.json`; rewrite bulk_tag test to assert on `bulk_add_tags`. 4. Add `patch.dict("os.environ")` + `env.pop("POLYLOGUE_FORCE_PLAIN")` to the logging test. 5. Refresh syrupy `test_terminal_snapshots.ambr` (same drift as #503; included here to make the unit suite green standalone). ## Verification ``` POLYLOGUE_FORCE_PLAIN=1 pytest tests/unit/mcp/ \ tests/unit/test_logging_runtime.py \ tests/unit/cli/test_terminal_snapshots.py --no-cov → all pass devtools verify --quick → all checks passed (pre-push hook) ``` ## Out of scope `test_cli_tail_list_json_exposes_tail_provenance` is failing on a TOCTOU warning from a parallel BlobStore fix (in `feature/fix/audit-final` / d295503). Tracked there; not in this PR. ## Related - #503 — baseline + syrupy refresh; this PR includes the syrupy bit again so master test suite is green even without #503. - #502 — topology projection cleanup; blocked on master CI being green. - #489 — the merge that introduced the 14 failures (test code wasn't updated alongside MCP authz/limits + clamp_limit + bulk_add_tags + the show/export help text changes that landed across several merges). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Enhanced CLI help text for export and show commands with clearer descriptions of conversation ID format handling and default output behavior. * Reordered MCP tool schema parameters with added validation constraints. * **Chores** * Added `typing-extensions>=4.7` as a runtime dependency. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Master CI has been red since 6b5c392 (#489) due to 14 unrelated test failures. This PR fixes them all in one mechanical pass so the architecture-series PRs (#502 and follow-ups) can land.
Problem
Failures span four root causes:
typing.TypedDicton Python < 3.12. 19 modules declare TypedDict subclasses; they all need to import fromtyping_extensions._get_tag_store, so resolve_id returned None and the tools short-circuited with "conversation not found"._clamp_limitcaps at 1000 but tests still echo unbounded inputs.get_stats_bygained an enum ongroup_bybut the witness wasn't regenerated.bulk_tag_conversationsswitched tobulk_add_tags(ids, tags)but the test still asserts N×Madd_tagawaits.configure_logginghonorsPOLYLOGUE_FORCE_PLAIN; CI sets that env to1, soConsoleRenderer(colors=True)is unreachable from inside CI.Solution
Six targeted fixes:
typing.TypedDicttotyping_extensions.TypedDict. Addtyping-extensions>=4.7topyproject.toml(works on all supported Pythons).resolved_idparameter tomake_query_store_mockand patch_get_query_storein affected mutation tests (add_tag,remove_tag,set_metadata,delete_metadata,delete_conversation)._clamp_limitparametrized cases (5000/10001/99999 → 1000); regentests/data/witnesses/mcp-tool-schemas.json; rewrite bulk_tag test to assert onbulk_add_tags.patch.dict("os.environ")+env.pop("POLYLOGUE_FORCE_PLAIN")to the logging test.test_terminal_snapshots.ambr(same drift as fix(baselines): refresh showcase help baselines after #482/#483 merges #503; included here to make the unit suite green standalone).Verification
Out of scope
test_cli_tail_list_json_exposes_tail_provenanceis failing on a TOCTOU warning from a parallel BlobStore fix (infeature/fix/audit-final/ d295503). Tracked there; not in this PR.Related
Summary by CodeRabbit
Documentation
Chores
typing-extensions>=4.7as a runtime dependency.