From 7be8b9c3d90b4ea83d41aefbbe9876fca2f014f7 Mon Sep 17 00:00:00 2001 From: laily Date: Wed, 14 Oct 2026 09:27:17 +0800 Subject: [PATCH] test(tester): cover nested catalog discovery --- tests/test_tester_catalog_roots.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_tester_catalog_roots.py diff --git a/tests/test_tester_catalog_roots.py b/tests/test_tester_catalog_roots.py new file mode 100644 index 0000000..a51658f --- /dev/null +++ b/tests/test_tester_catalog_roots.py @@ -0,0 +1,54 @@ +from __future__ import annotations + +import importlib.util +import json +import tempfile +import unittest +from contextlib import redirect_stdout +from io import StringIO +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parents[1] +CATALOG = REPO_ROOT / "skills" / "tester" / "scripts" / "catalog.py" + + +def load_catalog_module(): + spec = importlib.util.spec_from_file_location("tester_catalog", CATALOG) + assert spec and spec.loader + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +class TesterCatalogRootTests(unittest.TestCase): + def test_discovers_parent_and_nested_project_without_merging_cases(self) -> None: + catalog = load_catalog_module() + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + for project, name in ((root, "backend"), (root / "app", "Writes")): + (project / ".pouch" / "tester").mkdir(parents=True) + (project / ".pouch" / "tester" / "catalog.yaml").write_text( + f"project:\n name: {name}\n", encoding="utf-8" + ) + + self.assertEqual(catalog.discover_catalog_roots(root), [root, root / "app"]) + + def test_roots_command_reports_each_catalog_path(self) -> None: + catalog = load_catalog_module() + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + app = root / "app" / ".pouch" / "tester" + app.mkdir(parents=True) + (app / "catalog.yaml").write_text("project:\n name: Writes\n", encoding="utf-8") + output = StringIO() + with redirect_stdout(output): + self.assertEqual(catalog.cmd_roots(root), 0) + payload = json.loads(output.getvalue()) + self.assertEqual(payload["count"], 1) + self.assertEqual(payload["roots"][0]["relative"], "app") + self.assertEqual(payload["roots"][0]["project"], "Writes") + + +if __name__ == "__main__": + unittest.main()