"""The built-in devpi service spec (Phase-0-resolved values)."""

from __future__ import annotations

from mgf.cloud.providers import get_provider

from mgf.cloud_provision import apply, devpi_service_spec
from mgf.cloud_provision.models import Action


def test_devpi_spec_phase0_values() -> None:
    spec = devpi_service_spec()
    assert spec.name == "devpi-prod"
    assert spec.flavor == "a2-ram4-disk50-perf1"
    assert spec.image == "Ubuntu 24.04 LTS Noble Numbat"
    assert spec.network == "ext-net1"
    assert spec.cloud_init is not None
    assert "devpi" in spec.cloud_init.lower()


def test_devpi_spec_key_name_passthrough() -> None:
    assert devpi_service_spec(key_name="woodpecker-key").key_name == "woodpecker-key"


def test_devpi_spec_provisions_against_fake() -> None:
    # End-to-end skeleton check: the built-in spec converges on the fake provider.
    result = apply(devpi_service_spec(key_name="k"), get_provider("fake"))
    assert result.action is Action.CREATE
    assert result.server_id
