Skip to content

test_consolidate binds to the developer's real store: suite hangs at 58%, and can mutate production data #219

Description

@cdeust

Symptom

tests_py/handlers/test_consolidate.py::TestConsolidateHandler::test_empty_store_runs_clean
hangs indefinitely on any developer machine that has a populated PostgreSQL
store configured. The full suite stops at ~58% and never completes; nothing
times out, because pytest-timeout is not installed (pyproject.toml
configures timeout/timeout_method, and pytest reports both as
PytestConfigWarning: Unknown config option).

Reproduction

CORTEX_RERANKER_OFFLINE=1 python3 -m pytest \
  "tests_py/handlers/test_consolidate.py::TestConsolidateHandler::test_empty_store_runs_clean" -q
# never returns

Measured 2026-07-27. Reproduces identically on main (a2f5053) and on an
unrelated feature branch, so it is not caused by any in-flight change.

Root cause — the test has no store isolation

async def test_empty_store_runs_clean(self):
    from mcp_server.handlers.consolidate import handler
    result = await handler()
    assert result["decay"]["total_memories"] == 0

No fixture, no monkeypatch, no temp database. handler() resolves its
store through get_shared_store(settings.DB_PATH, ...), so it binds to
whatever backend the developer's environment points at — in practice the
real PostgreSQL corpus. The test then runs a full consolidation cycle (decay,
compression, CLS, causal discovery) across every production memory.

The assertion total_memories == 0 shows the intent: it was written against
an empty store. It only passes in CI because CI has no populated database.
That is coverage by accident of environment, not by construction (§13.1 G3:
tests must be deterministic and isolated).

The sibling tests in the same class (test_decay_only, test_compress_only)
share the defect.

Why it matters beyond the hang

A test that silently binds to the developer's production store can also
mutate it — consolidate decays heat, compresses memories to gist/tag,
and advances consolidation stages. Running the suite locally is currently a
write against real data.

Acceptance criteria

  1. TestConsolidateHandler binds to an isolated temp store (fixture setting
    CORTEX_MEMORY_STORE_BACKEND=sqlite + a tmp_path DB, clearing
    get_memory_settings cache and reset_shared_store()), so the assertions
    are true by construction rather than by environment.
  2. The whole class passes with a populated PostgreSQL database configured in
    the environment.
  3. pytest-timeout is installed (or the unknown timeout config keys are
    removed), so a hang fails loudly instead of stalling the suite — the two
    PytestConfigWarnings are themselves a seen defect.
  4. A test asserting that running the suite does not write to a store the test
    did not create.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions