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.

4.9 KB
Raw Blame
"""Keep pending release and release-gate runs from displacing each other."""

import importlib.util
from pathlib import Path
import shlex

import yaml


WORKFLOWS = Path(__file__).resolve().parents[2] / ".github" / "workflows"


def test_release_and_gate_retain_pending_runs_without_deadlocking() -> None:
    release = yaml.safe_load((WORKFLOWS / "release.yml").read_text())
    gate = yaml.safe_load((WORKFLOWS / "release-gate.yml").read_text())

    release_concurrency = release["concurrency"]
    gate_concurrency = gate["concurrency"]
    for concurrency in (release_concurrency, gate_concurrency):
        assert concurrency["cancel-in-progress"] is False
        assert concurrency["queue"] == "max"

    # The called gate cannot acquire the parent's group while the parent waits
    # for it. Keeping the groups distinct avoids a reusable-workflow deadlock.
    assert release_concurrency["group"] != gate_concurrency["group"]
    assert "github.workflow" not in gate_concurrency["group"]


def test_checkov_scans_workflows_with_queue_after_blanking_it() -> None:
    """Keep compatibility preparation before the workflow scan: earlier
    Checkov schemas rejected concurrency.queue and skipped affected files."""
    root = WORKFLOWS.parents[1]
    checkov = yaml.safe_load((WORKFLOWS / "checkov-scan.yml").read_text())
    steps = checkov["jobs"]["checkov"]["steps"]
    commands = [step.get("run", "") for step in steps]
    blank = next(
        i
        for i, run in enumerate(commands)
        if "strip-concurrency-queue.py .github/workflows/*.yml" in run
    )
    scan = next(
        i
        for i, step in enumerate(steps)
        if step.get("name") == "Run Checkov on GitHub Actions workflows"
    )
    invocation = next(
        line.strip()
        for line in commands[scan].replace("\\\n", " ").splitlines()
        if line.lstrip().startswith("checkov ")
    )
    arguments = shlex.split(invocation)
    assert arguments[arguments.index("-d") + 1] == ".github/workflows"
    assert arguments[arguments.index("--framework") + 1] == "github_actions"
    assert blank < scan

    script = root / ".github" / "scripts" / "strip-concurrency-queue.py"
    spec = importlib.util.spec_from_file_location("strip_queue", script)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    adapter_spec = importlib.util.spec_from_file_location(
        "adapter", module.HOOK
    )
    adapter = importlib.util.module_from_spec(adapter_spec)
    adapter_spec.loader.exec_module(adapter)
    for name in ("release.yml", "release-gate.yml"):
        source = (WORKFLOWS / name).read_text()
        stripped = adapter.strip_concurrency_queue(source)
        assert stripped.count("\n") == source.count("\n")
        parsed = yaml.safe_load(stripped)
        assert set(parsed["concurrency"]) == {"group", "cancel-in-progress"}


def test_version_check_skips_superseded_main_pushes() -> None:
    """queue: max keeps every main push waiting; without this skip each stale
    SHA would run the full release gates in its own serial turn."""
    release = yaml.safe_load((WORKFLOWS / "release.yml").read_text())
    steps = release["jobs"]["version-check"]["steps"]
    script = next(s["run"] for s in steps if s.get("id") == "check")
    bypass = script.index("workflow_dispatch")
    superseded = script.index("git/ref/heads/main")
    version = script.index("__version__.py")
    assert bypass < superseded < version
    assert '"$MAIN_SHA" != "$GITHUB_SHA"' in script


def test_main_pushes_trigger_release_only_on_version_change() -> None:
    """Ordinary merges must not each run the full gates while a bumped
    version is unreleased; tags and manual runs stay unfiltered."""
    release = yaml.safe_load((WORKFLOWS / "release.yml").read_text())
    # PyYAML parses the bare `on` key as True.
    push = release[True]["push"]
    assert push["branches"] == ["main"]
    assert push["paths"] == ["src/local_deep_research/__version__.py"]
    assert push["tags"] == ["v*.*.*"]


def test_dry_run_rehearsal_skips_build_and_everything_downstream() -> None:
    release = yaml.safe_load((WORKFLOWS / "release.yml").read_text())
    dry_run = release[True]["workflow_dispatch"]["inputs"]["dry_run"]
    assert dry_run["type"] == "boolean"
    assert dry_run["default"] is False

    jobs = release["jobs"]
    assert "!inputs.dry_run" in jobs["build"]["if"]

    # Every job that builds or publishes must transitively depend on build,
    # so skipping build is enough to keep a rehearsal side-effect free.
    gates = {"version-check"} | {
        name
        for name, job in jobs.items()
        if job.get("needs") == ["version-check"]
    }

    def depends_on_build(name: str) -> bool:
        needs = jobs[name].get("needs", [])
        needs = [needs] if isinstance(needs, str) else needs
        return "build" in needs or any(depends_on_build(n) for n in needs)

    for name in set(jobs) - gates - {"build"}:
        assert depends_on_build(name), name