feat(context): Decouple context composition from files and media

This commit is contained in:
2026-05-11 11:00:15 -04:00
parent abaeb56020
commit 9b3a4d6ec6
3 changed files with 74 additions and 12 deletions
@@ -0,0 +1,47 @@
import pytest
from src.app_controller import AppController
from src.models import FileItem
def test_context_files_is_decoupled():
controller = AppController()
# Verify both lists exist and are distinct
assert hasattr(controller, 'files')
assert hasattr(controller, 'context_files')
assert controller.files is not controller.context_files
# Modifying one should not affect the other
controller.files.append(FileItem(path="whitelist.txt"))
controller.context_files.append(FileItem(path="context.txt"))
assert len(controller.files) == 1
assert controller.files[0].path == "whitelist.txt"
assert len(controller.context_files) == 1
assert controller.context_files[0].path == "context.txt"
def test_do_generate_uses_context_files(monkeypatch):
controller = AppController()
controller.init_state()
controller.context_files = [FileItem(path="context.txt")]
controller.files = [FileItem(path="whitelist.txt")]
# Mock project_manager.flat_config and aggregate.run to verify passed data
import src.project_manager as pm
import src.aggregate as agg
def mock_flat_config(*args, **kwargs):
return {"files": {}}
def mock_aggregate_run(flat, **kwargs):
assert flat["files"]["paths"] == controller.context_files
return ("md", "path", [], "stable_md", "disc_text")
monkeypatch.setattr(pm, "flat_config", mock_flat_config)
monkeypatch.setattr(pm, "save_project", lambda *args: None)
monkeypatch.setattr(agg, "run", mock_aggregate_run)
monkeypatch.setattr(agg, "build_markdown_no_history", lambda *args, **kwargs: "stable")
monkeypatch.setattr(agg, "build_discussion_text", lambda *args, **kwargs: "disc")
# Should not raise assertion error
controller._do_generate()