Files
claude-config/bin/do_epic/test_status.py
T
2026-11-19 02:30:29 +01:00

73 lines
3.7 KiB
Python

import os
import pathlib
import tempfile
import unittest
from failure import Failure
from do_epic.test_scheduler import issue, Tmux
from do_epic import parked, status
from do_epic.scheduler import STATE
SINCE = 1_700_000_000
# SINCE as the status prints it.
SINCE_ON = "2023-11-14 22:13 UTC"
EPIC = "epic-ABC-12"
class TheStatusLines(unittest.TestCase):
def setUp(self) -> None:
self.home = pathlib.Path(tempfile.mkdtemp())
self.folder = self.home / STATE / "ABC-12"
def park(self, key: str, on: str) -> None:
parked.park(self.folder, parked.Parked(key, f"/code/api-{key}", "7", "s", on))
os.utime(parked.file_of(self.folder, key), (SINCE, SINCE))
def lines(self, issues: list, *windows: tuple[str, str, bool, str]) -> list[str] | Failure:
return status.lines("ABC-12", self.home, issues, Tmux(*windows))
def test_a_chunk_that_asks_says_where_to_answer_and_one_that_works_runs(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20 ?", False, ""), (EPIC, "ABC-21", False, ""))
self.assertEqual(found, ["ABC-20 asks you: answer its question in the tmux window epic-ABC-12:ABC-20", "ABC-21 runs"])
def test_a_parked_chunk_says_what_it_awaits_and_since_when(self) -> None:
self.park("ABC-20", "an approval")
self.assertEqual(self.lines([issue("ABC-20", "repo:api")], (EPIC, "ABC-20 awaits its checks", False, "")), [f"ABC-20 waits: it is parked: its pull request #7 awaits its checks, since {SINCE_ON}"])
def test_a_parked_chunk_that_awaits_a_slot_gives_no_time_since_its_gate_began(self) -> None:
self.park("ABC-20", "an approval")
self.assertEqual(self.lines([issue("ABC-20", "repo:api")], (EPIC, "ABC-20 awaits a slot", False, "")), ["ABC-20 waits: it is parked: its worker has work again on pull request #7 and awaits a slot"])
def test_a_parked_chunk_without_a_window_says_since_when_and_how_to_start_it_again(self) -> None:
self.park("ABC-20", "an approval")
self.assertEqual(self.lines([issue("ABC-20", "repo:api")]), [f"ABC-20 waits: it is parked: its pull request #7 awaits an approval, since {SINCE_ON}, and its window stopped; run `do-epic ABC-12` to start it again"])
def test_a_stopped_chunk_and_one_not_started_say_so(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20", True, ""))
self.assertEqual(found, ["ABC-20 waits: its window stopped; run `do-epic ABC-12` to start it again", "ABC-21 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room"])
def test_a_human_task_and_a_blocked_issue_say_why_they_wait(self) -> None:
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api", blockers=("ABC-20",)), issue("ABC-22", "do-epic-human")], (EPIC, "ABC-20", False, ""))
self.assertEqual(found, ["ABC-20 runs", "ABC-21 waits: ABC-20 blocks it", "ABC-22 waits: it is a human's task"])
def test_a_parked_chunk_that_cannot_be_read_is_a_failure(self) -> None:
(self.folder / parked.FOLDER).mkdir(parents=True)
(self.folder / parked.FOLDER / "ABC-20.json").write_text("{", encoding="utf-8")
self.assertIsInstance(self.lines([issue("ABC-20", "repo:api")]), Failure)
class TheTimeSinceParking(unittest.TestCase):
def test_is_the_time_of_the_chunks_file_to_the_minute(self) -> None:
folder = pathlib.Path(tempfile.mkdtemp())
chunk = parked.Parked("ABC-20", "/code/api", "7", "s", "an approval")
parked.park(folder, chunk)
os.utime(parked.file_of(folder, "ABC-20"), (SINCE, SINCE))
self.assertEqual(status.since(folder, chunk), f", since {SINCE_ON}")
def test_is_empty_where_the_chunks_file_is_gone(self) -> None:
self.assertEqual(status.since(pathlib.Path(tempfile.mkdtemp()), parked.Parked("ABC-20", "/code/api", "7", "s", "an approval")), "")
if __name__ == "__main__":
unittest.main()