This commit is contained in:
+39
-72
@@ -1,4 +1,4 @@
|
||||
"""Behavioral coverage for the two-human plus two-AI test mode."""
|
||||
"""Behavioral coverage for AI team enrollment in CS autochess."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -11,7 +11,7 @@ from test_jwebot_edge import MODULE, config
|
||||
from jwebot_official_extensions import cs_autochess as AUTOCHESS
|
||||
|
||||
|
||||
class Release065TwoHumanAiTests(unittest.TestCase):
|
||||
class Release065AiEnrollmentTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.engine = MODULE.EdgeApplication(config(Path(self.temp.name)))
|
||||
@@ -23,15 +23,20 @@ class Release065TwoHumanAiTests(unittest.TestCase):
|
||||
|
||||
def command(self, question, *, sender="Alice", event_id=None):
|
||||
self.counter += 1
|
||||
return self.engine.local.handle(
|
||||
response = self.engine.accept(
|
||||
{
|
||||
"question": question,
|
||||
"sender": sender,
|
||||
"group_fingerprint": "group-a",
|
||||
"event_id": event_id or f"two-ai-{self.counter}",
|
||||
},
|
||||
{},
|
||||
"group_fingerprint": "group-a",
|
||||
"sender": sender,
|
||||
"text": "@JWeBot " + question,
|
||||
"mention_bot": True,
|
||||
"confidence": 1.0,
|
||||
"sender_confidence": 1.0,
|
||||
"body_confidence": 1.0,
|
||||
}
|
||||
)
|
||||
self.assertEqual(response["status"], "reply")
|
||||
return list(response.get("texts") or [response["text"]])
|
||||
|
||||
def state(self):
|
||||
row = self.engine.ledger.connection.execute(
|
||||
@@ -45,88 +50,50 @@ class Release065TwoHumanAiTests(unittest.TestCase):
|
||||
self.assertIsNotNone(row)
|
||||
return json.loads(row[0])
|
||||
|
||||
def test_two_humans_add_two_ai_and_use_four_seed_bracket(self):
|
||||
def test_two_humans_add_two_ai_and_lock_registration(self):
|
||||
self.command("/自走棋开始")
|
||||
self.command("/自走棋报名", sender="Bob")
|
||||
added = self.command("/自走棋加AI战队")
|
||||
added = "\n".join(self.command("/自走棋加AI战队"))
|
||||
|
||||
self.assertIn("AI 战队 A、AI 战队 B", added)
|
||||
self.assertIn("第 3、4 种子", added)
|
||||
self.assertIn("2 人+2 AI", added)
|
||||
self.assertIn(
|
||||
"已经锁定参赛名单",
|
||||
self.command("/自走棋报名", sender="Carol"),
|
||||
"已经锁定",
|
||||
"\n".join(self.command("/自走棋报名", sender="Carol")),
|
||||
)
|
||||
|
||||
launch = self.command("/自走棋开赛")
|
||||
launch = "\n".join(self.command("/自走棋开赛"))
|
||||
state = self.state()
|
||||
self.assertIn("2 人+2 AI 测试赛", launch)
|
||||
self.assertEqual(state["ai_test_variant"], "two_plus_two")
|
||||
self.assertEqual(
|
||||
state["seed_order"][2:],
|
||||
[
|
||||
AUTOCHESS.AI_PERSON_KEY,
|
||||
AUTOCHESS.AI_SECOND_PERSON_KEY,
|
||||
],
|
||||
)
|
||||
self.assertEqual(
|
||||
state["preparation_order"],
|
||||
state["seed_order"][:2],
|
||||
)
|
||||
self.assertTrue(
|
||||
state["players"][AUTOCHESS.AI_PERSON_KEY]["is_ai"]
|
||||
)
|
||||
self.assertTrue(
|
||||
state["players"][AUTOCHESS.AI_SECOND_PERSON_KEY]["is_ai"]
|
||||
)
|
||||
semifinal = state["round_plan"][-2]
|
||||
self.assertEqual(
|
||||
semifinal["pairs"],
|
||||
[
|
||||
[state["seed_order"][0], state["seed_order"][3]],
|
||||
[state["seed_order"][1], state["seed_order"][2]],
|
||||
],
|
||||
[AUTOCHESS.AI_PERSON_KEY, AUTOCHESS.AI_SECOND_PERSON_KEY],
|
||||
)
|
||||
|
||||
self.assertIn("到 bob 做准备了", self.command("/结束回合"))
|
||||
self.assertIn(
|
||||
"全员准备完毕",
|
||||
self.command("/结束回合", sender="Bob"),
|
||||
)
|
||||
settled = self.command("/自走棋结算")
|
||||
self.assertIn("AI 战队 A 自动运营", settled)
|
||||
self.assertIn("AI 战队 B 自动运营", settled)
|
||||
self.assertEqual(
|
||||
self.engine.ledger.connection.execute(
|
||||
"""
|
||||
SELECT COUNT(*) FROM autochess_story_logs
|
||||
WHERE story_type = 'ai_operation'
|
||||
"""
|
||||
).fetchone()[0],
|
||||
2,
|
||||
)
|
||||
|
||||
def test_add_two_ai_is_idempotent_and_cannot_be_repeated(self):
|
||||
def test_three_humans_add_one_ai(self):
|
||||
self.command("/自走棋开始")
|
||||
self.command("/自走棋报名", sender="Bob")
|
||||
first = self.command(
|
||||
"/自走棋加AI战队",
|
||||
event_id="same-add-two-ai",
|
||||
)
|
||||
replay = self.command(
|
||||
"/自走棋加AI战队",
|
||||
event_id="same-add-two-ai",
|
||||
)
|
||||
self.command("/自走棋报名", sender="Carol")
|
||||
added = "\n".join(self.command("/自走棋加AI战队"))
|
||||
self.assertIn("3 人+1 AI", added)
|
||||
|
||||
self.command("/自走棋开赛")
|
||||
state = self.state()
|
||||
self.assertEqual(state["ai_test_variant"], "three_plus_one")
|
||||
self.assertEqual(state["seed_order"][-1], AUTOCHESS.AI_PERSON_KEY)
|
||||
self.assertTrue(state["players"][AUTOCHESS.AI_PERSON_KEY]["is_ai"])
|
||||
|
||||
def test_add_ai_replay_is_idempotent(self):
|
||||
self.command("/自走棋开始")
|
||||
self.command("/自走棋报名", sender="Bob")
|
||||
first = self.command("/自走棋加AI战队", event_id="same-add-two-ai")
|
||||
replay = self.command("/自走棋加AI战队", event_id="same-add-two-ai")
|
||||
self.assertEqual(first, replay)
|
||||
self.assertIn(
|
||||
"已经加入",
|
||||
self.command("/自走棋加AI战队"),
|
||||
)
|
||||
self.assertIn("已经加入", "\n".join(self.command("/自走棋加AI战队")))
|
||||
|
||||
state = self.state()
|
||||
self.assertEqual(
|
||||
sum(
|
||||
bool(player.get("is_ai"))
|
||||
for player in state["players"].values()
|
||||
),
|
||||
sum(bool(player.get("is_ai")) for player in state["players"].values()),
|
||||
2,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user