import sys
import unittest
from pathlib import Path
HERE = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(HERE))
sys.path.insert(0, str(HERE / "tests"))
import test_cli # noqa: E402
TASKS = """\
# Tasks — demo
## Awaiting your decision
## Pending
- **t-ok** [P1] (1h): Good. Headless.
Done: tests green.
- **t-nodone** [P1] (1h): No done line.
- **t-owner** [P1] (1h): Owner bound.
Done: tests green.
Sessions: owner
- **t-confirm** [P1] (1h): Confirm.
Done: owner confirms it works.
- **t-report** [P1] (1h): Report.
- Done: report to the owner.
- **t-parent** [P1] (5h): Parent.
Done: all slices.
Slices: [[t-parent-1]]
- **t-parent-1** [P1] (1h): Slice.
Done: ok.
Model: sonnet
- **t-doneparent** [P1] (10h): Slices all archived.
Done: all slices.
- Slices: [[t-gone]]
- **t-blk** [P1] (1h) (blocked: [[a-x]]): Blocked.
Done: ok.
"""
class Runner(test_cli.Cli):
tasks_text = TASKS
def col(self, *args):
return [l.split()[0] for l in self.ok("list", *args).splitlines()[:-1]]
def test_runner_filter(self):
self.assertEqual(self.col("--runner"), ["t-ok", "t-parent-1"])
self.assertEqual(self.col("--runner", "--model", "sonnet"), ["t-parent-1"])
def test_add_hint_without_done(self):
code, out, err = self.wf("add", "-p", "2", "-e", "1h", "Plain thing", hints=True)
self.assertEqual((code, err), (0, "hint: no Done line; add one (--done) so runners can pick it\n"))
def test_add_no_hint_with_done_or_awaiting(self):
code, out, err = self.wf("add", "-p", "2", "-e", "1h", "--body", "Body thing", stdin="Done: x\n", hints=True)
self.assertEqual((code, err), (0, ""))
code, out, err = self.wf("add", "-s", "awaiting", "Which one?", hints=True)
self.assertEqual((code, err), (0, ""))
def test_add_done_flag_writes_done_line(self):
code, out, err = self.wf("add", "-p", "2", "-e", "1h", "--done", "gate ALL GREEN", "Flagged thing", hints=True)
self.assertEqual((code, err), (0, ""))
self.assertIn("\n Done: gate ALL GREEN\n", self.ok("show", "t-flagged-thing") + "\n")
def test_add_p0_without_done_warns(self):
code, out, err = self.wf("add", "-p", "0", "-e", "1h", "Urgent thing", hints=True)
self.assertEqual((code, err), (0, 'wf: warning: P0 without Done line is not runner-pickable; use --done "<text>"\n'))
if __name__ == "__main__":
unittest.main()