Repository navigation
test: catalog-driven invariant tests for tags, embeddings, and ChatGPT metadata (#807) - #928
Conversation
…T metadata Add domain-coverage catalog and targeted behavioral tests for three previously under-tested domains identified in #807 recon: ChatGPT parser metadata permutations, tag CRUD lifecycle, and embedding status transitions. Also classify the two known orphan tests in the test-ownership manifest. - New tests/unit/storage/test_tag_contracts.py: 13 parametrized tests covering add/duplicate/remove/bulk/validation/isolation via async repository. - New tests/unit/storage/test_embedding_contracts.py: 9 tests covering embedding_status row lifecycle states (pending/embedded/needs-reindex/error) plus connection-level error propagation. - Extend tests/unit/sources/test_parsers_chatgpt.py with 12 catalog-driven metadata permutation roundtrip tests covering model/author/status/end_turn/ citations/code_execution/user_context fields individually and combined. - New docs/plans/test-coverage-domains.yaml: qualitative domain coverage catalog mapping 26 domains to covering test files, with coverage assessments and known gap documentation. - Extend docs/plans/test-ownership.yaml: classify two orphan tests (pre-push-hook, no-cli-imports) as legitimate structural tests. Ref #807 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR introduces comprehensive test coverage documentation and three new contract-driven test suites. It adds a test-coverage-domains catalog mapping production modules to covering tests, updates test-ownership classifications, and implements parameterized tests for ChatGPT parser metadata roundtrips, embedding stats lifecycle scenarios, and tag CRUD operations. ChangesTest Coverage Documentation and Storage Contracts
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Suggested labels
Poem
✨ 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6b8bef622
ℹ️ 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".
| listed = await repo.list_tags() | ||
| for expected_tag in expected: | ||
| assert expected_tag in listed, f"[{desc}] Expected tag '{expected_tag}' in list_tags: {listed}" |
There was a problem hiding this comment.
Assert removed tags are absent after remove operations
test_tag_lifecycle_crud only checks that expected tags are present in list_tags, but never checks that removed tags are absent. In the ("remove", ["review"], []) case this loop performs zero assertions, and in ("remove", ["review", "backlog"], ["backlog"]) the test still passes if remove_tag is a no-op because backlog remains present either way. This leaves the new remove-path coverage ineffective and can mask regressions in tag deletion behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds catalog-driven invariant/contract tests and planning manifests to improve behavioral coverage across ChatGPT parser metadata handling, tag CRUD lifecycles, and embedding status/stats transitions (per #807).
Changes:
- Added new unit test suites for tag CRUD invariants and embedding status/stat lifecycle behaviors.
- Expanded ChatGPT parser tests with parametrized metadata permutation roundtrip coverage through parse → materialize → hydrate.
- Introduced/updated documentation manifests for qualitative domain coverage and test “ownership” classification of structural/orphan tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/storage/test_tag_contracts.py | New catalog-driven async tests for tag lifecycle operations via ConversationRepository. |
| tests/unit/storage/test_embedding_contracts.py | New lifecycle/state tests for embedding stats reading across embedding_status conditions and error propagation. |
| tests/unit/sources/test_parsers_chatgpt.py | Adds parametrized metadata permutation tests validating metadata survival across the full pipeline. |
| docs/plans/test-ownership.yaml | Classifies additional structural/orphan tests as legitimate non-module-target tests. |
| docs/plans/test-coverage-domains.yaml | New qualitative domain-to-tests coverage catalog to complement import-reachability gates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for expected_tag in expected: | ||
| assert expected_tag in listed, f"[{desc}] Expected tag '{expected_tag}' in list_tags: {listed}" |
| # --------------------------------------------------------------------------- | ||
| # Schema bootstrap (same DDL as sqlite_vec_runtime.py) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| _EMBEDDING_STATUS_DDL = """ | ||
| CREATE TABLE IF NOT EXISTS embedding_status ( | ||
| conversation_id TEXT PRIMARY KEY, | ||
| message_count_embedded INTEGER DEFAULT 0, | ||
| last_embedded_at TEXT, | ||
| needs_reindex INTEGER DEFAULT 0, | ||
| error_message TEXT | ||
| ); | ||
| """ | ||
|
|
||
| _MESSAGE_EMBEDDINGS_DDL = """ | ||
| CREATE TABLE IF NOT EXISTS message_embeddings ( | ||
| message_id TEXT | ||
| ); | ||
| """ | ||
|
|
| def _assert_none_embedded(stats: EmbeddingStatsSnapshot, _conn: sqlite3.Connection) -> None: | ||
| assert stats.embedded_conversations == 0 | ||
| assert stats.embedded_messages == 0 | ||
| assert stats.pending_conversations == 0 | ||
|
|
||
|
|
||
| def _assert_all_pending(stats: EmbeddingStatsSnapshot, _conn: sqlite3.Connection) -> None: | ||
| assert stats.embedded_conversations == 0 | ||
| assert stats.embedded_messages == 0 | ||
| assert stats.pending_conversations >= 1 | ||
|
|
||
|
|
||
| def _assert_partially_embedded(stats: EmbeddingStatsSnapshot, _conn: sqlite3.Connection) -> None: | ||
| assert stats.embedded_conversations >= 1 | ||
| assert stats.pending_conversations >= 1 | ||
|
|
||
|
|
||
| def _assert_fully_embedded(stats: EmbeddingStatsSnapshot, _conn: sqlite3.Connection) -> None: | ||
| assert stats.embedded_conversations == 2 | ||
| assert stats.pending_conversations == 0 | ||
| assert stats.embedded_messages > 0 | ||
| # Pending derived from total conversations: when all are embedded, pending == 0 | ||
| # even though total_conversations count = 2 (they're tracked by conversations table) | ||
|
|
||
|
|
||
| def _assert_error_visible(stats: EmbeddingStatsSnapshot, conn: sqlite3.Connection) -> None: |
First wave of the #807 catalog-driven test architecture. The verify-test-ownership lint reported 0 uncovered modules, but that measures import presence, not behavior coverage; a domain recon found 11 uncovered or partially covered behavioral domains. - `tests/unit/storage/test_tag_contracts.py` (13 catalog-driven async tests) covers tag CRUD invariants — add/duplicate/remove, bulk operations, validation, isolation across conversations — through `ConversationRepository`. Tags previously had no dedicated CRUD test file. - `tests/unit/storage/test_embedding_contracts.py` (9 tests) covers the `embedding_status` row lifecycle states (empty, pending, partial, full, needs-reindex, error) plus connection error propagation, where existing tests only covered read paths. - `tests/unit/sources/test_parsers_chatgpt.py`: +12 parametrized metadata permutation tests covering model slugs, tool author metadata, status, end_turn, citations, code execution, user context, and the full combination through parser→materialize→hydrate. - `docs/plans/test-coverage-domains.yaml`: 26-domain qualitative coverage catalog used as the inventory for follow-up waves. - `docs/plans/test-ownership.yaml`: classifies the two known orphan tests as legitimate structural tests. Refs #807
First wave of the #807 catalog-driven test architecture. The verify-test-ownership lint reported 0 uncovered modules, but that measures import presence, not behavior coverage; a domain recon found 11 uncovered or partially covered behavioral domains. - `tests/unit/storage/test_tag_contracts.py` (13 catalog-driven async tests) covers tag CRUD invariants — add/duplicate/remove, bulk operations, validation, isolation across conversations — through `ConversationRepository`. Tags previously had no dedicated CRUD test file. - `tests/unit/storage/test_embedding_contracts.py` (9 tests) covers the `embedding_status` row lifecycle states (empty, pending, partial, full, needs-reindex, error) plus connection error propagation, where existing tests only covered read paths. - `tests/unit/sources/test_parsers_chatgpt.py`: +12 parametrized metadata permutation tests covering model slugs, tool author metadata, status, end_turn, citations, code execution, user context, and the full combination through parser→materialize→hydrate. - `docs/plans/test-coverage-domains.yaml`: 26-domain qualitative coverage catalog used as the inventory for follow-up waves. - `docs/plans/test-ownership.yaml`: classifies the two known orphan tests as legitimate structural tests. Refs #807
…ex (#1184) (#1194) ## Summary Mirrors the ChatGPT `_METADATA_PERMUTATION_CASES` catalog pattern in `tests/unit/sources/test_parsers_chatgpt.py` for the three remaining parsers called out in #1184: Claude-AI (web export), Gemini (Drive chunkedPrompt), and Codex (JSONL session envelopes). Each new test file is a module-level `@pytest.mark.parametrize` over a `(label, payload_factory, expectations)` triple that runs the full parser → transform → save → hydrate pipeline through the shared `tests.infra.pipeline_roundtrip` helpers. ## Problem PR #928 (under #997's predecessor #807) explicitly deferred parser contract tests for Claude-AI and Gemini — they remained in the AC3 "uncovered domains" list when #997 was reopened. ChatGPT now has catalog-driven metadata roundtrip coverage in `tests/unit/sources/test_parsers_chatgpt.py`; the equivalent did not exist for the other two providers. Codex had `test_parsers_codex.py` covering format detection / session metadata / git context, but no metadata-permutation catalog comparable to ChatGPT's. ## Solution Three new test files, each ~300 LOC, no per-case copy-paste: - `tests/unit/sources/test_parsers_claude_ai_catalog.py` — 9 parametrized cases over the `chat_messages` shape: plain text, model variants (claude-3-opus, claude-3-5-sonnet), thinking blocks, tool_use + tool_result pair (covering the `reclassify_tool_result_envelope` user→tool reclassification), attachments, citations metadata in content blocks, system prompt prelude, and a rich mixed turn. - `tests/unit/sources/test_parsers_drive_catalog.py` — 8 cases over `chunkedPrompt.chunks`: plain exchange, `displayName` fallback, role normalisation (`model` → `assistant`), thinking chunks (`isThought` + `thinkingBudget`), `executableCode` + `codeExecutionResult`, Drive document attachments, inline image attachments, and timestamp ordering. - `tests/unit/sources/test_parsers_codex_catalog.py` — 8 cases over Codex JSONL envelopes: plain exchange, `session_meta` with git context + instructions, `developer` → `system` normalisation, `function_call` + `function_call_output` → `tool_use` + `tool_result`, direct (non-envelope) format, role casing normalisation, multi-turn ordering, and state-record skipping. Each catalog: - Uses `@pytest.mark.parametrize` against a module-level list. - Reuses `tests.infra.pipeline_roundtrip.parse_and_transform_payload` / `save_transform_and_hydrate` and `tests.infra.storage_records.db_setup`. - Asserts title, role normalisation, content-block kinds, timestamp ordering, and attachment counts where applicable. - Includes a fast parser-only smoke test that walks the catalog without going through storage so a parser-side regression is caught before the pipeline roundtrip runs. Non-obvious decision: content-block kind assertions read `roundtrip.transform.bundle.content_blocks` (the materialisation boundary) instead of the hydrated `Message.content_blocks`, because the sync `store_records` helper does not currently propagate the bundle's content_block rows through `MessageRecord.content_blocks`; the materialised bundle is the canonical block representation the daemon write path persists. Title, role, and timestamp assertions still run against the hydrated `Conversation`. The AC's "reuse `schema_conformant_payload(provider)` where possible" is satisfied transitively: `test_parser_crashlessness.py` and `test_parsers_props.py` already drive the same parsers with schema-conformant Hypothesis payloads; this PR adds a complementary hand-curated catalog where each row exercises a specific named metadata surface. ## Verification ``` nix develop -c pytest tests/unit/sources/test_parsers_claude_ai_catalog.py \ tests/unit/sources/test_parsers_drive_catalog.py \ tests/unit/sources/test_parsers_codex_catalog.py \ -p no:cacheprovider -o "addopts=" # 28 passed, 1 warning in 0.30s nix develop -c devtools verify --quick # exit_code: 0 (format, lint, mypy, render-all --check, manifest gates) ``` Pre-existing master failures (`tests/infra/test_storage_records.py::test_store_records_commits_within_lock` — `no such table: user_marks`; topology-projection / artifact-graph cells; surface→storage boundary lint) are present on the underlying branch before this change and are unrelated to the catalog additions. Verified by stashing the three new files and re-running the affected suites. Closes #1184
Summary
Adds targeted behavioral tests for three previously under-tested domains identified in the #807 reconnaissance report: ChatGPT parser metadata permutations, tag CRUD lifecycle, and embedding status transitions. Also adds a qualitative domain coverage catalog and classifies the two known orphan tests.
Problem
The #807 recon found 11 uncovered or partially-covered domains. Import-reachability (verify-test-ownership) reported 0 uncovered modules but this is a false signal — it measures import presence, not behavior coverage. Three high-priority gaps were selected for this PR:
Solution
New files
Modified files
Verification
Pre-existing hook failures (not caused by this PR): mypy errors in support.py (SessionInsightStatusSnapshot attribute mismatch), ruff I001 in test_render_quality_reference.py, file-budget overage in test_fts5.py, render-all drift.
Ref #807
Summary by CodeRabbit
Documentation
Tests