Skip to content

Commit 774b4cd

Browse files
committed
Move ListHashUtil hash test to core
1 parent 0d4bbd6 commit 774b4cd

2 files changed

Lines changed: 49 additions & 43 deletions

File tree

agentscope-core/src/test/java/io/agentscope/core/session/ListHashUtilTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,55 @@ void testComputeHashSameListSameHash() {
5555
assertEquals(hash1, hash2);
5656
}
5757

58+
@Test
59+
void testComputeHashEquivalentMessageLists() {
60+
List<Msg> first =
61+
List.of(
62+
Msg.builder()
63+
.id("m-user-1")
64+
.timestamp("2026-05-08 14:00:00.000")
65+
.role(MsgRole.USER)
66+
.content(TextBlock.builder().text("hello").build())
67+
.build(),
68+
Msg.builder()
69+
.id("m-assistant-1")
70+
.timestamp("2026-05-08 14:00:01.000")
71+
.role(MsgRole.ASSISTANT)
72+
.content(TextBlock.builder().text("hello").build())
73+
.build());
74+
75+
List<Msg> second =
76+
List.of(
77+
Msg.builder()
78+
.id("m-user-1")
79+
.timestamp("2026-05-08 14:00:00.000")
80+
.role(MsgRole.USER)
81+
.content(TextBlock.builder().text("hello").build())
82+
.build(),
83+
Msg.builder()
84+
.id("m-assistant-1")
85+
.timestamp("2026-05-08 14:00:01.000")
86+
.role(MsgRole.ASSISTANT)
87+
.content(TextBlock.builder().text("hello").build())
88+
.build());
89+
90+
String h1 = ListHashUtil.computeHash(first);
91+
String h2 = ListHashUtil.computeHash(second);
92+
93+
assertEquals(h1, h2);
94+
}
95+
96+
@Test
97+
void testComputeHashListWithNullItem() {
98+
List<Msg> list = new ArrayList<>();
99+
list.add(null);
100+
101+
String hash1 = ListHashUtil.computeHash(list);
102+
String hash2 = ListHashUtil.computeHash(list);
103+
104+
assertEquals(hash1, hash2);
105+
}
106+
58107
@Test
59108
void testComputeHashListModifiedDifferentHash() {
60109
List<Msg> list = createMsgList(5);

agentscope-extensions/agentscope-extensions-session-mysql/src/test/java/io/agentscope/core/session/mysql/MysqlSessionTest.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
import static org.mockito.Mockito.verify;
2626
import static org.mockito.Mockito.when;
2727

28-
import io.agentscope.core.message.Msg;
29-
import io.agentscope.core.message.MsgRole;
30-
import io.agentscope.core.message.TextBlock;
31-
import io.agentscope.core.session.ListHashUtil;
3228
import io.agentscope.core.state.SessionKey;
3329
import io.agentscope.core.state.SimpleSessionKey;
3430
import io.agentscope.core.state.State;
@@ -286,45 +282,6 @@ void testSaveAndGetListState() throws SQLException {
286282
assertEquals("value2", loaded.get(1).value());
287283
}
288284

289-
@Test
290-
@DisplayName("Should compute same hash for equivalent message lists")
291-
void testComputeHashEquivalentMessageLists() {
292-
List<Msg> first =
293-
List.of(
294-
Msg.builder()
295-
.id("m-user-1")
296-
.timestamp("2026-05-08 14:00:00.000")
297-
.role(MsgRole.USER)
298-
.content(TextBlock.builder().text("hello").build())
299-
.build(),
300-
Msg.builder()
301-
.id("m-assistant-1")
302-
.timestamp("2026-05-08 14:00:01.000")
303-
.role(MsgRole.ASSISTANT)
304-
.content(TextBlock.builder().text("hello").build())
305-
.build());
306-
307-
List<Msg> second =
308-
List.of(
309-
Msg.builder()
310-
.id("m-user-1")
311-
.timestamp("2026-05-08 14:00:00.000")
312-
.role(MsgRole.USER)
313-
.content(TextBlock.builder().text("hello").build())
314-
.build(),
315-
Msg.builder()
316-
.id("m-assistant-1")
317-
.timestamp("2026-05-08 14:00:01.000")
318-
.role(MsgRole.ASSISTANT)
319-
.content(TextBlock.builder().text("hello").build())
320-
.build());
321-
322-
String h1 = ListHashUtil.computeHash(first);
323-
String h2 = ListHashUtil.computeHash(second);
324-
325-
assertEquals(h1, h2);
326-
}
327-
328285
@Test
329286
@DisplayName("Should commit incremental list save when connection auto-commit is disabled")
330287
void testSaveListIncrementalAppendCommitsWhenAutoCommitDisabled() throws SQLException {

0 commit comments

Comments
 (0)