Skip to content

Commit 9d87f56

Browse files
author
Peter Steinberger
committed
fix(qa-lab): support groups and isolate thread timelines
1 parent 82231b4 commit 9d87f56

5 files changed

Lines changed: 271 additions & 17 deletions

File tree

‎extensions/qa-lab/web/src/app.browser.test.ts‎

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { readFileSync } from "node:fs";
33
import path from "node:path";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5-
import type { Bootstrap, RunnerSelection } from "./ui-types.js";
5+
import type { Bootstrap, RunnerSelection, Snapshot } from "./ui-types.js";
66

77
const httpMock = vi.hoisted(() => {
88
class QaLabHttpError extends Error {
@@ -103,14 +103,17 @@ function createBootstrap(selection: RunnerSelection): Bootstrap {
103103
};
104104
}
105105

106-
async function mountRunner(selection: RunnerSelection) {
106+
async function mountRunner(
107+
selection: RunnerSelection,
108+
snapshot: Snapshot = { conversations: [], events: [], messages: [], threads: [] },
109+
) {
107110
let bootstrap = createBootstrap(selection);
108111
httpMock.getJson.mockImplementation(async (url: string) => {
109112
if (url === "/api/bootstrap") {
110113
return bootstrap;
111114
}
112115
if (url === "/api/state") {
113-
return { conversations: [], events: [], messages: [], threads: [] };
116+
return snapshot;
114117
}
115118
if (url === "/api/report") {
116119
return { report: null };
@@ -195,6 +198,66 @@ afterEach(() => {
195198
});
196199

197200
describe("QA Lab runner browser interactions", () => {
201+
it("sends group conversation messages from the interactive chat composer", async () => {
202+
const root = await mountRunner(
203+
{
204+
alternateModel: "mock-openai/gpt-5.6-luna-alt",
205+
channel: null,
206+
channelDriver: "qa-channel",
207+
evidenceMode: "full",
208+
fastMode: false,
209+
primaryModel: "mock-openai/gpt-5.6-luna",
210+
profile: "all",
211+
providerMode: "mock-openai",
212+
runtimePair: null,
213+
runtimePairLane: null,
214+
scenarioIds: ["dm-chat-baseline"],
215+
},
216+
{
217+
conversations: [{ accountId: "default", id: "qa-room", kind: "channel" }],
218+
events: [],
219+
messages: [],
220+
threads: [
221+
{
222+
accountId: "default",
223+
conversationId: "qa-room",
224+
id: "owned-thread",
225+
title: "Owned thread",
226+
},
227+
],
228+
},
229+
);
230+
httpMock.postJson.mockResolvedValue({ message: { id: "group-message" } });
231+
232+
root.querySelector<HTMLButtonElement>("[data-thread-select='owned-thread']")?.click();
233+
selectValue(root, "#conversation-kind", "group");
234+
const conversationInput = root.querySelector<HTMLInputElement>("#conversation-id");
235+
if (!conversationInput) {
236+
throw new Error("missing group conversation input");
237+
}
238+
conversationInput.value = "qa-group";
239+
conversationInput.dispatchEvent(new Event("input", { bubbles: true }));
240+
const composer = root.querySelector<HTMLTextAreaElement>("#composer-text");
241+
if (!composer) {
242+
throw new Error("missing group message composer");
243+
}
244+
composer.value = "hello group";
245+
composer.dispatchEvent(new Event("input", { bubbles: true }));
246+
root.querySelector<HTMLButtonElement>("[data-action='send']")?.click();
247+
248+
await vi.waitFor(() => expect(httpMock.postJson).toHaveBeenCalledTimes(1));
249+
expect(httpMock.postJson).toHaveBeenCalledWith(
250+
"/api/inbound/message",
251+
expect.objectContaining({
252+
accountId: "default",
253+
conversation: { id: "qa-group", kind: "group", title: "qa-group" },
254+
text: "hello group",
255+
}),
256+
);
257+
const submittedPayload = httpMock.postJson.mock.calls[0]?.[1] as Record<string, unknown>;
258+
expect(submittedPayload).not.toHaveProperty("threadId");
259+
});
260+
198261
it("keeps scenario rows from collapsing inside the scrolling list", async () => {
199262
const root = await mountRunner({
200263
alternateModel: "mock-openai/gpt-5.6-luna-alt",

‎extensions/qa-lab/web/src/app.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,23 +579,29 @@ export async function createQaLabApp(root: HTMLDivElement) {
579579
state.selectedConversationKey,
580580
);
581581
const accountId = selectedConversation?.accountId ?? "default";
582+
const selectedThreadId =
583+
selectedConversation?.id === conversationId &&
584+
selectedConversation.kind === state.composer.conversationKind
585+
? state.selectedThreadId
586+
: null;
582587
await postJson("/api/inbound/message", {
583588
accountId,
584589
conversation: {
585590
id: conversationId,
586591
kind: state.composer.conversationKind,
587-
...(state.composer.conversationKind === "channel" ? { title: conversationId } : {}),
592+
...(state.composer.conversationKind !== "direct" ? { title: conversationId } : {}),
588593
},
589594
senderId: state.composer.senderId.trim() || "alice",
590595
senderName: state.composer.senderName.trim() || undefined,
591596
text,
592-
...(state.selectedThreadId ? { threadId: state.selectedThreadId } : {}),
597+
...(selectedThreadId ? { threadId: selectedThreadId } : {}),
593598
});
594599
state.selectedConversationKey = conversationSelectionKey({
595600
accountId,
596601
id: conversationId,
597602
kind: state.composer.conversationKind,
598603
});
604+
state.selectedThreadId = selectedThreadId;
599605
state.composer.text = "";
600606
chatScrollLocked = true;
601607
await refresh();
@@ -1737,8 +1743,9 @@ export async function createQaLabApp(root: HTMLDivElement) {
17371743

17381744
/* Composer form */
17391745
root.querySelector<HTMLSelectElement>("#conversation-kind")?.addEventListener("change", (e) => {
1746+
const selectedKind = (e.currentTarget as HTMLSelectElement).value;
17401747
state.composer.conversationKind =
1741-
(e.currentTarget as HTMLSelectElement).value === "channel" ? "channel" : "direct";
1748+
selectedKind === "channel" || selectedKind === "group" ? selectedKind : "direct";
17421749
});
17431750
root.querySelector<HTMLInputElement>("#conversation-id")?.addEventListener("input", (e) => {
17441751
state.composer.conversationId = (e.currentTarget as HTMLInputElement).value;

‎extensions/qa-lab/web/src/ui-render-content.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,24 @@ function deriveSelectedThread(state: UiState): string | null {
6969

7070
function filteredMessages(state: UiState) {
7171
const messages = state.snapshot?.messages ?? [];
72+
const selectedConversationThreadIds = new Set(
73+
(state.snapshot?.threads ?? [])
74+
.filter((thread) => threadConversationSelectionKey(thread) === state.selectedConversationKey)
75+
.map((thread) => thread.id),
76+
);
7277
return messages.filter((message) => {
7378
if (
7479
state.selectedConversationKey &&
7580
messageConversationSelectionKey(message) !== state.selectedConversationKey
7681
) {
7782
return false;
7883
}
79-
if (state.selectedThreadId && message.threadId !== state.selectedThreadId) {
80-
return false;
84+
if (state.selectedThreadId) {
85+
return message.threadId === state.selectedThreadId;
8186
}
82-
return true;
87+
// External thread ids have no sidebar record, even when the conversation
88+
// also owns navigable threads, so keep their messages in the root view.
89+
return !message.threadId || !selectedConversationThreadIds.has(message.threadId);
8390
});
8491
}
8592

@@ -88,18 +95,28 @@ function formatConversationLabel(
8895
conversations: Conversation[],
8996
): string {
9097
const label = conversation.title || conversation.id;
91-
const hasAccountCollision = conversations.some(
98+
const sidebarCollisions = conversations.filter(
9299
(candidate) =>
93-
candidate.accountId !== conversation.accountId &&
94-
candidate.kind === conversation.kind &&
95-
candidate.id === conversation.id,
100+
candidate !== conversation &&
101+
candidate.id === conversation.id &&
102+
(candidate.kind === "direct") === (conversation.kind === "direct"),
103+
);
104+
const hasAccountCollision = sidebarCollisions.some(
105+
(candidate) => candidate.accountId !== conversation.accountId,
106+
);
107+
const hasKindCollision = sidebarCollisions.some(
108+
(candidate) => candidate.kind !== conversation.kind,
96109
);
97-
return hasAccountCollision ? `${label} (${conversation.accountId})` : label;
110+
const disambiguators = [
111+
...(hasKindCollision ? [conversation.kind] : []),
112+
...(hasAccountCollision ? [conversation.accountId] : []),
113+
];
114+
return disambiguators.length > 0 ? `${label} (${disambiguators.join(", ")})` : label;
98115
}
99116

100117
export function renderChatView(state: UiState): string {
101118
const conversations = state.snapshot?.conversations ?? [];
102-
const channels = conversations.filter((c) => c.kind === "channel");
119+
const channels = conversations.filter((c) => c.kind === "channel" || c.kind === "group");
103120
const dms = conversations.filter((c) => c.kind === "direct");
104121
const threads = (state.snapshot?.threads ?? []).filter(
105122
(thread) =>
@@ -205,6 +222,7 @@ export function renderChatView(state: UiState): string {
205222
<select id="conversation-kind">
206223
<option value="direct"${state.composer.conversationKind === "direct" ? " selected" : ""}>DM</option>
207224
<option value="channel"${state.composer.conversationKind === "channel" ? " selected" : ""}>Channel</option>
225+
<option value="group"${state.composer.conversationKind === "group" ? " selected" : ""}>Group</option>
208226
</select>
209227
<span>as</span>
210228
<input id="sender-name" value="${esc(state.composer.senderName)}" placeholder="Name" />

‎extensions/qa-lab/web/src/ui-render.test.ts‎

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,172 @@ describe("QA Lab UI evidence render", () => {
158158
expect(html).toContain(
159159
`data-conversation-key="${selectedConversationKey.replaceAll('"', "&quot;")}"`,
160160
);
161+
162+
const crossAccountKindHtml = renderQaLabUi(
163+
evidenceState({
164+
activeTab: "chat",
165+
snapshot: {
166+
conversations: [
167+
{ accountId: "account-a", id: "shared", kind: "group" },
168+
{ accountId: "account-b", id: "shared", kind: "channel" },
169+
],
170+
events: [],
171+
messages: [],
172+
threads: [],
173+
},
174+
}),
175+
);
176+
expect(crossAccountKindHtml).toContain("shared (group, account-a)");
177+
expect(crossAccountKindHtml).toContain("shared (channel, account-b)");
178+
});
179+
180+
it("shows group conversations in the sidebar and composer without leaking same-id rooms", () => {
181+
const selectedConversationKey = JSON.stringify(["account-a", "group", "shared"]);
182+
const html = renderQaLabUi(
183+
evidenceState({
184+
activeTab: "chat",
185+
selectedConversationKey,
186+
composer: {
187+
conversationId: "shared",
188+
conversationKind: "group",
189+
senderId: "alice",
190+
senderName: "Alice",
191+
text: "",
192+
},
193+
snapshot: {
194+
conversations: [
195+
{ accountId: "account-a", id: "shared", kind: "group" },
196+
{ accountId: "account-b", id: "shared", kind: "group" },
197+
{ accountId: "account-a", id: "shared", kind: "channel" },
198+
{ accountId: "account-a", id: "shared", kind: "direct" },
199+
],
200+
events: [],
201+
messages: [
202+
{
203+
accountId: "account-a",
204+
conversation: { id: "shared", kind: "group" },
205+
direction: "inbound",
206+
id: "selected-group-message",
207+
reactions: [],
208+
senderId: "alice",
209+
text: "selected group message",
210+
timestamp: 1,
211+
},
212+
{
213+
accountId: "account-b",
214+
conversation: { id: "shared", kind: "group" },
215+
direction: "inbound",
216+
id: "foreign-group-message",
217+
reactions: [],
218+
senderId: "bob",
219+
text: "foreign group message",
220+
timestamp: 2,
221+
},
222+
{
223+
accountId: "account-a",
224+
conversation: { id: "shared", kind: "channel" },
225+
direction: "outbound",
226+
id: "same-id-channel-message",
227+
reactions: [],
228+
senderId: "openclaw",
229+
text: "same-id channel message",
230+
timestamp: 3,
231+
},
232+
],
233+
threads: [],
234+
},
235+
}),
236+
);
237+
238+
expect(html).toContain("shared (group, account-a)");
239+
expect(html).toContain("shared (group, account-b)");
240+
expect(html).toContain("shared (channel, account-a)");
241+
expect(html).toContain("selected group message");
242+
expect(html).not.toContain("foreign group message");
243+
expect(html).not.toContain("same-id channel message");
244+
expect(html).toContain('<option value="group" selected>Group</option>');
245+
expect(html).toContain(
246+
`data-conversation-key="${selectedConversationKey.replaceAll('"', "&quot;")}"`,
247+
);
248+
});
249+
250+
it("keeps thread replies out of the root timeline when thread navigation exists", () => {
251+
const selectedConversationKey = JSON.stringify(["default", "channel", "qa-room"]);
252+
const snapshot: NonNullable<UiState["snapshot"]> = {
253+
conversations: [{ accountId: "default", id: "qa-room", kind: "channel" }],
254+
events: [],
255+
messages: [
256+
{
257+
accountId: "default",
258+
conversation: { id: "qa-room", kind: "channel" },
259+
direction: "outbound",
260+
id: "root-message",
261+
reactions: [],
262+
senderId: "openclaw",
263+
text: "root timeline message",
264+
timestamp: 1,
265+
},
266+
{
267+
accountId: "default",
268+
conversation: { id: "qa-room", kind: "channel" },
269+
direction: "outbound",
270+
id: "thread-message",
271+
reactions: [],
272+
senderId: "openclaw",
273+
text: "thread-only reply",
274+
threadId: "owned-thread",
275+
timestamp: 2,
276+
},
277+
{
278+
accountId: "default",
279+
conversation: { id: "qa-room", kind: "channel" },
280+
direction: "outbound",
281+
id: "external-thread-message",
282+
reactions: [],
283+
senderId: "openclaw",
284+
text: "externally observed thread reply",
285+
threadId: "external-thread",
286+
timestamp: 3,
287+
},
288+
],
289+
threads: [
290+
{
291+
accountId: "default",
292+
conversationId: "qa-room",
293+
id: "owned-thread",
294+
title: "Owned thread",
295+
},
296+
],
297+
};
298+
299+
const rootHtml = renderQaLabUi(
300+
evidenceState({ activeTab: "chat", selectedConversationKey, snapshot }),
301+
);
302+
expect(rootHtml).toContain("Main timeline");
303+
expect(rootHtml).toContain("root timeline message");
304+
expect(rootHtml).not.toContain("thread-only reply");
305+
expect(rootHtml).toContain("externally observed thread reply");
306+
307+
const threadHtml = renderQaLabUi(
308+
evidenceState({
309+
activeTab: "chat",
310+
selectedConversationKey,
311+
selectedThreadId: "owned-thread",
312+
snapshot,
313+
}),
314+
);
315+
expect(threadHtml).not.toContain("root timeline message");
316+
expect(threadHtml).toContain("thread-only reply");
317+
expect(threadHtml).not.toContain("externally observed thread reply");
318+
319+
const externalThreadHtml = renderQaLabUi(
320+
evidenceState({
321+
activeTab: "chat",
322+
selectedConversationKey,
323+
snapshot: { ...snapshot, threads: [] },
324+
}),
325+
);
326+
expect(externalThreadHtml).toContain("thread-only reply");
161327
});
162328

163329
it("renders capture startup commands without personal home paths", () => {

0 commit comments

Comments
 (0)