53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from scripts.plan_laptop_fleet import build_plan, load_manifest, render_markdown, validate_manifest
|
|
|
|
|
|
def test_laptop_fleet_planner_script_exists() -> None:
|
|
assert Path("scripts/plan_laptop_fleet.py").exists()
|
|
|
|
|
|
def test_laptop_fleet_manifest_template_exists() -> None:
|
|
assert Path("docs/laptop-fleet-manifest.example.yaml").exists()
|
|
|
|
|
|
def test_build_plan_selects_two_lowest_idle_watt_laptops_as_anchors() -> None:
|
|
data = load_manifest("docs/laptop-fleet-manifest.example.yaml")
|
|
plan = build_plan(data)
|
|
assert plan["anchor_agents"] == ["timmy-anchor-a", "timmy-anchor-b"]
|
|
assert plan["desktop_nas"] == "timmy-desktop-nas"
|
|
assert plan["role_mapping"]["timmy-daylight-a"]["schedule"] == "10:00-16:00"
|
|
|
|
|
|
def test_validate_manifest_requires_unique_hostnames() -> None:
|
|
data = {
|
|
"machines": [
|
|
{"hostname": "dup", "machine_type": "laptop", "ram_gb": 8, "cpu_cores": 4, "os": "Linux", "adapter_condition": "good"},
|
|
{"hostname": "dup", "machine_type": "laptop", "ram_gb": 16, "cpu_cores": 8, "os": "Linux", "adapter_condition": "good"},
|
|
]
|
|
}
|
|
try:
|
|
validate_manifest(data)
|
|
except ValueError as exc:
|
|
assert "duplicate hostname" in str(exc)
|
|
assert "unique hostnames" in str(exc)
|
|
else:
|
|
raise AssertionError("validate_manifest should reject duplicate hostname")
|
|
|
|
|
|
def test_markdown_contains_anchor_agents_and_daylight_schedule() -> None:
|
|
data = load_manifest("docs/laptop-fleet-manifest.example.yaml")
|
|
plan = build_plan(data)
|
|
content = render_markdown(plan, data)
|
|
assert "24/7 anchor agents: timmy-anchor-a, timmy-anchor-b" in content
|
|
assert "Daylight schedule: 10:00-16:00" in content
|
|
assert "desktop_nas" in content
|
|
|
|
|
|
def test_manifest_template_is_valid_yaml() -> None:
|
|
data = yaml.safe_load(Path("docs/laptop-fleet-manifest.example.yaml").read_text())
|
|
assert data["fleet_name"] == "timmy-laptop-fleet"
|
|
assert len(data["machines"]) == 6
|