feat: add deterministic small cluster seed

This commit is contained in:
Sergey Antropoff
2026-07-12 23:56:06 +03:00
parent 882ae97fcf
commit 7a668127a3
7 changed files with 179 additions and 1 deletions
+21
View File
@@ -7,6 +7,7 @@ import asyncpg # type: ignore[import-untyped]
import pytest
from app.db.migrations import migrate
from app.simulation.seed import apply_seed, small_profile
pytestmark = [
pytest.mark.integration,
@@ -34,3 +35,23 @@ async def test_migration_is_repeatable_and_constraints_hold() -> None:
)
finally:
await connection.close()
async def test_small_seed_is_idempotent() -> None:
connection = await asyncpg.connect(os.environ["TEST_DATABASE_URL"])
try:
await migrate(connection)
await apply_seed(connection, small_profile())
await apply_seed(connection, small_profile())
assert (
await connection.fetchval("SELECT count(*) FROM nodes WHERE name IN ('pve1', 'pve2')")
== 2
)
assert (
await connection.fetchval(
"SELECT count(*) FROM resources WHERE external_id IN ('100', 'local')"
)
== 2
)
finally:
await connection.close()
+36
View File
@@ -0,0 +1,36 @@
"""Deterministic seed profile tests."""
from app.simulation.seed import small_profile, stable_id
def test_small_profile_has_stable_logical_state() -> 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": "storage",
"external_id": "local",
"node": "pve1",
"state": {"content": ["iso", "backup"]},
},
],
}
def test_stable_ids_are_namespaced_and_repeatable() -> None:
assert stable_id("qemu:100") == stable_id("qemu:100")
assert stable_id("qemu:100") != stable_id("qemu:101")