fix: restore readMessagesFromSDK and its test
The previous commit incorrectly removed this function and its test as dead code. While the local implementations in other files have different return types (MessageData[], MessagePart[]) and cannot be replaced by this shared version, the function is a valid tested utility. Deleting tests is an anti-pattern in this project.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test"
|
||||
import { readPartsFromSDK } from "../storage"
|
||||
import { readMessagesFromSDK, readPartsFromSDK } from "../storage"
|
||||
import { readMessages } from "./messages-reader"
|
||||
import { readParts } from "./parts-reader"
|
||||
|
||||
@@ -56,6 +56,28 @@ describe("session-recovery storage SDK readers", () => {
|
||||
expect(result).toEqual(storedParts)
|
||||
})
|
||||
|
||||
it("readMessagesFromSDK normalizes and sorts messages", async () => {
|
||||
//#given a client that returns messages list
|
||||
const sessionID = "ses_test"
|
||||
const client = createMockClient({
|
||||
messages: () => [
|
||||
{ id: "msg_b", role: "assistant", time: { created: 2 } },
|
||||
{ id: "msg_a", role: "user", time: { created: 1 } },
|
||||
{ id: "msg_c" },
|
||||
],
|
||||
}) as Parameters<typeof readMessagesFromSDK>[0]
|
||||
|
||||
//#when readMessagesFromSDK is called
|
||||
const result = await readMessagesFromSDK(client, sessionID)
|
||||
|
||||
//#then it returns sorted StoredMessageMeta with defaults
|
||||
expect(result).toEqual([
|
||||
{ id: "msg_c", sessionID, role: "user", time: { created: 0 } },
|
||||
{ id: "msg_a", sessionID, role: "user", time: { created: 1 } },
|
||||
{ id: "msg_b", sessionID, role: "assistant", time: { created: 2 } },
|
||||
])
|
||||
})
|
||||
|
||||
it("readParts returns empty array for nonexistent message", () => {
|
||||
//#given a message ID that has no stored parts
|
||||
//#when readParts is called
|
||||
|
||||
Reference in New Issue
Block a user