chore: add test to make sure all files committed in cli add new service command
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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]}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user