diff --git a/tests/ffe/README.md b/tests/ffe/README.md index bf46dcbf00a..399314b2fa3 100644 --- a/tests/ffe/README.md +++ b/tests/ffe/README.md @@ -27,11 +27,16 @@ first, then refresh the snapshot: python3 utils/scripts/update_ffe_fixtures.py --ref ``` -The updater imports `ufc-config.json`, `evaluation-cases/*.json`, and -`flag-selection/selection-vectors.json`. Ordinary test runs use those checked-in files without submodules or network access. A -weekly/manual workflow opens a signed draft PR when their contents change and -leaves any existing fixture update PR untouched. Review and resolve newly exposed -SDK failures before merging an update. +The updater imports `ufc-config.json`, `evaluation-cases/*.json`, +`flag-selection/selection-vectors.json`, and every self-contained suite under +`evaluation-suites/`. Suite discovery is structural, so adding a suite or a case +file does not require an importer change. Importing a suite does not select it +for execution: each test harness separately decides whether suite existence or +explicit opt-in controls execution. Ordinary test runs use those checked-in +files without submodules or network access. A weekly/manual workflow opens a +signed draft PR when their contents change and leaves any existing fixture +update PR untouched. Review and resolve newly exposed SDK failures before +merging an update. Dynamic evaluation checks each case's value, reason, and explicit error code. `Test_Feature_Flag_Split_Features` additionally checks every canonical case with diff --git a/tests/test_the_test/test_update_ffe_fixtures.py b/tests/test_the_test/test_update_ffe_fixtures.py index c941356161a..3828159b362 100644 --- a/tests/test_the_test/test_update_ffe_fixtures.py +++ b/tests/test_the_test/test_update_ffe_fixtures.py @@ -53,9 +53,10 @@ def test_validate_fixture_ref_rejects_unsafe_refs(fixture_ref: str) -> None: @scenarios.test_the_test -def test_copy_fixture_snapshot_imports_only_consumed_fixture_data(tmp_path: Path) -> None: +def test_copy_fixture_snapshot_discovers_evaluation_suites(tmp_path: Path) -> None: source = tmp_path / "source" snapshot = tmp_path / "snapshot" + suite_names = ("dependent-flags", "flag-selection", "future-feature") (source / "evaluation-cases").mkdir(parents=True) snapshot.mkdir() (source / "evaluation-cases" / "case.json").write_text("[]", encoding="utf-8") @@ -63,11 +64,16 @@ def test_copy_fixture_snapshot_imports_only_consumed_fixture_data(tmp_path: Path (source / "README.md").write_text("upstream documentation", encoding="utf-8") (source / "AGENTS.md").write_text("upstream instructions", encoding="utf-8") (source / "precomputed-assignments").mkdir() - suite = source / "evaluation-suites" / "feature" - (suite / "cases").mkdir(parents=True) - (suite / "ufc-config.json").write_text('{"flags": {"flag": {}}}', encoding="utf-8") - (suite / "cases" / "case.json").write_text('[{"flag": "flag"}]', encoding="utf-8") - (suite / "AGENTS.md").write_text("upstream instructions", encoding="utf-8") + for suite_name in suite_names: + suite = source / "evaluation-suites" / suite_name + (suite / "cases").mkdir(parents=True) + (suite / "ufc-config.json").write_text('{"flags": {"flag": {}}}', encoding="utf-8") + (suite / "cases" / "case.json").write_text('[{"flag": "flag"}]', encoding="utf-8") + (suite / "AGENTS.md").write_text("upstream instructions", encoding="utf-8") + (suite / "README.md").write_text("upstream documentation", encoding="utf-8") + (source / "evaluation-suites" / "flag-selection" / "flag-tags.json").write_text( + '{"flags": [{"key": "flag", "tags": []}]}', encoding="utf-8" + ) _write_selection_vectors(source) (source / "flag-selection" / "README.md").write_text("upstream documentation", encoding="utf-8") (source / "flag-selection" / "AGENTS.md").write_text("upstream instructions", encoding="utf-8") @@ -76,9 +82,16 @@ def test_copy_fixture_snapshot_imports_only_consumed_fixture_data(tmp_path: Path assert (snapshot / "ufc-config.json").is_file() assert (snapshot / "evaluation-cases" / "case.json").is_file() - for path in (Path("ufc-config.json"), Path("cases/case.json")): - assert (snapshot / "evaluation-suites" / "feature" / path).read_bytes() == (suite / path).read_bytes() - assert not (snapshot / "evaluation-suites" / "feature" / "AGENTS.md").exists() + for suite_name in suite_names: + source_suite = source / "evaluation-suites" / suite_name + snapshot_suite = snapshot / "evaluation-suites" / suite_name + for path in (Path("ufc-config.json"), Path("cases/case.json")): + assert (snapshot_suite / path).read_bytes() == (source_suite / path).read_bytes() + assert not (snapshot_suite / "AGENTS.md").exists() + assert not (snapshot_suite / "README.md").exists() + assert (snapshot / "evaluation-suites" / "flag-selection" / "flag-tags.json").read_bytes() == ( + source / "evaluation-suites" / "flag-selection" / "flag-tags.json" + ).read_bytes() assert not (snapshot / "README.md").exists() assert not (snapshot / "AGENTS.md").exists() assert not (snapshot / "precomputed-assignments").exists() @@ -89,6 +102,49 @@ def test_copy_fixture_snapshot_imports_only_consumed_fixture_data(tmp_path: Path assert not (snapshot / "flag-selection" / "AGENTS.md").exists() +@scenarios.test_the_test +@pytest.mark.parametrize("entry_name", ["notes.md", "notes.json"]) +def test_copy_evaluation_suite_rejects_unknown_entries(tmp_path: Path, entry_name: str) -> None: + source = tmp_path / "source" + destination = tmp_path / "destination" + (source / "cases").mkdir(parents=True) + (source / "ufc-config.json").write_text("{}", encoding="utf-8") + (source / entry_name).write_text("unexpected", encoding="utf-8") + + with pytest.raises(ValueError, match="Unexpected entry in FFE evaluation suite"): + update_ffe_fixtures._copy_evaluation_suite(source, destination) + + +@scenarios.test_the_test +@pytest.mark.parametrize("guide_name", ["AGENTS.md", "README.md"]) +def test_copy_evaluation_suite_rejects_guide_symlinks(tmp_path: Path, guide_name: str) -> None: + assert guide_name in update_ffe_fixtures.SUITE_GUIDE_FILES + source = tmp_path / "source" + destination = tmp_path / "destination" + (source / "cases").mkdir(parents=True) + (source / "ufc-config.json").write_text("{}", encoding="utf-8") + target = tmp_path / "guide" + target.write_text("guide", encoding="utf-8") + (source / guide_name).symlink_to(target) + + with pytest.raises(ValueError, match="Refusing to copy symbolic link"): + update_ffe_fixtures._copy_evaluation_suite(source, destination) + + +@scenarios.test_the_test +def test_copy_fixture_snapshot_rejects_empty_evaluation_suites(tmp_path: Path) -> None: + source = tmp_path / "source" + snapshot = tmp_path / "snapshot" + (source / "evaluation-cases").mkdir(parents=True) + (source / "evaluation-suites").mkdir() + (source / "ufc-config.json").write_text("{}", encoding="utf-8") + _write_selection_vectors(source) + snapshot.mkdir() + + with pytest.raises(ValueError, match="must contain at least one feature suite"): + update_ffe_fixtures._copy_fixture_snapshot(source, snapshot) + + @scenarios.test_the_test def test_copy_fixture_snapshot_rejects_symbolic_links(tmp_path: Path) -> None: source = tmp_path / "source" diff --git a/utils/scripts/update_ffe_fixtures.py b/utils/scripts/update_ffe_fixtures.py index b36ef796237..b7bf6a20869 100644 --- a/utils/scripts/update_ffe_fixtures.py +++ b/utils/scripts/update_ffe_fixtures.py @@ -17,6 +17,7 @@ SELECTION_VECTORS_PATH = Path("flag-selection/selection-vectors.json") SELECTION_DROP_REASONS = frozenset({"malformed_selection", "too_many_values", "invalid_key_pattern", "invalid_tag"}) SUITE_FLAG_TAGS_FILE = "flag-tags.json" +SUITE_GUIDE_FILES = frozenset({"AGENTS.md", "README.md"}) def _validate_fixture_ref(fixture_ref: str) -> None: @@ -63,12 +64,32 @@ def _copy_entry(source: Path, destination: Path) -> None: destination.mkdir(parents=True, exist_ok=True) for child in sorted(source.iterdir()): - # Upstream documentation, such as a suite's AGENTS.md, is not fixture data. - if child.suffix == ".md" and not child.is_dir(): - continue _copy_entry(child, destination / child.name) +def _copy_evaluation_suite(source: Path, destination: Path) -> None: + if source.is_symlink() or not source.is_dir(): + msg = f"Refusing to copy unsupported FFE evaluation suite: {source}" + raise ValueError(msg) + + runtime_entries = {"ufc-config.json", "cases", SUITE_FLAG_TAGS_FILE} + for entry in source.iterdir(): + if entry.is_symlink(): + msg = f"Refusing to copy symbolic link from FFE fixture repository: {entry}" + raise ValueError(msg) + if entry.name in SUITE_GUIDE_FILES and entry.is_file(): + continue + if entry.name not in runtime_entries: + msg = f"Unexpected entry in FFE evaluation suite {source.name}: {entry}" + raise ValueError(msg) + + for name in ("ufc-config.json", "cases"): + _copy_entry(source / name, destination / name) + flag_tags = source / SUITE_FLAG_TAGS_FILE + if flag_tags.exists() or flag_tags.is_symlink(): + _copy_entry(flag_tags, destination / SUITE_FLAG_TAGS_FILE) + + def _copy_fixture_snapshot(source: Path, snapshot: Path) -> None: # Import rules-based evaluator corpora and selection vectors, not precomputed assignments. for name in ("ufc-config.json", "evaluation-cases"): @@ -80,7 +101,15 @@ def _copy_fixture_snapshot(source: Path, snapshot: Path) -> None: feature_suites = source / "evaluation-suites" if feature_suites.exists() or feature_suites.is_symlink(): - _copy_entry(feature_suites, snapshot / feature_suites.name) + if feature_suites.is_symlink() or not feature_suites.is_dir(): + msg = f"Refusing to copy unsupported FFE evaluation suites: {feature_suites}" + raise ValueError(msg) + suites = sorted(feature_suites.iterdir()) + if not suites: + msg = "FFE evaluation-suites must contain at least one feature suite" + raise ValueError(msg) + for suite in suites: + _copy_evaluation_suite(suite, snapshot / feature_suites.name / suite.name) def _validate_evaluation_suite(config_path: Path, cases_directory: Path) -> int: