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.

3.4 KB
Raw Blame
"""Keep reviewed package license exceptions bounded to their intended use."""

from pathlib import Path

import yaml


ROOT = Path(__file__).resolve().parents[2]
WORKFLOW = ROOT / ".github/workflows/dependency-review.yml"


def _workflow() -> dict:
    return yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))


def test_dependency_review_covers_all_manifest_and_include_changes() -> None:
    # Includes can use arbitrary filenames: every PR must run the guard.
    assert _workflow()[True]["pull_request"] == {
        "branches": ["main", "develop"]
    }


def test_license_scope_guard_is_mandatory_before_dependency_review() -> None:
    job = _workflow()["jobs"]["dependency-review"]
    assert not {"if", "continue-on-error", "defaults"} & job.keys()
    steps = job["steps"]
    commands = [
        "python -m pip install --require-hashes --only-binary=:all: -r requirements/dependency-review.txt",
        "python -m unittest discover -s tests/ci/standalone -p 'test_dependency_licenses.py' -v",
        "python .github/scripts/check_dependency_licenses.py",
    ]
    indexes = []
    for command in commands:
        step = next(step for step in steps if step.get("run") == command)
        assert set(step) == {"name", "run"}
        indexes.append(steps.index(step))
    review = next(
        step
        for step in steps
        if step.get("uses", "").startswith("actions/dependency-review-action@")
    )
    assert indexes[0] < indexes[1] < indexes[2] < steps.index(review)
    assert "if" not in review
    assert "continue-on-error" not in review


def test_package_exceptions_preserve_general_license_and_vulnerability_policy() -> (
    None
):
    steps = _workflow()["jobs"]["dependency-review"]["steps"]
    review = next(
        step
        for step in steps
        if step.get("uses", "").startswith("actions/dependency-review-action@")
    )
    policy = review["with"]
    allowed = {item.strip() for item in policy["allow-licenses"].split(",")}
    exceptions = {
        item.strip()
        for item in policy["allow-dependencies-licenses"].split(",")
    }
    assert "MIT-0" in allowed
    assert "MIT-CMU" in allowed
    assert exceptions == {
        "pkg:npm/dompurify",
        "pkg:pypi/aiohappyeyeballs",
        "pkg:pypi/contextlib2",
        "pkg:pypi/docutils",
        "pkg:pypi/regex",
        "pkg:pypi/semgrep",
        "pkg:pypi/protobuf",
        "pkg:pypi/spdx-tools",
        "pkg:pypi/typing-extensions",
        "pkg:pypi/wcwidth",
    }
    assert "LGPL-2.1-or-later" not in allowed
    assert "GPL-1.0-or-later" not in allowed
    assert policy["fail-on-severity"] == "high"
    assert policy.get("license-check", True) in (True, "true")


def test_license_guard_can_reach_pypi() -> None:
    # The guard reads each locked release's license from pypi.org and
    # downloads locked docutils wheels from files.pythonhosted.org, failing
    # closed without them. A block egress policy must allow both.
    steps = _workflow()["jobs"]["dependency-review"]["steps"]
    harden = next(
        step
        for step in steps
        if step.get("uses", "").startswith("step-security/harden-runner@")
    )
    policy = harden.get("with", {})
    if policy.get("egress-policy") == "block":
        allowed = policy.get("allowed-endpoints", "").split()
        assert {"pypi.org:443", "files.pythonhosted.org:443"} <= set(allowed)
    else:
        assert policy.get("egress-policy") == "audit"