fix(project): Reload context_files from new project on project switch
When switching projects, the previous project's context_files remained visible in the Context Composition panel because the controller's self.context_files list was not reloaded from the new project's TOML files.paths entry. Fix in _refresh_from_project: - After loading self.files from the project TOML, populate self.context_files with deep copies of those FileItem objects - Reset self._app.ui_selected_context_files to match the new project's auto_aggregate set - Guard the _app access with hasattr so the controller is usable standalone (in tests, headless mode, etc.) without an attached App Test: 1 new test in tests/test_project_switch_persona_preset.py - test_switch_project_resets_context_files: switches from project_a (forth + gte_hello files) to project_b (gencpp timing files) and asserts context_files contains ONLY project_b's files
This commit is contained in:
@@ -170,3 +170,51 @@ def test_load_context_preset_missing_raises_keyerror(tmp_path, monkeypatch):
|
||||
|
||||
with pytest.raises(KeyError, match="Context preset 'NonexistentPreset' not found"):
|
||||
ctrl.load_context_preset("NonexistentPreset")
|
||||
|
||||
|
||||
def test_switch_project_resets_context_files(tmp_path, monkeypatch):
|
||||
project_a_path, project_b_path = _setup_two_projects(tmp_path)
|
||||
|
||||
proj_a_data = '''[project]
|
||||
name = "project_a"
|
||||
[files]
|
||||
base_dir = "."
|
||||
paths = [
|
||||
{ path = "C:/projects/forth/bootslop/main.c", view_mode = "full" },
|
||||
{ path = "C:/projects/Pikuma/ps1/code/gte_hello/hello_gte.c", view_mode = "full" },
|
||||
]
|
||||
'''
|
||||
project_a_path.write_text(proj_a_data)
|
||||
|
||||
proj_b_data = '''[project]
|
||||
name = "project_b"
|
||||
[files]
|
||||
base_dir = "."
|
||||
paths = [
|
||||
{ path = "C:/projects/gencpp/base/dependencies/timing.cpp", view_mode = "full" },
|
||||
{ path = "C:/projects/gencpp/base/dependencies/timing.hpp", view_mode = "full" },
|
||||
]
|
||||
'''
|
||||
project_b_path.write_text(proj_b_data)
|
||||
|
||||
ctrl = AppController()
|
||||
monkeypatch.setattr(ctrl, "_rebuild_rag_index", lambda: None)
|
||||
monkeypatch.setattr(ctrl, "_flush_to_project", lambda: None)
|
||||
|
||||
ctrl.active_project_path = str(project_a_path)
|
||||
ctrl.project = project_manager.load_project(str(project_a_path))
|
||||
ctrl.preset_manager = presets.PresetManager(Path(project_a_path).parent)
|
||||
ctrl.tool_preset_manager = tool_presets.ToolPresetManager(Path(project_a_path).parent)
|
||||
ctrl.persona_manager = PersonaManager(Path(project_a_path).parent)
|
||||
ctrl._refresh_from_project()
|
||||
|
||||
assert len(ctrl.context_files) == 2
|
||||
assert any("forth" in f.path for f in ctrl.context_files)
|
||||
assert any("gte_hello" in f.path for f in ctrl.context_files)
|
||||
|
||||
ctrl._switch_project(str(project_b_path))
|
||||
|
||||
assert len(ctrl.context_files) == 2
|
||||
assert all("gencpp" in f.path for f in ctrl.context_files)
|
||||
assert not any("forth" in f.path for f in ctrl.context_files)
|
||||
assert not any("gte_hello" in f.path for f in ctrl.context_files)
|
||||
|
||||
Reference in New Issue
Block a user