Files
nix-estimator/tests/test_provision.py
T
2026-07-08 17:28:56 +03:00

75 lines
2.5 KiB
Python

"""Tests for the --provision EphemeralBuilder renderer (issue #14).
The CR schema is illustrative; these tests pin the *contract* nix-estimator
emits (keys/values, arch mapping, determinism), not the real operator CRD.
"""
from nix_estimator.provision import arch_for_system, render_ephemeral_builder
def test_arch_mapping():
assert arch_for_system("aarch64-linux") == "arm64"
assert arch_for_system("x86_64-linux") == "amd64"
assert arch_for_system("aarch64-darwin") == "arm64"
assert arch_for_system("x86_64-darwin") == "amd64"
# unknown / missing systems fall back to amd64
assert arch_for_system(None) == "amd64"
assert arch_for_system("riscv64-linux") == "amd64"
def test_render_contains_expected_shape():
yaml = render_ephemeral_builder(
nodes=4, cores=16, system="aarch64-linux", est_makespan_min=12.34
)
assert "apiVersion: builder-arbitrage.oleks.space/v1" in yaml
assert "kind: EphemeralBuilder" in yaml
assert "class: nix-builder" in yaml
assert "replicas: 4" in yaml
assert "cores: 16" in yaml
assert "arch: arm64" in yaml
assert "system: aarch64-linux" in yaml
# makespan is rounded and stored as a calibration annotation
assert "builder-arbitrage.oleks.space/estimated-makespan-min: 12.3" in yaml
assert yaml.endswith("\n")
def test_render_amd64_and_custom_class_and_name():
yaml = render_ephemeral_builder(
nodes=1,
cores=32,
system="x86_64-linux",
builder_class="ci",
name="my-builder",
)
assert "arch: amd64" in yaml
assert "class: ci" in yaml
assert "name: my-builder" in yaml
assert "replicas: 1" in yaml
def test_makespan_omitted_when_none():
yaml = render_ephemeral_builder(nodes=2, cores=8, system="x86_64-linux")
assert "estimated-makespan-min" not in yaml
# a sensible default name is derived from arch + cores
assert "name: nix-estimator-amd64-8c" in yaml
def test_system_omitted_when_none():
yaml = render_ephemeral_builder(nodes=2, cores=8, system=None)
assert "arch: amd64" in yaml
assert "system:" not in yaml
def test_output_is_deterministic():
kwargs = dict(nodes=3, cores=16, system="aarch64-linux", est_makespan_min=5.0)
assert render_ephemeral_builder(**kwargs) == render_ephemeral_builder(**kwargs)
def test_invalid_counts_rejected():
import pytest
with pytest.raises(ValueError):
render_ephemeral_builder(nodes=0, cores=8, system="x86_64-linux")
with pytest.raises(ValueError):
render_ephemeral_builder(nodes=1, cores=0, system="x86_64-linux")