mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-16 03:49:26 +00:00
merge(learn): advisory-fix harvest and slice 2 -- six families out-of-repo
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
@@ -171,3 +171,34 @@ def test_pair_sides_join_the_record_stored_under_their_harvest_unit_pin() -> Non
|
||||
assert build_examples([lab], records_by_key([stored]), lines_of, sources=SOURCES).summary()["examples"] == 0
|
||||
build = build_examples([lab], records_by_key([stored]), lines_of, sources=SOURCES, pins=pins)
|
||||
assert build.summary()["examples"] == 1 and build.rows[0]["pin"] == unit_pin
|
||||
|
||||
|
||||
def test_side_reader_reads_every_pair_kind_source(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Labels from the corpus catalog and from a second pair-kind source (advisory-fixes) are both source ``pairs``;
|
||||
the reader must find either side, not only the first catalog's (the 2026-10-02 advisory rebuild read 0 of 194)."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
import openultrasast.pairs as pairs
|
||||
from openultrasast.learn.examples import SideReader
|
||||
|
||||
files = {}
|
||||
for name in ("corpus-case", "advisory-case"):
|
||||
files[name] = tmp_path / f"{name}.py"
|
||||
files[name].write_text("def handler(request):\n return 1\n")
|
||||
catalogs = {"corpus.toml": "corpus-case", "advisory.toml": "advisory-case"}
|
||||
|
||||
def fake(path: Path) -> tuple[Any, ...]:
|
||||
name = catalogs[Path(path).name]
|
||||
return (SimpleNamespace(name=name, vuln_file=files[name], fixed_file=files[name], license="MIT"),)
|
||||
|
||||
monkeypatch.setattr(pairs, "load_pair_catalog", fake)
|
||||
sources = Sources(
|
||||
(Source("pairs", "pairs", ("corpus.toml",), (), "2026-09-30", "development"),
|
||||
Source("advisory-fixes", "pairs", ("advisory.toml",), (), "2026-10-01", "development")),
|
||||
frozenset(), {}, Path("sources.toml"),
|
||||
) # fmt: skip
|
||||
reader = SideReader(tmp_path, tmp_path, sources, [])
|
||||
for name in catalogs.values():
|
||||
lab = label(source="pairs", source_ref=name, pin="")
|
||||
assert reader(lab, "vulnerable") == ["def handler(request):", " return 1"]
|
||||
assert reader.license(lab) == "MIT"
|
||||
|
||||
@@ -136,6 +136,24 @@ def test_near_duplicates_drop_in_evaluation_and_stay_in_deployment() -> None:
|
||||
assert kept.near_duplicates == 0 and twin.id in {e.id for e in kept.examples}
|
||||
|
||||
|
||||
def test_a_near_duplicate_demonstration_is_swapped_in_evaluation_and_kept_in_deployment() -> None:
|
||||
"""A compiled demonstration whose excerpt is a near-duplicate of the target's (cos >= 0.98) is ineligible in
|
||||
evaluation, like a retrieved one: swapped for its alternate, or dropped. Before 2026-10-02 only the pre-call
|
||||
assertion checked it, and the advisory-fix slice stopped there (BoundaryViolation: near duplicate)."""
|
||||
twin = example("demo-twin", group="fork/repo", label=1)
|
||||
alt = example("demo-alt", group="a/b", label=1)
|
||||
vectors = {twin.excerpt_sha: [1.0, 0.0], alt.excerpt_sha: [0.0, 1.0]}
|
||||
target = replace(_target(), vector=[1.0, 0.0])
|
||||
evaluation = replace(outer_folds([twin], k=1)[0], eval_groups=frozenset())
|
||||
demos = [{"example_id": twin.id, "alternate": {"example_id": alt.id}}]
|
||||
usable = demonstrations_for(demos, by_id([twin, alt]), target, evaluation, vectors=vectors)
|
||||
assert [d["example_id"] for d in usable] == [alt.id]
|
||||
assert_boundary([d["example_id"] for d in usable], by_id([twin, alt]), target, evaluation, vectors=vectors)
|
||||
assert demonstrations_for([{"example_id": twin.id, "alternate": None}], by_id([twin]), target, evaluation, vectors=vectors) == []
|
||||
deployed, _ = deployment_fold("https://github.com/someone/else", ["fork/repo"])
|
||||
assert [d["example_id"] for d in demonstrations_for(demos, by_id([twin, alt]), target, deployed, vectors=vectors)] == [twin.id]
|
||||
|
||||
|
||||
def test_deployment_excludes_the_scanned_repository_when_it_is_a_corpus_group() -> None:
|
||||
own = example("own", group="acme/webapp", label=1)
|
||||
fold, note = deployment_fold("https://github.com/Acme/WebApp.git", ["acme/webapp", "x/y"])
|
||||
|
||||
Reference in New Issue
Block a user