Scan all eligible CodeQL benchmark pairs
Browse files- codeql_compare.py +8 -4
- test_codeql_compare.py +23 -1
codeql_compare.py
CHANGED
|
@@ -32,15 +32,17 @@ def rows(path):
|
|
| 32 |
|
| 33 |
|
| 34 |
def selected_pairs(args):
|
| 35 |
-
cohort = json.loads(Path(args.cohort).read_text())
|
| 36 |
selected = {}
|
| 37 |
for domain in ("bug", "security"):
|
| 38 |
-
repos = set(cohort[domain])
|
| 39 |
selected[domain] = [
|
| 40 |
pair for pair in rows(Path(args.data) / domain / "benchmark.jsonl")
|
| 41 |
-
if pair["repository"] in repos
|
| 42 |
and pair["language"].lower() in LANGUAGES
|
| 43 |
-
and all(pair[role].get("revision")
|
|
|
|
|
|
|
| 44 |
]
|
| 45 |
return selected
|
| 46 |
|
|
@@ -390,6 +392,8 @@ def main():
|
|
| 390 |
parser.add_argument("--data", required=True, help="directory with bug/security/benchmark.jsonl")
|
| 391 |
parser.add_argument("--predictions", required=True, help="directory with bug/security/jev.jsonl")
|
| 392 |
parser.add_argument("--cohort", default=str(Path(__file__).with_name("codeql-cohort.json")))
|
|
|
|
|
|
|
| 393 |
parser.add_argument("--codeql", help="unpacked CodeQL CLI directory")
|
| 394 |
parser.add_argument("--rebench-parquet", help="SWE-rebench-V2 source Parquet with gold patches")
|
| 395 |
parser.add_argument("--image", default="node:22-bookworm")
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def selected_pairs(args):
|
| 35 |
+
cohort = None if args.all_supported else json.loads(Path(args.cohort).read_text())
|
| 36 |
selected = {}
|
| 37 |
for domain in ("bug", "security"):
|
| 38 |
+
repos = set(cohort[domain]) if cohort else None
|
| 39 |
selected[domain] = [
|
| 40 |
pair for pair in rows(Path(args.data) / domain / "benchmark.jsonl")
|
| 41 |
+
if (repos is None or pair["repository"] in repos)
|
| 42 |
and pair["language"].lower() in LANGUAGES
|
| 43 |
+
and all(isinstance(pair[role].get("revision"), str)
|
| 44 |
+
and re.fullmatch(r"[0-9a-f]{40}", pair[role]["revision"])
|
| 45 |
+
for role in ("before", "after"))
|
| 46 |
]
|
| 47 |
return selected
|
| 48 |
|
|
|
|
| 392 |
parser.add_argument("--data", required=True, help="directory with bug/security/benchmark.jsonl")
|
| 393 |
parser.add_argument("--predictions", required=True, help="directory with bug/security/jev.jsonl")
|
| 394 |
parser.add_argument("--cohort", default=str(Path(__file__).with_name("codeql-cohort.json")))
|
| 395 |
+
parser.add_argument("--all-supported", action="store_true",
|
| 396 |
+
help="scan every pair in supported languages with two Git revisions")
|
| 397 |
parser.add_argument("--codeql", help="unpacked CodeQL CLI directory")
|
| 398 |
parser.add_argument("--rebench-parquet", help="SWE-rebench-V2 source Parquet with gold patches")
|
| 399 |
parser.add_argument("--image", default="node:22-bookworm")
|
test_codeql_compare.py
CHANGED
|
@@ -3,11 +3,33 @@ import sys
|
|
| 3 |
import tempfile
|
| 4 |
import unittest
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
|
| 7 |
-
from codeql_compare import codeql_alert, method_span, metrics, run
|
| 8 |
|
| 9 |
|
| 10 |
class CodeQLComparisonTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def test_alert_requires_primary_location_inside_method_and_relevant_tag(self):
|
| 12 |
side = {
|
| 13 |
"path": "src/example.py",
|
|
|
|
| 3 |
import tempfile
|
| 4 |
import unittest
|
| 5 |
from pathlib import Path
|
| 6 |
+
from types import SimpleNamespace
|
| 7 |
|
| 8 |
+
from codeql_compare import codeql_alert, method_span, metrics, run, selected_pairs
|
| 9 |
|
| 10 |
|
| 11 |
class CodeQLComparisonTests(unittest.TestCase):
|
| 12 |
+
def test_all_supported_selects_every_eligible_repository(self):
|
| 13 |
+
revision = "a" * 40
|
| 14 |
+
eligible = {"pair_id": "eligible", "repository": "other/repo", "language": "python",
|
| 15 |
+
"before": {"revision": revision}, "after": {"revision": revision}}
|
| 16 |
+
unsupported = {**eligible, "pair_id": "unsupported", "language": "php"}
|
| 17 |
+
missing_revision = {**eligible, "pair_id": "missing",
|
| 18 |
+
"after": {"revision": None}}
|
| 19 |
+
with tempfile.TemporaryDirectory() as directory:
|
| 20 |
+
root = Path(directory)
|
| 21 |
+
for domain in ("bug", "security"):
|
| 22 |
+
path = root / domain / "benchmark.jsonl"
|
| 23 |
+
path.parent.mkdir()
|
| 24 |
+
path.write_text("".join(json.dumps(row) + "\n" for row in
|
| 25 |
+
(eligible, unsupported, missing_revision)))
|
| 26 |
+
cohort = root / "cohort.json"
|
| 27 |
+
cohort.write_text(json.dumps({"bug": ["selected/repo"],
|
| 28 |
+
"security": ["selected/repo"]}))
|
| 29 |
+
args = SimpleNamespace(data=str(root), cohort=str(cohort), all_supported=True)
|
| 30 |
+
self.assertEqual([row["pair_id"] for row in selected_pairs(args)["bug"]],
|
| 31 |
+
["eligible"])
|
| 32 |
+
|
| 33 |
def test_alert_requires_primary_location_inside_method_and_relevant_tag(self):
|
| 34 |
side = {
|
| 35 |
"path": "src/example.py",
|