feat: expand domain schema and seed profiles

This commit is contained in:
Sergey Antropoff
2026-07-13 01:13:26 +03:00
parent 636f42ce9d
commit 67f75e5484
9 changed files with 558 additions and 65 deletions
+17
View File
@@ -33,3 +33,20 @@ def test_repository_migration_defines_required_planes() -> None:
assert f"CREATE TABLE {table}" in migration.sql
assert "CREATE TABLE realms" in migrations[1].sql
assert "CREATE TABLE api_tokens" in migrations[1].sql
domain = migrations[3].sql
for table in (
"clusters",
"virtual_machines",
"containers",
"storages",
"storage_contents",
"snapshots",
"backups",
"pools",
"identity_groups",
"contract_paths",
"observed_contracts",
"scenario_rules",
"fault_injections",
):
assert f"CREATE TABLE {table}" in domain
+40 -29
View File
@@ -1,40 +1,51 @@
"""Deterministic seed profile tests."""
from app.simulation.seed import small_profile, stable_id
import pytest
from app.simulation.seed import build_profile, large_profile, small_profile, stable_id
def test_small_profile_has_stable_logical_state() -> None:
def test_small_profile_matches_required_logical_shape() -> None:
first = small_profile()
second = small_profile()
assert first == second
assert first.logical_state() == {
"profile": "small",
"nodes": [
{"name": "pve1", "status": "online"},
{"name": "pve2", "status": "online"},
],
"resources": [
{
"kind": "qemu",
"external_id": "100",
"node": "pve1",
"state": {"name": "demo", "status": "stopped"},
},
{
"kind": "qemu",
"external_id": "101",
"node": "pve1",
"state": {"name": "worker", "status": "stopped"},
},
{
"kind": "storage",
"external_id": "local",
"node": "pve1",
"state": {"content": ["iso", "backup"]},
},
],
}
state = first.logical_state()
assert state == second.logical_state()
assert state["nodes"] == [{"name": "pve1", "status": "online"}]
resources = state["resources"]
assert isinstance(resources, list)
assert [resource["kind"] for resource in resources].count("qemu") == 2
assert [resource["kind"] for resource in resources].count("lxc") == 1
assert [resource["kind"] for resource in resources].count("storage") == 2
tasks = state["tasks"]
assert isinstance(tasks, list)
assert len(tasks) == 2
def test_medium_and_fault_profiles_are_deterministic() -> None:
medium = build_profile("medium")
assert len(medium.nodes) == 3
assert sum(resource.kind == "qemu" for resource in medium.resources) == 50
assert sum(resource.kind == "lxc" for resource in medium.resources) == 20
assert build_profile("ha-demo") == build_profile("ha-demo")
broken = build_profile("broken-storage")
assert any(resource.state.get("status") == "offline" for resource in broken.resources)
def test_large_profile_is_configurable_and_stable() -> None:
first = large_profile(node_count=4, resource_count=1_000)
second = large_profile(node_count=4, resource_count=1_000)
assert first == second
assert len(first.nodes) == 4
assert len(first.resources) == 1_000
def test_profile_validation() -> None:
with pytest.raises(ValueError, match="unknown seed profile"):
build_profile("missing")
with pytest.raises(ValueError, match="positive"):
large_profile(node_count=0, resource_count=1)
def test_stable_ids_are_namespaced_and_repeatable() -> None: