mempalace/tests
Igor Lins e Silva e334e257bf fix(mcp): retry _get_collection once on transient failure (#1286)
A transient chromadb exception inside `_get_collection` was swallowed by
the bare `except Exception: return None`, leaving every subsequent tool
call hitting the same poisoned cache silently. The fix wraps the body
in a `for attempt in range(2)` loop: on attempt 0 failure, log via
`logger.exception(...)` and clear `_client_cache` / `_collection_cache`
/ `_metadata_cache` so the next iteration forces `_get_client()` to
rebuild from scratch — that path now re-runs `quarantine_stale_hnsw`
(per #1322), so the second attempt heals the common stale-handle case
automatically. If both attempts fail, return `None` (matches the prior
contract for permanent failures).

Two new tests in `tests/test_mcp_server.py::TestCacheInvalidation`:
- `test_get_collection_retries_once_on_exception` — first attempt raises
  via a monkeypatched `_get_client`, second attempt succeeds; assert the
  caller gets the collection back, not None.
- `test_get_collection_returns_none_after_two_failures` — both attempts
  fail, assert we exhaust the loop and return None (no infinite retry).

Surgical extraction from PR #1286, which carried the same fix idea
(plus a fork-sync bundle that couldn't be merged); credit to the
original author below.

Co-authored-by: Jeffrey Hein <jp@jphein.com>
2026-05-06 04:52:18 -03:00
..
benchmarks test(mcp): migrate _kg monkeypatches to _get_kg (#1136) 2026-05-03 17:43:00 +05:00
conftest.py fix(hnsw): gate quarantine_stale_hnsw to cold-start, not every reconnect 2026-04-26 09:40:25 -07:00
test_backends.py fix(backends/chroma): release SQLite file lock on close_palace/close (#1067) 2026-05-03 19:16:25 +05:00
test_chroma_collection_lock.py style: ruff format new test files (CI lint) 2026-05-06 01:47:46 -03:00
test_claude_plugin_hook_wrappers.py test: normalize wrapper script path for bash on Windows 2026-04-19 10:34:11 +02:00
test_cli.py fix(cli, fact-checker): per-stream stdio errors policy on Windows 2026-05-03 21:37:12 +05:00
test_closet_llm.py fix: paginate closet_llm col.get (#1073) 2026-04-29 19:01:54 -04:00
test_closets.py test: verify mine_lock via disjoint critical-section intervals 2026-04-13 19:08:57 -03:00
test_collection_metric_invariant.py fix(test): use tmp_path for full-stack invariant test (Windows CI) 2026-04-25 00:39:37 -03:00
test_config.py fix(kg): reject partial ISO dates to avoid silent empty result sets 2026-04-30 15:21:18 +02:00
test_config_extra.py test(config): make palace_path tests portable across POSIX and Windows 2026-04-24 11:13:51 +02:00
test_convo_miner.py feat(normalize): auto-rebuild stale drawers via NORMALIZE_VERSION schema gate 2026-04-13 16:20:55 -03:00
test_convo_miner_size_cap.py Raise convo_miner MAX_FILE_SIZE cap 10 MB → 500 MB 2026-04-18 12:52:01 -03:00
test_convo_miner_unit.py test: tidy embedding follow-up imports 2026-04-24 23:10:20 +00:00
test_convo_scanner.py fix(llm): tighter refinement — word boundaries, JSON extraction, authoritative sources 2026-04-24 01:30:40 -03:00
test_corpus_origin.py feat(init): context-aware corpus detection 2026-04-26 12:37:26 -07:00
test_corpus_origin_integration.py feat(privacy): blocking consent gate for env-fallback LLM API keys 2026-04-27 00:44:57 -07:00
test_dedup.py refactor: route all chromadb access through ChromaBackend 2026-04-14 00:31:16 -03:00
test_dialect.py fix: align cmd_compress dict keys with compression_stats() return values (#569) 2026-04-11 16:16:31 -07:00
test_embedding.py test: isolate embedding module state with monkeypatch 2026-04-24 23:11:29 +00:00
test_empty_chromadb_results.py fix(searcher): guard against empty ChromaDB query results (#195) (#865) 2026-04-15 00:26:38 -07:00
test_entity_detector.py feat(graph): cross-wing tunnels by shared topics (#1180) 2026-04-24 23:06:26 -03:00
test_entity_registry.py fix(entity_registry): atomic write to prevent partial corruption on crash 2026-05-04 11:08:14 +02:00
test_exporter.py feat: new MCP tools — get/list/update drawer, hook settings, export (resolves #635) (#667) 2026-04-11 21:25:04 -07:00
test_fact_checker.py fix(cli, fact-checker): per-stream stdio errors policy on Windows 2026-05-03 21:37:12 +05:00
test_general_extractor.py style: format test files with ruff 2026-04-08 21:08:49 +03:00
test_hall_detection.py fix: README audit — 42 TDD tests + hall detection + 7 claim fixes (#835) 2026-04-13 17:11:11 -07:00
test_hnsw_capacity.py fix(repair): scale HNSW divergence floor with hnsw:sync_threshold 2026-05-01 00:31:47 +00:00
test_hooks_cli.py fix(lint): hoist hooks_cli_mod import to top of test_hooks_cli (E402) 2026-05-06 01:57:44 -03:00
test_hooks_shell.py fix(hooks): MEMPAL_PYTHON override for .sh hooks' internal python3 calls 2026-04-21 01:43:08 -03:00
test_hybrid_candidate_union.py fix(searcher): address Copilot review on #1306 2026-05-03 06:09:10 -03:00
test_hybrid_search.py merge: pr/closet-llm-generic + harden LLM regen path for production 2026-04-13 18:40:36 -03:00
test_i18n.py Merge pull request #1051 from itfarrier/feat/i18n-belarusian 2026-04-21 01:09:54 -03:00
test_i18n_lang_case.py fix(i18n): resolve language codes case-insensitively (#927) 2026-04-15 23:33:42 +02:00
test_init_gitignore_protection.py fix(init): auto-add per-project files to .gitignore in git repos (#185) (#866) 2026-04-15 00:26:41 -07:00
test_instructions_cli.py fix: add explicit UTF-8 encoding to read_text() calls (#776) 2026-04-16 16:00:29 +05:00
test_kg_thread_safety.py fix: add missing self._lock to KnowledgeGraph.close() 2026-04-14 13:09:10 -07:00
test_knowledge_graph.py fix(kg): reject inverted intervals in add_triple (valid_to < valid_from) 2026-04-26 13:00:27 +02:00
test_knowledge_graph_extra.py test: bring coverage to 85%, set threshold to 85, reset version to 3.0.11 2026-04-08 21:38:12 +03:00
test_known_entities_registry.py feat(graph): cross-wing tunnels by shared topics (#1180) 2026-04-24 23:06:26 -03:00
test_layers.py fix: guard None metadata/doc in tool_check_duplicate and Layer1/Layer2 2026-04-19 11:13:50 +03:00
test_llm_client.py feat(privacy): blocking consent gate for env-fallback LLM API keys 2026-04-27 00:44:57 -07:00
test_llm_refine.py feat(graph): cross-wing tunnels by shared topics (#1180) 2026-04-24 23:06:26 -03:00
test_mcp_server.py fix(mcp): retry _get_collection once on transient failure (#1286) 2026-05-06 04:52:18 -03:00
test_mcp_stdio_protection.py fix(mcp): redirect stdout to stderr during import to protect JSON-RPC channel (#225) (#864) 2026-04-15 00:26:51 -07:00
test_migrate.py fix(migrate): harden swap rollback against partial cross-device copy 2026-04-24 13:12:10 +09:00
test_miner.py fix(miner,convo_miner): close remaining wing-name normalization gaps (#1194) 2026-04-27 03:12:06 -03:00
test_miner_jsonl_visibility.py Harden sweeper for production: verbatim tool blocks, full session_id, logged failures 2026-04-18 13:14:32 -03:00
test_normalize.py fix(normalize): discard user/gemini turns before session_metadata sentinel 2026-04-27 21:41:48 +00:00
test_onboarding.py fix: add explicit UTF-8 encoding to read_text() calls (#776) 2026-04-16 16:00:29 +05:00
test_palace_graph.py fix(palace_graph): skip None metadata in build_graph 2026-04-25 11:06:32 -07:00
test_palace_graph_tunnels.py fix(tunnels): normalize wing names in topic tunnel lookup for hyphenated dirs (#1194) 2026-04-27 03:05:14 -03:00
test_palace_locks.py style: ruff format new test files (CI lint) 2026-05-06 01:47:46 -03:00
test_project_scanner.py feat(graph): cross-wing tunnels by shared topics (#1180) 2026-04-24 23:06:26 -03:00
test_query_sanitizer.py fix: make quote trimming explicit 2026-04-12 22:19:58 -03:00
test_readme_claims.py docs+tests: fix CI after README slim (#875) 2026-04-14 21:59:55 -03:00
test_repair.py fix(repair): decode BLOB embeddings.seq_id in max-seq-id heuristic (#1254) 2026-04-30 22:04:41 -03:00
test_room_detector_local.py fix: skip unreachable reparse points in detect_rooms_from_folders (#558) 2026-04-11 16:16:06 -07:00
test_save_hook_mines.py test(hooks): skip bash subprocess validator test on Windows 2026-04-27 02:45:04 -03:00
test_save_hook_verbose.py feat: add MEMPAL_VERBOSE toggle — developers see diaries in chat (#871) 2026-04-14 10:55:56 -07:00
test_searcher.py style: ruff format tests/test_searcher.py (CI lint) 2026-05-06 02:19:54 -03:00
test_sources.py fix(sources): address Copilot review on #1014 2026-04-18 17:17:50 -03:00
test_spellcheck.py style: format test files with ruff 2026-04-08 21:08:49 +03:00
test_spellcheck_extra.py test: bring coverage to 85%, set threshold to 85, reset version to 3.0.11 2026-04-08 21:38:12 +03:00
test_split_mega_files.py test: expand coverage to 70%, fix mcp_server CI crash (threshold 60%) 2026-04-08 21:07:03 +03:00
test_sweeper.py Address Copilot review: cursor tie-break, honest metrics, accurate comments 2026-04-18 13:22:18 -03:00
test_version_consistency.py fix: unify package and MCP version reporting 2026-04-07 08:53:25 +01:00