mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
fix(valid-detection-benchmark): fail cohort selection closed on a malformed pending ledger
_ledger_facts accepted any pending_entries value and turned it into a set; a ledger outside the durable shape is now a STATE_MISMATCH on both selection rounds. The _pending_by_ecosystem docstring now states the conflicting-accepted-review corner accurately.
This commit is contained in:
@@ -273,6 +273,7 @@ def _ledger_facts(batches: Sequence[CohortBatchOutcomeV1]) -> _LedgerFacts:
|
|||||||
eco_policy = _closed_digest(batch.ecosystem_policy_digest)
|
eco_policy = _closed_digest(batch.ecosystem_policy_digest)
|
||||||
gt_policy = _closed_digest(batch.ground_truth_policy_digest)
|
gt_policy = _closed_digest(batch.ground_truth_policy_digest)
|
||||||
digests.add(_closed_digest(batch.batch_digest))
|
digests.add(_closed_digest(batch.batch_digest))
|
||||||
|
_closed_vocabulary(batch.pending_entries, _DIGEST)
|
||||||
batch_families: set[str] = set()
|
batch_families: set[str] = set()
|
||||||
for positive in batch.accepted_positives:
|
for positive in batch.accepted_positives:
|
||||||
for scope in positive.verified_scopes:
|
for scope in positive.verified_scopes:
|
||||||
@@ -501,13 +502,21 @@ def _pending_by_ecosystem(
|
|||||||
state: SourcingQueueStateV1,
|
state: SourcingQueueStateV1,
|
||||||
batches: Sequence[CohortBatchOutcomeV1],
|
batches: Sequence[CohortBatchOutcomeV1],
|
||||||
) -> dict[str, tuple[ReviewQueueEntryV1, ...]]:
|
) -> dict[str, tuple[ReviewQueueEntryV1, ...]]:
|
||||||
"""Pending entries per ecosystem from every batch's resolved records.
|
"""Pending entries per ecosystem, derived from every batch's record outcomes.
|
||||||
|
|
||||||
A record resolves its entry only through the committed review machinery:
|
A record resolves its entry only when it is an accepted record or carries
|
||||||
accepted positives and review-level exclusions answer the entry, while
|
a review-level exclusion reason; unreadable or evidence-invalid records
|
||||||
unreadable or evidence-invalid records leave it pending. A narrowed
|
leave it pending. Reading records instead of a batch's ``pending_entries``
|
||||||
selection batch therefore surrenders exactly the entries its records
|
keeps a narrowed selection batch from answering the whole shared queue:
|
||||||
resolved, never the whole shared queue.
|
only entries whose records resolved are marked answered here.
|
||||||
|
|
||||||
|
This view is not equivalent to the third round's ``pending_entries`` view
|
||||||
|
in one corner. Ingestion marks an entry answered as soon as its review
|
||||||
|
pair validates, so a record then excluded as a conflicting accepted review
|
||||||
|
is absent from ``pending_entries`` and the third round counts it answered,
|
||||||
|
while here it stays pending because that exclusion reason is not
|
||||||
|
review-level. The fourth round therefore offers such an entry again rather
|
||||||
|
than dropping it.
|
||||||
"""
|
"""
|
||||||
queued = {
|
queued = {
|
||||||
ecosystem: {entry.entry_digest for entry in _queue_for(state, ecosystem).entries}
|
ecosystem: {entry.entry_digest for entry in _queue_for(state, ecosystem).entries}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ from benchmarks.valid.cohort_selection import ( # noqa: E402
|
|||||||
CohortSelectionStatus,
|
CohortSelectionStatus,
|
||||||
cohort_selection,
|
cohort_selection,
|
||||||
cohort_selection_bytes,
|
cohort_selection_bytes,
|
||||||
|
select_fourth_cohort_batch,
|
||||||
select_third_cohort_batch,
|
select_third_cohort_batch,
|
||||||
)
|
)
|
||||||
from benchmarks.valid.cohort_selection_store import ( # noqa: E402
|
from benchmarks.valid.cohort_selection_store import ( # noqa: E402
|
||||||
@@ -306,6 +307,43 @@ def test_malformed_ledgers_and_states_fail_closed():
|
|||||||
_select({"python_queue": ()}, ledger)
|
_select({"python_queue": ()}, ledger)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"select",
|
||||||
|
(select_third_cohort_batch, select_fourth_cohort_batch),
|
||||||
|
ids=("third", "fourth"),
|
||||||
|
)
|
||||||
|
def test_forged_pending_entries_outside_the_durable_shape_fail_closed(select) -> None:
|
||||||
|
state, _, ledger = _prepared()
|
||||||
|
batch = next(item for item in ledger if item.pending_entries)
|
||||||
|
intact = replace(batch, pending_entries=tuple(batch.pending_entries))
|
||||||
|
rest = tuple(item for item in ledger if item is not batch)
|
||||||
|
|
||||||
|
def decided(pending_entries):
|
||||||
|
return select(
|
||||||
|
state=state,
|
||||||
|
accepted_batches=(replace(batch, pending_entries=pending_entries), *rest),
|
||||||
|
expected_ecosystem_policy_digest=ECOSYSTEM_POLICY,
|
||||||
|
expected_ground_truth_policy_digest=GROUND_TRUTH_POLICY,
|
||||||
|
)
|
||||||
|
|
||||||
|
baseline = decided(intact.pending_entries)
|
||||||
|
assert baseline.status is CohortSelectionStatus.SELECTED
|
||||||
|
assert intact.pending_entries and all(len(item) == 64 for item in intact.pending_entries)
|
||||||
|
|
||||||
|
for forged in (
|
||||||
|
list(intact.pending_entries),
|
||||||
|
set(intact.pending_entries),
|
||||||
|
iter(intact.pending_entries),
|
||||||
|
intact.pending_entries[0],
|
||||||
|
(*intact.pending_entries[:-1], "not-a-digest"),
|
||||||
|
(*intact.pending_entries, intact.pending_entries[0]),
|
||||||
|
None,
|
||||||
|
):
|
||||||
|
with pytest.raises(CohortSelectionStateError) as error:
|
||||||
|
decided(forged)
|
||||||
|
assert error.value.reason is CohortSelectionStateReason.STATE_MISMATCH
|
||||||
|
|
||||||
|
|
||||||
def test_selection_module_and_outputs_avoid_out_of_scope_machinery():
|
def test_selection_module_and_outputs_avoid_out_of_scope_machinery():
|
||||||
root = Path(__file__).resolve().parents[1]
|
root = Path(__file__).resolve().parents[1]
|
||||||
for name in ("benchmarks/valid/cohort_selection.py", "benchmarks/valid/cohort_selection_store.py"):
|
for name in ("benchmarks/valid/cohort_selection.py", "benchmarks/valid/cohort_selection_store.py"):
|
||||||
|
|||||||
Reference in New Issue
Block a user