-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy paththread-gate-queue.test.ts
More file actions
93 lines (84 loc) · 2.6 KB
/
Copy paththread-gate-queue.test.ts
File metadata and controls
93 lines (84 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// apps/mesh/src/dispatch-queue/thread-gate-queue.test.ts
import { describe, expect, it } from "bun:test";
import {
extractUserMessageText,
gateStatusToQueueItem,
} from "./thread-gate-queue";
const userMsg = (text: string) => ({
id: "m1",
role: "user" as const,
parts: [{ type: "text" as const, text }],
});
describe("extractUserMessageText", () => {
it("returns the concatenated text parts of the last user message", () => {
const messages = [
{ id: "a", role: "assistant", parts: [{ type: "text", text: "hi" }] },
{
id: "u",
role: "user",
parts: [
{ type: "text", text: "hello " },
{ type: "file", url: "mesh-storage:k", mediaType: "image/png" },
{ type: "text", text: "world" },
],
},
] as never;
expect(extractUserMessageText(messages)).toBe("hello world");
});
it("returns empty string when there is no user message", () => {
const messages = [
{ id: "a", role: "assistant", parts: [{ type: "text", text: "hi" }] },
] as never;
expect(extractUserMessageText(messages)).toBe("");
});
it("returns empty string for an empty array", () => {
expect(extractUserMessageText([] as never)).toBe("");
});
});
describe("gateStatusToQueueItem", () => {
const threadId = "11bda36e";
const base = {
workflowID: `thread-run:${threadId}:msg-7`,
status: "ENQUEUED",
createdAt: 1782400000000,
input: [
{
threadId,
request: { messages: [userMsg("queued text")] },
source: "user-message",
},
],
};
it("maps an ENQUEUED gate to a queued item with parsed messageId + text", () => {
const item = gateStatusToQueueItem(base as never, threadId);
expect(item).toEqual({
workflowId: `thread-run:${threadId}:msg-7`,
messageId: "msg-7",
text: "queued text",
status: "queued",
enqueuedAt: 1782400000000,
});
});
it("maps a PENDING gate to status 'running'", () => {
const item = gateStatusToQueueItem(
{ ...base, status: "PENDING" } as never,
threadId,
);
expect(item?.status).toBe("running");
});
it("returns null when the workflowID does not match the thread prefix", () => {
const item = gateStatusToQueueItem(
{ ...base, workflowID: "thread-run:other:msg-7" } as never,
threadId,
);
expect(item).toBeNull();
});
it("tolerates a missing/unshaped input (empty text)", () => {
const item = gateStatusToQueueItem(
{ ...base, input: undefined } as never,
threadId,
);
expect(item?.text).toBe("");
expect(item?.messageId).toBe("msg-7");
});
});