Note a delegation whose brief asks for something the person will look at but states no look
Rule 5 gains one sentence: the brief states the look, chosen with the person from previews. The delegation hook adds a note (never a block) when the brief makes something, names two or more screen terms and states no look (no Look:/Design system: line, fewer than three of the four groups). Five lines are merged elsewhere in hooks.py; the labelled-set test skips while tests/data/screen_briefs.jsonl is absent.
This commit is contained in:
1 parent
8e2654892e
commit
58ee83fa38
3 files changed
+101
-19
No files matched your search
+67
-3
@@ -1953,6 +1953,70 @@ cli.main(["tick"])
|
||||
os.remove(os.path.join(self.data, "models.md"))
|
||||
self.assertEqual(self.tool("Agent", tool_input={"model": "sonnet"}), (0, "", ""))
|
||||
|
||||
PAGE = ("Build a status page for the service: a header, a toolbar with a refresh button, a sidebar listing the jobs, and a table of runs. "
|
||||
"It must work at phone width. Time limit 20 minutes.")
|
||||
SERVER = ("Add a /api/status endpoint that the dashboard page polls every five seconds: it returns JSON and records the user who "
|
||||
"opens the browser session. Cover it with a test.")
|
||||
SCREEN_BRIEFS = os.path.join(REPO, "tests", "data", "screen_briefs.jsonl")
|
||||
|
||||
def test_a_brief_for_something_the_person_will_look_at_states_its_look(self):
|
||||
from sisi import hooks
|
||||
f = hooks.screen_brief_without_look
|
||||
self.assertTrue(f(self.PAGE)) # screen work, no look
|
||||
self.assertFalse(f(self.PAGE + "\nLook: the existing settings page")) # a line says which design it follows
|
||||
self.assertFalse(f(self.PAGE + "\n- Design system: the one in docs/ui.md")) # in a bullet, and by its other name
|
||||
self.assertFalse(f(self.PAGE + "Type: Inter at 14/16/20. Spacing: 8px padding, 12px gaps. Grid: two columns above 900px.")) # three of four groups
|
||||
self.assertTrue(f(self.PAGE + "Type: Inter at 14/16/20. Grid: two columns above 900px.")) # two groups are not a look
|
||||
self.assertFalse(f(self.SERVER)) # "page" and "browser" alone are not screen work
|
||||
self.assertFalse(f("Review the settings page: at phone width the toolbar overlaps the sidebar and the headline wraps. "
|
||||
"Report findings only.")) # looks, never makes
|
||||
for bad in ("", None, 12, {"prompt": self.PAGE}, [self.PAGE]):
|
||||
self.assertFalse(f(bad), bad)
|
||||
|
||||
def test_a_delegation_whose_brief_states_no_look_is_noted_and_never_blocked(self):
|
||||
self.hook("tick"), self.hook("prompt", prompt="go"), self.done()
|
||||
for name, field in (("Agent", "prompt"), ("mcp__t3__delegate_task", "prompt"), ("spawn_agent", "message"), ("Task", "task")):
|
||||
rc, out, err = self.tool(name, tool_input={field: self.PAGE})
|
||||
self.assertEqual((rc, err), (0, ""), (name, out, err))
|
||||
doc = json.loads(out)
|
||||
self.assertEqual(sorted(doc), ["hookSpecificOutput"], doc) # context only: no decision, so no block
|
||||
self.assertIn("states no look", doc["hookSpecificOutput"]["additionalContext"])
|
||||
self.assertIn("'Look: <the existing design it follows>'", doc["hookSpecificOutput"]["additionalContext"])
|
||||
self.assertEqual(self.tool("Agent", tool_input={"prompt": self.SERVER}), (0, "", "")) # nothing to say
|
||||
self.assertEqual(self.tool("Agent", tool_input={"prompt": None}), (0, "", "")) # a missing brief is no error
|
||||
self.table(WORKERS)
|
||||
err = self.note(self.tool("Bash", tool_input={"command": 'opencode run -m other/model "%s"' % self.PAGE}))
|
||||
self.assertEqual(("states no look" in err, "do not shell out" in err), (True, True)) # a worker started from the shell too
|
||||
|
||||
def test_the_screen_brief_rule_on_the_labelled_briefs(self):
|
||||
if not os.path.exists(self.SCREEN_BRIEFS):
|
||||
self.skipTest("tests/data/screen_briefs.jsonl is absent, so the labelled set was not scored")
|
||||
from sisi import hooks
|
||||
rows = [json.loads(l) for l in self.read(self.SCREEN_BRIEFS).splitlines() if l.strip()]
|
||||
wrong = [r for r in rows if hooks.screen_brief_without_look(r["text"]) != (r["label"] == "note")]
|
||||
acc = {}
|
||||
for split in ("train", "held"):
|
||||
part = [r for r in rows if r["split"] == split]
|
||||
self.assertTrue(part, "no %s rows in the labelled set" % split)
|
||||
acc[split] = 1 - sum(r in part for r in wrong) / len(part)
|
||||
self.assertGreaterEqual(acc[split], 0.85, "screen briefs, %s %.2f; wrong: %s" % (split, acc[split], [(r["label"], r["text"][:120]) for r in wrong if r in part]))
|
||||
self.assertEqual([r["text"][:120] for r in wrong if r.get("real")], [], "real briefs the rule gets wrong")
|
||||
print("screen briefs: train %.2f, held %.2f" % (acc["train"], acc["held"]))
|
||||
|
||||
def test_the_labelled_brief_test_scores_each_split_and_every_real_brief(self):
|
||||
import contextlib, io
|
||||
row = lambda split, label, real, text: json.dumps(dict(split=split, label=label, real=real, text=text))
|
||||
path = self.write(os.path.join(self.tmp, "b.jsonl"), "\n".join([row("train", "note", True, self.PAGE), row("held", "quiet", True, self.SERVER),
|
||||
row("held", "quiet", False, self.SERVER)]))
|
||||
with mock.patch.object(Core, "SCREEN_BRIEFS", path), contextlib.redirect_stdout(out := io.StringIO()):
|
||||
self.test_the_screen_brief_rule_on_the_labelled_briefs() # every brief right: it passes and prints
|
||||
self.assertEqual(out.getvalue().strip(), "screen briefs: train 1.00, held 1.00")
|
||||
for held, why in (([row("held", "quiet", False, self.SERVER), row("held", "quiet", False, self.PAGE)], "held 0.50"), # one split under the bar
|
||||
([row("held", "note", True, self.SERVER)] + [row("held", "note", False, self.PAGE)] * 6, "real briefs the rule gets wrong")): # 6 of 7, but a real one
|
||||
self.write(path, "\n".join([row("train", "note", True, self.PAGE)] + held))
|
||||
with mock.patch.object(Core, "SCREEN_BRIEFS", path), contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertRaisesRegex(AssertionError, why, self.test_the_screen_brief_rule_on_the_labelled_briefs)
|
||||
|
||||
def test_unknown_worker_delegation_marks_models_table_stale(self):
|
||||
self.table(WORKERS)
|
||||
self.hook("tick")
|
||||
@@ -3805,10 +3869,10 @@ cli.main(["tick"])
|
||||
|
||||
def test_the_product_stays_small(self):
|
||||
code = sum(len(self.read(p).splitlines()) for p in glob.glob(os.path.join(REPO, "sisi", "*.py")))
|
||||
self.assertLessEqual(code, 2267, "sisi is two loops. If it needs more than this, find the simpler shape.")
|
||||
self.assertLessEqual(code, 2283, "sisi is two loops. If it needs more than this, find the simpler shape.")
|
||||
rulebook = self.read(REPO, "canon", "core.md")
|
||||
self.assertLess(len(rulebook.splitlines()), 137)
|
||||
self.assertLessEqual(len(rulebook), 10561)
|
||||
self.assertLess(len(rulebook.splitlines()), 139)
|
||||
self.assertLessEqual(len(rulebook), 10711)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user