~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
ci(osv): fail PR scans only on vulnerabilities the change introduces (#7466)
LearningCircuiteb7d36afee09
diff --git a/.github/SECURITY_ALERTS.md b/.github/SECURITY_ALERTS.mdindex 21b7fea4b0..c49e353852 100644--- a/.github/SECURITY_ALERTS.md+++ b/.github/SECURITY_ALERTS.md@@ -107,7 +107,13 @@ suppression. Change one only through a reviewed PR that records the reason anda tracking link beside the entry, and remove the entry once the fix ships.- **OSV-Scanner** (`osv-scan`): any vulnerability in a completed scan fails the- job. Add an `[[IgnoredVulns]]` entry with `id`, `ignoreUntil`, and `reason`+ job in the release gate, the weekly schedule and pushes. On pull requests and+ in the merge queue only a vulnerability the change introduces fails it; one+ already on the base branch is reported as a warning and still uploaded.+ Findings are compared by advisory, lockfile and package name, not version:+ moving an already-vulnerable package to another vulnerable version does not+ fail, while the same advisory in a new package does. Add an+ `[[IgnoredVulns]]` entry with `id`, `ignoreUntil`, and `reason`to the `osv-scanner.toml` in the affected lockfile's directory. `ignoreUntil`is a native expiry: afterwards the finding fails the scan again. The two v2release entries in [osv-scanner.toml](../osv-scanner.toml)diff --git a/.github/scripts/run_osv_scan.py b/.github/scripts/run_osv_scan.pyindex 6aff5a6579..5a700052b4 100644--- a/.github/scripts/run_osv_scan.py+++ b/.github/scripts/run_osv_scan.py@@ -8,12 +8,19 @@ Run the hash-verified binary directly, accepting only its documented 0/1statuses with no error-level diagnostics. OSV prioritizes exit 1 over loggedextraction errors when both occur. A completed vulnerable scan still failsthe job, but its validated findings are uploaded.++With ``--baseline-root`` (pull requests and the merge queue), the base commit+is scanned too and only findings the change introduces fail the job. An+advisory published against a dependency already on the base branch is then+reported as a warning and still uploaded, instead of failing every PR; the+release gate and scheduled scans pass no baseline and fail on any finding."""import argparseimport jsonimport osfrom pathlib import Path+import reimport secretsimport shutilimport subprocess@@ -73,63 +80,174 @@ def validate_report(path: Path, exit_code: int) -> int:return findings-def scan(scanner: Path, root: Path, output: Path) -> int:+_PACKAGE = re.compile(r"^Package '(.+?)@[^@']*'")+++def finding_keys(path: Path, root: Path) -> set[tuple[str, str, str]]:+ """(advisory id, lockfile relative to the scanned root, package name).++ The package version is left out, so a PR that moves an already-vulnerable+ package to another still-vulnerable version does not count as+ introducing the advisory, while a different package under the same+ advisory does. A message the package pattern does not match keys with+ an empty package name, which ``compare_with_baseline`` always treats as+ introduced: an unattributable finding cannot be matched to the base.+ """+ report = json.loads(path.read_text(encoding="utf-8"))+ keys = set()+ prefix = root.as_posix().rstrip("/") + "/"+ for run in report["runs"]:+ for result in run["results"]:+ uri = ""+ locations = result.get("locations")+ if isinstance(locations, list) and locations:+ location = locations[0]+ physical = (+ location.get("physicalLocation")+ if isinstance(location, dict)+ else None+ )+ artifact = (+ physical.get("artifactLocation")+ if isinstance(physical, dict)+ else None+ )+ if isinstance(artifact, dict):+ uri = str(artifact.get("uri", ""))+ uri = uri.removeprefix("file://")+ uri = uri.removeprefix(prefix).removeprefix("./")+ package = _PACKAGE.match(result["message"]["text"])+ keys.add(+ (result["ruleId"], uri, package.group(1) if package else "")+ )+ return keys+++def _printable(text: str) -> str:+ """Repository-controlled text, safe inside a workflow command."""+ return re.sub(r"[^A-Za-z0-9._/@+-]", "?", text)+++def run_scanner(scanner: Path, root: Path, pending: Path) -> tuple[int, int]:+ """Run one complete scan of ``root`` into ``pending``.++ Returns the scanner's status and the number of findings.+ """+ command = [+ str(scanner),+ "scan",+ "source",+ "--format=sarif",+ "--verbosity=error",+ f"--output-file={pending}",+ "-r",+ "./",+ ]+ # Scanner logs include repository-controlled package names and paths.+ token = secrets.token_hex(16)+ print(f"::stop-commands::{token}", flush=True)+ with tempfile.TemporaryFile(+ mode="w+", encoding="utf-8", errors="replace"+ ) as diagnostics:+ try:+ completed = subprocess.run(+ command,+ cwd=root,+ timeout=600,+ check=False,+ stdout=diagnostics,+ stderr=subprocess.STDOUT,+ )+ except (OSError, subprocess.TimeoutExpired) as exc:+ raise ScanError(+ "OSV-Scanner could not complete its invocation"+ ) from exc+ finally:+ has_errors = bool(diagnostics.seek(0, os.SEEK_END))+ diagnostics.seek(0)+ shutil.copyfileobj(diagnostics, sys.stdout)+ print(f"\n::{token}::", flush=True)+ if completed.returncode not in (0, 1):+ raise ScanError(+ f"OSV-Scanner exited {completed.returncode}; refusing partial evidence"+ )+ if has_errors:+ raise ScanError("OSV-Scanner logged errors; refusing partial evidence")+ return completed.returncode, validate_report(pending, completed.returncode)+++def scan(+ scanner: Path, root: Path, output: Path, baseline: Path | None = None+) -> int:# An earlier invocation or a checked-in file must never qualify this scan.output.unlink(missing_ok=True)with tempfile.TemporaryDirectory(prefix=".osv-scan-", dir=output.parent) as tmp:pending = Path(tmp) / "results.sarif"- command = [- str(scanner),- "scan",- "source",- "--format=sarif",- "--verbosity=error",- f"--output-file={pending}",- "-r",- "./",- ]- # Scanner logs include repository-controlled package names and paths.- token = secrets.token_hex(16)- print(f"::stop-commands::{token}", flush=True)- with tempfile.TemporaryFile(- mode="w+", encoding="utf-8", errors="replace"- ) as diagnostics:- try:- completed = subprocess.run(- command,- cwd=root,- timeout=600,- check=False,- stdout=diagnostics,- stderr=subprocess.STDOUT,- )- except (OSError, subprocess.TimeoutExpired) as exc:- raise ScanError(- "OSV-Scanner could not complete its invocation"- ) from exc- finally:- has_errors = bool(diagnostics.seek(0, os.SEEK_END))- diagnostics.seek(0)- shutil.copyfileobj(diagnostics, sys.stdout)- print(f"\n::{token}::", flush=True)- if completed.returncode not in (0, 1):- raise ScanError(- f"OSV-Scanner exited {completed.returncode}; refusing partial evidence"- )- if has_errors:- raise ScanError(- "OSV-Scanner logged errors; refusing partial evidence"- )- findings = validate_report(pending, completed.returncode)+ returncode, findings = run_scanner(scanner, root, pending)+ keys = finding_keys(pending, root)pending.replace(output)github_output = os.environ.get("GITHUB_OUTPUT")if github_output:with open(github_output, "a", encoding="utf-8") as stream:stream.write("scan_complete=true\n")print(f"OSV scan completed: {findings} SARIF findings", flush=True)- return completed.returncode+ if returncode == 0 or baseline is None:+ return returncode+ return compare_with_baseline(scanner, baseline, output.parent, keys)+++def compare_with_baseline(+ scanner: Path,+ baseline: Path,+ workdir: Path,+ keys: set[tuple[str, str, str]],+) -> int:+ """Fail only on findings absent from the base commit's own scan."""+ with tempfile.TemporaryDirectory(+ prefix=".osv-baseline-", dir=workdir+ ) as tmp:+ pending = Path(tmp) / "results.sarif"+ try:+ run_scanner(scanner, baseline, pending)+ base_keys = finding_keys(pending, baseline)+ except (OSError, ScanError, ValueError) as exc:+ # Without a complete baseline nothing can be called pre-existing.+ print(+ f"::warning::Baseline OSV scan unusable ({exc}); "+ "failing on every finding",+ flush=True,+ )+ return 1+ # An empty package name means the message did not parse; matching it+ # against the base would let any package under that advisory through.+ introduced = sorted(+ key for key in keys if not key[2] or key not in base_keys+ )+ for rule, location, package in sorted(set(keys) - set(introduced)):+ print(+ f"::warning::{_printable(rule)} ({_printable(package)}) in "+ f"{_printable(location)} is "+ "already on the base branch; not introduced by this change",+ flush=True,+ )+ for rule, location, package in introduced:+ if not package:+ print(+ f"::error::{_printable(rule)} in {_printable(location)} "+ "names no recognisable package, so it cannot be matched to "+ "the base branch; failing closed",+ flush=True,+ )+ continue+ print(+ f"::error::{_printable(rule)} ({_printable(package)}) in "+ f"{_printable(location)} is "+ "introduced by this change",+ flush=True,+ )+ return 1 if introduced else 0def main() -> int:@@ -137,10 +255,18 @@ def main() -> int:parser.add_argument("--scanner", type=Path, required=True)parser.add_argument("--root", type=Path, default=Path.cwd())parser.add_argument("--output", type=Path, default=Path("results.sarif"))+ parser.add_argument(+ "--baseline-root",+ type=Path,+ help="checkout of the base commit; fail only on findings it lacks",+ )args = parser.parse_args()try:return scan(- args.scanner.resolve(), args.root.resolve(), args.output.absolute()+ args.scanner.resolve(),+ args.root.resolve(),+ args.output.absolute(),+ args.baseline_root.resolve() if args.baseline_root else None,)except (OSError, ScanError) as exc:print(f"::error::{exc}", flush=True)diff --git a/.github/workflows/osv-scan-reusable.yml b/.github/workflows/osv-scan-reusable.ymlindex 0adee4a85d..efdd0076d4 100644--- a/.github/workflows/osv-scan-reusable.yml+++ b/.github/workflows/osv-scan-reusable.yml@@ -9,6 +9,14 @@ on:description: Exact commit to scantype: stringdefault: ''+ baseline_parent:+ description: >-+ For pull requests and the merge queue: also scan the first parent+ of the scanned merge commit (the base it merges into) and fail only+ on findings absent from it. The release gate and scheduled scans+ leave it false and fail on any finding.+ type: boolean+ default: falsepermissions: {}@@ -17,7 +25,8 @@ jobs:# caller-dependent SARIF category. Category alignment is tracked in #7220.osv-scan:runs-on: ubuntu-latest- timeout-minutes: 15+ # Two serial scans (head and baseline) of up to 10 minutes each.+ timeout-minutes: 25permissions:contents: readactions: read@@ -31,6 +40,8 @@ jobs:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:persist-credentials: false+ # The baseline is the merge commit's first parent.+ fetch-depth: ${{ inputs.baseline_parent && 2 || 1 }}ref: ${{ inputs.ref || github.sha }}- name: Install verified OSV-Scanner@@ -45,15 +56,28 @@ jobs:printf '%s %s\n' "$OSV_SHA256" "$RUNNER_TEMP/osv-scanner" | sha256sum --check --strictchmod +x "$RUNNER_TEMP/osv-scanner"+ # An advisory published against a dependency already on main must not+ # fail every open PR; the change is judged only on what it introduces.+ # The first parent is exact: refs/pull/N/merge and merge-queue commits+ # are rebuilt on the current base, which pull_request.base.sha is not.+ - name: Check out the baseline commit+ if: ${{ inputs.baseline_parent }}+ run: git worktree add --detach "$RUNNER_TEMP/osv-baseline" HEAD^1+- name: Scan and validate completionid: scanenv:GOTOOLCHAIN: auto+ BASELINE_PARENT: ${{ inputs.baseline_parent }}run: |- python3 .github/scripts/run_osv_scan.py \- --scanner "$RUNNER_TEMP/osv-scanner" --output results.sarif+ args=(--scanner "$RUNNER_TEMP/osv-scanner" --output results.sarif)+ if [ "$BASELINE_PARENT" = true ]; then+ args+=(--baseline-root "$RUNNER_TEMP/osv-baseline")+ fi+ python3 .github/scripts/run_osv_scan.py "${args[@]}"- # Completed vulnerable scans exit 1 and fail the job, while their findings+ # Completed vulnerable scans exit 1 and fail the job (with a baseline,+ # only for findings the change introduces), while their findings# remain uploadable. Failed/partial scans never set scan_complete.- name: Upload artifactif: ${{ !cancelled() && steps.scan.outputs.scan_complete == 'true' }}diff --git a/.github/workflows/osv-scanner.yml b/.github/workflows/osv-scanner.ymlindex 652c3bddc5..8800701e07 100644--- a/.github/workflows/osv-scanner.yml+++ b/.github/workflows/osv-scanner.yml@@ -40,3 +40,7 @@ jobs:uses: $/.github/workflows/osv-scan-reusable.ymlwith:ref: ${{ github.sha }}+ # PRs and the merge queue fail only on findings they introduce. The+ # release gate (workflow_call from release-gate.yml) and the weekly+ # schedule get no baseline and still fail on any finding.+ baseline_parent: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}diff --git a/tests/ci/standalone/test_osv_scan.py b/tests/ci/standalone/test_osv_scan.pyindex fe9186029e..82c961ccd8 100644--- a/tests/ci/standalone/test_osv_scan.py+++ b/tests/ci/standalone/test_osv_scan.py@@ -1,6 +1,7 @@"""Exercise OSV's exit/report boundary without network or application imports."""import hashlib+import importlib.utilimport jsonimport osfrom pathlib import Path@@ -16,7 +17,35 @@ SCRIPT = ROOT / ".github/scripts/run_osv_scan.py"WORKFLOW = ROOT / ".github/workflows/osv-scan-reusable.yml"-def report(findings=False):+def report(findings=False, rules=None):+ if rules is not None:+ return {+ "version": "2.1.0",+ "runs": [+ {+ "tool": {"driver": {"name": "osv-scanner"}},+ "results": [+ {+ "ruleId": rule,+ "message": {+ "text": f"Package '{package}@1.0' is "+ f"vulnerable to '{rule}'."+ },+ "locations": [+ {+ "physicalLocation": {+ "artifactLocation": {+ "uri": f"file://{root}/pdm.lock"+ }+ }+ }+ ],+ }+ for rule, root, package in rules+ ],+ }+ ],+ }return {"version": "2.1.0","runs": [@@ -37,6 +66,20 @@ def report(findings=False):}+def _load_script():+ spec = importlib.util.spec_from_file_location("run_osv_scan", SCRIPT)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def _pairs(rules):+ """Rules as (advisory, package); a bare advisory names package pkg."""+ return [+ rule if isinstance(rule, tuple) else (rule, "pkg") for rule in rules+ ]++def run_block(name):"""Read a workflow step's real shell script, including all its lines."""text = WORKFLOW.read_text(encoding="utf-8")@@ -64,24 +107,45 @@ class ScanBoundaryTests(unittest.TestCase):"pathlib.Path(os.environ['FAKE_ARGS']).write_text(json.dumps(\n"" {'args': sys.argv[1:], 'cwd': os.getcwd()}))\n""out = next(x.split('=', 1)[1] for x in sys.argv if x.startswith('--output-file='))\n"+ "base = os.environ.get('FAKE_BASELINE_ROOT')\n"+ "pre = 'FAKE_BASELINE_' if base and os.getcwd() == base else 'FAKE_'\n""if os.environ['FAKE_WRITE'] == '1':\n"- " pathlib.Path(out).write_text(os.environ['FAKE_REPORT'])\n"+ " pathlib.Path(out).write_text(os.environ[pre + 'REPORT'])\n""if os.environ.get('FAKE_LOG'):\n"" print(os.environ['FAKE_LOG'], flush=True)\n"- "sys.exit(int(os.environ['FAKE_EXIT']))\n",+ "sys.exit(int(os.environ[pre + 'EXIT']))\n",encoding="utf-8",)self.scanner.chmod(0o700)self.output = self.directory / "results.sarif"self.github_output = self.directory / "github-output"self.args = self.directory / "scanner-args.json"+ # Where the workflow step checks out the base commit.+ self.baseline_root = self.directory / "osv-baseline"def invoke(- self, status=0, payload=None, write=True, workflow=False, log=""+ self,+ status=0,+ payload=None,+ write=True,+ workflow=False,+ log="",+ baseline=None,):+ """``baseline`` is (status, payload) for a scan of the base commit."""self.github_output.unlink(missing_ok=True)+ extra = {}+ if baseline is not None:+ self.baseline_root.mkdir(exist_ok=True)+ extra = dict(+ FAKE_BASELINE_ROOT=str(self.baseline_root),+ FAKE_BASELINE_EXIT=str(baseline[0]),+ FAKE_BASELINE_REPORT=baseline[1],+ BASELINE_PARENT="true",+ )env = dict(os.environ,+ **extra,GITHUB_OUTPUT=str(self.github_output),FAKE_ARGS=str(self.args),FAKE_EXIT=str(status),@@ -114,6 +178,8 @@ class ScanBoundaryTests(unittest.TestCase):"--output",str(self.output),]+ if baseline is not None:+ command += ["--baseline-root", str(self.baseline_root)]result = subprocess.run(command,cwd=self.root,@@ -232,6 +298,114 @@ class ScanBoundaryTests(unittest.TestCase):"::error::repository-controlled", result.stdout[start:end])+ def pr_and_base(self, pr_rules, base_rules, base_status=None):+ pr = json.dumps(+ report(rules=[(r, self.root, p) for r, p in _pairs(pr_rules)])+ )+ base = json.dumps(+ report(+ rules=[+ (r, self.baseline_root, p) for r, p in _pairs(base_rules)+ ]+ )+ )+ if base_status is None:+ base_status = 1 if base_rules else 0+ return pr, (base_status, base)++ def test_findings_already_on_the_base_branch_do_not_fail(self):+ # An advisory published against a dependency main already locks+ # must not fail every open PR.+ for workflow in [False, True]:+ with self.subTest(workflow=workflow):+ pr, base = self.pr_and_base(["GHSA-old"], ["GHSA-old"])+ result, flags = self.invoke(+ 1, pr, baseline=base, workflow=workflow+ )+ self.assertEqual(+ result.returncode, 0, result.stdout + result.stderr+ )+ self.assertIn(+ "::warning::GHSA-old (pkg) in pdm.lock is already on the "+ "base branch",+ result.stdout,+ )+ # Still uploaded, so the alert stays visible.+ self.assertEqual(flags, "scan_complete=true\n")+ self.assertEqual(self.output.read_text(), pr)++ def test_findings_the_change_introduces_still_fail(self):+ for workflow in [False, True]:+ with self.subTest(workflow=workflow):+ pr, base = self.pr_and_base(+ ["GHSA-old", "GHSA-new"], ["GHSA-old"]+ )+ result, flags = self.invoke(+ 1, pr, baseline=base, workflow=workflow+ )+ self.assertEqual(result.returncode, 1)+ self.assertIn(+ "::error::GHSA-new (pkg) in pdm.lock is introduced",+ result.stdout,+ )+ self.assertNotIn(+ "GHSA-old (pkg) in pdm.lock is introduced", result.stdout+ )+ self.assertEqual(flags, "scan_complete=true\n")++ def test_same_advisory_in_another_package_is_introduced(self):+ pr, base = self.pr_and_base(+ [("GHSA-shared", "old-pkg"), ("GHSA-shared", "new-pkg")],+ [("GHSA-shared", "old-pkg")],+ )+ result, _ = self.invoke(1, pr, baseline=base)+ self.assertEqual(result.returncode, 1)+ self.assertIn(+ "::error::GHSA-shared (new-pkg) in pdm.lock is introduced",+ result.stdout,+ )++ def test_another_vulnerable_version_of_the_same_package_is_not_new(self):+ pr, base = self.pr_and_base(["GHSA-old"], ["GHSA-old"])+ pr = pr.replace("@1.0'", "@1.1'")+ result, _ = self.invoke(1, pr, baseline=base)+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)++ def test_unattributable_finding_fails_closed(self):+ # Two different packages whose messages both miss the package+ # pattern must not collapse into one key and pass as pre-existing.+ pr, base = self.pr_and_base(+ [("GHSA-9", "new-pkg")], [("GHSA-9", "old-pkg")]+ )+ pr = pr.replace("Package '", "Commit '")+ base = (base[0], base[1].replace("Package '", "Commit '"))+ result, flags = self.invoke(1, pr, baseline=base)+ self.assertEqual(result.returncode, 1, result.stdout)+ self.assertIn("names no recognisable package", result.stdout)+ self.assertNotIn("already on the base branch", result.stdout)+ self.assertEqual(flags, "scan_complete=true\n")++ def test_unusable_baseline_fails_on_every_finding(self):+ for base_status in [2, 128]:+ with self.subTest(base_status=base_status):+ pr, base = self.pr_and_base(+ ["GHSA-old"], ["GHSA-old"], base_status=base_status+ )+ result, _ = self.invoke(1, pr, baseline=base)+ self.assertEqual(result.returncode, 1)+ self.assertIn("Baseline OSV scan unusable", result.stdout)++ def test_clean_scan_skips_the_baseline(self):+ _, base = self.pr_and_base([], [], base_status=2)+ result, _ = self.invoke(0, json.dumps(report()), baseline=base)+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)++ def test_finding_text_cannot_inject_workflow_commands(self):+ pr, base = self.pr_and_base(["GHSA-x\n::error::forged"], [])+ result, _ = self.invoke(1, pr, baseline=base)+ self.assertEqual(result.returncode, 1)+ self.assertNotIn("\n::error::forged", result.stdout)+def test_real_workflow_scan_step_preserves_all_three_outcomes(self):for status, findings, accepted in [(0, False, True),@@ -248,6 +422,43 @@ class ScanBoundaryTests(unittest.TestCase):self.assertEqual(self.output.exists(), accepted)+class FindingKeyTests(unittest.TestCase):+ def keys(self, root, uri, text):+ payload = report(rules=[("GHSA-k", root, "pkg")])+ result = payload["runs"][0]["results"][0]+ result["message"]["text"] = text+ result["locations"][0]["physicalLocation"]["artifactLocation"][+ "uri"+ ] = uri+ with tempfile.TemporaryDirectory() as tmp:+ path = Path(tmp) / "r.sarif"+ path.write_text(json.dumps(payload), encoding="utf-8")+ return _load_script().finding_keys(path, Path(root))++ def test_package_name_matching_is_not_greedy(self):+ for text, package in [+ ("Package '[email protected]' is vulnerable to 'a@b'.", "pkg"),+ ("Package '@scope/[email protected]' is vulnerable to 'x'.", "@scope/name"),+ ]:+ with self.subTest(package=package):+ self.assertEqual(+ self.keys("/r", "file:///r/pdm.lock", text),+ {("GHSA-k", "pdm.lock", package)},+ )++ def test_lockfile_uri_forms_key_identically(self):+ text = "Package '[email protected]' is vulnerable to 'GHSA-k'."+ expected = {("GHSA-k", "sub/pdm.lock", "pkg")}+ for root, uri in [+ ("/head", "file:///head/sub/pdm.lock"),+ ("/base", "/base/sub/pdm.lock"),+ ("/base", "./sub/pdm.lock"),+ ("/base", "sub/pdm.lock"),+ ]:+ with self.subTest(uri=uri):+ self.assertEqual(self.keys(root, uri, text), expected)++class WorkflowTests(unittest.TestCase):def test_checksum_mismatch_never_makes_download_executable(self):with tempfile.TemporaryDirectory() as directory:@@ -315,6 +526,39 @@ class WorkflowTests(unittest.TestCase):(ROOT / ".github/workflows/osv-scanner.yml").read_text(),)+ def test_only_pull_requests_and_the_merge_queue_get_a_baseline(self):+ # The release gate calls osv-scanner.yml via workflow_call and must+ # keep failing on any finding, pre-existing or not.+ caller = (ROOT / ".github/workflows/osv-scanner.yml").read_text()+ lines = [+ line.strip()+ for line in caller.splitlines()+ if line.strip().startswith("baseline_parent:")+ ]+ self.assertEqual(+ lines,+ [+ "baseline_parent: ${{ github.event_name == 'pull_request' "+ "|| github.event_name == 'merge_group' }}"+ ],+ )+ text = WORKFLOW.read_text()+ # Pushes to main and the weekly schedule never pass a baseline.+ scheduled = (+ ROOT / ".github/workflows/osv-scanner-scheduled.yml"+ ).read_text()+ self.assertNotIn("baseline_parent", scheduled)+ self.assertIn("default: false", text.split("baseline_parent:", 1)[1])+ self.assertIn("if: ${{ inputs.baseline_parent }}", text)+ # The baseline is the scanned merge commit's own first parent.+ self.assertIn(+ 'git worktree add --detach "$RUNNER_TEMP/osv-baseline" HEAD^1',+ text,+ )+ self.assertIn(+ "fetch-depth: ${{ inputs.baseline_parent && 2 || 1 }}", text+ )+if __name__ == "__main__":unittest.main()