Scheduling core, state store, CLI and unit tests
One tick polls in-flight runs, posts results, classifies the first line and moves state/assignee; failures get a structured note with transient retry and backoff, timeouts are killed and handed over, resume failures and long threads rebuild with a handoff summary. Then the lowest Todo items are dispatched within terminal concurrency and serialize groups, and a heartbeat is written. CLI: tick, new, show, comment, state, assign, smoke, check-config.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import unittest
|
||||
|
||||
from agentd.core import build_prompt, handoff_summary
|
||||
|
||||
ISSUE = {"name": "T-1 do it", "description_html": "<p>goal & scope</p>"}
|
||||
COMMENTS = [
|
||||
{"id": "c1", "created_at": "t1", "comment_html": "<p>please also check X</p>"},
|
||||
{"id": "c2", "created_at": "t2", "comment_html": "<p>[worker] 第 1 轮开始</p>"},
|
||||
{"id": "c3", "created_at": "t3", "comment_html": "<p>[codex] 第 1 轮结束</p><pre>[question] A or B?</pre>"},
|
||||
{"id": "c4", "created_at": "t4", "comment_html": "<p>B, please</p>"},
|
||||
]
|
||||
|
||||
|
||||
class PromptTest(unittest.TestCase):
|
||||
def test_fresh_prompt_has_everything_but_worker_comments(self):
|
||||
p = build_prompt("GW-1", ISSUE, COMMENTS, set(), False, protocol="PROTO", intro="INTRO")
|
||||
self.assertTrue(p.startswith("INTRO"))
|
||||
self.assertIn("## 协议\nPROTO", p)
|
||||
self.assertIn("## 工作项 GW-1: T-1 do it\n\ngoal & scope", p)
|
||||
self.assertIn("please also check X", p)
|
||||
self.assertIn("[question] A or B?", p)
|
||||
self.assertNotIn("[worker]", p)
|
||||
self.assertTrue(p.rstrip().endswith("不要等待人工回复。"))
|
||||
|
||||
def test_resumed_prompt_only_new_comments(self):
|
||||
p = build_prompt("GW-1", ISSUE, COMMENTS, {"c1", "c2", "c3"}, True, protocol="PROTO", intro="INTRO")
|
||||
self.assertNotIn("PROTO", p)
|
||||
self.assertNotIn("INTRO", p)
|
||||
self.assertNotIn("please also check X", p)
|
||||
self.assertIn("B, please", p)
|
||||
self.assertIn("同一线程", p)
|
||||
|
||||
def test_resumed_without_new_comments_asks_to_continue(self):
|
||||
p = build_prompt("GW-1", ISSUE, COMMENTS, {"c1", "c2", "c3", "c4"}, True)
|
||||
self.assertIn("没有新评论", p)
|
||||
p = build_prompt("GW-1", ISSUE, COMMENTS, {"c1", "c2", "c3", "c4"}, True, retry_note="RETRY")
|
||||
self.assertIn("RETRY", p)
|
||||
self.assertNotIn("没有新评论", p)
|
||||
|
||||
def test_handoff(self):
|
||||
rec = {"runs": 3, "tags": ["progress", "progress", "question"], "last_message": "[question] A or B?"}
|
||||
h = handoff_summary(rec, "线程已续 3 轮")
|
||||
self.assertIn("3 轮", h)
|
||||
self.assertIn("progress, progress, question", h)
|
||||
self.assertIn("[question] A or B?", h)
|
||||
p = build_prompt("GW-1", ISSUE, COMMENTS, set(), False, handoff=h)
|
||||
self.assertIn("## 交接摘要\n" + h, p)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user