Private
Public Access
0
0

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:
2026-06-04 21:03:16 -04:00
parent 7df65dff14
commit 36f3292249
2 changed files with 58 additions and 0 deletions
+10
View File
@@ -2723,6 +2723,16 @@ class AppController:
self.files.append(models.FileItem.from_dict(p))
else:
self.files.append(models.FileItem(path=str(p)))
import copy
self.context_files = []
for f in self.files:
if isinstance(f, models.FileItem):
fi = copy.deepcopy(f)
else:
fi = models.FileItem(path=str(f))
self.context_files.append(fi)
if hasattr(self, "_app") and self._app is not None:
self._app.ui_selected_context_files = {f.path for f in self.context_files if f.auto_aggregate}
self.screenshots = list(self.project.get("screenshots", {}).get("paths", []))
disc_sec = self.project.get("discussion", {})
self.disc_roles = list(disc_sec.get("roles", ["User", "AI", "Vendor API", "System"]))