Plan fixes: issued chores only, brief from any field, first-line node, exact judge match, concurrency-based isolation, running nodes kept on re-record, lead join, damaged state; single claim path, one outcomes pass
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a8974c02cc
commit
df744edc7c
6 files changed
+301
-187
No files matched your search
+2
-2
@@ -3100,7 +3100,7 @@ cli.main(["tick"])
|
||||
self.assertIn("8 direct tool calls this turn (the limit is 8)", msg)
|
||||
self.assertIn('sisi direct "<reason>"', msg)
|
||||
self.assertEqual(self.state()["direct"], 9)
|
||||
# unpicked known and unknown delegations both go through, remind of sisi pick, and record starts for sisi judge
|
||||
# unpicked known and unknown delegations both go through (reminder mode) and remind of sisi pick; jobs started earlier are judged
|
||||
self.table(self.CLAUDE)
|
||||
self.hook("tick", sid="s2")
|
||||
self.hook("prompt", sid="s2", prompt="go")
|
||||
@@ -3109,7 +3109,7 @@ cli.main(["tick"])
|
||||
self.assertIn("sisi pick", self.note(self.tool("Agent", sid="s2", tool_input={"model": "new-maker-9"})))
|
||||
with open(os.path.join(self.tmp, "state", "core-sessions", "s2.json"), "r+") as f:
|
||||
st = json.load(f)
|
||||
st["starts"]["claude-sonnet-5-5"] = [time.time() - 12 * 60 - 5]
|
||||
st.setdefault("starts", {})["claude-sonnet-5-5"] = [time.time() - 12 * 60 - 5]
|
||||
st["starts"]["new-maker-9"] = [time.time() - 7 * 60 - 5]
|
||||
f.seek(0), f.truncate(), json.dump(st, f)
|
||||
self.assertEqual(self.sisi("judge", "sonnet", "good", "finished the job cleanly", sid="s2")[0], 0)
|
||||
|
||||
+109
-6
@@ -1,7 +1,10 @@
|
||||
"""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
|
||||
try: # the module, not its class: its tests must not run twice
|
||||
from tests import test_core
|
||||
except ImportError:
|
||||
import test_core
|
||||
sys.path.insert(0, test_core.REPO)
|
||||
|
||||
TABLE = test_core.HEADER + (
|
||||
@@ -96,6 +99,13 @@ class Plan(unittest.TestCase):
|
||||
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_a_final_join_that_is_not_the_leads(self):
|
||||
self.refused(PLAN.replace("| join | lead | c | - | - |", "| join | hard | c | p-j | docs |"), "the final join join must be class lead")
|
||||
|
||||
def test_refuses_a_worker_node_without_files_or_check(self):
|
||||
self.refused(PLAN.replace("| sisi/b.py |", "| - |"), "worker node b needs files it may change and a check")
|
||||
self.refused(PLAN.replace("| test b passes |", "| - |"), "worker node b needs files it may change and a check")
|
||||
|
||||
def test_refuses_no_table(self):
|
||||
self.refused("just words", "no table found")
|
||||
|
||||
@@ -130,7 +140,14 @@ class Plan(unittest.TestCase):
|
||||
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(), {})
|
||||
self.assertEqual(self.nodes(), {"a": "running"}) # a running node keeps its state by id
|
||||
rc, out, _ = self.record(PLAN.replace("| sisi/a.py |", "| sisi/a2.py |"))
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn("node a is running", out)
|
||||
self.assertIn("a", self.nodes())
|
||||
rc, out, _ = self.record(PLAN.replace("| a | routine | - |", "| a2 | routine | - |").replace("| a, b |", "| a2, b |"))
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn("node a is running", out)
|
||||
|
||||
def pick_header(self, node, sid="s1"):
|
||||
st = self.state(sid)
|
||||
@@ -192,8 +209,29 @@ class Plan(unittest.TestCase):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.done()
|
||||
brief = self.sisi("plan", "brief", sid="s1")[1]
|
||||
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
|
||||
self.assertEqual(self.decision(self.agent("gamma", "sisi chore: plan\nYou are a worker.")), {})
|
||||
self.assertEqual(self.decision(self.agent("gamma", brief)), {})
|
||||
self.assertEqual(self.state().get("chores"), []) # spent
|
||||
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
|
||||
self.denied(self.agent("gamma", brief), "was not printed by sisi in this session")
|
||||
|
||||
def test_an_invented_chore_line_is_denied(self):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="build it")
|
||||
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
|
||||
why = self.denied(self.agent("gamma", "sisi chore: anything\nDo it."), "`sisi chore: anything` was not printed by sisi")
|
||||
self.assertIn("no done is recorded", why)
|
||||
|
||||
def test_sisis_own_chore_briefs_carry_their_line_and_pass(self):
|
||||
self.table(TABLE)
|
||||
self.hook("prompt", prompt="tidy up")
|
||||
for args, line in ((("rules", "organize"), "sisi chore: rules organize"), (("models", "research"), "sisi chore: models research")):
|
||||
rc, brief, _ = self.sisi(*args, sid="s1")
|
||||
self.assertEqual((rc, brief.splitlines()[0]), (0, line))
|
||||
self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0)
|
||||
self.assertNotIn("permissionDecision", self.decision(self.agent("alpha", brief)), line)
|
||||
self.assertEqual(self.state()["chores"], [])
|
||||
|
||||
def test_deny_an_unpicked_model(self):
|
||||
self.ready_plan()
|
||||
@@ -208,12 +246,17 @@ class Plan(unittest.TestCase):
|
||||
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")
|
||||
self.denied(self.agent("zeta", self.pick_header("a")), "not in the models table")
|
||||
|
||||
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")
|
||||
self.denied(self.agent("alpha", "You are a worker. Do it."), "first line must be `sisi node: ID`")
|
||||
|
||||
def test_deny_a_node_line_that_is_not_the_first_line(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.denied(self.agent("alpha", "Do this.\nsisi node: a"), "first line must be `sisi node: ID`")
|
||||
|
||||
def test_deny_a_node_that_is_not_ready(self):
|
||||
self.ready_plan()
|
||||
@@ -288,7 +331,7 @@ class Plan(unittest.TestCase):
|
||||
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("first line must be `sisi node: ID`", d["additionalContext"])
|
||||
self.assertIn("the wheel did not give you", d["additionalContext"])
|
||||
self.assertEqual(self.state()["delegations_since"], 1)
|
||||
|
||||
@@ -302,6 +345,66 @@ class Plan(unittest.TestCase):
|
||||
self.assertEqual((rc, out), (0, ""))
|
||||
self.assertIn("boom", self.read(self.tmp, "state", "core-errors.log"))
|
||||
|
||||
def test_a_brief_in_another_field_is_read(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
res = self.tool("subagent_spawn", tool_input={"objective": self.pick_header("a"), "model": "alpha"})
|
||||
d = self.decision(res)
|
||||
self.assertNotIn("permissionDecision", d) # a tool with no isolation field: reminded only
|
||||
self.assertIn('isolation "worktree"', d["additionalContext"])
|
||||
self.assertEqual(self.nodes(), {"a": "running"})
|
||||
|
||||
def test_a_call_with_no_text_is_reminded_not_denied(self):
|
||||
self.ready_plan()
|
||||
d = self.decision(self.tool("Workflow", tool_input={"steps": [1, 2]}))
|
||||
self.assertNotIn("permissionDecision", d)
|
||||
self.assertIn("first line must be", d["additionalContext"])
|
||||
|
||||
def test_a_session_with_no_request_yet_is_reminded_not_denied(self):
|
||||
self.table(TABLE)
|
||||
d = self.decision(self.agent("alpha", "Do it.", sid="fresh"))
|
||||
self.assertNotIn("permissionDecision", d)
|
||||
self.assertIn("no done is recorded", d["additionalContext"])
|
||||
|
||||
def test_a_node_in_sequence_needs_no_worktree(self):
|
||||
seq = COLS + ("| a | routine | - | p-a | sisi/a.py | test a passes | x |\n| b | routine | a | p-b | sisi/b.py | test b passes | x |\n"
|
||||
"| join | lead | b | - | - | suite passes | x |\n")
|
||||
self.ready_plan(text=seq)
|
||||
self.pick("a")
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("a"), isolation=None)), {})
|
||||
|
||||
def test_done_refuses_a_running_worker_node(self):
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.agent("alpha", self.pick_header("a"))
|
||||
rc, out, _ = self.sisi("plan", "--done", "a", "it looks finished to me", sid="s1")
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("sisi judge WORKER", out)
|
||||
self.assertEqual(self.nodes(), {"a": "running"})
|
||||
|
||||
def test_a_damaged_plan_state_does_not_crash(self):
|
||||
self.ready_plan()
|
||||
path = os.path.join(self.tmp, "state", "core-sessions", "s1.json")
|
||||
s = self.state()
|
||||
s["plan"]["state"] = {"a": "junk", "b": {"st": 5}, "c": None}
|
||||
self.write(path, json.dumps(s))
|
||||
rc, out, err = self.sisi("plan", sid="s1")
|
||||
self.assertEqual((rc, err), (0, ""), out)
|
||||
self.assertIn("ready: a, b", out)
|
||||
self.assertEqual(self.sisi("pick", "--node", "a", sid="s1")[0], 0)
|
||||
s["plan"]["state"] = ["junk"]
|
||||
self.write(path, json.dumps(s))
|
||||
self.assertEqual(self.sisi("plan", sid="s1")[0], 0)
|
||||
|
||||
def test_judge_moves_only_the_node_its_job_started(self):
|
||||
from sisi import plan
|
||||
s = {"plan": {"nodes": [{"id": "a", "cls": "routine", "needs": [], "branch": "b", "files": ["x"], "check": "c"}],
|
||||
"state": {"a": {"st": "running", "worker": "alpha", "since": 100.0}}}}
|
||||
plan.judged(s, "alpha", 200.0, "good")
|
||||
self.assertEqual(s["plan"]["state"]["a"]["st"], "running")
|
||||
plan.judged(s, "alpha", 100.0, "good")
|
||||
self.assertEqual(s["plan"]["state"]["a"]["st"], "done")
|
||||
|
||||
# judge and the end of the turn
|
||||
|
||||
def test_judge_good_marks_done_and_bad_reopens(self):
|
||||
|
||||
Reference in new issue
Block a user