Merge branch 'plan-dag' into join
# Conflicts: # sisi/store.py
This commit is contained in:
commit
a3e717af36
8 files changed
+753
-35
No files matched your search
+18
-13
@@ -60,6 +60,8 @@ REAL_HOME = os.path.expanduser("~")
|
||||
|
||||
|
||||
class Core(unittest.TestCase):
|
||||
ENFORCE = False
|
||||
|
||||
def setUp(self):
|
||||
before = tree()
|
||||
self.addCleanup(lambda: self.assertEqual(tree(), before, "a test wrote into the product tree"))
|
||||
@@ -84,6 +86,9 @@ class Core(unittest.TestCase):
|
||||
for name in ("SISI_SESSION_ID", "CLAUDE_ENV_FILE", "XDG_DATA_HOME", "XDG_STATE_HOME", "CODEX_HOME"):
|
||||
self.env.pop(name, None)
|
||||
self.proj = self.project("alpha")
|
||||
if not self.ENFORCE: # these tests hold the reminders; tests/test_plan.py holds the denials
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False}}))
|
||||
|
||||
def project(self, name):
|
||||
path = os.path.join(self.tmp, name)
|
||||
@@ -1216,7 +1221,7 @@ class Core(unittest.TestCase):
|
||||
self.assertNotIn("could not be recorded", out, (rnd, out))
|
||||
self.assertNotIn("commit failed", out, (rnd, out))
|
||||
self.assertFalse(os.path.exists(old_c), rnd)
|
||||
dirty = [l for l in subprocess.run(["git", "status", "--porcelain"], cwd=self.data, capture_output=True, text=True, check=True).stdout.splitlines() if not l.startswith(("?? generated/", "?? locks/"))]
|
||||
dirty = [l for l in subprocess.run(["git", "status", "--porcelain"], cwd=self.data, capture_output=True, text=True, check=True).stdout.splitlines() if not l.startswith(("?? generated/", "?? locks/", "?? config.json"))]
|
||||
self.assertEqual(dirty, [], rnd)
|
||||
|
||||
def test_concurrent_learns_hold_project_lock_through_store_commit(self):
|
||||
@@ -2227,7 +2232,7 @@ cli.main(["tick"])
|
||||
|
||||
def test_a_worker_called_from_the_shell_is_never_marked_unknown(self):
|
||||
marker = self.lead(WORKERS)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"shell_workers": True}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "shell_workers": True}}))
|
||||
err = self.note(self.tool("Bash", tool_input={"command": 'opencode run -m other/model "fix the login bug in auth.py"'}))
|
||||
self.assertEqual(("the wheel did not give you" in err, os.path.exists(marker)), (True, False))
|
||||
self.assertNotIn("login bug", self.hook("tick", sid="s2")[1])
|
||||
@@ -2277,7 +2282,7 @@ cli.main(["tick"])
|
||||
self.assertIn("do not shell out to a worker", self.note(self.tool("Bash", tool_input=shell))) # warned even with a pick
|
||||
self.assertEqual(self.sisi("pick", "ordinary", sid="s1")[0], 0)
|
||||
self.assertEqual(self.tool("mcp__t3__delegate_task", tool_input={"target": {"model": "zai-coding-plan/glm-5.4"}}), (0, "", ""))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"shell_workers": True}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "shell_workers": True}}))
|
||||
self.assertIn("opencode run -m zai-coding-plan/glm-5.4", self.sisi("pick", "ordinary", sid="s1")[1])
|
||||
self.assertIn("the wheel did not give you", self.note(self.tool("Bash", tool_input={"command": 'opencode run -m other/model "x"'})))
|
||||
self.assertEqual(self.tool("Bash", tool_input=shell), (0, "", ""))
|
||||
@@ -2825,11 +2830,11 @@ cli.main(["tick"])
|
||||
bash = lambda c: self.tool("Bash", tool_input={"command": c})
|
||||
err = self.note(bash('opencode run -m x "y"')) # a shell worker before done
|
||||
self.assertEqual(("do not shell out" in err, "sisi done --goal" in err), (True, True))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"shell_workers": True}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "shell_workers": True}}))
|
||||
err = self.note(bash('opencode run -m x "y"'))
|
||||
self.assertEqual(("sisi done --goal" in err, "do not shell out" in err), (True, False))
|
||||
self.done()
|
||||
os.remove(os.path.join(self.data, "config.json"))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False}}))
|
||||
for c in ('cd /tmp && opencode run -m x "y"', 'nohup opencode run -m x "y" &', 'echo x; opencode run -m x "y"',
|
||||
'FOO=1 env time /usr/bin/agy --print "y"', 'ls | agy --print "y"'):
|
||||
self.assertIn("do not shell out", self.note(bash(c)), c)
|
||||
@@ -3068,7 +3073,7 @@ cli.main(["tick"])
|
||||
self.assertNotIn("changed things", out)
|
||||
|
||||
def test_sisi_with_quoted_operators_is_free_and_real_operators_are_not(self):
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"direct_calls": 0}}))
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"enforce": False, "direct_calls": 0}}))
|
||||
self.hook("tick")
|
||||
self.hook("prompt", prompt="go")
|
||||
bash = lambda c: self.tool("Bash", tool_input={"command": c})
|
||||
@@ -3144,7 +3149,7 @@ cli.main(["tick"])
|
||||
|
||||
def test_the_gate_blocks_on_a_worker_that_was_started_and_never_reported(self):
|
||||
self.table(WORKERS)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"worker_minutes": 15}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "worker_minutes": 15}}))
|
||||
self.hook("tick")
|
||||
self.hook("prompt", prompt="go")
|
||||
self.done()
|
||||
@@ -3208,7 +3213,7 @@ cli.main(["tick"])
|
||||
|
||||
def test_retro_row_records_session_id_and_demand_to_record_seconds(self):
|
||||
self.table(WORKERS)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"worker_minutes": 15}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "worker_minutes": 15}}))
|
||||
self.hook("tick")
|
||||
self.hook("prompt", prompt="go")
|
||||
self.done()
|
||||
@@ -3306,7 +3311,7 @@ cli.main(["tick"])
|
||||
|
||||
def test_a_lead_waiting_on_a_worker_that_is_not_late_is_not_stopped_for_open_checks(self):
|
||||
self.table(WORKERS)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"worker_minutes": 15}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "worker_minutes": 15}}))
|
||||
self.hook("tick")
|
||||
self.hook("prompt", prompt="go")
|
||||
self.done()
|
||||
@@ -3353,7 +3358,7 @@ cli.main(["tick"])
|
||||
self.assertIn("no retro yet", work("f", -1)) # a clock that went backwards: the retro
|
||||
self.assertIn("no retro yet", work("d", 4, delegate=True)) # a delegation: the retro
|
||||
self.assertEqual(len(self.records()), 1)
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"retro_minutes": 10}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "retro_minutes": 10}}))
|
||||
self.assertEqual(work("e", 6), "") # the limit is a setting
|
||||
self.assertEqual(len(self.records()), 2)
|
||||
|
||||
@@ -3399,7 +3404,7 @@ cli.main(["tick"])
|
||||
self.hook("tick", sid="w1")
|
||||
self.hook("prompt", sid="w1", prompt="You are a worker. Do this task yourself.")
|
||||
self.assertEqual(self.hook("gate", sid="w1")[1], "") # worker skipped
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"gate": False}}))
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False, "gate": False}}))
|
||||
self.assertEqual(self.hook("gate", sid="s2")[1], "") # gate setting off
|
||||
|
||||
def test_faults_shown_on_tick_prompt_retro_meter_free_and_scoped_to_project(self):
|
||||
@@ -3426,7 +3431,7 @@ cli.main(["tick"])
|
||||
self.assertIn("linker crashed ten times", rep)
|
||||
self.assertIn("scratch folder filled up", rep)
|
||||
# meter lets `sisi fault ...` through even with direct_calls=0
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"direct_calls": 0}}))
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"enforce": False, "direct_calls": 0}}))
|
||||
self.assertEqual(self.tool("Bash", sid="s2", tool_input={"command": 'sisi fault "new crash in test runner"'})[0], 0)
|
||||
# a different project's faults are not shown or gated
|
||||
beta = self.project("beta")
|
||||
@@ -3696,7 +3701,7 @@ cli.main(["tick"])
|
||||
wt5 = self.mkdir(p5, ".git", "worktrees")
|
||||
for i in range(10):
|
||||
self.mkdir(wt5, "w%d" % i)
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"disk_free_percent": 0, "disk_drop_percent": 0, "checkouts": 0}}))
|
||||
self.write(self.mkdir(self.data) + "/config.json", json.dumps({"core": {"enforce": False, "disk_free_percent": 0, "disk_drop_percent": 0, "checkouts": 0}}))
|
||||
self.env["SISI_TEST_STATVFS"] = "1000000000000:50000000000"
|
||||
self.assertEqual(self.hook("prompt", sid="off1", cwd=p5, prompt="all off")[1], "")
|
||||
self.assertIn("no open faults", self.sisi("fault", cwd=p5)[1])
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
"""The plan: a dependency graph recorded before any work is handed out, and the hooks that hold the lead to it."""
|
||||
import io, json, os, sys, unittest
|
||||
from unittest import mock
|
||||
import test_core # the module, not its class: its tests must not run twice
|
||||
sys.path.insert(0, test_core.REPO)
|
||||
|
||||
TABLE = test_core.HEADER + (
|
||||
"| alpha | host subagent model `alpha` | routine | free | quick | |\n"
|
||||
"| beta | host subagent model `beta` | ordinary | free | edits | |\n"
|
||||
"| gamma | host subagent model `gamma` | hard | per use | everything | |\n")
|
||||
COLS = "| node | class | needs | branch | files | check | why |\n|---|---|---|---|---|---|---|\n"
|
||||
PLAN = COLS + (
|
||||
"| a | routine | - | p-a | sisi/a.py | test a passes | exact spec, test decides |\n"
|
||||
"| b | ordinary | - | p-b | sisi/b.py | test b passes | some judgement |\n"
|
||||
"| c | hard | a, b | p-c | sisi/c.py | test c passes | design judgement, redo costly |\n"
|
||||
"| join | lead | c | - | - | full suite passes | the lead merges |\n")
|
||||
|
||||
|
||||
class Plan(unittest.TestCase):
|
||||
ENFORCE = True
|
||||
setUp, project, sisi, hook, tool, done, table, state, read, write, in_process = (
|
||||
test_core.Core.setUp, test_core.Core.project, test_core.Core.sisi, test_core.Core.hook, test_core.Core.tool, test_core.Core.done,
|
||||
test_core.Core.table, test_core.Core.state, test_core.Core.read, test_core.Core.write, test_core.Core.in_process)
|
||||
|
||||
def record(self, text, sid="s1"):
|
||||
return self.sisi("plan", "--record", self.write(os.path.join(self.tmp, "plan.md"), text), sid=sid)
|
||||
|
||||
def refused(self, text, why):
|
||||
rc, out, _ = self.record(text)
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn(why, out)
|
||||
self.assertIn("Nothing was recorded", out)
|
||||
self.assertNotIn("plan", self.state() if os.path.exists(os.path.join(self.tmp, "state", "core-sessions", "s1.json")) else {})
|
||||
|
||||
def ready_plan(self, sid="s1", text=PLAN):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", sid=sid, prompt="build it")
|
||||
self.done(sid)
|
||||
rc, out, _ = self.record(text, sid)
|
||||
self.assertEqual(rc, 0, out)
|
||||
return out
|
||||
|
||||
def pick(self, node, sid="s1"):
|
||||
rc, out, _ = self.sisi("pick", "--node", node, sid=sid)
|
||||
self.assertEqual(rc, 0, out)
|
||||
return out
|
||||
|
||||
def agent(self, model, brief, sid="s1", **extra):
|
||||
return self.tool("Agent", sid=sid, tool_input=dict({"model": model, "prompt": brief, "isolation": "worktree"}, **extra))
|
||||
|
||||
def decision(self, res):
|
||||
rc, out, err = res
|
||||
self.assertEqual((rc, err), (0, ""), res)
|
||||
return json.loads(out)["hookSpecificOutput"] if out.strip() else {}
|
||||
|
||||
def denied(self, res, why):
|
||||
d = self.decision(res)
|
||||
self.assertEqual(d.get("permissionDecision"), "deny", d)
|
||||
self.assertIn(why, d["permissionDecisionReason"])
|
||||
return d["permissionDecisionReason"]
|
||||
|
||||
def nodes(self, sid="s1"):
|
||||
return {i: v.get("st") for i, v in self.state(sid)["plan"]["state"].items()}
|
||||
|
||||
# recording: each refusal
|
||||
|
||||
def test_refuses_a_bad_node_id(self):
|
||||
self.refused(PLAN.replace("| a |", "| A_1 |"), "node id 'A_1' is not")
|
||||
|
||||
def test_refuses_a_duplicate_node(self):
|
||||
self.refused(PLAN.replace("| b | ordinary | - | p-b | sisi/b.py", "| a | ordinary | - | p-b | sisi/b.py"), "node a appears twice")
|
||||
|
||||
def test_refuses_a_missing_need(self):
|
||||
self.refused(PLAN.replace("| a, b |", "| a, zz |"), "node c needs zz, which is not a node")
|
||||
|
||||
def test_refuses_a_cycle(self):
|
||||
self.refused(PLAN.replace("| a | routine | - |", "| a | routine | c |"), "cycle")
|
||||
|
||||
def test_refuses_an_unknown_class(self):
|
||||
self.refused(PLAN.replace("| routine |", "| cheap |"), "class 'cheap'")
|
||||
|
||||
def test_refuses_two_worker_nodes_on_one_branch(self):
|
||||
self.refused(PLAN.replace("| p-b |", "| p-a |"), "branch p-a is given to more than one node")
|
||||
|
||||
def test_refuses_a_worker_node_without_a_branch(self):
|
||||
self.refused(PLAN.replace("| p-b |", "| - |"), "node b needs a branch of its own")
|
||||
|
||||
def test_refuses_parallel_nodes_that_share_files(self):
|
||||
for a, b in (("sisi/a.py", "sisi/a.py"), ("sisi", "sisi/b.py"), ("sisi/*.py", "sisi/b.py")):
|
||||
self.refused(PLAN.replace("| sisi/a.py |", "| %s |" % a).replace("| sisi/b.py |", "| %s |" % b),
|
||||
"nodes a and b can run at the same time")
|
||||
|
||||
def test_nodes_in_sequence_may_share_files(self):
|
||||
self.ready_plan(text=PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/b.py |"))
|
||||
|
||||
def test_refuses_more_than_one_sink(self):
|
||||
self.refused(PLAN.replace("| c | hard | a, b |", "| c | hard | a |"), "exactly one final join")
|
||||
|
||||
def test_refuses_no_table(self):
|
||||
self.refused("just words", "no table found")
|
||||
|
||||
def test_record_prints_waves_critical_path_dispatch_line_why_and_record(self):
|
||||
out = self.ready_plan()
|
||||
self.assertIn("critical path 3 wave(s)", out)
|
||||
self.assertIn("wave 1: a (routine: exact spec, test decides), b (ordinary: some judgement)", out)
|
||||
self.assertIn("dispatch wave 1 now, all in one message: a, b", out)
|
||||
self.assertIn("record (last 20 judged per class): routine none judged yet", out)
|
||||
self.assertEqual(self.nodes(), {})
|
||||
|
||||
def test_a_table_without_the_why_column_records(self):
|
||||
six = "\n".join("|".join(l.split("|")[:-2]) + "|" if l.startswith("|") else l for l in PLAN.splitlines()) + "\n"
|
||||
self.assertNotIn("why", six)
|
||||
out = self.ready_plan(text=six)
|
||||
self.assertIn("wave 1: a (routine), b (ordinary)", out)
|
||||
|
||||
def test_record_line_counts_the_last_twenty_judged_per_class(self):
|
||||
self.table(TABLE)
|
||||
line = lambda w, v: json.dumps({"ts": "2026-11-20T10:00:00", "worker": w, "verdict": v, "why": "did it fine"})
|
||||
self.write(os.path.join(self.data, "outcomes.jsonl"), "\n".join(
|
||||
[line("alpha", "bad")] * 5 + [line("alpha", "good")] * 18 + [line("beta", "bad")] + [line("gamma", "out")] + [line("nobody", "good")]) + "\n")
|
||||
from sisi import plan
|
||||
self.assertEqual(self.in_process(plan.record_line)[0],
|
||||
"record (last 20 judged per class): routine 18/20 good, ordinary 0/1 good, hard none judged yet")
|
||||
|
||||
def test_rerecording_keeps_the_state_of_unchanged_nodes(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("a"))), {})
|
||||
self.assertEqual(self.nodes(), {"a": "running"})
|
||||
self.assertEqual(self.record(PLAN.replace("test b passes", "test b and b2 pass"))[0], 0)
|
||||
self.assertEqual(self.nodes(), {"a": "running"})
|
||||
self.assertEqual(self.record(PLAN.replace("test a passes", "test a2 passes"))[0], 0)
|
||||
self.assertEqual(self.nodes(), {})
|
||||
|
||||
def pick_header(self, node, sid="s1"):
|
||||
st = self.state(sid)
|
||||
n = next(x for x in st["plan"]["nodes"] if x["id"] == node)
|
||||
return "sisi node: %s\nbranch: %s\nYou are a worker.\nDo it." % (node, n["branch"])
|
||||
|
||||
def test_plan_brief_is_a_chore_built_from_done_with_the_total_cost_rule(self):
|
||||
self.ready_plan()
|
||||
rc, out, _ = self.sisi("plan", "brief", sid="s1")
|
||||
self.assertEqual(rc, 0, out)
|
||||
self.assertEqual(out.splitlines()[0], "sisi chore: plan")
|
||||
for want in ("export every row without losing any", "1. row counts match", "| node | class | needs | branch | files | check | why |",
|
||||
"Class by total cost", "routine nodes whenever their", "record (last 20 judged per class)"):
|
||||
self.assertIn(want, out)
|
||||
|
||||
def test_a_retro_clears_the_plan(self):
|
||||
self.ready_plan()
|
||||
self.assertEqual(self.sisi("retro", "--no-gap", "every check passed with the tests shown", *test_core.NG, sid="s1")[0], 0)
|
||||
self.assertNotIn("plan", self.state())
|
||||
|
||||
# pick --node
|
||||
|
||||
def test_pick_node_takes_class_and_branch_and_prints_the_header(self):
|
||||
self.ready_plan()
|
||||
out = self.pick("a")
|
||||
self.assertIn("worker: alpha", out)
|
||||
for want in ("sisi node: a", "branch: p-a (its own worktree and build folder)", "may change: sisi/a.py", "check: test a passes", "needs done: -"):
|
||||
self.assertIn(want, out)
|
||||
self.assertIn("record (last 20 judged per class)", out)
|
||||
self.assertEqual(self.state()["pending"]["alpha"], [{"limit": None, "branch": "p-a", "node": "a"}])
|
||||
|
||||
def test_pick_node_refuses_a_waiting_or_lead_node(self):
|
||||
self.ready_plan()
|
||||
rc, out, _ = self.sisi("pick", "--node", "c", sid="s1")
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("node c is not ready (needs not done: a, b)", out)
|
||||
rc, out, _ = self.sisi("pick", "--node", "join", sid="s1")
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn('sisi plan --done join', out)
|
||||
|
||||
# the hook: each reason to deny
|
||||
|
||||
def test_deny_without_done(self):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.denied(self.agent("alpha", "Do it."), "no done is recorded yet")
|
||||
|
||||
def test_deny_without_a_plan(self):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.done()
|
||||
self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0)
|
||||
why = self.denied(self.agent("alpha", "Do it."), "no plan is recorded")
|
||||
self.assertIn("sisi plan brief", why)
|
||||
self.assertEqual(self.state().get("delegations_since", 0), 0) # a denied call is no delegation
|
||||
self.assertEqual(self.state()["picked"], ["alpha"]) # and spends no pick
|
||||
|
||||
def test_a_chore_brief_passes_without_a_plan(self):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.done()
|
||||
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
|
||||
self.assertEqual(self.decision(self.agent("gamma", "sisi chore: plan\nYou are a worker.")), {})
|
||||
|
||||
def test_deny_an_unpicked_model(self):
|
||||
self.ready_plan()
|
||||
self.denied(self.agent("alpha", self.pick_header("a")), "the wheel did not give you this worker")
|
||||
|
||||
def test_deny_a_call_with_no_model(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
res = self.tool("Agent", tool_input={"prompt": self.pick_header("a"), "isolation": "worktree"})
|
||||
self.denied(res, "no model is named")
|
||||
|
||||
def test_deny_a_model_not_in_the_table(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.denied(self.agent("zeta", self.pick_header("a")), "sisi pick --node ID")
|
||||
|
||||
def test_deny_a_brief_without_a_node_line(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.denied(self.agent("alpha", "You are a worker. Do it."), "names no plan node")
|
||||
|
||||
def test_deny_a_node_that_is_not_ready(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.denied(self.agent("alpha", "sisi node: c\nDo it."), "node c is not ready (needs not done: a, b)")
|
||||
|
||||
def test_deny_a_node_already_running(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("a"))), {})
|
||||
self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0)
|
||||
self.denied(self.agent("alpha", self.pick_header("a")), "node a is not ready (already running)")
|
||||
|
||||
def test_deny_a_worker_picked_for_another_node(self):
|
||||
self.ready_plan(text=PLAN.replace("| b | ordinary |", "| b | routine |"))
|
||||
self.pick("a")
|
||||
self.denied(self.agent("alpha", "sisi node: b\nDo it."), "picked for node a, not b")
|
||||
|
||||
def test_two_picks_of_one_worker_are_spent_by_node_not_by_order(self):
|
||||
self.ready_plan(text=PLAN.replace("| b | ordinary |", "| b | routine |"))
|
||||
self.pick("a")
|
||||
self.pick("b")
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("b"))), {})
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("a"))), {})
|
||||
self.assertEqual(self.nodes(), {"a": "running", "b": "running"})
|
||||
|
||||
def test_deny_a_shell_out_to_a_worker(self):
|
||||
self.table(test_core.WORKERS)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.done()
|
||||
self.denied(self.tool("Bash", tool_input={"command": 'agy --print "sisi chore: x"'}), "do not shell out to a worker")
|
||||
|
||||
def test_deny_a_parallel_node_without_its_own_worktree(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.denied(self.agent("alpha", self.pick_header("a"), isolation=None), 'isolation "worktree"')
|
||||
self.pick("b")
|
||||
res = self.tool("mcp__t3-code__delegate_task", tool_input={"task": self.pick_header("b"), "target": {"model": "beta"}, "isolation": "shared"})
|
||||
self.denied(res, 'isolation "worktree"')
|
||||
|
||||
def test_the_deny_is_the_decision_not_a_reminder(self):
|
||||
"""Fails if watch stops printing a deny: the call would go through with only a note."""
|
||||
self.ready_plan()
|
||||
d = self.decision(self.agent("alpha", "Do it."))
|
||||
self.assertEqual(d.get("permissionDecision"), "deny")
|
||||
self.assertNotIn("additionalContext", d)
|
||||
|
||||
def test_the_planned_delegation_passes_and_runs_its_node(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.pick("b")
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("a"))), {})
|
||||
res = self.tool("mcp__t3-code__delegate_task", tool_input={"task": self.pick_header("b"), "target": {"model": "beta"}, "isolation": "worktree"})
|
||||
self.assertEqual(self.decision(res), {})
|
||||
self.assertEqual(self.nodes(), {"a": "running", "b": "running"})
|
||||
self.assertEqual(self.state()["delegations_since"], 2)
|
||||
|
||||
def test_sisi_commands_and_direct_edits_are_never_denied(self):
|
||||
self.ready_plan()
|
||||
self.assertEqual(self.decision(self.tool("Bash", tool_input={"command": "sisi plan"})), {})
|
||||
d = self.decision(self.tool("Edit", tool_input={"file_path": "x"}))
|
||||
self.assertNotIn("permissionDecision", d)
|
||||
|
||||
def test_workers_are_never_denied(self):
|
||||
self.table(TABLE)
|
||||
self.assertEqual(self.decision(self.tool("Agent", sid="w1", agent_id="sub1", tool_input={"prompt": "Do it."})), {})
|
||||
self.hook("prompt", sid="w2", prompt="You are a worker. Do this task yourself.")
|
||||
self.assertEqual(self.decision(self.tool("Agent", sid="w2", tool_input={"prompt": "Do it."})), {})
|
||||
|
||||
def test_enforce_false_gives_reminders(self):
|
||||
self.ready_plan()
|
||||
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"enforce": False}}))
|
||||
d = self.decision(self.agent("alpha", "Do it."))
|
||||
self.assertNotIn("permissionDecision", d)
|
||||
self.assertIn("names no plan node", d["additionalContext"])
|
||||
self.assertIn("the wheel did not give you", d["additionalContext"])
|
||||
self.assertEqual(self.state()["delegations_since"], 1)
|
||||
|
||||
def test_an_error_inside_watch_lets_the_call_through(self):
|
||||
self.ready_plan()
|
||||
from sisi import cli, plan
|
||||
stdin = io.StringIO(json.dumps({"session_id": "s1", "cwd": self.proj, "hook_event_name": "PreToolUse", "tool_name": "Agent",
|
||||
"tool_input": {"model": "alpha", "prompt": "Do it."}}))
|
||||
with mock.patch.object(plan, "deny", side_effect=RuntimeError("boom")), mock.patch.object(sys, "stdin", stdin):
|
||||
rc, out = self.in_process(cli.main, ["watch"])
|
||||
self.assertEqual((rc, out), (0, ""))
|
||||
self.assertIn("boom", self.read(self.tmp, "state", "core-errors.log"))
|
||||
|
||||
# judge and the end of the turn
|
||||
|
||||
def test_judge_good_marks_done_and_bad_reopens(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.pick("b")
|
||||
self.agent("alpha", self.pick_header("a"))
|
||||
self.tool("Agent", tool_input={"model": "beta", "prompt": self.pick_header("b"), "isolation": "worktree"})
|
||||
self.assertEqual(self.sisi("judge", "alpha", "good", "did the work well", sid="s1")[0], 0)
|
||||
self.assertEqual(self.sisi("judge", "beta", "bad", "broke the tests badly", sid="s1")[0], 0)
|
||||
self.assertEqual(self.nodes(), {"a": "done", "b": "failed"})
|
||||
out = self.sisi("plan", sid="s1")[1]
|
||||
self.assertIn("ready: b", out)
|
||||
self.assertIn("a [routine] done", out)
|
||||
|
||||
def test_gate_sends_the_lead_back_while_nodes_are_ready_and_not_started(self):
|
||||
self.ready_plan()
|
||||
rc, out, _ = self.hook("gate")
|
||||
self.assertIn('"block"', out)
|
||||
self.assertIn("nodes a, b are ready and not started", out)
|
||||
self.assertIn("`sisi pick --node a` `sisi pick --node b`", out)
|
||||
|
||||
def test_gate_lets_the_turn_end_while_nodes_only_run(self):
|
||||
self.ready_plan()
|
||||
for n, m in (("a", "alpha"), ("b", "beta")):
|
||||
self.pick(n)
|
||||
self.assertEqual(self.decision(self.agent(m, self.pick_header(n))), {})
|
||||
self.assertEqual(self.hook("gate")[1], "")
|
||||
|
||||
def test_gate_names_the_lead_join_when_only_it_is_ready(self):
|
||||
self.ready_plan()
|
||||
for n in ("a", "b", "c"):
|
||||
self.assertEqual(self.sisi("plan", "--done", n, "done by hand and tested", sid="s1")[0], 0)
|
||||
out = self.hook("gate")[1]
|
||||
self.assertIn("node join is yours and ready: full suite passes", out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user