apexbase 1.31.1

High-performance HTAP embedded database with Rust core
import re
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
WORKFLOW = (ROOT / ".github" / "workflows" / "build_release.yml").read_text(
    encoding="utf-8"
)
PYTEST_CONFIG = (ROOT / "pytest.ini").read_text(encoding="utf-8")


def _job_block(name):
    match = re.search(
        rf"(?ms)^  {re.escape(name)}:\n(?P<body>.*?)(?=^  [a-zA-Z0-9_-]+:\n|\Z)",
        WORKFLOW,
    )
    assert match is not None, f"workflow job {name!r} is missing"
    return match.group("body")


def _job_needs(name):
    block = _job_block(name)
    match = re.search(r"(?m)^    needs: \[(?P<jobs>[^\]]+)\]$", block)
    assert match is not None, f"workflow job {name!r} must use an explicit needs list"
    return {job.strip() for job in match.group("jobs").split(",")}


def test_package_publication_waits_for_all_tests_and_artifacts():
    assert _job_needs("publish-packages") == {
        "resolve-release",
        "test",
        "rust-test",
        "build-wheels-linux",
        "build-wheels",
        "build-sdist",
    }


def test_release_workflow_runs_every_rust_test_even_for_manual_dispatch():
    block = _job_block("rust-test")
    assert "cargo test --no-default-features" in block
    assert "cargo check" not in block


def test_release_workflow_does_not_filter_or_silently_skip_python_tests():
    block = _job_block("test")
    configured_addopts = PYTEST_CONFIG.split("# Markers", 1)[0]
    for selector in ("--ignore", "--deselect"):
        assert selector not in block
        assert selector not in configured_addopts
    assert re.search(r"(?m)^\s+-[km]\s", block) is None
    assert re.search(r"(?m)^\s+-[km]\s", configured_addopts) is None
    for dependency in (
        "duckdb==1.1.3",
        "pylance==0.32.0",
        "sqliteai-vector==1.0.0",
    ):
        assert dependency in block
    assert '"apsw==3.50.1.0"' in block
    assert 'else "apsw==3.53.1.0"' in block
    assert "--junitxml=pytest-results.xml" in block
    assert 'findall(".//skipped")' in block


def test_cargo_and_pypi_publish_from_the_same_job_step():
    block = _job_block("publish-packages")
    publish_step = re.search(
        r"(?ms)^    - name: Publish missing packages together\n"
        r"(?P<body>.*?)(?=^    - name: |\Z)",
        block,
    )

    assert publish_step is not None
    assert "cargo publish --no-default-features" in publish_step.group("body")
    assert "python -m twine upload" in publish_step.group("body")


def test_github_release_requires_the_combined_publication_job():
    assert _job_needs("create-release") == {
        "resolve-release",
        "publish-packages",
        "publish-legacy",
    }
    block = _job_block("create-release")
    assert "needs.resolve-release.outputs.package_kind == 'maturin'" in block
    assert "needs.resolve-release.outputs.package_kind == 'legacy'" in block
    assert "needs.publish-packages.result == 'success'" in block
    assert "needs.publish-legacy.result == 'success'" in block
    assert "needs.publish.result" not in block
    assert "needs.publish-crate.result" not in block


def test_github_release_reads_notes_from_the_release_tag():
    block = _job_block("create-release")

    assert "ref: ${{ needs.resolve-release.outputs.tag_name }}" in block
    assert "github.event.repository.default_branch" not in block


def test_publication_confirms_both_registries():
    block = _job_block("publish-packages")

    assert "Confirm both registries contain the version" in block
    assert "https://crates.io/api/v1/crates/apexbase/${VERSION}" in block
    assert "https://pypi.org/pypi/apexbase/${VERSION}/json" in block