generated from coulomb/repo-seed
Implement SAND-WP-0006: SaaS payments, routing, and ext.saas-stub
Add credits store, metering on create/destroy, extension routing resolver, metered SaaS stub extension, burst/saas profiles, credits CLI, docs, and tests.
This commit is contained in:
59
tests/test_routing.py
Normal file
59
tests/test_routing.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Extension routing tests."""
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from sandboxer.extensions.registry import load_extension
|
||||
from sandboxer.models import Profile, RouteSpec, RouteStrategy
|
||||
from sandboxer.routing.resolver import resolve_extension
|
||||
|
||||
|
||||
def _burst_profile() -> Profile:
|
||||
return Profile.model_validate(
|
||||
{
|
||||
"id": "profile.burst-sandbox",
|
||||
"version": "1.0.0",
|
||||
"extension": "ext.compose-ssh",
|
||||
"route": {
|
||||
"strategy": "prefer-self-hosted",
|
||||
"extensions": ["ext.compose-ssh", "ext.saas-stub"],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_explicit_uses_profile_extension() -> None:
|
||||
profile = Profile.model_validate(
|
||||
{
|
||||
"id": "profile.compose-e2e",
|
||||
"version": "1.0.0",
|
||||
"extension": "ext.compose-ssh",
|
||||
}
|
||||
)
|
||||
ext = resolve_extension(profile, {}, host_override="coulombcore")
|
||||
assert ext.id == "ext.compose-ssh"
|
||||
|
||||
|
||||
def test_prefer_self_hosted_when_host_set(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("SANDBOXER_HOST", "coulombcore")
|
||||
ext = resolve_extension(_burst_profile(), {"repo": "/tmp/x"}, host_override=None)
|
||||
assert ext.id == "ext.compose-ssh"
|
||||
|
||||
|
||||
def test_prefer_self_hosted_falls_back_to_saas(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.delenv("SANDBOXER_HOST", raising=False)
|
||||
monkeypatch.setenv("SANDBOXER_FORCE_SAAS", "1")
|
||||
ext = resolve_extension(_burst_profile(), {}, host_override=None)
|
||||
assert ext.id == "ext.saas-stub"
|
||||
assert ext.capabilities.pricing_model == "metered"
|
||||
|
||||
|
||||
def test_lowest_cost_picks_metered_when_forced(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
profile = _burst_profile()
|
||||
profile.route = RouteSpec(
|
||||
strategy=RouteStrategy.LOWEST_COST,
|
||||
extensions=["ext.compose-ssh", "ext.saas-stub"],
|
||||
)
|
||||
monkeypatch.setenv("SANDBOXER_FORCE_SAAS", "1")
|
||||
ext = resolve_extension(profile, {}, host_override=None)
|
||||
assert load_extension(ext.id).capabilities.pricing_model == "metered"
|
||||
Reference in New Issue
Block a user