claire/tests/test_scheduler.py
autocommit 6d212b7dbe refactor(testing-test): ♻️ Update test imports to use claire instead of clare in package references
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-20 19:54:05 -07:00

67 lines
1.9 KiB
Python

from __future__ import annotations
import uuid as _uuid
from claire.domain import Session, Task, TaskStatus
from claire.scheduler import next_task_for_session, rank_open_tasks, session_attention_score
def _task(prio: int, status: TaskStatus = TaskStatus.TODO, hlc: str = "0") -> Task:
return Task(
id=_uuid.uuid4(),
project_id=_uuid.uuid4(),
title="t",
status=status,
priority=prio,
created_hlc=hlc,
updated_hlc=hlc,
)
def test_rank_open_tasks_drops_done() -> None:
tasks = [
_task(0, TaskStatus.DONE),
_task(2),
_task(1),
]
ranked = rank_open_tasks(tasks)
assert [t.priority for t in ranked] == [1, 2]
def test_rank_open_tasks_orders_by_priority_then_created() -> None:
t_a = _task(1, hlc="00000000001")
t_b = _task(1, hlc="00000000002")
t_c = _task(0, hlc="00000000003")
ranked = rank_open_tasks([t_a, t_b, t_c])
assert ranked == [t_c, t_a, t_b]
def test_next_task_for_session_returns_top_owned() -> None:
sid = _uuid.uuid4()
other_sid = _uuid.uuid4()
t1 = _task(2)
t2 = _task(0)
t3 = _task(1)
active = {t1.id: sid, t2.id: other_sid, t3.id: sid}
nxt = next_task_for_session([t1, t2, t3], active, sid)
assert nxt == t3 # priority 1 (owned by sid) beats priority 2
def test_next_task_for_session_none_when_no_assignments() -> None:
sid = _uuid.uuid4()
nxt = next_task_for_session([_task(0)], {}, sid)
assert nxt is None
def test_session_attention_score_inverts_priority() -> None:
def make_session(prio: int | None) -> Session:
return Session(
uuid=_uuid.uuid4(),
host="local",
last_triage_priority=prio,
updated_hlc="0",
)
assert session_attention_score(make_session(0)) == 4
assert session_attention_score(make_session(4)) == 0
assert session_attention_score(make_session(None)) == 0