forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming_fidelity.test.ts
More file actions
74 lines (58 loc) · 2.69 KB
/
Copy pathstreaming_fidelity.test.ts
File metadata and controls
74 lines (58 loc) · 2.69 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { describe, expect, it } from "vitest";
import { SessionEvent, approveAll } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext";
describe("Streaming Fidelity", async () => {
const { copilotClient: client } = await createSdkTestContext();
it("should produce delta events when streaming is enabled", async () => {
const session = await client.createSession({
onPermissionRequest: approveAll,
streaming: true,
});
const events: SessionEvent[] = [];
session.on((event) => {
events.push(event);
});
await session.sendAndWait({
prompt: "Count from 1 to 5, separated by commas.",
});
const types = events.map((e) => e.type);
// Should have streaming deltas before the final message
const deltaEvents = events.filter((e) => e.type === "assistant.message_delta");
expect(deltaEvents.length).toBeGreaterThanOrEqual(1);
// Deltas should have content
for (const delta of deltaEvents) {
expect(delta.data.deltaContent).toBeDefined();
expect(typeof delta.data.deltaContent).toBe("string");
}
// Should still have a final assistant.message
expect(types).toContain("assistant.message");
// Deltas should come before the final message
const firstDeltaIdx = types.indexOf("assistant.message_delta");
const lastAssistantIdx = types.lastIndexOf("assistant.message");
expect(firstDeltaIdx).toBeLessThan(lastAssistantIdx);
await session.destroy();
});
it("should not produce deltas when streaming is disabled", async () => {
const session = await client.createSession({
onPermissionRequest: approveAll,
streaming: false,
});
const events: SessionEvent[] = [];
session.on((event) => {
events.push(event);
});
await session.sendAndWait({
prompt: "Say 'hello world'.",
});
const deltaEvents = events.filter((e) => e.type === "assistant.message_delta");
// No deltas when streaming is off
expect(deltaEvents.length).toBe(0);
// But should still have a final assistant.message
const assistantEvents = events.filter((e) => e.type === "assistant.message");
expect(assistantEvents.length).toBeGreaterThanOrEqual(1);
await session.destroy();
});
});