Problem
tests/e2e/test_verify_databases_parity.py::_run_database_parity_e2e sets the Neo4j credentials in the pytest process's environment and never restores them (lines 264-266 on main 1b595a6):
os.environ.setdefault('NEO4J_URI', 'bolt://localhost:7687')
os.environ.setdefault('NEO4J_USERNAME', 'neo4j')
os.environ.setdefault('NEO4J_PASSWORD', '12345678')
(Line 88 assigns NEO4J_PASSWORD = '12345678' too, but inside the indexing subprocess script, where it is harmless.)
Every test that runs later in the same pytest process therefore sees a "configured" Neo4j. core._is_neo4j_configured() checks only that these three variables are set, so it flips to True, and that feeds get_database_manager()'s implicit selection.
Repro on main 1b595a6, without changing code. A small driver runs the parity test through pytest.main() and then reads the environment. NEO4J_URI points at a closed port, so the Neo4j leg skips without touching a server:
# leak_probe.py, run from the repo root with PYTHONPATH=.:src
import os, pytest
keys = ("NEO4J_URI", "NEO4J_USERNAME", "NEO4J_PASSWORD")
print("BEFORE", {k: os.environ.get(k) for k in keys})
pytest.main(["-q", "tests/e2e/test_verify_databases_parity.py"])
print("AFTER", {k: os.environ.get(k) for k in keys})
from codegraphcontext.core import _is_neo4j_configured
print("_is_neo4j_configured()", _is_neo4j_configured())
$ env -u NEO4J_USERNAME -u NEO4J_PASSWORD NEO4J_URI=bolt://127.0.0.1:1 python leak_probe.py
BEFORE {'NEO4J_URI': 'bolt://127.0.0.1:1', 'NEO4J_USERNAME': None, 'NEO4J_PASSWORD': None}
1 skipped in 270.20s
AFTER {'NEO4J_URI': 'bolt://127.0.0.1:1', 'NEO4J_USERNAME': 'neo4j', 'NEO4J_PASSWORD': '12345678'}
_is_neo4j_configured() True
With NEO4J_URI unset as well, all three variables leak, including bolt://localhost:7687.
Impact
- Order-dependent test environment.
tests/e2e sorts before tests/integration and tests/unit. So in ./tests/run_tests.sh all / pytest tests/, every integration and unit test after the parity test runs with fake Neo4j credentials in os.environ. Tests that read these variables include tests/unit/core/test_database.py, tests/unit/cli/test_bug001_config_override.py, tests/unit/cli/test_setup_wizard_credentials.py and tests/integration/cli/test_cli_commands.py. Most of them patch the environment themselves, which is why nothing visibly fails on main today. Any new test that relies on "Neo4j not configured" will pass alone and fail in the full run.
- Default backend selection. With the variables set,
get_database_manager()'s implicit path counts Neo4j as configured for the rest of the session.
- A downstream fork hit this as an order-dependency trap: tests that pass in isolation but behave differently after the e2e directory.
Proposed fix
Scope the variables to the test: take pytest's monkeypatch fixture (monkeypatch.setenv) or save and restore os.environ around _run_database_parity_e2e, and pass the credentials to the indexing subprocess through its env= argument instead of the parent's environment. No fix exists in a downstream fork yet. This is reported as a gap, not a finished patch.
Related