feat(cfold): canonicalize custom test layout
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
autonomic-bot
2026-06-12 16:08:18 +00:00
parent 87928a9096
commit 44e02425ab
110 changed files with 306 additions and 241 deletions

View File

@ -1,8 +1,8 @@
"""Unit tests for Phase-2 discovery additions (plan §4.1).
Proves the `custom_tests` discovery covers exactly the per-recipe `functional/` + `playwright/`
subdirs as well as the top-level dir, while still excluding lifecycle `test_<op>.py` names and
honouring the HC2 repo-local approval gate.
Proves the `custom_tests` discovery covers exactly the per-recipe `custom/` dir, still honors the
deprecated `functional/` + `playwright/` aliases, excludes top-level lifecycle `test_<op>.py`
names, and honors the HC2 repo-local approval gate.
Run with: `cc-ci-run -m pytest tests/unit`. Located under tests/unit/ so the orchestrator never
picks these up as overlays/custom tests.
@ -27,29 +27,24 @@ def teardown_function():
os.environ.pop("CCCI_REPO_LOCAL_APPROVED_FILE", None)
def test_custom_tests_placement_rule_functional_playwright_only(tmp_path, monkeypatch):
"""Placement rule (rcust P4): custom tests are discovered ONLY under functional/ +
playwright/. A top-level non-lifecycle test_*.py is NOT discovered (top level is reserved
for lifecycle overlays); lifecycle names inside the subdirs stay excluded (defensive)."""
# Point cc-ci's per-recipe dir at a fake recipe in tmp_path
def test_custom_tests_placement_rule_custom_only(tmp_path, monkeypatch):
"""Placement rule (cfold): custom tests are discovered under custom/. A top-level
non-lifecycle test_*.py is NOT discovered (top level is reserved for lifecycle overlays);
lifecycle names inside custom/ stay excluded (defensive)."""
fake_recipe = "ccci-phase2-fixture"
fake_dir = tmp_path / "tests" / fake_recipe
(fake_dir / "functional").mkdir(parents=True)
(fake_dir / "playwright").mkdir()
(fake_dir / "custom").mkdir(parents=True)
(fake_dir / "test_sso_smoke.py").write_text("# top-level — NOT discovered since P4\n")
(fake_dir / "functional" / "test_health_check.py").write_text("# parity port\n")
(fake_dir / "functional" / "test_content_roundtrip.py").write_text("# recipe-specific\n")
(fake_dir / "playwright" / "test_login_flow.py").write_text("# UI flow\n")
# lifecycle name in functional/ should be ignored (defensive)
(fake_dir / "functional" / "test_install.py").write_text("# misfiled lifecycle name\n")
(fake_dir / "custom" / "test_health_check.py").write_text("# parity port\n")
(fake_dir / "custom" / "test_content_roundtrip.py").write_text("# recipe-specific\n")
(fake_dir / "custom" / "test_login_flow.py").write_text("# UI flow\n")
(fake_dir / "custom" / "test_install.py").write_text("# misfiled lifecycle name\n")
# Patch the cc-ci dir resolver to point at our fixture
monkeypatch.setattr(discovery, "cc_ci_dir", lambda r: str(tmp_path / "tests" / r))
customs = discovery.custom_tests(fake_recipe, None)
names = sorted((src, os.path.basename(p)) for src, p in customs)
# functional/ + playwright/ discovered; top-level custom + lifecycle name are NOT
assert ("cc-ci", "test_health_check.py") in names
assert ("cc-ci", "test_content_roundtrip.py") in names
assert ("cc-ci", "test_login_flow.py") in names
@ -58,20 +53,20 @@ def test_custom_tests_placement_rule_functional_playwright_only(tmp_path, monkey
def test_custom_tests_repo_local_subdirs_gated(tmp_path, monkeypatch):
"""HC2 gate still applies to functional/playwright subdirs under repo-local: not approved -> the
repo-local subdir contents are ignored even if they exist."""
"""HC2 gate still applies to custom/ under repo-local: not approved -> the repo-local
subdir contents are ignored even if they exist."""
fake_recipe = "ccci-phase2-fixture"
monkeypatch.setattr(discovery, "cc_ci_dir", lambda r: str(tmp_path / "cc-ci" / r))
(tmp_path / "cc-ci" / fake_recipe).mkdir(parents=True)
rl = tmp_path / "repo"
(rl / "functional").mkdir(parents=True)
(rl / "functional" / "test_repo_local_specific.py").write_text("# repo-local custom\n")
(rl / "custom").mkdir(parents=True)
(rl / "custom" / "test_repo_local_specific.py").write_text("# repo-local custom\n")
_approve(tmp_path) # empty allowlist → default-deny
_approve(tmp_path)
assert discovery.custom_tests(fake_recipe, str(rl)) == []
_approve(tmp_path, fake_recipe) # approved → repo-local subdir honored
_approve(tmp_path, fake_recipe)
customs = discovery.custom_tests(fake_recipe, str(rl))
names = {(src, os.path.basename(p)) for src, p in customs}
assert ("repo-local", "test_repo_local_specific.py") in names