Q141: reply to a specific message in its thread, and see what each reply answers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 23:01:57 -04:00
1 parent a6ab09d6b5
commit 87c297dd45
17 files changed
+377 -57

No files matched your search

+15
View File
@@ -118,6 +118,21 @@ test("the pinned CEO conversation is the Messages front door", async () => {
await expect(composer).toHaveValue("Draft for the CEO only");
await page.locator(".convo-item", { hasText: "general" }).click();
await expect(composer).toHaveValue("Draft for general");
// A reply goes into the thread of the message it answers, and the timeline says what it answers.
await page.locator(".convo-item").first().click();
const root = chatLog.locator(".chat-message", { hasText: "How are we tracking against the goal?" }).first();
await root.getByRole("button", { name: "Reply in thread" }).click();
const thread = page.getByRole("complementary", { name: "Thread" });
await expect(thread).toContainText("How are we tracking against the goal?");
await thread.getByRole("textbox", { name: "Reply" }).fill("Also: which task is late?");
await thread.getByRole("button", { name: "Send reply" }).click();
await expect(thread.locator(".chat-message", { hasText: "Also: which task is late?" })).toBeVisible();
const reply = chatLog.locator(".chat-message", { hasText: "Also: which task is late?" });
await expect(reply.getByRole("button", { name: /^Replying to Yang/ })).toContainText("How are we tracking against the goal?");
await expect(root).toContainText("1 reply");
await thread.getByRole("button", { name: "Close thread" }).click();
await expect(thread).toHaveCount(0);
} finally {
await app.close();
}
+39
View File
@@ -0,0 +1,39 @@
import { randomUUID } from "node:crypto";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
import { DatabaseConnection } from "../../src/main/database/connection";
import { OrganizationService } from "../../src/main/services/organization-service";
import { ChatService } from "../../src/main/services/chat-service";
import { SnapshotService } from "../../src/main/services/snapshot-service";
import { threadHistory } from "../../src/main/services/chat-history";
describe("a thread's history", () => {
test("holds the whole thread even after newer traffic pushed it out of the recent window", () => {
const connection = new DatabaseConnection(join(tmpdir(), `ac-thread-history-${randomUUID()}.db`));
const chat = new ChatService(connection.db);
let orgId = "";
connection.transaction(() => {
orgId = new OrganizationService(connection.db).createOrganization({ organizationName: "Acme", employeeName: "Yang", mission: "m", goal: "g" });
});
const employeeId = (connection.db.prepare("select id from employees where org_id = ?").get(orgId) as { id: string }).id;
const spaceId = (connection.db.prepare("select id from chat_spaces where org_id = ? and name = 'general'").get(orgId) as { id: string }).id;
const send = (bodyMd: string, threadId: string | null) => connection.transaction(() => chat.sendMessage({
orgId, spaceId, threadId, senderType: "employee", senderId: employeeId, bodyMd, attachmentFileIds: [],
}));
const rootId = send("Root question", null);
const threadId = (connection.db.prepare("select thread_id from chat_messages where id = ?").get(rootId) as { thread_id: string }).thread_id;
send("First answer", threadId);
for (let index = 0; index < 500; index += 1) send(`Filler ${index}`, null);
send("Late answer", threadId);
const snapshot = new SnapshotService(connection.db).load();
expect(snapshot.chatMessages.some((message) => message.id === rootId)).toBe(false);
// The thread of every loaded message is in the snapshot, however many threads are newer.
const loadedThreads = new Set(snapshot.chatThreads.map((thread) => thread.id));
expect(snapshot.chatMessages.filter((message) => message.threadId && !loadedThreads.has(message.threadId))).toEqual([]);
expect(threadHistory(connection.db, orgId, threadId).messages.map((message) => message.bodyMd)).toEqual(["Root question", "First answer", "Late answer"]);
expect(() => threadHistory(connection.db, orgId, "thread_missing")).toThrow("Chat thread was not found.");
connection.close();
}, 60_000);
});