diff --git a/tests/test_rag_phase4_final_verify.py b/tests/test_rag_phase4_final_verify.py index 9bb13e0c..7121658f 100644 --- a/tests/test_rag_phase4_final_verify.py +++ b/tests/test_rag_phase4_final_verify.py @@ -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 # /.slop_cache/chroma_. 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