Skip to content

~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.

2.5 KB
Raw Blame
"""Contracts for when the Bearer workflow may upload to code scanning."""

# allow: no-sut-import — this test parses .github/workflows/bearer.yml
# directly; the "system under test" is CI configuration, not application
# code, so there is nothing under local_deep_research to import.

from pathlib import Path

import yaml


REPO_ROOT = Path(__file__).resolve().parents[2]
WORKFLOW = REPO_ROOT / ".github" / "workflows" / "bearer.yml"


def _steps() -> list[dict]:
    workflow = yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))
    return workflow["jobs"]["bearer-scan"]["steps"]


def _step(prefix: str) -> dict:
    return next(
        step
        for step in _steps()
        if str(step.get("uses", "")).startswith(prefix)
    )


def test_code_scanning_upload_needs_a_successful_scan():
    """A failed Bearer run can leave a partial SARIF behind.

    Uploading it under the same category would mark the missing findings as
    fixed, so the upload must run only after every earlier step succeeded
    and must read the prepared report, never the raw scanner output.
    """
    upload = _step("github/codeql-action/upload-sarif@")
    condition = upload["if"]
    assert condition.startswith("success() && ")
    assert "always()" not in condition
    assert "steps.check-sarif.outputs.exists == 'true'" in condition
    assert upload["with"]["sarif_file"] == "bearer-results.github.sarif"
    assert upload["with"]["category"] == "bearer-security"
    assert "continue-on-error" not in upload


def test_report_is_prepared_before_upload_and_scan_failures_are_not_masked():
    steps = _steps()
    names = [step.get("name", "") for step in steps]
    prepare = names.index("Prepare successful Bearer SARIF for GitHub")
    upload = next(
        index
        for index, step in enumerate(steps)
        if str(step.get("uses", "")).startswith(
            "github/codeql-action/upload-sarif@"
        )
    )
    assert prepare < upload
    assert "if" not in steps[prepare], "prepare must not run after a failure"
    assert (
        "prepare_bearer_sarif.py bearer-results.sarif" in steps[prepare]["run"]
    )
    scanner = _step("bearer/bearer-action@")
    assert "continue-on-error" not in scanner
    assert "if" not in scanner


def test_fork_pull_requests_scan_without_uploading():
    condition = _step("github/codeql-action/upload-sarif@")["if"]
    assert (
        "github.event_name != 'pull_request' || "
        "github.event.pull_request.head.repo.full_name == github.repository"
    ) in condition