Skip to content

test: catalog-driven invariant tests for tags, embeddings, and ChatGPT metadata (#807) - #928

Merged
Sinity merged 1 commit into
masterfrom
feature/test/test-architecture-807
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/test-architecture-807

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026 •

Copy link
Copy Markdown
Owner

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:

  1. ChatGPT parser: existing metadata roundtrip test covers a single golden path; no permutations
  2. Tags: no dedicated CRUD invariant test file exists; tags are tested incidentally through lifecycle harness
  3. Embeddings: existing stats tests cover read paths but not the state machine lifecycle

Solution

New files

  • tests/unit/storage/test_tag_contracts.py — 13 catalog-driven async tests covering add/duplicate/remove/bulk/validation/isolation via ConversationRepository
  • tests/unit/storage/test_embedding_contracts.py — 9 tests covering embedding_status row lifecycle states (empty/pending/partially-embedded/fully-embedded/needs-reindex/error-state) plus connection-level error propagation
  • docs/plans/test-coverage-domains.yaml — 26-domain qualitative coverage catalog with coverage assessments (covered/partial/uncovered) and known gap documentation

Modified files

  • tests/unit/sources/test_parsers_chatgpt.py — +12 parametrized metadata permutation tests covering model slug variants, tool author metadata, status, end_turn, citations, code_execution, user_context, and the full combination. Each permutation verifies the complete parser->materialize->hydrate pipeline.
  • docs/plans/test-ownership.yaml — classified two orphan tests (test_pre_push_hook.py, test_no_cli_imports.py) as legitimate structural tests

Verification

pytest tests/unit/sources/test_parsers_chatgpt.py tests/unit/storage/test_tag_contracts.py tests/unit/storage/test_embedding_contracts.py -v
# 90 passed in 10.09s

ruff check (3 files): All checks passed
mypy --strict (3 files): Success, no issues found

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

    • Added test-coverage mapping catalog documenting domain-to-test relationships and coverage status across architecture layers.
    • Updated test-ownership documentation with additional test categorizations.
  • Tests

    • Enhanced ChatGPT parser tests with comprehensive metadata persistence validation.
    • Added embedding system contract tests covering lifecycle scenarios and error handling.
    • Added tag management contract tests for CRUD operations, isolation, and validation.

…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]>
Copilot AI review requested due to automatic review settings May 7, 2026 17:27
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f6e6c944-142b-4c87-9cda-367ebe2ce30b

📥 Commits

Reviewing files that changed from the base of the PR and between 18e68c0 and d6b8bef.

📒 Files selected for processing (5)
  • docs/plans/test-coverage-domains.yaml
  • docs/plans/test-ownership.yaml
  • tests/unit/sources/test_parsers_chatgpt.py
  • tests/unit/storage/test_embedding_contracts.py
  • tests/unit/storage/test_tag_contracts.py

📝 Walkthrough

Walkthrough

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

Changes

Test Coverage Documentation and Storage Contracts

Layer / File(s) Summary
Test Coverage Catalog
docs/plans/test-coverage-domains.yaml, docs/plans/test-ownership.yaml
New test-coverage-domains catalog maps production domains to covering tests across architectural rings; test-ownership is updated to classify structural tests.
Parser Metadata Roundtrip Tests
tests/unit/sources/test_parsers_chatgpt.py
Catalog-driven test suite verifies ChatGPT metadata (author, status, end_turn, recipient fields) survives materialization and hydration cycles, with assertion that hydrated messages do not depend on provider_meta.raw.
Embedding Stats Contract Tests
tests/unit/storage/test_embedding_contracts.py
Lifecycle contract tests seed embedding_status/message_embeddings/conversations DDL, exercise pending/embedded/reindex/error states, and validate EmbeddingStatsSnapshot counts; includes error propagation and optional vec0 module handling.
Tag Storage Contract Tests
tests/unit/storage/test_tag_contracts.py
Async CRUD invariant tests verify tag lifecycle (add/remove/duplicates), isolation across conversations, and validation rejection of empty/whitespace/oversized tags via repository interface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Suggested labels

type:test, area:storage, area:parser, area:qa

Poem

🐰 Hops through the test domains with glee,
Metadata roundtrips, embedding sprees,
Tags catalog-checked, contracts made whole,
Storage and parsing—quality's soul!

✨ 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/test-architecture-807

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.

@Sinity
Sinity merged commit f2bccb1 into master May 7, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/test/test-architecture-807 branch May 7, 2026 17:29

@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: 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".

Comment on lines +102 to +104
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}"

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

Copilot AI 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.

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.

Comment on lines +103 to +104
for expected_tag in expected:
assert expected_tag in listed, f"[{desc}] Expected tag '{expected_tag}' in list_tags: {listed}"
Comment on lines +25 to +44
# ---------------------------------------------------------------------------
# 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
);
"""

Comment on lines +75 to +100
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:
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 17, 2026
…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
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.

2 participants