Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

4.2 KB
Raw Blame
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.

"""ARROW_WOA_REF must stay a commit SHA: the fork's batch files build a wheel we sign and publish."""

from __future__ import annotations

import re
from pathlib import Path

import pytest
import yaml


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

COMMIT_SHA = re.compile(r"^[0-9a-f]{40}$")


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


def _steps(workflow, job):
    return workflow["jobs"][job]["steps"]


def _dispatch_inputs(workflow):
    # YAML 1.1 reads a bare `on` as boolean true.
    triggers = workflow["on"] if "on" in workflow else workflow[True]
    return triggers["workflow_dispatch"]["inputs"]


def test_arm64_overlay_is_pinned_to_a_commit():
    ref = _workflow()["env"]["ARROW_WOA_REF"]
    assert COMMIT_SHA.match(str(ref)), (
        f"ARROW_WOA_REF is {ref!r}. A branch or tag on {_workflow()['env']['ARROW_WOA_REPO']} "
        "is mutable, and its batch files are executed to build a wheel we sign and publish."
    )


def test_overlay_checkout_uses_that_pin():
    checkouts = [
        step
        for step in _steps(_workflow(), "build-pyarrow")
        if str(step.get("uses", "")).startswith("actions/checkout")
    ]
    overlay = [
        step
        for step in checkouts
        if step.get("with", {}).get("repository") == "${{ env.ARROW_WOA_REPO }}"
    ]
    assert len(overlay) == 1, f"expected one overlay checkout, got {len(overlay)}"
    assert (
        overlay[0]["with"]["ref"] == "${{ env.ARROW_WOA_REF }}"
    ), "the overlay checkout must take the pinned ref, not a literal branch"


def test_the_run_re_checks_the_pin_before_copying_the_batch_files():
    steps = _steps(_workflow(), "build-pyarrow")
    names = [step.get("name") for step in steps]
    assert "Confirm the overlay is the pinned commit" in names, names
    guard = names.index("Confirm the overlay is the pinned commit")
    overlay = names.index("Overlay the ARM64 build support onto the release tag")
    assert guard < overlay, "the pin has to be confirmed before the fork's files are copied"
    body = steps[guard]["run"]
    assert "rev-parse HEAD" in body
    assert "[0-9a-f]{40}" in body


def test_upstream_sources_are_tags_not_branches():
    inputs = _dispatch_inputs(_workflow())
    assert inputs["arrow_tag"]["default"].startswith("apache-arrow-")
    assert re.match(r"^v\d+\.\d+\.\d+$", inputs["sqlite_vec_tag"]["default"])


def test_publishing_is_off_by_default():
    publish = _dispatch_inputs(_workflow())["publish"]
    assert publish["type"] == "boolean"
    assert publish["default"] is False


@pytest.mark.parametrize(
    "job,path,tag_input,commit_input,step",
    [
        (
            "build-pyarrow",
            "arrow",
            "arrow_tag",
            "arrow_commit",
            "Confirm the Arrow tag is the pinned commit",
        ),
        (
            "build-sqlite-vec",
            "sv",
            "sqlite_vec_tag",
            "sqlite_vec_commit",
            "Confirm the sqlite-vec tag is the pinned commit",
        ),
    ],
)
def test_upstream_tags_are_checked_against_a_pinned_commit(
    job, path, tag_input, commit_input, step
):
    # A third-party tag can be moved, and these sources are built into wheels we sign and publish.
    inputs = _dispatch_inputs(_workflow())
    assert COMMIT_SHA.match(str(inputs[commit_input]["default"])), inputs[commit_input]
    steps = _steps(_workflow(), job)
    names = [s.get("name") for s in steps]
    assert step in names, names
    checkout = next(
        i
        for i, s in enumerate(steps)
        if s.get("with", {}).get("path") == path
        and s.get("with", {}).get("ref") == f"${{{{ inputs.{tag_input} }}}}"
    )
    guard = names.index(step)
    assert guard == checkout + 1, "the pin must be confirmed straight after the checkout"
    body = steps[guard]["run"]
    # Through the environment, never interpolated into the script.
    assert steps[guard]["env"]["PINNED_COMMIT"] == f"${{{{ inputs.{commit_input} }}}}"
    assert "${{" not in body
    assert "$env:PINNED_COMMIT" in body and "rev-parse HEAD" in body and "[0-9a-f]{40}" in body