forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-config.spec.ts
More file actions
165 lines (145 loc) · 5.29 KB
/
Copy pathagent-config.spec.ts
File metadata and controls
165 lines (145 loc) · 5.29 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { test, expect } from "@playwright/test";
test.describe("Agent Config Object", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/demos/agent-config");
});
test("page loads with config card and default dropdown values", async ({
page,
}) => {
await expect(
page.getByRole("heading", { name: "Agent Config" }),
).toBeVisible();
await expect(
page.locator('[data-testid="agent-config-card"]'),
).toBeVisible();
await expect(
page.locator('[data-testid="agent-config-tone-select"]'),
).toHaveValue("professional");
await expect(
page.locator('[data-testid="agent-config-expertise-select"]'),
).toHaveValue("intermediate");
await expect(
page.locator('[data-testid="agent-config-length-select"]'),
).toHaveValue("concise");
await expect(page.getByPlaceholder("Type a message")).toBeVisible();
});
test("changing a dropdown updates its DOM value immediately", async ({
page,
}) => {
const toneSelect = page.locator('[data-testid="agent-config-tone-select"]');
await toneSelect.selectOption("enthusiastic");
await expect(toneSelect).toHaveValue("enthusiastic");
const expertiseSelect = page.locator(
'[data-testid="agent-config-expertise-select"]',
);
await expertiseSelect.selectOption("expert");
await expect(expertiseSelect).toHaveValue("expert");
const lengthSelect = page.locator(
'[data-testid="agent-config-length-select"]',
);
await lengthSelect.selectOption("detailed");
await expect(lengthSelect).toHaveValue("detailed");
});
test("send produces an assistant response", async ({ page }) => {
const input = page.getByPlaceholder("Type a message");
await input.fill("Hello");
await input.press("Enter");
await expect(
page.locator('[data-testid="copilot-assistant-message"]').first(),
).toBeVisible({
timeout: 30000,
});
});
test("properties object propagates to runtime requests", async ({ page }) => {
const requestBodies: string[] = [];
await page.route("**/api/copilotkit-agent-config**", async (route) => {
const req = route.request();
if (req.method() === "POST") {
const body = req.postData() ?? "";
requestBodies.push(body);
}
await route.continue();
});
// Change all three dropdowns from defaults
await page
.locator('[data-testid="agent-config-tone-select"]')
.selectOption("enthusiastic");
await page
.locator('[data-testid="agent-config-expertise-select"]')
.selectOption("expert");
await page
.locator('[data-testid="agent-config-length-select"]')
.selectOption("detailed");
// Send
const input = page.getByPlaceholder("Type a message");
await input.fill("Hello");
await input.press("Enter");
// Wait for at least one POST to land
await expect
.poll(() => requestBodies.length, { timeout: 15000 })
.toBeGreaterThan(0);
const payload = requestBodies.join("\n");
expect(payload).toContain("enthusiastic");
expect(payload).toContain("expert");
expect(payload).toContain("detailed");
});
test("changing config between sends produces distinct request payloads", async ({
page,
}) => {
// Only capture agent/run POSTs — agent/stop requests arrive
// asynchronously and would pollute the "afterChange" slice.
const requestBodies: string[] = [];
await page.route("**/api/copilotkit-agent-config**", async (route) => {
const req = route.request();
if (req.method() === "POST") {
const body = req.postData() ?? "";
try {
const parsed = JSON.parse(body);
if (parsed.method === "agent/stop") {
await route.continue();
return;
}
} catch {
// non-JSON body — keep it
}
requestBodies.push(body);
}
await route.continue();
});
const input = page.getByPlaceholder("Type a message");
// Send 1 with defaults
await input.fill("First");
await input.press("Enter");
await expect(
page.locator('[data-testid="copilot-assistant-message"]').first(),
).toBeVisible({
timeout: 30000,
});
// Wait for the chat to finish processing (data-copilot-running="false")
// before attempting the second send — some backends finalize the SSE
// stream slightly after the assistant message is rendered.
await expect(page.locator('[data-copilot-running="false"]')).toBeVisible({
timeout: 15000,
});
const firstCount = requestBodies.length;
// Change config
await page
.locator('[data-testid="agent-config-tone-select"]')
.selectOption("casual");
await page
.locator('[data-testid="agent-config-length-select"]')
.selectOption("detailed");
// Send 2
await input.fill("Second");
await input.press("Enter");
await expect
.poll(() => requestBodies.length, { timeout: 15000 })
.toBeGreaterThan(firstCount);
const beforeChange = requestBodies.slice(0, firstCount).join("\n");
const afterChange = requestBodies.slice(firstCount).join("\n");
expect(beforeChange).toContain("professional");
expect(beforeChange).toContain("concise");
expect(afterChange).toContain("casual");
expect(afterChange).toContain("detailed");
});
});