feat(cloud): enforce host governance budgets
Tests / Test passed: 662

This commit is contained in:
2026-07-13 22:56:31 +08:00
parent 2cd314b183
commit b4803f90e6
28 changed files with 1311 additions and 14 deletions
+29
View File
@@ -264,3 +264,32 @@ def test_unavailable_explicit_target_is_never_rerouted(tmp_path) -> None:
task = pool.store.get_task(task_id)
assert task is not None
assert task.status == "queued"
def test_host_active_task_policy_keeps_excess_tasks_queued(tmp_path) -> None:
from datetime import UTC, datetime
pool = _pool_with_devices(
tmp_path,
_device("device-a"),
_device("device-b"),
host_id="host-a",
)
pool.store.upsert_host_governance_policy(
host_id="host-a",
self_submission_enabled=True,
max_active_tasks=1,
daily_token_budget=None,
updated_at=datetime.now(UTC),
)
scheduler = TaskScheduler(pool, pool.store, _config())
first_id = scheduler.submit(goal="first")
second_id = scheduler.submit(goal="second")
assignments = scheduler.assign()
assert [assignment.task_id for assignment in assignments] == [first_id]
assert pool.store.count_active_tasks_for_host("host-a") == 1
second = pool.store.get_task(second_id)
assert second is not None
assert second.status == "queued"