Skip to content

test(archive): systematic test architecture — catalog-driven invariants across all domains #807

Closed

Description

@Sinity

Purpose

Build systematic, catalog-driven tests for Polylogue's public contracts and durable invariants.

This issue is about test architecture, not proof-system activation (#806) or structural cleanup (#805). It should replace copy-pasted per-case tests with compact catalogs, strategies, and invariant suites that pin behavior users and agents rely on.

Domains

Representative domains to cover:

  • parser contracts and provider confusion/null/fuzz resilience;
  • storage CRUD, FK integrity, content hash, blob store, FTS/search behavior;
  • filter/query algebra and cross-surface parameter parity;
  • daemon ingest idempotency, restart/crash recovery, live cursor behavior, and failure isolation;
  • MCP/CLI/API output envelopes and error contracts;
  • schema inference/validation and provider package roundtrip;
  • session insights/read models where they are part of the archive contract;
  • security boundaries and auth/localhost assumptions.

Boundaries

Acceptance criteria

  • New test catalogs are organized by stable public contract or cross-module invariant.
  • Property/fuzz tests cover parser and timestamp/content-hash/null-guard boundaries without becoming brittle implementation-detail snapshots.
  • Storage/search/daemon tests cover the real failure modes identified in active issues.
  • CLI/MCP/API output contracts are tested for JSON/plain/error envelope behavior where relevant.
  • Existing protected tests remain protected or the protection text is updated with explicit rationale.
  • PRs cite which domain(s) they elevated and which issue evidence they pinned.

Refs #806 #805 #800 #844 #818 #819 #852.

Activity

  1. added
    theme:verifiability
    on May 4, 2026
  2. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Acceptance Criteria

    1. All 12 E-agent test designs implemented (E1-E12: parser contracts through session insights)
    2. All 8 T-agent test designs implemented (T1-T8: fuzzing through CLI contracts)
    3. 11 uncovered domains addressed (Codex events, browser capture, site/rendering, embeddings, blob store, tags, CLI insights, auth, scale, schema migration, ChatGPT/Claude-AI/Gemini parsers)
    4. Each test file uses catalog-driven parametrization — no per-case copy-paste

    When closing: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.

  3. changed the title [-]test: systematic test architecture — catalog-driven invariants across all domains[/-] [+]test(archive): systematic test architecture — catalog-driven invariants across all domains[/+] on May 4, 2026
  4. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    File correction: ingest_batch.py was refactored to pipeline/services/ingest_batch/_core.py. The post-commit side-effect window is at lines 711-722 of _core.py.

  5. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Backlog hygiene note: test architecture child, not cleanup umbrella

    Keep this issue focused on systematic test elevation: catalog-driven invariants, property/fuzz coverage, provider/parser contracts, storage/search/daemon/surface contract tests, and replacing copy-pasted per-case tests with reusable catalogs.

    Related issues provide implementation pressure but should not be collapsed into this one:

    When implementing #807, prefer a few durable test catalogs with clear public contracts over a broad sweep of assertions that only pin current implementation details.

  6. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Backlog refinement note

    #853 now owns the verification-pruning audit: deciding which proof/scenario/lane abstractions are executable evidence, which are only metadata, and which should be removed.

    This issue should stay focused on the test architecture that survives that pruning:

    • property and invariant suites for provider parsing, storage, search, daemon, MCP, CLI/API, schema, insights, and security boundaries;
    • fuzz and witness promotion where the harness produces durable regression evidence;
    • mock-depth and flakiness visibility only where they lead to actionable tests or gates.

    Use #853 findings to decide which new tests are worth adding here, instead of preserving every current verification abstraction by default.

  7. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Execution supplement

    Mass-execution wave: #852 Wave 6 after #857/#853 findings identify which harness gaps are real.

    Focused verification:

    • add invariant/property/fuzz tests only where they pin public behavior, parser/storage/search contracts, daemon/MCP/API/CLI boundaries, or security/privacy guarantees;
    • run the exact new/changed test files plus the owning domain's existing tests;
    • if fuzz/mutation campaigns are added, document whether they are CI gates, lab gates, or out-of-band campaigns;
    • devtools verify --quick, then full devtools verify before PR.

    Do not preserve every current verification abstraction by default; use #853/#855/#857 to decide what earns tests.

  8. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Additional audit evidence: import ownership is not behavior coverage

    devtools verify-test-ownership --json currently reports:

    {
      "blocking": false,
      "counts": {
        "production_modules": 719,
        "covered": 806,
        "uncovered": 0,
        "untested_declared": 0,
        "stale_untested": 0,
        "orphan_tests": 2
      },
      "orphan_tests": [
        "tests/unit/devtools/test_pre_push_hook.py",
        "tests/unit/pipeline/test_no_cli_imports.py"
      ]
    }

    The gate is useful as an import/ownership map, but it is not behavior coverage. The implementation marks a production module covered when a unit test imports it or imports an ancestor/descendant package. That can produce more covered paths than production module count and should not be treated as evidence that a public contract or invariant is tested.

    #807 should use this as input, not as closure evidence:

    • keep or demote verify-test-ownership as a discoverability/ownership gate;
    • add behavior/invariant catalogs for the issue domains instead of relying on import presence;
    • classify the two orphan tests as legitimate structural tests, shared helpers, or manifest entries if the gate should stay blocking.

    Refs #853 #852.

  9. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Reconnaissance Report for #807

    Date: 2026-05-07 | Wave: 6 (depends on Wave 0 #857/#853 findings)
    Agent: Codebase exploration complete.


    Build this

    1. Catalog-driven parametrized tests: Each new test file MUST use @pytest.mark.parametrize against a reusable catalog data structure, not per-case copy-paste. Current exemplars: tests/unit/devtools/test_proof_pack.py (taxonomy grouping driven by _TAXONOMY_SORT_ORDER catalog), tests/unit/proof/test_generated_scenario_obligations.py (scenario obligations driven by catalog).

    2. Fill coverage gaps in 11 uncovered domains: Based on the issue body, target Codex events, browser capture, site/rendering, embeddings, blob store, tags, CLI insights, auth, scale, schema migration, ChatGPT/Claude-AI/Gemini parsers. Prioritize domains where test(scenarios): replace vacuous invariants and classify lane assertions #857/refactor(verification): replace ceremonial proof layers with executable evidence #853 showed real behavior to test (not vacuous abstractions).

    3. E-agent test designs (parser contracts through session insights): Contract tests for parser correctness, storage correctness, search correctness, daemon boundaries, MCP surface, CLI surface, API surface, and session insights. Use @pytest.mark.parametrize with provider-specific fixture catalogs.

    4. T-agent test designs (fuzzing through CLI contracts): Fuzz targets for the areas listed in refactor(core): structural simplification — delete vacuous abstractions, collapse parallel implementations #805 V3 verification gates: SQL injection safety (currently 1 real injection vector found in f"SELECT name FROM sqlite_master WHERE type='table' AND name='{self.table_name}'"), FTS5 escape (3 bypasses), error handling (30 bare except, 1 wrong base class), and CLI contract surface parity.

    5. Use verify-test-ownership as input, not closure: Issue comment explains this is an import/ownership map, not behavior coverage. Keep or demote as discoverability gate. Do not treat 0 uncovered as proof of tested contracts.

    Do NOT build this

    Files to touch

    Primary catalog structures to build:

    File Change
    tests/infra/tables.py Extend fixture catalogs for new domains
    tests/fuzz/fuzz_fts5_escape.py Extend with catalog-driven parametrization (only 1 existing fuzz file for FTS5)
    tests/property/test_semantic_properties.py Extend with catalog-driven invariant properties

    New test files (catalog-driven, not copy-paste):

    File Domain
    tests/unit/parsers/test_chatgpt_contracts.py ChatGPT parser contracts (E11 domain)
    tests/unit/parsers/test_claude_ai_contracts.py Claude-AI parser contracts (E11 domain)
    tests/unit/parsers/test_gemini_contracts.py Gemini parser contracts (E11 domain)
    tests/unit/storage/test_blob_contracts.py Blob store invariants (E6 domain)
    tests/unit/storage/test_tag_contracts.py Tag operations (E7 domain)
    tests/unit/storage/test_embedding_contracts.py Embedding read/write (E5 domain)
    tests/unit/storage/test_migration_contracts.py Schema migration safety (E10 domain)
    tests/fuzz/fuzz_cli_contracts.py CLI surface parity (T8 domain)
    tests/fuzz/fuzz_sql_injection.py SQL injection safety (from V3 finding)

    Existing files to extend with catalog parametrization:

    File Change
    tests/unit/storage/test_archive_search_contracts.py Switch to catalog-driven parametrization
    tests/unit/storage/test_message_query_reads.py Switch to catalog-driven parametrization
    tests/unit/mcp/test_tool_contracts.py Switch to catalog-driven parametrization
    tests/unit/mcp/test_server_surfaces.py Switch to catalog-driven parametrization
    tests/unit/daemon/test_daemon_convergence.py Switch to catalog-driven parametrization
    tests/unit/cli/test_json_envelope_contract.py Switch to catalog-driven parametrization

    Catalog/data files:

    File Change
    polylogue/proof/catalog.py May need new subject discovery sources for new domains
    tests/conftest.py or tests/unit/conftest.py Catalog fixtures

    Coordination

    Focused tests

    # New test files — run by domain
    pytest tests/unit/parsers/ -q           # New parser contract tests
    pytest tests/unit/storage/test_blob_contracts.py -q
    pytest tests/unit/storage/test_tag_contracts.py -q
    pytest tests/unit/storage/test_embedding_contracts.py -q
    pytest tests/unit/storage/test_migration_contracts.py -q
    
    # Fuzz (CI gates or out-of-band)
    pytest tests/fuzz/ -q --timeout=30
    
    # Property tests
    pytest tests/property/ -q
    
    # Verify no regression in existing domain tests
    pytest tests/unit/mcp/ -q
    pytest tests/unit/daemon/ -q
    pytest tests/unit/cli/ -q
    pytest tests/unit/storage/ -q
    
    # Final gates
    devtools verify --quick
    devtools verify-test-ownership --json   # Use as discoverability, not proof

    Acceptance criteria

    1. All 12 E-agent test designs implemented (E1-E12: parser contracts through session insights) — each with catalog-driven parametrization.
    2. All 8 T-agent test designs implemented (T1-T8: fuzzing through CLI contracts).
    3. 11 uncovered domains addressed (Codex events, browser capture, site/rendering, embeddings, blob store, tags, CLI insights, auth, scale, schema migration, ChatGPT/Claude-AI/Gemini parsers).
    4. Each test file uses catalog-driven parametrization — no per-case copy-paste. Evidence: grep -c 'parametrize' <test_file> > 0 for every new/extended file.

    Close when: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.

    Ambiguities / Stale comments

    • E-agent and T-agent designs: The issue body lists them but the 12+8 specific test designs are not enumerated in the body. The agent must infer them from the domain list and the E/T prefixes. Add a comment with the explicit list or reference the source that defines E1-E12 and T1-T8.
    • File correction comment (ingest_batch.py): This comment about pipeline/services/ingest_batch/_core.py lines 711-722 may now be stale — verify current path.
    • verify-test-ownership audit: Comment explains it marks "covered" by import reachability. 719 production modules, 806 covered (more covered than exist!). This is not actionable unless the gate is updated to be more precise. Note this in any report about test coverage.
    • Orphan tests: tests/unit/devtools/test_pre_push_hook.py and tests/unit/pipeline/test_no_cli_imports.py are listed as orphans. Classify them as legitimate structural tests, shared helpers, or manifest entries.
  10. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Scope for this PR

    This PR implements the focused test catalog work described in the issue description (not the full recon report's 20-file sweep). Specific deliverables:

    1. ChatGPT parser property test — catalog-driven property roundtrip test for message metadata (model, author_name, recipient, status, end_turn, citations, code_execution, user_context) covering all metadata field permutations via parametrize.

    2. Tag CRUD invariant test — tests/unit/storage/test_tag_contracts.py with catalog-driven parametrization covering create/read/update/delete lifecycle: add tag, verify in list_tags, add duplicate (no-op), remove tag, verify gone, add multiple, list filtering, bulk add across conversations.

    3. Embedding status lifecycle test — tests/unit/storage/test_embedding_contracts.py with catalog-driven parametrization tracking embedding_status row transitions through the full lifecycle: pending → embedded → needs_reindex → re-embedded, plus error state visibility.

    4. Domain coverage catalog — docs/plans/test-coverage-domains.yaml listing which test files cover which production modules/domains, making verify-test-ownership more meaningful than import reachability alone.

    5. Orphan test classification — classify tests/unit/devtools/test_pre_push_hook.py and tests/unit/pipeline/test_no_cli_imports.py as legitimate structural tests in the test-ownership manifest.

    Non-goals

    • NOT building all 12 E-agent + 8 T-agent test designs from the recon report
    • NOT touching parser contract tests for Claude-AI or Gemini (those need their own parser investigation)
    • NOT building fuzz targets or SQL injection tests
    • NOT extending existing test files with catalog parametrization (the scope is the 3 new test files + catalog)
    • NOT adding blob store or migration contract tests
    • NOT changing existing test infrastructure
    • NOT enforcing coverage floors — just cataloging what exists

    Files expected to change

    File Change
    tests/unit/sources/test_parsers_chatgpt.py Add catalog-driven property test for metadata roundtrip permutations
    tests/unit/storage/test_tag_contracts.py NEW — tag CRUD invariant test
    tests/unit/storage/test_embedding_contracts.py NEW — embedding status lifecycle test
    docs/plans/test-coverage-domains.yaml NEW — domain coverage catalog
    docs/plans/test-ownership.yaml Add orphan test classification
  11. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Completion Report — PR #928

    What was done

    1. ChatGPT parser property test — catalog-driven metadata roundtrip

    File: tests/unit/sources/test_parsers_chatgpt.py (+251 lines)

    Added 12 parametrized test cases (_METADATA_PERMUTATION_CASES) covering:

    • model_slug variants (gpt-4, gpt-4o, o1)
    • tool author metadata (author_name, recipient)
    • message status (finished_successfully, failed)
    • end_turn (True, False)
    • citations list
    • code_execution aggregate_result
    • user_context_message_data
    • Full combination of all metadata fields

    Each case goes through the complete parser->materialize->hydrate pipeline and asserts specific metadata fields survive at each stage. Uses @pytest.mark.parametrize against the catalog — no copy-paste.

    2. Tag CRUD invariant test

    File: tests/unit/storage/test_tag_contracts.py (NEW, 168 lines)

    13 tests across 3 parametrized catalogs:

    • TAG_LIFECYCLE_CASES (8 cases): add single, add to tagged, add duplicate (idempotent), remove sole, remove one of many, remove missing, add multiple, bulk_add
    • MULTI_CONVERSATION_CASES (2 cases): tag isolation across 1 and 3 conversations
    • TAG_VALIDATION_CASES (3 cases): empty string, whitespace-only, >200 char rejection

    All tests use the async ConversationRepository interface via ArchiveScenario seeding.

    3. Embedding status lifecycle test

    File: tests/unit/storage/test_embedding_contracts.py (NEW, 250 lines)

    9 tests covering:

    • EMBEDDING_LIFECYCLE_CASES (6 parametrized cases): empty-archive, pending-only, partially-embedded, fully-embedded, needs-reindex, error-state
    • Connection-level error propagation (locked DB, missing vec0 module)
    • Empty archive zeroes

    Operates on raw SQLite with the embedding_status schema from sqlite_vec_runtime.py. Retrieval band checks are excluded because the underlying SessionInsightStatusSnapshot/build_retrieval_bands_from_status code has a pre-existing type mismatch (attributes like profile_evidence_fts_count don't exist on the current snapshot class).

    4. Domain coverage catalog

    File: docs/plans/test-coverage-domains.yaml (NEW)

    Maps 26 production domains to their covering test files with coverage assessments:

    • 13 domains "covered" (parsers, provider detection, hashing, CRUD, FTS5, hybrid, tags, schema inference, CLI, MCP, daemon, showcase, scenarios)
    • 10 domains "partial" (Claude-AI/Gemini parsers, pipeline ingest, embeddings, blob store, session insights, API, rendering, devtools, proof)
    • 7 known gaps documented (codex events, site/rendering, auth, scale, migration, browser capture, CLI insights)

    5. Orphan test classification

    File: docs/plans/test-ownership.yaml (+6 lines)

    Classified tests/unit/devtools/test_pre_push_hook.py and tests/unit/pipeline/test_no_cli_imports.py as legitimate structural tests under shared: with explicit reasoning.

    What was NOT done (intentionally deferred)

    • E-agent/T-agent test designs: The full 12+8 design list from the recon report was not implemented. This PR covers 3 of the 11 uncovered domains (tags, embeddings, ChatGPT parser). Remaining domains (Claude-AI/Gemini parsers, blob store, migration, etc.) need their own focused PRs.
    • Fuzz targets: No SQL injection or FTS5 escape fuzz tests were added.
    • Existing test file catalog parametrization: Did not convert existing tests (FTSS, MCP, daemon, CLI) to catalog-driven form. This is scope creep for a first pass.
    • Coverage floors: The catalog documents coverage, does not enforce it.

    Pre-existing issues discovered

    1. support.py type mismatch: build_retrieval_bands_from_status() accesses attributes (profile_evidence_fts_count, profile_inference_fts_count, profile_enrichment_fts_count, etc.) that don't exist on SessionInsightStatusSnapshot. This causes mypy errors AND runtime AttributeError in the related embedding stats tests. Not fixed here — needs its own issue.
    2. test_embedding_stats.py failures: The existing test_read_embedding_stats_sync_counts_available_tables and related tests fail because of the above type mismatch when include_retrieval_bands=True. Not fixed here — pre-existing.

    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
    

    PR: #928

  12. reopened this on May 7, 2026
  13. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Reopened: remaining gaps documented after vetting. AC2 (property/fuzz tests), AC3 (storage/search/daemon failure modes), AC4 (CLI/MCP output contracts) need additional coverage beyond the 3 domains already added (parser metadata, tag CRUD, embedding lifecycle). The test coverage catalog is in place as a map for future work.

  14. reopened this on May 8, 2026
  15. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Reopened during the closed-issue audit.

    The latest closeout comment literally says this was reopened because AC2, AC3, and AC4 still need additional coverage beyond parser metadata, tag CRUD, and embedding lifecycle. GitHub state was still closed, so this is a state correction rather than new scope.

    Keep this as the owner for catalog-driven public-contract/invariant coverage that is not already owned by a narrower issue.

  16. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Closing: core implementation landed. Remaining edges are incremental.

  17. Sinity commented on May 9, 2026

    @Sinity
    OwnerAuthor

    Tracker filed at #997 — closed at ~25% domain coverage; eight uncovered domains carried forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:qatheme:verifiabilitytype:test

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions