MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / test_recorder

Method test_recorder

tests/explorer/proxy_test.py:38–85  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

36 os.remove(db_path)
37
38 async def test_recorder(self):
39 recorder = HistoryRecorder(
40 db_url="sqlite:///" + db_path,
41 table_name="experience",
42 )
43 self.assertIsInstance(recorder, HistoryRecorder)
44
45 experiences_1 = get_dummy_experience(3)
46 await recorder.record_history(experiences_1)
47
48 msg_ids_1 = [exp.eid.suffix for exp in experiences_1]
49 experiences_2 = get_dummy_experience(2)
50 await recorder.record_history(experiences_2)
51 updated_experiences = await recorder.update_reward(
52 reward=1.0, msg_ids=msg_ids_1, run_id=1, task_id="test_task"
53 )
54 self.assertEqual(len(updated_experiences), 3)
55 for exp in updated_experiences:
56 self.assertEqual(exp.reward, 1.0)
57 self.assertEqual(exp.eid.run, 1)
58 self.assertEqual(str(exp.eid.task), "test_task")
59
60 updated_experiences_empty = await recorder.update_reward(
61 reward=2.0, msg_ids=["non_existing_id"], run_id=1, task_id="test_task"
62 )
63 self.assertEqual(len(updated_experiences_empty), 0)
64
65 await recorder.record_history([])
66
67 updated_experiences_2 = await recorder.update_reward(
68 reward=3.0,
69 msg_ids=[exp.eid.suffix for exp in experiences_2],
70 run_id=2,
71 task_id="test_task_2",
72 )
73 self.assertEqual(len(updated_experiences_2), 2)
74 for exp in updated_experiences_2:
75 self.assertEqual(exp.reward, 3.0)
76 self.assertEqual(exp.eid.run, 2)
77 self.assertEqual(str(exp.eid.task), "test_task_2")
78
79 updated_experiences_3 = await recorder.update_reward(
80 reward=4.0,
81 msg_ids=[exp.eid.suffix for exp in experiences_2],
82 run_id=3,
83 task_id="test_task_3",
84 )
85 self.assertEqual(len(updated_experiences_3), 0) # already consumed

Callers

nothing calls this directly

Calls 4

record_historyMethod · 0.95
update_rewardMethod · 0.95
HistoryRecorderClass · 0.90
get_dummy_experienceFunction · 0.85

Tested by

no test coverage detected