from pathlib import Path from app.architecture import build_architecture def test_architecture_resolves_python_and_relative_typescript_imports(tmp_path: Path) -> None: (tmp_path / "src").mkdir() (tmp_path / "web").mkdir() (tmp_path / "src" / "core.py").write_text("VALUE = 1\n", encoding="utf-8") (tmp_path / "src" / "app.py").write_text("import src.core\n", encoding="utf-8") (tmp_path / "web" / "util.ts").write_text("export const value = 1\n", encoding="utf-8") (tmp_path / "web" / "app.ts").write_text("import { value } from './util'\n", encoding="utf-8") (tmp_path / "web" / "side-effect.ts").write_text("import './util.js'\n", encoding="utf-8") source_texts = { "src/core.py": "VALUE = 1\n", "src/app.py": "import src.core\n", "web/util.ts": "export const value = 1\n", "web/app.ts": "import { value } from './util'\n", "web/side-effect.ts": "import './util.js'\n", } languages = { "src/core.py": "Python", "src/app.py": "Python", "web/util.ts": "TypeScript", "web/app.ts": "TypeScript", "web/side-effect.ts": "TypeScript", } loc = {path: 1 for path in source_texts} graph, hotspots = build_architecture( tmp_path, source_texts, languages, loc, {path: 0 for path in source_texts}, {"src/core.py": 100, "src/app.py": 200}, ) pairs = {(edge.source, edge.target) for edge in graph.edges} assert ("src/app.py", "src/core.py") in pairs assert ("web/app.ts", "web/util.ts") in pairs assert ("web/side-effect.ts", "web/util.ts") in pairs assert {node.id for node in graph.nodes} == set(source_texts) assert hotspots[0].path in {"src/app.py", "src/core.py"} def test_architecture_edge_bound_is_explicit(tmp_path: Path) -> None: source_texts = { "src/a.py": "import src.b\n", "src/b.py": "import src.c\n", "src/c.py": "VALUE = 1\n", } languages = {path: "Python" for path in source_texts} graph, _ = build_architecture( tmp_path, source_texts, languages, {path: 1 for path in source_texts}, {path: 0 for path in source_texts}, {}, max_edges=1, ) assert len(graph.edges) == 1 assert graph.truncated is True def test_architecture_resolves_jsconfig_aliases_and_local_workspace_packages(tmp_path: Path) -> None: (tmp_path / "src" / "components").mkdir(parents=True) (tmp_path / "packages" / "shared" / "src").mkdir(parents=True) (tmp_path / "jsconfig.json").write_text( '{"compilerOptions":{"baseUrl":".","paths":{"@/*":["src/*"]}}}', encoding="utf-8", ) (tmp_path / "package.json").write_text('{"name":"workspace-root"}', encoding="utf-8") (tmp_path / "packages" / "shared" / "package.json").write_text( '{"name":"@workspace/shared"}', encoding="utf-8" ) source_texts = { "src/app.ts": "import { Button } from '@/components/Button'\nimport { shared } from '@workspace/shared'\n", "src/components/Button.ts": "export const Button = () => null\n", "packages/shared/src/index.ts": "export const shared = true\n", } graph, _ = build_architecture( tmp_path, source_texts, {path: "TypeScript" for path in source_texts}, {path: 1 for path in source_texts}, {path: 0 for path in source_texts}, {}, ) pairs = {(edge.source, edge.target) for edge in graph.edges} assert ("src/app.ts", "src/components/Button.ts") in pairs assert ("src/app.ts", "packages/shared/src/index.ts") in pairs