Skip to content

test: isolate API tests from the real ~/.claude (fixes #93) - #123

Merged
JayantDevkar merged 1 commit into
mainfrom
fix/93-test-isolation
Oct 21, 2026
Merged

JayantDevkar merged 1 commit into
mainfrom
fix/93-test-isolation

Conversation

@JayantDevkar

Copy link
Copy Markdown
Owner

Problem

Six tests in test_background_shells_router.py fail on any machine with real Claude Code data and take 40 to 50 s each, while CI stays green (#93). GET /shells calls _maybe_sync(), which scans settings.projects_dir, and the fixture isolated the DB path but not the ingest source, so the real ~/.claude/projects was ingested into the temp DB. The authors of #97 and #101 both hit this and had to explain it in their PR bodies.

Changes

  • tests/api/conftest.py: an autouse fixture points settings.claude_base at an empty per-test temp dir, so no API test can read the real ~/.claude. With no projects/ subdir, an accidental sync_all_projects() returns early, as it does on CI.
  • test_background_shells_router.py: the old fixture becomes shells_app with the lazy sync left live and the debounce clock reset; client stubs _maybe_sync, so every existing query test is unchanged. A new TestListShellsLazySync builds a fake projects dir with one background Bash session and asserts GET /shells ingests it (a negative control stubbing sync_all_projects fails with 0 == 1).
  • background_shells is the only router that syncs lazily; admin.py syncs only on the explicit POST /admin/reindex.

Test code only. No production change.

Verification

On this machine with real data, same interpreter:

before after
test_background_shells_router.py 6 failed, 10 passed in 402 s 17 passed in 0.6 s
full api suite 6 failed 1929 passed, 6 skipped in 8.8 s

ruff check tests/ routers/ clean, ruff format --check clean.

Follow-ups

  • Found while instrumenting: five tests in tests/api/test_set_session_title.py open the real ~/.claude_karma/metadata.db through services/session_title_cache.py, and test_set_title_success runs ensure_schema on it via get_writer_db(). No rows change (fake uuid), but it is the actual leak the memory note blamed on the app lifespan. Tracked in a separate issue.
  • The pre-fix real-data sync logged NOT NULL constraint failed: background_shells.spawned_at for several real sessions; looks like a separate extractor bug on real JSONL. Same issue.

@JayantDevkar
JayantDevkar merged commit 9c30ef8 into main Oct 21, 2026
13 checks passed
@JayantDevkar
JayantDevkar deleted the fix/93-test-isolation branch October 21, 2026 18:44
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.

1 participant