-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathinterrupt.test.ts
More file actions
78 lines (73 loc) · 2.23 KB
/
Copy pathinterrupt.test.ts
File metadata and controls
78 lines (73 loc) · 2.23 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
import { EventType } from "@ag-ui/client";
import { createRunRenderer } from "@copilotkit/channels/slack/render";
import { describe, expect, it, vi } from "vitest";
import { parseConfirmWriteInterrupt } from "./interrupt.js";
const realEnvelope = {
__copilotkit_interrupt_value__: {
action: "confirm_write",
args: {
action: "Create Linear issue",
detail: "CPK-9: Checkout 500s",
},
},
__copilotkit_messages__: [
{
content: "",
type: "ai",
tool_calls: [
{
id: "tool-confirm-write",
name: "confirm_write",
args: {
action: "Create Linear issue",
detail: "CPK-9: Checkout 500s",
},
type: "tool_call",
},
],
},
],
};
describe("parseConfirmWriteInterrupt", () => {
it("parses ag_ui_langgraph's JSON-stringified interrupt envelope", () => {
expect(parseConfirmWriteInterrupt(JSON.stringify(realEnvelope))).toEqual(
realEnvelope.__copilotkit_interrupt_value__,
);
});
it("parses the object produced by the canary Slack renderer", () => {
const renderer = createRunRenderer({
transport: {
setStatus: vi.fn(async () => undefined),
postMessage: vi.fn(async () => ({ ts: "1.0" })),
updateMessage: vi.fn(async () => undefined),
},
target: { channel: "C1", threadTs: "1.0" },
});
renderer.subscriber.onCustomEvent?.({
event: {
type: EventType.CUSTOM,
name: "on_interrupt",
value: JSON.stringify(realEnvelope),
},
} as never);
const renderedPayload = renderer.getPendingInterrupt()?.value;
expect(renderedPayload).toEqual(realEnvelope);
expect(parseConfirmWriteInterrupt(renderedPayload)).toEqual(
realEnvelope.__copilotkit_interrupt_value__,
);
});
it("rejects malformed envelopes and other actions", () => {
expect(() =>
parseConfirmWriteInterrupt(
JSON.stringify({
...realEnvelope,
__copilotkit_interrupt_value__: {
action: "delete_without_confirmation",
args: { action: "Delete everything" },
},
}),
),
).toThrow(/confirm_write/);
expect(() => parseConfirmWriteInterrupt("{broken")).toThrow();
});
});