OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
test: share saved-scan export and integrity fixtures (#1365)
mldangelo-oaib9c8244af93c
diff --git a/plugins/codex-security/tests/test_finalize_scan_contract.py b/plugins/codex-security/tests/test_finalize_scan_contract.pyindex 366a93581..b3c34021c 100644--- a/plugins/codex-security/tests/test_finalize_scan_contract.py+++ b/plugins/codex-security/tests/test_finalize_scan_contract.py@@ -22,6 +22,7 @@ from workbench_test_support import ScanFixtureTestCase, load_script, windows_filFINALIZER = load_script("finalize_scan_contract")EXAMPLE_DIR = Path(__file__).resolve().parent.parent / "examples" / "completed-scan"+CANONICAL_FILES = ("scan-manifest.json", "findings.json", "coverage.json")class FinalizeScanContractTest(ScanFixtureTestCase):@@ -220,6 +221,41 @@ The extraction root is not enforced.self.assertEqual(accepted, findings)self.assertEqual((self.scan_dir / "findings.json").read_bytes(), sealed_bytes)+ def sarif_finding(self, fingerprint: str, suffix: str = "example") -> dict:+ finding = copy.deepcopy(self.finding)+ finding["findingId"] = f"csf_{suffix}"+ finding["occurrenceId"] = f"occ_{suffix}"+ finding["fingerprints"] = {"primary": fingerprint}+ return finding++ def write_line_hash_source(self) -> Path:+ source_root = self.scan_dir / "source"+ source_path = source_root / "src" / "extract.py"+ source_path.parent.mkdir(parents=True)+ source_path.write_text(+ "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"+ )+ return source_root++ def export_csv(self) -> csv.DictReader:+ self.findings["findings"] = [copy.deepcopy(self.finding)]+ self.write_sealed_scan()+ result = self.run_finalizer("--export-format", "csv")+ self.assertEqual(result.returncode, 0, result.stderr)+ return csv.DictReader(io.StringIO(result.stdout, newline=""))++ def write_sealed_receipt_scan(self, receipt_ref: str) -> Path:+ self.coverage["surfaces"][0]["receiptRefs"] = [receipt_ref]+ self.write_scan()+ receipt_path = self.scan_dir / receipt_ref+ receipt_path.parent.mkdir(parents=True)+ receipt_path.write_text('{"status":"reviewed"}\n', encoding="utf-8")+ FINALIZER.finalize_scan(self.scan_dir)+ return receipt_path++ def scan_file_bytes(self, *names: str) -> dict[str, bytes]:+ return {name: (self.scan_dir / name).read_bytes() for name in names}+def test_finalize_seals_manifest_deterministically(self) -> None:self.write_scan()@@ -388,13 +424,7 @@ The extraction root is not enforced.self.write_sealed_scan()findings = self.read_json("findings.json")findings["findings"][0]["extensions"]["note"] = "bad-" + chr(0xD800)- self.write_json("findings.json", findings)- manifest = self.read_json("scan-manifest.json")- for artifact in manifest["scan"]["artifacts"]:- if artifact["path"] == "findings.json":- artifact["sha256"] = self.sha256_file("findings.json")- break- self.write_json("scan-manifest.json", manifest)+ self.rewrite_sealed_artifact("findings.json", findings)before = {path.name: path.read_bytes() for path in self.scan_dir.iterdir() if path.is_file()}@@ -742,12 +772,7 @@ The extraction root is not enforced.self.write_sealed_scan()first_manifest = (self.scan_dir / "scan-manifest.json").read_bytes()- source_root = self.scan_dir / "source"- source_path = source_root / "src" / "extract.py"- source_path.parent.mkdir(parents=True)- source_path.write_text(- "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"- )+ source_root = self.write_line_hash_source()FINALIZER.finalize_scan(self.scan_dir, source_root=source_root)self.assertEqual(first_manifest, (self.scan_dir / "scan-manifest.json").read_bytes())@@ -777,10 +802,7 @@ The extraction root is not enforced.self.write_sealed_scan()sarif_path = self.scan_dir / "exports" / "results.sarif"sarif_path.unlink()- canonical = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json", "report.md")- }+ canonical = self.scan_file_bytes(*CANONICAL_FILES, "report.md")result = self.run_finalizer("--sarif-only")@@ -793,9 +815,7 @@ The extraction root is not enforced.self.assertEqual(rule["properties"]["security-severity"], "8.1")self.assertIn("external/cwe/cwe-022", rule["properties"]["tags"])self.assertFalse(sarif_path.exists())- self.assertEqual(- canonical, {name: (self.scan_dir / name).read_bytes() for name in canonical}- )+ self.assertEqual(canonical, self.scan_file_bytes(*canonical))def test_export_entrypoint_writes_json_csv_and_sarif_without_mutating_a_sealed_scan(self,@@ -807,10 +827,7 @@ The extraction root is not enforced.]self.findings["findings"] = [copy.deepcopy(self.finding)]self.write_sealed_scan()- canonical = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json", "report.md")- }+ canonical = self.scan_file_bytes(*CANONICAL_FILES, "report.md")for export_format in ("json", "csv", "sarif"):with self.subTest(export_format=export_format):@@ -860,19 +877,13 @@ The extraction root is not enforced.self.assertEqual(json.loads(result.stdout)["version"], "2.1.0")self.assertEqual(canonical,- {name: (self.scan_dir / name).read_bytes() for name in canonical},+ self.scan_file_bytes(*canonical),)def test_deep_csv_export_includes_the_canonical_candidate_id(self) -> None:self.coverage["mode"] = "deep_repository"self.finding["extensions"] = {"candidateId": "DSS-145", "reportId": "DSS-145-rogue"}- self.findings["findings"] = [copy.deepcopy(self.finding)]- self.write_sealed_scan()-- result = self.run_finalizer("--export-format", "csv")-- self.assertEqual(result.returncode, 0, result.stderr)- reader = csv.DictReader(io.StringIO(result.stdout, newline=""))+ reader = self.export_csv()self.assertIn("candidate_id", reader.fieldnames or [])row = next(reader)self.assertEqual(row["candidate_id"], "DSS-145")@@ -882,13 +893,7 @@ The extraction root is not enforced.self.coverage["mode"] = "scoped_path"self.finding["extensions"] = {"candidateId": "DSS-146", "reportId": "DSS-146-rogue"}self.finding["locations"] = [{"path": "src/extract.py", "startLine": 41, "role": "sink"}]- self.findings["findings"] = [copy.deepcopy(self.finding)]- self.write_sealed_scan()-- result = self.run_finalizer("--export-format", "csv")-- self.assertEqual(result.returncode, 0, result.stderr)- reader = csv.DictReader(io.StringIO(result.stdout, newline=""))+ reader = self.export_csv()self.assertIn("candidate_id", reader.fieldnames or [])row = next(reader)self.assertEqual(row["candidate_id"], "DSS-146")@@ -903,39 +908,21 @@ The extraction root is not enforced.with self.subTest(field=field):self.coverage["mode"] = coverage_modeself.finding["extensions"] = {field: f"legacy-{field}"}- self.findings["findings"] = [copy.deepcopy(self.finding)]- self.write_sealed_scan()-- result = self.run_finalizer("--export-format", "csv")-- self.assertEqual(result.returncode, 0, result.stderr)- reader = csv.DictReader(io.StringIO(result.stdout, newline=""))+ reader = self.export_csv()self.assertIn("candidate_id", reader.fieldnames or [])self.assertEqual(next(reader)["candidate_id"], f"legacy-{field}")def test_scoped_csv_export_does_not_classify_ordinary_ledger_ids_as_deep(self) -> None:self.coverage["mode"] = "scoped_path"self.finding["extensions"] = {"ledgerRowId": "SCAN-001-parser"}- self.findings["findings"] = [copy.deepcopy(self.finding)]- self.write_sealed_scan()-- result = self.run_finalizer("--export-format", "csv")-- self.assertEqual(result.returncode, 0, result.stderr)- reader = csv.DictReader(io.StringIO(result.stdout, newline=""))+ reader = self.export_csv()self.assertNotIn("candidate_id", reader.fieldnames or [])def test_csv_export_escapes_newline_and_full_width_formula_prefixes(self) -> None:self.finding["title"] = "\n=1+1"self.finding["summary"] = "=1+1"self.finding["remediation"] = " \t+1+1"- self.findings["findings"] = [copy.deepcopy(self.finding)]- self.write_sealed_scan()-- result = self.run_finalizer("--export-format", "csv")-- self.assertEqual(result.returncode, 0, result.stderr)- row = next(csv.DictReader(io.StringIO(result.stdout, newline="")))+ row = next(self.export_csv())self.assertEqual(row["title"], "'\n=1+1")self.assertEqual(row["summary"], "'=1+1")self.assertEqual(row["remediation"], "' \t+1+1")@@ -1085,10 +1072,7 @@ The extraction root is not enforced.):with self.subTest(arguments=arguments):self.write_scan()- before = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json")- }+ before = self.scan_file_bytes(*CANONICAL_FILES)result = self.run_finalizer(*arguments)@@ -1096,7 +1080,7 @@ The extraction root is not enforced.self.assertIn("requires", result.stderr)self.assertEqual(before,- {name: (self.scan_dir / name).read_bytes() for name in before},+ self.scan_file_bytes(*before),)def test_sarif_only_entrypoint_rejects_changed_sealed_artifact(self) -> None:@@ -1253,12 +1237,7 @@ The extraction root is not enforced.self.write_sealed_scan()findings = self.read_json("findings.json")findings["findings"][0]["locations"][0]["path"] = "../../outside.py"- self.write_json("findings.json", findings)- manifest = self.read_json("scan-manifest.json")- for artifact in manifest["scan"]["artifacts"]:- if artifact["path"] == "findings.json":- artifact["sha256"] = self.sha256_file("findings.json")- self.write_json("scan-manifest.json", manifest)+ self.rewrite_sealed_artifact("findings.json", findings)with self.assertRaisesRegex(FINALIZER.ContractError, "safe repository-relative"):FINALIZER.write_sarif_projection(self.scan_dir)@@ -1363,12 +1342,7 @@ The extraction root is not enforced.def test_sarif_projection_revalidates_sealed_coverage_receipts(self) -> None:receipt_ref = "artifacts/02_discovery/work_ledger.jsonl"- self.coverage["surfaces"][0]["receiptRefs"] = [receipt_ref]- self.write_scan()- receipt_path = self.scan_dir / receipt_ref- receipt_path.parent.mkdir(parents=True)- receipt_path.write_text('{"status":"reviewed"}\n', encoding="utf-8")- FINALIZER.finalize_scan(self.scan_dir)+ self.write_sealed_receipt_scan(receipt_ref)manifest = self.read_json("scan-manifest.json")manifest["scan"]["artifacts"] = [artifact@@ -1904,25 +1878,21 @@ The extraction root is not enforced.self.findings["findings"][0]["validation"] = {"score": float("nan")}self.write_scan()- with self.assertRaisesRegex(FINALIZER.ContractError, "invalid JSON.*NaN"):+ with self.assertRaisesRegex(+ FINALIZER.ContractError, "invalid JSON.*non-finite JSON number.*NaN"+ ):FINALIZER.finalize_scan(self.scan_dir)with self.assertRaisesRegex(FINALIZER.ContractError, "cannot encode canonical JSON"):FINALIZER._json_bytes({"score": float("nan")})def test_sealed_rerun_regenerates_reports_without_mutating_canonical_artifacts(self) -> None:self.write_sealed_scan()- canonical_before = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json")- }+ canonical_before = self.scan_file_bytes(*CANONICAL_FILES)(self.scan_dir / "report.md").write_text("# stale report\n", encoding="utf-8")FINALIZER.finalize_scan(self.scan_dir)- canonical_after = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json")- }+ canonical_after = self.scan_file_bytes(*CANONICAL_FILES)self.assertEqual(canonical_before, canonical_after)self.assertNotIn("stale report", (self.scan_dir / "report.md").read_text(encoding="utf-8"))self.assertFalse((self.scan_dir / "report.html").exists())@@ -1945,19 +1915,13 @@ The extraction root is not enforced.self.findings["findings"][0]["findingId"] = "csf_wrong"self.coverage["openQuestions"] = [" Which path is reachable? "]self.write_scan()- before = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json", "report.md")- }+ before = self.scan_file_bytes(*CANONICAL_FILES, "report.md")prepared = FINALIZER._prepare_scan_finalization(self.scan_dir)self.assertEqual(before,- {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json", "report.md")- },+ self.scan_file_bytes(*CANONICAL_FILES, "report.md"),)FINALIZER._write_prepared_scan_finalization(prepared)manifest = self.read_json("scan-manifest.json")@@ -1992,18 +1956,6 @@ The extraction root is not enforced.self.assertNotIn("sealedAt", manifest["scan"])self.assertNotIn("artifacts", manifest["scan"])- def test_rejects_non_finite_json_numbers(self) -> None:- self.write_scan()- findings_path = self.scan_dir / "findings.json"- raw = findings_path.read_text(encoding="utf-8").replace(- '"attackPath": null',- '"attackPath": {"likelihood": NaN}',- )- findings_path.write_text(raw, encoding="utf-8")-- with self.assertRaisesRegex(FINALIZER.ContractError, "non-finite JSON number"):- FINALIZER.finalize_scan(self.scan_dir)-def test_rerun_preserves_additional_sealed_artifact_records(self) -> None:self.write_sealed_scan()extra_path = self.scan_dir / "exports" / "extra.json"@@ -2023,13 +1975,7 @@ The extraction root is not enforced.def test_seals_coverage_receipt_refs(self) -> None:receipt_ref = "artifacts/02_discovery/./work_ledger.jsonl"normalized_ref = "artifacts/02_discovery/work_ledger.jsonl"- self.coverage["surfaces"][0]["receiptRefs"] = [receipt_ref]- self.write_scan()- receipt_path = self.scan_dir / receipt_ref- receipt_path.parent.mkdir(parents=True)- receipt_path.write_text('{"status":"reviewed"}\n', encoding="utf-8")-- FINALIZER.finalize_scan(self.scan_dir)+ receipt_path = self.write_sealed_receipt_scan(receipt_ref)manifest = self.read_json("scan-manifest.json")coverage = self.read_json("coverage.json")@@ -2044,12 +1990,7 @@ The extraction root is not enforced.def test_verifies_legacy_aliased_receipt_ref(self) -> None:receipt_ref = "artifacts/02_discovery/work_ledger.jsonl"legacy_ref = "artifacts/02_discovery/./work_ledger.jsonl"- self.coverage["surfaces"][0]["receiptRefs"] = [receipt_ref]- self.write_scan()- receipt_path = self.scan_dir / receipt_ref- receipt_path.parent.mkdir(parents=True)- receipt_path.write_text('{"status":"reviewed"}\n', encoding="utf-8")- FINALIZER.finalize_scan(self.scan_dir)+ self.write_sealed_receipt_scan(receipt_ref)coverage = self.read_json("coverage.json")coverage["surfaces"][0]["receiptRefs"] = [legacy_ref]@@ -2069,12 +2010,7 @@ The extraction root is not enforced.def test_rejects_unsealed_coverage_receipt_ref_in_sealed_bundle(self) -> None:receipt_ref = "artifacts/02_discovery/work_ledger.jsonl"- self.coverage["surfaces"][0]["receiptRefs"] = [receipt_ref]- self.write_scan()- receipt_path = self.scan_dir / receipt_ref- receipt_path.parent.mkdir(parents=True)- receipt_path.write_text('{"status":"reviewed"}\n', encoding="utf-8")- FINALIZER.finalize_scan(self.scan_dir)+ self.write_sealed_receipt_scan(receipt_ref)manifest = self.read_json("scan-manifest.json")manifest["scan"]["artifacts"] = [artifact@@ -2143,10 +2079,7 @@ The extraction root is not enforced.self.assertEqual(second["properties"]["security-severity"], "9.4")def test_sarif_adds_only_candidate_id_to_deep_result_presentation(self) -> None:- finding = copy.deepcopy(self.finding)- finding["findingId"] = "csf_example"- finding["occurrenceId"] = "occ_example"- finding["fingerprints"] = {"primary": "fingerprint"}+ finding = self.sarif_finding("fingerprint")finding["extensions"] = {"candidateId": "DSS-145","reportId": "DSS-145-rogue-fw",@@ -2552,10 +2485,7 @@ The extraction root is not enforced.binding["startedAt"] = manifest["scan"]["startedAt"]binding["completedAt"] = manifest["scan"]["completedAt"]binding["producer"] = {"name": "wrong-producer", "version": "0.1.0"}- canonical = {- name: (self.scan_dir / name).read_bytes()- for name in ("scan-manifest.json", "findings.json", "coverage.json", "report.md")- }+ canonical = self.scan_file_bytes(*CANONICAL_FILES, "report.md")with self.assertRaisesRegex(FINALIZER.ContractError,@@ -2569,7 +2499,7 @@ The extraction root is not enforced.self.assertEqual(canonical,- {name: (self.scan_dir / name).read_bytes() for name in canonical},+ self.scan_file_bytes(*canonical),)def test_completion_binding_preserves_required_unbound_diff_snapshot_digest(self) -> None:@@ -2688,10 +2618,7 @@ The extraction root is not enforced.def test_sarif_encodes_location_as_relative_uri(self) -> None:self.finding["locations"][0]["path"] = "src/archive handlers/extract.py"- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "fingerprint"}+ sarif_finding = self.sarif_finding("fingerprint")result = FINALIZER._sarif_result(sarif_finding, 0)location = result["locations"][0]["physicalLocation"]["artifactLocation"]uri = location["uri"]@@ -2704,10 +2631,7 @@ The extraction root is not enforced.self.assertNotIn("originalUriBaseIds", sarif["runs"][0])def test_sarif_keeps_root_first_and_preserves_sink_and_evidence_locations(self) -> None:- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "fingerprint"}+ sarif_finding = self.sarif_finding("fingerprint")sarif_finding["locations"] = [{"path": "src/route.py", "startLine": 10, "role": "entrypoint/wrapper"},{"path": "src/control.py", "startLine": 20, "role": "root_control"},@@ -2772,10 +2696,7 @@ The extraction root is not enforced.@pytest.mark.cross_platformdef test_sarif_includes_legacy_code_evidence_locations(self) -> None:- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "fingerprint"}+ sarif_finding = self.sarif_finding("fingerprint")sarif_finding["codeEvidence"] = [{"id": "canonical-source",@@ -2802,6 +2723,10 @@ The extraction root is not enforced.location["physicalLocation"]["artifactLocation"]["uri"]: locationfor location in result["locations"]}+ self.assertEqual(+ locations["src/canonical.py"]["physicalLocation"]["region"],+ {"startLine": 12, "endLine": 12},+ )self.assertEqual(locations["src/legacy.py"],{@@ -2815,10 +2740,7 @@ The extraction root is not enforced.@pytest.mark.cross_platformdef test_sarif_normalizes_invalid_legacy_code_evidence_bounds(self) -> None:- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "fingerprint"}+ sarif_finding = self.sarif_finding("fingerprint")sarif_finding["code_evidence"] = [{"id": "legacy-null-end",@@ -2857,10 +2779,7 @@ The extraction root is not enforced.@pytest.mark.cross_platformdef test_sarif_omits_invalid_legacy_code_evidence_locations(self) -> None:- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "fingerprint"}+ sarif_finding = self.sarif_finding("fingerprint")sarif_finding["code_evidence"] = [{"id": "legacy-zero-start",@@ -2904,32 +2823,16 @@ The extraction root is not enforced.)def test_sarif_emits_github_line_hash_when_source_is_available(self) -> None:- source_root = self.scan_dir / "source"- source_path = source_root / "src" / "extract.py"- source_path.parent.mkdir(parents=True)- source_path.write_text(- "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"- )- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ source_root = self.write_line_hash_source()+ sarif_finding = self.sarif_finding("semantic-fingerprint")result = FINALIZER._sarif_result(sarif_finding, 0, source_root)fingerprints = result["partialFingerprints"]self.assertEqual(fingerprints["codexSecurity/v1"], "semantic-fingerprint")self.assertEqual(fingerprints["primaryLocationLineHash"], "614150a715d5311d:1")def test_sarif_emits_github_line_hash_through_windows_backend(self) -> None:- source_root = self.scan_dir / "source"- source_path = source_root / "src" / "extract.py"- source_path.parent.mkdir(parents=True)- source_path.write_text(- "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"- )- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ source_root = self.write_line_hash_source()+ sarif_finding = self.sarif_finding("semantic-fingerprint")backend = mock.Mock()backend.open_read_fd.side_effect = lambda root, relative_path, _context: os.open(root / relative_path, os.O_RDONLY@@ -2957,10 +2860,7 @@ The extraction root is not enforced.entrypoint_path.parent.mkdir(parents=True)entrypoint_path.write_text("entrypoint\n", encoding="utf-8")control_path.write_text("root control\n", encoding="utf-8")- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ sarif_finding = self.sarif_finding("semantic-fingerprint")sarif_finding["locations"] = [{"path": "src/route.py", "startLine": 1, "role": "entrypoint/wrapper"},{"path": "src/control.py", "startLine": 1, "role": "root_control"},@@ -2981,10 +2881,7 @@ The extraction root is not enforced.source_path = source_root / "src" / "extract.py"source_path.parent.mkdir(parents=True)source_path.write_bytes(b"\n" * 40 + b"invalid: \xff\n")- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ sarif_finding = self.sarif_finding("semantic-fingerprint")result = FINALIZER._sarif_result(sarif_finding, 0, source_root)self.assertIn("primaryLocationLineHash", result["partialFingerprints"])@@ -2998,10 +2895,7 @@ The extraction root is not enforced."\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8")source_path.symlink_to(external_path)- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ sarif_finding = self.sarif_finding("semantic-fingerprint")result = FINALIZER._sarif_result(sarif_finding, 0, source_root)self.assertNotIn("primaryLocationLineHash", result["partialFingerprints"])@@ -3060,16 +2954,8 @@ The extraction root is not enforced.self.assertNotEqual(line_hashes[41], external_hashes[41])def test_sarif_line_hash_skips_source_read_error(self) -> None:- source_root = self.scan_dir / "source"- source_path = source_root / "src" / "extract.py"- source_path.parent.mkdir(parents=True)- source_path.write_text(- "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"- )- sarif_finding = copy.deepcopy(self.finding)- sarif_finding["findingId"] = "csf_example"- sarif_finding["occurrenceId"] = "occ_example"- sarif_finding["fingerprints"] = {"primary": "semantic-fingerprint"}+ source_root = self.write_line_hash_source()+ sarif_finding = self.sarif_finding("semantic-fingerprint")with mock.patch.object(FINALIZER, "_github_line_hashes", side_effect=PermissionError):result = FINALIZER._sarif_result(sarif_finding, 0, source_root)self.assertNotIn("primaryLocationLineHash", result["partialFingerprints"])@@ -3095,10 +2981,7 @@ The extraction root is not enforced.for index in range(2):relative_path = f"src/extract-{index}.py"(source_root / relative_path).write_text(" " * (6 * 1024 * 1024) + "x")- finding = copy.deepcopy(self.finding)- finding["findingId"] = f"csf_{index}"- finding["occurrenceId"] = f"occ_{index}"- finding["fingerprints"] = {"primary": f"fingerprint-{index}"}+ finding = self.sarif_finding(f"fingerprint-{index}", str(index))finding["locations"][0] = {"path": relative_path, "startLine": 1}findings.append(finding)@@ -3109,18 +2992,10 @@ The extraction root is not enforced.self.assertIn("primaryLocationLineHash", result["partialFingerprints"])def test_sarif_caches_line_hashes_per_source_file(self) -> None:- source_root = self.scan_dir / "source"- source_path = source_root / "src" / "extract.py"- source_path.parent.mkdir(parents=True)- source_path.write_text(- "\n".join(f"line {index}" for index in range(1, 60)), encoding="utf-8"- )+ source_root = self.write_line_hash_source()findings = []for index in range(2):- finding = copy.deepcopy(self.finding)- finding["findingId"] = f"csf_{index}"- finding["occurrenceId"] = f"occ_{index}"- finding["fingerprints"] = {"primary": f"fingerprint-{index}"}+ finding = self.sarif_finding(f"fingerprint-{index}", str(index))finding["locations"][0]["startLine"] += indexfinding["locations"][0]["endLine"] += indexfindings.append(finding)