mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 10:18:18 +00:00
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.
This commit is contained in:
@@ -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", "")),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user