~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
"""Keep clean Bearer uploads valid without hiding failed scans or findings."""
import copy
import importlib.util
import json
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
SPEC = importlib.util.spec_from_file_location(
"prepare_bearer", ROOT / ".github/scripts/prepare_bearer_sarif.py"
)
PREPARE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(PREPARE)
class BearerSarifTests(unittest.TestCase):
def setUp(self):
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
self.source = Path(directory.name) / "raw.sarif"
self.destination = Path(directory.name) / "upload.sarif"
self.report = {
"version": "2.1.0",
"runs": [{"tool": {"driver": {"name": "Bearer"}}, "results": None}],
}
def prepare(self):
raw = json.dumps(self.report)
self.source.write_text(raw)
PREPARE.prepare(self.source, self.destination)
self.assertEqual(self.source.read_text(), raw)
return json.loads(self.destination.read_text())
def test_native_null_becomes_empty_array_only(self):
expected = copy.deepcopy(self.report)
expected["runs"][0]["results"] = []
self.assertEqual(self.prepare(), expected)
def test_existing_findings_and_metadata_are_preserved(self):
run = self.report["runs"][0]
run["results"] = [
{"ruleId": "python_lang_code_injection", "level": "error"}
]
run["tool"]["driver"]["rules"] = [{"id": "python_lang_code_injection"}]
run["properties"] = {"scan": "canary"}
run["invocations"] = [{"executionSuccessful": True}]
self.assertEqual(self.prepare(), self.report)
def test_valid_empty_scan_is_preserved(self):
self.report["runs"][0]["results"] = []
self.assertEqual(self.prepare(), self.report)
def test_incomplete_wrong_tool_and_failed_scans_do_not_create_upload(self):
mutations = (
lambda r: r.update(version="1.0.0"),
lambda r: r.update(runs=[]),
lambda r: r["runs"].append(copy.deepcopy(r["runs"][0])),
lambda r: r["runs"][0].pop("results"),
lambda r: r["runs"][0].update(results={}),
lambda r: r["runs"][0].update(results=[None]),
lambda r: r["runs"][0].update(tool=None),
lambda r: r["runs"][0]["tool"]["driver"].update(name="other"),
lambda r: r["runs"][0].update(
invocations=[{"executionSuccessful": False}]
),
lambda r: r["runs"][0].update(invocations=[{}]),
lambda r: r["runs"][0].update(
invocations=[{"executionSuccessful": 1}]
),
)
original = copy.deepcopy(self.report)
for mutate in mutations:
with self.subTest(mutation=mutate):
self.report = copy.deepcopy(original)
mutate(self.report)
with self.assertRaises(ValueError):
self.prepare()
self.assertFalse(self.destination.exists())
def test_missing_or_invalid_input_does_not_create_upload(self):
with self.assertRaises(FileNotFoundError):
PREPARE.prepare(self.source, self.destination)
self.source.write_text("{truncated")
with self.assertRaises(ValueError):
PREPARE.prepare(self.source, self.destination)
self.assertFalse(self.destination.exists())
def test_non_standard_json_constants_do_not_create_upload(self):
for constant in ("NaN", "Infinity", "-Infinity"):
with self.subTest(constant=constant):
self.source.write_text(
json.dumps(self.report).replace(
'"results": null',
'"results": [], "properties": {"score": %s}' % constant,
)
)
with self.assertRaises(ValueError):
PREPARE.prepare(self.source, self.destination)
self.assertFalse(self.destination.exists())
def test_level_counts_fall_back_to_rule_default_then_warning(self):
run = self.report["runs"][0]
run["tool"]["driver"]["rules"] = [
{"id": "ruled", "defaultConfiguration": {"level": "error"}},
{"id": "unruled"},
]
run["results"] = [
{"ruleId": "ruled"},
{"ruleId": "ruled", "level": "note"},
{"ruleId": "unruled"},
{"ruleId": "unknown", "level": "warning"},
]
self.prepare()
self.assertEqual(PREPARE.level_counts(self.destination), (1, 2, 1, 4))
def test_level_counts_of_a_clean_scan(self):
self.prepare()
self.assertEqual(PREPARE.level_counts(self.destination), (0, 0, 0, 0))
def test_cannot_overwrite_raw_report(self):
self.source.write_text(json.dumps(self.report))
with self.assertRaises(ValueError):
PREPARE.prepare(self.source, self.source)
self.assertEqual(json.loads(self.source.read_text()), self.report)
if __name__ == "__main__":
unittest.main()