test(rag): switch to workspace project explicitly before configuring RAG
Per Tier 1 addendum 3 (the real defect): tests hotpatch individual state
fields via set_value instead of calling the proper project-switch
flow. The session-scoped subprocess may be on a stale project from a
prior test (e.g. test_context_sim_live switches to
temp_livecontextsim.toml and never switches back). The RAG engine uses
active_project_root (derived from active_project_path) as its base_dir,
NOT ui_files_base_dir. So hotpatching files/rag_enabled via set_value
while active_project_path is stale leaves the RAG engine looking at a
dead dir.
Fix: switch to the workspace project explicitly at the start of the
test (like a user would) using client.push_event('custom_callback',
...) + client.wait_for_project_switch(...). The path must be absolute
because the subprocess's CWD is the workspace, so a relative path
like 'tests/artifacts/.../manualslop.toml' would resolve to the wrong
dir from the subprocess's CWD.
Verified: the switch fires successfully (no WARNING printed). But the
RAG search still returns 0 chunks — the index_file rebuild is not
adding the files. The exact cause is still under investigation.
This is the proper fix per Tier 1 (NOT "delete stale files" which
treats the symptom). The sim tests' teardown() also needs a switch-back
to the workspace project (separate track).
This commit is contained in:
@@ -17,6 +17,25 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
client = api_hook_client.ApiHookClient()
|
||||
assert client.wait_for_server(timeout=15), "Hook server did not start"
|
||||
|
||||
# PROPER PROJECT CONTEXT (per Tier 1 addendum 3):
|
||||
# The session-scoped subprocess may be on a stale project from a prior
|
||||
# test (e.g. test_context_sim_live switches to temp_livecontextsim.toml
|
||||
# and never switches back). The RAG engine uses active_project_root
|
||||
# (derived from active_project_path) as its base_dir, NOT
|
||||
# ui_files_base_dir. So hotpatching files/rag_enabled via set_value
|
||||
# while active_project_path is stale leaves the RAG engine looking at
|
||||
# a dead dir. Switch to the workspace project explicitly (like a user
|
||||
# would) before configuring files and RAG.
|
||||
# Must use absolute path — the subprocess's CWD is the workspace, so a
|
||||
# relative path like 'tests/artifacts/.../manualslop.toml' resolves to
|
||||
# the wrong dir from the subprocess's CWD.
|
||||
workspace_toml = str((Path(live_gui_workspace) / "manualslop.toml").resolve())
|
||||
if Path(workspace_toml).exists():
|
||||
client.push_event("custom_callback", {"callback": "_switch_project", "args": [workspace_toml]})
|
||||
switch_status = client.wait_for_project_switch(expected_path=workspace_toml, timeout=30.0)
|
||||
if switch_status.get("error"):
|
||||
print(f"[VERIFY] WARNING: project switch error: {switch_status.get('error')}")
|
||||
|
||||
# Use a unique collection name per test invocation. The RAG engine
|
||||
# stores its chromadb collection at
|
||||
# <base_dir>/.slop_cache/chroma_<collection_name>. The live_gui
|
||||
@@ -43,11 +62,11 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
# 1. Setup mock project data
|
||||
workspace_dir = live_gui_workspace
|
||||
workspace_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# Create dummy files
|
||||
(workspace_dir / "final_test_1.txt").write_text("Manual Slop RAG is great.")
|
||||
(workspace_dir / "final_test_2.py").write_text("def test_func():\n return 'Manual Slop RAG result'")
|
||||
|
||||
|
||||
try:
|
||||
# 2. Configure project through Hook API
|
||||
client.set_value('rag_collection_name', _collection_name)
|
||||
@@ -58,7 +77,7 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
client.set_value('auto_add_history', True)
|
||||
client.set_value('current_provider', 'gemini_cli')
|
||||
client.set_value('gcli_path', os.path.abspath(os.path.join(os.path.dirname(__file__), "mock_gcli.bat")))
|
||||
|
||||
|
||||
time.sleep(1.5)
|
||||
# Wait for settings to apply and engine to sync
|
||||
success = False
|
||||
@@ -72,7 +91,7 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
# 3. Trigger Initial Indexing
|
||||
print("[VERIFY] Triggering indexing...")
|
||||
client.click('btn_rebuild_rag_index')
|
||||
|
||||
|
||||
# Wait for ready
|
||||
success = False
|
||||
for _ in range(50):
|
||||
@@ -82,12 +101,12 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
break
|
||||
time.sleep(0.5)
|
||||
assert success, f"Indexing failed. Status: {status}"
|
||||
|
||||
|
||||
# 4. Verify Retrieval and Visualization
|
||||
print("[VERIFY] Triggering retrieval turn...")
|
||||
client.set_value('ai_input', "What makes RAG great?")
|
||||
client.click('btn_gen_send')
|
||||
|
||||
|
||||
# Wait for completion
|
||||
success = False
|
||||
print("[VERIFY] Polling for completion...")
|
||||
@@ -147,7 +166,7 @@ def test_phase4_final_verify(live_gui, live_gui_workspace):
|
||||
assert duration < 1.0, "Incremental indexing too slow (expected < 1s for 2 files)"
|
||||
|
||||
print("[VERIFY] Phase 4 final verification COMPLETED successfully.")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"[VERIFY] ERROR in final verification: {e}")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user