Skip to content

Commit 789afd1

Browse files
committed
test(ui): scope cross-agent outbox proof to the active pane
Retained hidden panes can contain the same conversation output. Keep strict visible-owner assertions and require one canonical reply and one send instead of querying every cached pane in the page. Keep fixture session and run identities tied to the agent, not its busy flag, and verify that recovery history queries retain the Work owner. Reproduced both page-wide locator failures before correction. The original 26-file selection and fitting siblings pass; timeouts, runtime behavior, and deliberate raw-event fault injection remain unchanged.
1 parent 1038fb3 commit 789afd1

1 file changed

Lines changed: 50 additions & 13 deletions

File tree

‎ui/src/e2e/chat-outbox-agent-scope.e2e.test.ts‎

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ suite.define(() => {
2424
viewport: { height: 900, width: 1280 },
2525
});
2626
const page = await context.newPage();
27+
const activePane = page.locator(".chat-pane-cache__pane--active");
2728
const agentsList = {
2829
agents: [
2930
{ id: "main", name: "Main" },
@@ -33,11 +34,11 @@ suite.define(() => {
3334
mainKey: "main",
3435
scope: "global",
3536
};
36-
const historyResponse = (active: boolean) => ({
37+
const historyResponse = (agentId: "main" | "work", active: boolean) => ({
3738
messages: [],
38-
sessionId: active ? "main-global-session" : "work-global-session",
39+
sessionId: `${agentId}-global-session`,
3940
sessionInfo: {
40-
activeRunIds: active ? ["main-active-run"] : [],
41+
activeRunIds: active ? [`${agentId}-active-run`] : [],
4142
hasActiveRun: active,
4243
key: "global",
4344
status: active ? "running" : "done",
@@ -63,19 +64,25 @@ suite.define(() => {
6364
"agents.list": agentsList,
6465
"chat.history": {
6566
cases: [
66-
{ match: { agentId: "work", sessionKey: "global" }, response: historyResponse(true) },
67-
{ match: { agentId: "main", sessionKey: "global" }, response: historyResponse(true) },
67+
{
68+
match: { agentId: "work", sessionKey: "global" },
69+
response: historyResponse("work", true),
70+
},
71+
{
72+
match: { agentId: "main", sessionKey: "global" },
73+
response: historyResponse("main", true),
74+
},
6875
],
6976
},
7077
"chat.startup": {
7178
cases: [
7279
{
7380
match: { agentId: "work" },
74-
response: { ...historyResponse(false), agentsList },
81+
response: { ...historyResponse("work", false), agentsList },
7582
},
7683
{
7784
match: { agentId: "main" },
78-
response: { ...historyResponse(true), agentsList },
85+
response: { ...historyResponse("main", true), agentsList },
7986
},
8087
],
8188
},
@@ -144,8 +151,14 @@ suite.define(() => {
144151
await gateway.deferNext("chat.send");
145152
await gateway.setMethodResponse("chat.history", {
146153
cases: [
147-
{ match: { agentId: "work", sessionKey: "global" }, response: historyResponse(false) },
148-
{ match: { agentId: "main", sessionKey: "global" }, response: historyResponse(true) },
154+
{
155+
match: { agentId: "work", sessionKey: "global" },
156+
response: historyResponse("work", false),
157+
},
158+
{
159+
match: { agentId: "main", sessionKey: "global" },
160+
response: historyResponse("main", true),
161+
},
149162
],
150163
});
151164
await gateway.emitGatewayEvent("sessions.changed", {
@@ -162,6 +175,17 @@ suite.define(() => {
162175
expect(params).toMatchObject({ agentId: "work", message: prompt, sessionKey: "global" });
163176
const runId = requireString(params.idempotencyKey, "inactive-agent outbox run id");
164177
await expectRequestCountStable(gateway, "chat.send", 1);
178+
const recoveryRequests = (await gateway.getRequests("chat.history"))
179+
.map((entry) => requireRecord(entry.params))
180+
.filter((historyParams) => Array.isArray(historyParams.inputRunIds));
181+
expect(recoveryRequests.length).toBeGreaterThan(0);
182+
for (const historyParams of recoveryRequests) {
183+
expect(historyParams).toMatchObject({
184+
agentId: "work",
185+
sessionKey: "global",
186+
inputRunIds: [runId],
187+
});
188+
}
165189
const workPath = controlUiSessionPath("agent:work:main");
166190
await page.evaluate((pathname) => {
167191
const app = document.querySelector("openclaw-app") as HTMLElement & {
@@ -202,7 +226,7 @@ suite.define(() => {
202226
sessionKey: "global",
203227
status: "running",
204228
});
205-
await page.locator(".chat-group.user").getByText(prompt).waitFor({ timeout: 10_000 });
229+
await activePane.locator(".chat-group.user").getByText(prompt).waitFor({ timeout: 10_000 });
206230
await gateway.resolveDeferred("chat.send", { runId, status: "started" });
207231
if (artifactDir) {
208232
await page.screenshot({
@@ -223,11 +247,24 @@ suite.define(() => {
223247
state: "final",
224248
});
225249
await queue.waitFor({ state: "detached", timeout: 10_000 });
226-
await page
250+
// Retained panes also receive this conversation's events; assert its rendered owner.
251+
const reply = activePane
227252
.locator(".chat-group.assistant")
228-
.getByText("Work outbox delivered.", { exact: true })
229-
.waitFor({ timeout: 10_000 });
253+
.getByText("Work outbox delivered.", { exact: true });
254+
await reply.waitFor({ timeout: 10_000 });
230255
await expectRequestCountStable(gateway, "chat.send", 1);
256+
expect(await activePane.count()).toBe(1);
257+
expect(await reply.count()).toBe(1);
258+
const messages = await activePane.evaluate(
259+
(pane) => (pane as HTMLElement & { state: { chatMessages: unknown[] } }).state.chatMessages,
260+
);
261+
expect(messages.map(requireRecord).filter((message) => message.role === "assistant")).toEqual(
262+
[
263+
expect.objectContaining({
264+
content: [{ text: "Work outbox delivered.", type: "text" }],
265+
}),
266+
],
267+
);
231268
if (artifactDir) {
232269
await page.screenshot({
233270
path: `${artifactDir}/inactive-agent-delivered.png`,

0 commit comments

Comments
 (0)