from __future__ import annotations from unittest.mock import AsyncMock, patch import pytest from app.core.deep_agent import format_folder_manifest, MANIFEST_TOKEN_BUDGET pytestmark = pytest.mark.asyncio def test_format_folder_manifest_basic(): manifest = { "folderPath": "D:\\Acme", "lastScannedAt": "2h ago", "files": [ {"relPath": "briefs/kickoff.md", "kind": "text", "summary": "Kickoff notes; scope and deadlines."}, {"relPath": "logos/logo-v3.png", "kind": "image", "summary": "Final logo on white."}, ], } out = format_folder_manifest(manifest) assert "" in out assert "/briefs/kickoff.md" in out or "briefs/kickoff.md" in out assert "[text]" in out assert "[image]" in out def test_format_folder_manifest_truncates_past_budget(): files = [ {"relPath": f"f{i}.md", "kind": "text", "summary": "x" * 100, "mtimeMs": i} for i in range(2000) ] out = format_folder_manifest({"folderPath": "p", "lastScannedAt": "now", "files": files}) assert "more files omitted" in out # Rough token check assert len(out) // 4 < MANIFEST_TOKEN_BUDGET + 200 def test_format_folder_manifest_null_returns_empty(): assert format_folder_manifest(None) == "" assert format_folder_manifest({"files": []}) == "" async def test_brief_multi_project_manifest_top_5_per_project(): fake_response = [ { "projectId": "p1", "projectName": "Acme", "folderPath": "/a", "lastScannedAt": "now", "files": [ {"relPath": f"f{i}.md", "kind": "text", "summary": "s", "mtimeMs": i} for i in range(10) ], }, { "projectId": "p2", "projectName": "Beta", "folderPath": "/b", "lastScannedAt": "now", "files": [{"relPath": "x.md", "kind": "text", "summary": "s", "mtimeMs": 1}], }, ] with patch( "app.core.deep_agent.execute_on_client", new=AsyncMock(return_value={"projects": fake_response}), ): from app.core.deep_agent import build_brief_multi_project_manifest out = await build_brief_multi_project_manifest() # Project 1 has 10 files, only top 5 by mtimeMs should appear assert out.count("[p1]") <= 5 # Project 2 has 1 file, must appear assert "[p2]" in out or "Beta" in out