diff --git a/docs/design/track_b_holdout_registry_mutations.json b/docs/design/track_b_holdout_registry_mutations.json index 7e011ba9..2adda697 100644 --- a/docs/design/track_b_holdout_registry_mutations.json +++ b/docs/design/track_b_holdout_registry_mutations.json @@ -2,9 +2,9 @@ "schema_version": 1, "verification_class": "accounting conformance", "admitted_scope": "The held-out data registry's rules on invented registries, temporary git repositories and the committed registry; no population, behavioral or forecast claim.", - "mutation_method": "One deliberate production-line change per check; both registry test modules run in full and are expected to fail; original bytes restored before the next check. No mutated implementation is committed.", + "mutation_method": "One deliberate production-line change per check; both registry test modules run in full and are expected to fail; original bytes restored before the next check. Failed test ids are pytest's own report node ids, written by a reporting plugin, not parsed from summary lines. No mutated implementation is committed.", "restored_source_sha256": { - "src/populace_dynamics/track_b/holdout_registry.py": "a1fd1d999f59abecb6a8ca08801a7b2bbf7c4960cf3581f8c77e6cf2972ee354" + "src/populace_dynamics/track_b/holdout_registry.py": "9ca7fc52839d637f29596f369578ff255a528114fe8956c767e4fb3d84ddac5d" }, "checks": [ { @@ -42,7 +42,8 @@ "tests/test_track_b_holdout_registry.py::test_keys_overlap_on_source_and_intersecting_years", "tests/test_track_b_holdout_registry.py::test_settled_registries_are_valid", "tests/test_track_b_holdout_registry.py::test_shared_units_match_the_independent_rule", - "tests/test_track_b_holdout_registry_committed.py::test_the_committed_registry_keeps_its_rules" + "tests/test_track_b_holdout_registry_committed.py::test_the_committed_registry_keeps_its_rules", + "tests/test_track_b_holdout_registry_committed.py::test_the_committed_registry_only_appends_to_its_base" ] }, { @@ -302,8 +303,8 @@ }, { "mutation": "entries without ids reach diagnostics", - "old": "isinstance(entry, Mapping) and isinstance(entry.get(\"id\"), str)", - "new": "isinstance(entry, Mapping)", + "old": "isinstance(entry, Mapping) and isinstance(entry.get(\"id\"), str)\n for entry in entries\n", + "new": "isinstance(entry, Mapping)\n for entry in entries\n", "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ @@ -575,6 +576,10 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_repeated_id_or_rule_is_reported[rule]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_in_the_pull_requests_own_order_waits_for_the_end[rules]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_keeps_each_copy_of_a_repeated_rule[drops_a_copy-inner]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_keeps_each_copy_of_a_repeated_rule[drops_a_copy-trailing]", "tests/test_track_b_holdout_registry.py::test_sources_rules_and_completeness_only_move_forward" ] }, @@ -605,10 +610,20 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_a_landed_branch_is_merged_in_the_landed_order[branch]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_failing_own_commit_unions_the_last_valid[drop]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_cannot_drop_the_pull_requests_own_entry", + "tests/test_track_b_holdout_registry.py::test_a_merge_of_contained_history_keeps_its_own_predecessor", "tests/test_track_b_holdout_registry.py::test_a_push_compares_with_its_before_commit", "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[False-append_then_remove]", "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[True-append_then_remove]", + "tests/test_track_b_holdout_registry.py::test_a_stale_landed_branch_cannot_drop_what_the_pull_request_holds", + "tests/test_track_b_holdout_registry.py::test_an_entry_a_landed_merge_adds_is_held_from_then_on", + "tests/test_track_b_holdout_registry.py::test_an_octopus_of_a_landed_and_a_contained_parent_is_one_line", "tests/test_track_b_holdout_registry.py::test_any_json_in_any_field_is_reported_not_raised", + "tests/test_track_b_holdout_registry.py::test_only_commits_that_remove_or_rewrite_entries_are_reported", + "tests/test_track_b_holdout_registry.py::test_own_commits_after_a_master_merge_are_checked[drop_landed]", + "tests/test_track_b_holdout_registry.py::test_own_commits_after_a_master_merge_are_checked[merge_drops_landed]", "tests/test_track_b_holdout_registry.py::test_removing_or_reordering_entries_is_refused", "tests/test_track_b_holdout_registry.py::test_the_base_branch_compares_with_its_parent" ] @@ -620,11 +635,18 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_a_first_commit_that_merges_unlanded_history_starts_at_the_fork[rewrite]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_failing_own_commit_unions_the_last_valid[rewrite]", + "tests/test_track_b_holdout_registry.py::test_a_pull_request_cannot_hide_a_change_it_undoes[False]", + "tests/test_track_b_holdout_registry.py::test_a_pull_request_cannot_hide_a_change_it_undoes[True]", + "tests/test_track_b_holdout_registry.py::test_a_push_is_compared_from_its_before_commit[rewrite]", "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[False-edit_then_restore]", "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[True-edit_then_restore]", "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[24]", "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[35]", "tests/test_track_b_holdout_registry.py::test_changing_an_earlier_entry_is_refused", + "tests/test_track_b_holdout_registry.py::test_only_commits_that_remove_or_rewrite_entries_are_reported", + "tests/test_track_b_holdout_registry.py::test_own_commits_after_a_master_merge_are_checked[rewrite]", "tests/test_track_b_holdout_registry.py::test_sha256_object_ids_bound_histories" ] }, @@ -635,6 +657,7 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_keeps_the_pull_requests_own_extensions[drops]", "tests/test_track_b_holdout_registry.py::test_extending_lists_never_shrink" ] }, @@ -667,7 +690,7 @@ "exit_code": 1, "failed_tests": [ "tests/test_track_b_holdout_registry.py::test_a_push_compares_with_its_before_commit", - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"}]", + "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"created\": true}]", "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[24]", "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[35]", "tests/test_track_b_holdout_registry.py::test_sha256_object_ids_bound_histories" @@ -693,8 +716,11 @@ "exit_code": 1, "failed_tests": [ "tests/test_track_b_holdout_registry.py::test_a_clean_history_has_no_problems", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_an_own_registry_with_malformed_sources", "tests/test_track_b_holdout_registry.py::test_a_pull_request_compares_with_its_merge_base", - "tests/test_track_b_holdout_registry_committed.py::test_the_committed_registry_only_appends_to_its_base" + "tests/test_track_b_holdout_registry.py::test_a_pull_request_from_before_the_registry_passes[False]", + "tests/test_track_b_holdout_registry.py::test_a_pull_request_from_before_the_registry_passes[True]", + "tests/test_track_b_holdout_registry.py::test_only_commits_that_remove_or_rewrite_entries_are_reported" ] }, { @@ -783,14 +809,29 @@ }, { "mutation": "history checks only the endpoint", - "old": "previous_commit, previous = commit, current", - "new": "previous_commit = commit", + "old": "previous_label, previous = label, current", + "new": "previous_label = label", "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ "tests/test_track_b_holdout_registry.py::test_a_clean_history_has_no_problems", + "tests/test_track_b_holdout_registry.py::test_a_conflicting_landed_merge_leaves_the_union_as_predecessor", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_failing_own_commit_unions_the_last_valid[drop]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_repeated_id_or_rule_is_reported[id]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_a_repeated_id_or_rule_is_reported[rule]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_after_an_own_registry_with_malformed_sources", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_cannot_drop_the_pull_requests_own_entry", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_cannot_reorder_the_pull_requests_own_entries", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_in_the_pull_requests_own_order_waits_for_the_end[entries]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_in_the_pull_requests_own_order_waits_for_the_end[rules]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_keeps_the_pull_requests_own_extensions[diverges]", + "tests/test_track_b_holdout_registry.py::test_a_landed_merge_keeps_the_pull_requests_own_extensions[drops]", + "tests/test_track_b_holdout_registry.py::test_a_merge_of_unlanded_history_extends_its_own_predecessor[False]", "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[False-append_then_remove]", - "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[True-append_then_remove]" + "tests/test_track_b_holdout_registry.py::test_a_run_of_commits_cannot_hide_a_change_it_undoes[True-append_then_remove]", + "tests/test_track_b_holdout_registry.py::test_a_stacked_pull_request_stays_valid_once_its_base_lands[landed]", + "tests/test_track_b_holdout_registry.py::test_a_stacked_pull_request_stays_valid_once_its_base_lands[own]", + "tests/test_track_b_holdout_registry.py::test_an_entry_a_landed_merge_adds_is_held_from_then_on" ] }, { @@ -800,9 +841,7 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"}]", - "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[24]", - "tests/test_track_b_holdout_registry.py::test_a_transient_failure_at_the_push_boundary_raises[35]" + "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\", \"created\": true}]" ] }, { @@ -812,9 +851,8 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"HEAD\"}]", - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": null}]", - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{}]" + "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": \"HEAD\", \"created\": true}]", + "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[{\"before\": null, \"created\": true}]" ] }, { @@ -824,8 +862,8 @@ "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", "exit_code": 1, "failed_tests": [ - "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[[]", - "tests/test_track_b_holdout_registry.py::test_an_unreadable_pull_request_event_raises[[]" + "tests/test_track_b_holdout_registry.py::test_a_push_without_a_resolvable_before_raises[[]]", + "tests/test_track_b_holdout_registry.py::test_an_unreadable_pull_request_event_raises[[]]" ] }, { @@ -852,6 +890,30 @@ "tests/test_track_b_holdout_registry.py::test_a_failed_object_hash_fails_closed[failure1]", "tests/test_track_b_holdout_registry.py::test_a_failed_object_hash_fails_closed[failure2]" ] + }, + { + "mutation": "an unset event path leaks TypeError", + "old": " except (TypeError, ValueError, OSError) as error:\n raise LookupError(f\"cannot read the GitHub event: {error}\") from None", + "new": " except (ValueError, OSError) as error:\n raise LookupError(f\"cannot read the GitHub event: {error}\") from None", + "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", + "exit_code": 1, + "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_an_unset_event_path_raises[pull_request]", + "tests/test_track_b_holdout_registry.py::test_an_unset_event_path_raises[push]" + ] + }, + { + "mutation": "a zero push boundary falls back without created", + "old": " if event.get(\"created\") is not True:\n raise LookupError(\n \"an all-zero before commit needs a push that creates its \"\n \"branch\"\n )\n", + "new": "", + "command": "PYTHONPATH=$PWD/src OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 OMP_WAIT_POLICY=PASSIVE python -m pytest -q -p no:cacheprovider -rf tests/test_track_b_holdout_registry.py tests/test_track_b_holdout_registry_committed.py", + "exit_code": 1, + "failed_tests": [ + "tests/test_track_b_holdout_registry.py::test_a_zero_push_boundary_needs_a_created_branch[1]", + "tests/test_track_b_holdout_registry.py::test_a_zero_push_boundary_needs_a_created_branch[False]", + "tests/test_track_b_holdout_registry.py::test_a_zero_push_boundary_needs_a_created_branch[None]", + "tests/test_track_b_holdout_registry.py::test_a_zero_push_boundary_needs_a_created_branch[true]" + ] } ] } diff --git a/src/populace_dynamics/track_b/holdout_registry.py b/src/populace_dynamics/track_b/holdout_registry.py index b1efd6b2..fc3256c3 100644 --- a/src/populace_dynamics/track_b/holdout_registry.py +++ b/src/populace_dynamics/track_b/holdout_registry.py @@ -1378,7 +1378,9 @@ def base_commit(repository: Path) -> str: - On a push (``GITHUB_EVENT_NAME=push``), the event's ``before`` commit, which was the branch tip before the push. An all-zero - ``before`` (a branch's first push) falls through to the merge base. + ``before`` falls through to the merge base only when the event + says the push created the branch (``created`` is true), as on a + branch's first push. - Otherwise, the merge base of ``HEAD`` and the base branch (``GITHUB_BASE_REF`` on a pull request, otherwise ``master``), preferring its ``origin/`` ref. @@ -1386,14 +1388,16 @@ def base_commit(repository: Path) -> str: first parent. Raises ``LookupError`` when none of these resolves, and on a push - whose event cannot be read or whose ``before`` commit does not - resolve: a push is compared with its own boundary, never with a - nearer commit that would check less history.""" + whose event cannot be read, whose ``before`` commit does not + resolve, or whose all-zero ``before`` comes without ``created``: a + push is compared with its own boundary, never with a nearer commit + that would check less history.""" head = _commit(repository, "HEAD") if head is None: raise LookupError(f"no HEAD in {repository}") if os.environ.get("GITHUB_EVENT_NAME") == "push": - before = _event().get("before") + event = _event() + before = event.get("before") if not isinstance(before, str) or SHA_RX.fullmatch(before) is None: raise LookupError("the push event names no before commit") if set(before) != {"0"}: @@ -1402,6 +1406,11 @@ def base_commit(repository: Path) -> str: f"the push's before commit {before} does not resolve" ) return before + if event.get("created") is not True: + raise LookupError( + "an all-zero before commit needs a push that creates its " + "branch" + ) branch = os.environ.get("GITHUB_BASE_REF") or "master" for ref in (f"origin/{branch}", branch): found = _git(repository, "merge-base", "HEAD", ref) diff --git a/tests/README-tiers.md b/tests/README-tiers.md index d033bd34..6daa58ab 100644 --- a/tests/README-tiers.md +++ b/tests/README-tiers.md @@ -39,9 +39,9 @@ pytest --collect-only -q -m oracle_policyengine | tail -1 | Tier | Tests at HEAD | |---|---:| -| `unit` | 18,780 | +| `unit` | 18,789 | | `artifact` | 4,271 | | `integration_psid` | 1,471 | | `reproduction_legacy` | 520 | | `oracle_policyengine` | 308 | -| **Total** | **25,350** | +| **Total** | **25,359** | diff --git a/tests/test_track_b_holdout_registry.py b/tests/test_track_b_holdout_registry.py index 636e1110..3543dbf1 100644 --- a/tests/test_track_b_holdout_registry.py +++ b/tests/test_track_b_holdout_registry.py @@ -2712,10 +2712,52 @@ def test_a_push_compares_with_its_before_commit( assert registry.append_only_problems( registry.base_registry(repository), emptied ) - event.write_text(json.dumps({"before": "0" * 40}), encoding="utf-8") + event.write_text( + json.dumps({"before": "0" * 40, "created": True}), encoding="utf-8" + ) assert registry.base_registry(repository) == middle +@pytest.mark.parametrize("created", [None, False, "true", 1]) +def test_a_zero_push_boundary_needs_a_created_branch( + tmp_path, no_ci_env, monkeypatch, created +): + """GitHub sends an all-zero ``before`` when a push creates its branch, + and says so with ``created: true``. Without that the boundary is + unknown, so the push raises rather than fall back to the merge base, + which would check less history.""" + repository = init_repository(tmp_path) + first = registered(["candidate"]) + commit_registry(repository, first, "registry") + payload = {"before": "0" * 40} + if created is not None: + payload["created"] = created + event = tmp_path / "event.json" + event.write_text(json.dumps(payload), encoding="utf-8") + monkeypatch.setenv("GITHUB_EVENT_NAME", "push") + monkeypatch.setenv("GITHUB_EVENT_PATH", str(event)) + with pytest.raises(LookupError): + registry.base_commit(repository) + with pytest.raises(LookupError): + registry.base_registry(repository) + + +@pytest.mark.parametrize("event_name", ["push", "pull_request"]) +def test_an_unset_event_path_raises( + tmp_path, no_ci_env, monkeypatch, event_name +): + """With ``GITHUB_EVENT_PATH`` unset the event cannot be read: a push + and a pull request each raise ``LookupError``, never ``TypeError``.""" + repository = init_repository(tmp_path) + commit_registry(repository, registered(["candidate"]), "registry") + monkeypatch.setenv("GITHUB_EVENT_NAME", event_name) + with pytest.raises(LookupError): + if event_name == "push": + registry.base_commit(repository) + else: + registry.pull_request_head() + + @pytest.mark.parametrize( "payload", [ @@ -2726,6 +2768,9 @@ def test_a_push_compares_with_its_before_commit( json.dumps({"before": None}), json.dumps({"before": "HEAD"}), json.dumps({"before": "b" * 40}), + json.dumps({"before": None, "created": True}), + json.dumps({"before": "HEAD", "created": True}), + json.dumps({"before": "b" * 40, "created": True}), ], ) def test_a_push_without_a_resolvable_before_raises( diff --git a/tests/tier_counts.json b/tests/tier_counts.json index dc8fbb4a..cab2876f 100644 --- a/tests/tier_counts.json +++ b/tests/tier_counts.json @@ -1,7 +1,7 @@ { "schema_version": 1, "counts": { - "unit": 18780, + "unit": 18789, "artifact": 4271, "integration_psid": 1471, "reproduction_legacy": 520,