feat(contributor-scan): retain first-party JavaScript tests in graphs

This commit is contained in:
Marius Ciepluch
2026-09-13 11:29:48 +02:00
parent d02406e758
commit 51fabef9ea
15 changed files with 1329 additions and 26 deletions
+26
View File
@@ -1103,3 +1103,29 @@ def test_the_interpreter_must_read_the_frontend_parser_too(tmp_path: Path, monke
backend = JoernBackend(runner=runner)
assert backend.build(tmp_path / "repo", language="php") is None
assert "php-parser.php" in backend.last_failure and "mounts the repository but not this install" in backend.last_failure
def test_javascript_partition_uses_declared_frontend_not_legacy_autodetection(tmp_path, monkeypatch):
from openultrasast.cpg.backend import JoernBackend
(tmp_path / "tests").mkdir()
(tmp_path / "tests/probe.js").write_bytes(b"function first_party_test(x) { return x; }")
commands = []
def runner(command, **kwargs):
if _is_overlay(command):
return _overlaid(command, kwargs.get("cwd"))
commands.append(command)
assert Path(command[0]).name == "jssrc2cpg"
Path(command[command.index("-o") + 1]).write_bytes(b"graph")
return subprocess.CompletedProcess(command, 0, "", "")
monkeypatch.setattr("shutil.which", lambda name: f"/opt/joern/{name}")
monkeypatch.setenv("OPENULTRASAST_JOERN_PROBE", "on")
result = JoernBackend(runner=runner).build(tmp_path, language="javascript")
try:
assert result is not None
assert len(commands) == 1
finally:
if result is not None:
result.cleanup()
+2
View File
@@ -168,6 +168,8 @@ def test_explicit_build_budget_is_retained_without_mutating_backend(tmp_path: Pa
calls.append(kwargs["timeout"])
if "--output" in command:
Path(command[command.index("--output") + 1]).write_bytes(b"graph fixture")
elif "-o" in command:
Path(command[command.index("-o") + 1]).write_bytes(b"graph fixture")
return subprocess.CompletedProcess(command, 0, f'{BEGIN}\n{{"r":[]}}\n{END}', "")
monkeypatch.setattr(module.shutil, "which", lambda name: name)
+31
View File
@@ -0,0 +1,31 @@
"""Explicit frontend input policy must survive both subprocess paths."""
from openultrasast.cpg.backend import JoernBackend
def test_first_party_tests_enabled_by_backend(monkeypatch):
monkeypatch.setenv("OUSAST_INCLUDE_TESTS", "0")
assert JoernBackend()._jvm_env()["OUSAST_INCLUDE_TESTS"] == "1"
def test_retention_can_be_disabled_explicitly():
assert JoernBackend(include_tests=False)._jvm_env()["OUSAST_INCLUDE_TESTS"] == "0"
def test_builder_rejects_unrecognized_dependency_before_download(tmp_path):
import importlib.util
from pathlib import Path
import pytest
spec = importlib.util.spec_from_file_location("retention_builder", Path("ops/frontend-retention/install.py"))
assert spec is not None and spec.loader is not None
builder = importlib.util.module_from_spec(spec)
spec.loader.exec_module(builder)
jar = tmp_path / "frontends/jssrc2cpg/lib/io.joern.jssrc2cpg-4.0.625.jar"
jar.parent.mkdir(parents=True)
jar.write_bytes(b"different dependency")
with pytest.raises(ValueError, match="pristine Joern"):
builder.build(tmp_path)
assert jar.read_bytes() == b"different dependency"
assert not (tmp_path / "ousast-frontend-retention-v1").exists()