From 67bc37cac67e7e5a5b734304fa056c6f14d9c586 Mon Sep 17 00:00:00 2001 From: Marius Ciepluch <11855163+norandom@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:40:09 +0100 Subject: [PATCH] fix(valid-detection-benchmark): break sourcing-queue ties on fix-site path and function Candidates that differed only in fix-site path or function were selected by input order under the queue cap. Both scalars are now part of the request order, so cap selection no longer depends on input order for them. --- benchmarks/valid/sourcing_queue_build.py | 6 ++- tests/test_valid_benchmark_sourcing_queue.py | 53 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/benchmarks/valid/sourcing_queue_build.py b/benchmarks/valid/sourcing_queue_build.py index 1f43e928..af202099 100644 --- a/benchmarks/valid/sourcing_queue_build.py +++ b/benchmarks/valid/sourcing_queue_build.py @@ -96,7 +96,9 @@ def _request_order(request: SourcingCandidateRequest) -> tuple[str, ...]: Task 10.1 review fold-in: distinct candidates tying on the first four keys used to be ordered by input position, so cap selection was permutation-sensitive; the advisory, package-manifest, and license digests - make the order a function of content only. + make the order a function of content only. The fix-site path and function + are the non-digest scalars two otherwise identical requests can still + differ on; appending them keeps every existing order intact. """ digest = request.model_assistance_digest or "" return ( @@ -107,6 +109,8 @@ def _request_order(request: SourcingCandidateRequest) -> tuple[str, ...]: request.family.advisory_digest, request.package_evidence.manifest.content_digest, request.license_evidence.source.content_digest, + str(request.case.get("path", "")), + str(request.case.get("function", "")), ) diff --git a/tests/test_valid_benchmark_sourcing_queue.py b/tests/test_valid_benchmark_sourcing_queue.py index 4f9f8482..0687d11b 100644 --- a/tests/test_valid_benchmark_sourcing_queue.py +++ b/tests/test_valid_benchmark_sourcing_queue.py @@ -3,6 +3,7 @@ from __future__ import annotations import io +import itertools import json import sys import tomllib @@ -398,6 +399,58 @@ def test_bounded_queues_enforce_caps_deterministically(): assert reversed_state.exclusions == state.exclusions +class _TwinPathReader(FakeReader): + """The py-app revisions also carry a second fix site under a different path.""" + + def __init__(self) -> None: + super().__init__() + parent, fix = _REVISIONS["py-app"] + self._blobs[(parent, "twin.py")] = SECOND_VULNERABLE + self._blobs[(fix, "twin.py")] = SECOND_FIXED + + +def _build_with_reader(reader, requests, policy): + resolver = _resolver() + return build_sourcing_queue( + requests, + reader=reader, + resolver=resolver, + authority=_authority(resolver), + policy=policy, + enumeration_actor=ENUMERATION_ACTOR, + enumeration_reviewer=ENUMERATION_REVIEWER, + ) + + +def test_fix_site_scalars_break_otherwise_tied_candidates_under_a_cap(): + first = _request("py-app") + second = _request("py-app", path="twin.py", function="load") + requests = [first, second, _request("js-app", family="output_encoding", cwe="CWE-79")] + policy = _policy(per_ecosystem_cap=1) + assert (first.family, first.reachability, first.package_evidence, first.license_evidence) == ( + second.family, + second.reachability, + second.package_evidence, + second.license_evidence, + ) + assert (first.case["url"], first.model_assistance_digest) == (second.case["url"], second.model_assistance_digest) + assert (first.case["path"], first.case["function"]) == ("app.py", "handler") + assert (second.case["path"], second.case["function"]) == ("twin.py", "load") + + digests = set() + for order in itertools.permutations(requests): + state = _build_with_reader(_TwinPathReader(), list(order), policy) + (queued,) = state.python_queue.entries + assert (queued.fix_site.path, queued.fix_site.function) == ("app.py", "handler") + digests.add((state.state_digest, pending_queue_identities(state))) + + assert len(digests) == 1 + state = _build_with_reader(_TwinPathReader(), requests, policy) + (capped,) = [item for item in state.exclusions if item.reason is SourcingQueueReason.QUEUE_CAP_EXCEEDED] + assert capped.candidate_digest != state.python_queue.entries[0].candidate_digest + assert len(state.javascript_queue.entries) == 1 + + def test_durable_resume_reproduces_pending_identities(): client = _Client() store = S3ArtifactRepository(_settings(), client)