From 6fd97bf813d70f3ff07b21e90ca2dacb175f6f84 Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Mon, 27 Jul 2026 11:37:09 +0200 Subject: [PATCH] chore: add test to make sure all files committed in cli add new service command --- cli/src/config/paths.py | 1 + cli/tests/tests/test_service_creator.py | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/cli/src/config/paths.py b/cli/src/config/paths.py index 29e6733..dd5592e 100644 --- a/cli/src/config/paths.py +++ b/cli/src/config/paths.py @@ -30,6 +30,7 @@ class Paths(BaseSettings): staged_paths = [ service_current, + self.qt_dir, self.service_registry_file, self.master_hla_names_file, self.master_ioc_subs_file, diff --git a/cli/tests/tests/test_service_creator.py b/cli/tests/tests/test_service_creator.py index b959b51..d87f6fa 100644 --- a/cli/tests/tests/test_service_creator.py +++ b/cli/tests/tests/test_service_creator.py @@ -77,6 +77,9 @@ def test_add_new_service(tmp_path, mocker: MockerFixture): assert_are_dir_trees_equal(tmp_path, EXPECTED_OUTPUT_DIR, tmp_path) + files_to_stage = ctx._write_paths.get_files_to_stage(service_dir_name="test-service") + assert_all_files_staged(tmp_path, files_to_stage) + def assert_are_dir_trees_equal(dir1, dir2, curr_dir: Path | None = None): """ @@ -116,3 +119,34 @@ def assert_files_equal(f1, f2): diff = list(unified_diff(actual_lines, expected_lines, n=0)) assert diff == [], f"Unexpected file contents in file {f1}:\n" + "".join(diff) + + +def assert_all_files_staged(tmp_path, files_to_stage: list[str]): + """ + Assert that all files in 'tests/fixtures/expected_output' except + for 'packages/agebd/pyproject.toml' (see above, only used for uv.lock generation) + are committed and pushed. + """ + + def is_path_covered(file_path: Path, staged_paths: set[Path]) -> bool: + """Checks if file_path is explicitly listed or inside any directory in staged_paths.""" + return any( + file_path == staged or file_path.is_relative_to(staged) for staged in staged_paths + ) + + # Convert to resolved Path objects + staged_paths = {Path(tmp_path / p).resolve() for p in files_to_stage} + + # Verify every actual file in tmp_path is covered by staged_paths + repo_root = tmp_path + for file_path in repo_root.rglob("*"): + if "pyproject.toml" in str(file_path): + continue + if file_path.is_file() and ".git" not in file_path.parts: + resolved_file = file_path.resolve() + + assert is_path_covered(resolved_file, staged_paths), ( + f"File '{file_path.relative_to(repo_root)}' exists in tmp_path " + f"but is NOT covered by any file or directory in files_to_stage!\n" + f"Staged items were: {[str(p.relative_to(repo_root)) for p in staged_paths]}" + )