Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

test: stabilize chat e2e seeding

Louis Beaumont751c37bbf5d9
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index da2b514ef..c762c7172 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -3944,48 +3944,54 @@ export function StandaloneChat({
// never read from production code paths.
useEffect(() => {
if (typeof window === "undefined") return;
- (window as any).__e2eSeedUserMessage = (sid: string, text: string) => {
- const id = `e2e-user-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
- const userMsg = {
- id,
- role: "user" as const,
- content: text,
- timestamp: Date.now(),
- };
-
- // (2) Ensure the session record exists in the store so subsequent
- // appendMessage / setStreaming / snapshotSession calls actually
- // mutate something. upsert overwrites if existing, so we read first
- // and merge messages by hand.
+ const seedE2eSessionMessage = (
+ sid: string,
+ message: any,
+ preview: string,
+ ) => {
const store = useChatStore.getState();
const existing = store.sessions[sid];
+ const existingMessages = Array.isArray(existing?.messages)
+ ? existing.messages
+ : [];
+ const nextMessages = [...existingMessages, message];
+
if (!existing) {
store.actions.upsert({
id: sid,
title: "e2e",
- preview: text.slice(0, 60),
+ preview,
status: "idle",
- messageCount: 1,
+ messageCount: nextMessages.length,
createdAt: Date.now(),
updatedAt: Date.now(),
pinned: false,
unread: false,
- messages: [userMsg as any],
+ messages: nextMessages,
});
} else {
- store.actions.appendMessage(sid, userMsg as any);
+ store.actions.appendMessage(sid, message, preview);
}
- // (1) Mirror to local React state so `ensureAssistantPlaceholder`
- // sees the user-tail on the next text_delta. Always do this — the
- // test only ever seeds for the about-to-stream session, which is
- // by definition what the panel is rendering.
- setMessages((prev) => [...prev, userMsg as any]);
-
- // (3) Force the session ref in case the panel hasn't finished
- // switching yet. Otherwise text_deltas with this sid would route
- // to the wrong handler.
+ store.actions.setCurrent(sid);
+ store.actions.setPanelSession(sid);
+ setMessages(nextMessages as any);
+ setConversationId(sid);
piSessionIdRef.current = sid;
+ piSessionSyncedRef.current = true;
+ void emit("chat-current-session", { id: sid });
+ };
+
+ (window as any).__e2eSeedUserMessage = (sid: string, text: string) => {
+ const id = `e2e-user-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
+ const userMsg = {
+ id,
+ role: "user" as const,
+ content: text,
+ timestamp: Date.now(),
+ };
+
+ seedE2eSessionMessage(sid, userMsg as any, text.slice(0, 60));
};
// E2E hook: seed a finished assistant message carrying source citations,
@@ -4005,27 +4011,11 @@ export function StandaloneChat({
sourceCitations: payload.sourceCitations ?? [],
};
- const store = useChatStore.getState();
- const existing = store.sessions[sid];
- if (!existing) {
- store.actions.upsert({
- id: sid,
- title: "e2e",
- preview: (payload.content ?? "").slice(0, 60),
- status: "idle",
- messageCount: 1,
- createdAt: Date.now(),
- updatedAt: Date.now(),
- pinned: false,
- unread: false,
- messages: [assistantMsg as any],
- });
- } else {
- store.actions.appendMessage(sid, assistantMsg as any);
- }
-
- setMessages((prev) => [...prev, assistantMsg as any]);
- piSessionIdRef.current = sid;
+ seedE2eSessionMessage(
+ sid,
+ assistantMsg as any,
+ (payload.content ?? "").slice(0, 60),
+ );
};
return () => {
delete (window as any).__e2eSeedUserMessage;
diff --git a/apps/screenpipe-app-tauri/e2e/specs/zz-owned-browser-background-nav.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/zz-owned-browser-background-nav.spec.ts
index 381fdf191..78f2ee86c 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/zz-owned-browser-background-nav.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/zz-owned-browser-background-nav.spec.ts
@@ -196,20 +196,6 @@ async function readBrowserStateCacheUrl(
}, `screenpipe:browser-state:${chatId}`)) as string | null;
}
-async function waitForChatSeedHook(): Promise<void> {
- await browser.waitUntil(
- async () =>
- (await browser.execute(
- () => typeof (window as any).__e2eSeedUserMessage === "function",
- )) as boolean,
- {
- timeout: t(10_000),
- interval: 100,
- timeoutMsg: "E2E chat seed hook did not mount",
- },
- );
-}
-
/** Capture every `chat-current-session` the page emits so the test can prove
* which conversation the on-screen BrowserSidebar is actually bound to. The
* gate is `owner && conversationId && owner !== conversationId`, so a null
@@ -235,20 +221,6 @@ async function installSessionCapture(): Promise<void> {
});
}
-async function seedChat(sessionId: string, text: string): Promise<void> {
- await browser.execute(
- (sid: string, msg: string) => {
- const fn = (window as any).__e2eSeedUserMessage as (
- s: string,
- t: string,
- ) => void;
- fn(sid, msg);
- },
- sessionId,
- text,
- );
-}
-
async function loadChatIntoHome(conversationId: string): Promise<void> {
await browser.executeAsync(
(id: string, done: (v?: unknown) => void) => {
@@ -345,7 +317,6 @@ describe("Owned browser — per-chat navigation ownership", function () {
before(async () => {
await waitForAppReady();
await openHomeWindow();
- await waitForChatSeedHook();
removeChatFile(OWN_CHAT);
});
@@ -362,8 +333,7 @@ describe("Owned browser — per-chat navigation ownership", function () {
// chat-current-session (the gate falls through on a null conversationId,
// so this keeps the assertion honest on the fixed build).
await installSessionCapture();
- await seedChat(OWN_CHAT, "(e2e) owned-browser ownership probe");
- await browser.pause(t(200));
+ writeSeedChatFile(OWN_CHAT, "(e2e) owned-browser ownership probe");
await loadChatIntoHome(OWN_CHAT);
await waitForActiveConversation(OWN_CHAT);
@@ -422,8 +392,7 @@ describe("Owned browser — per-chat navigation ownership", function () {
"reveals the on-screen chat's own agent navigation",
async () => {
await installSessionCapture();
- await seedChat(OWN_CHAT, "(e2e) owned-browser reveal probe");
- await browser.pause(t(200));
+ writeSeedChatFile(OWN_CHAT, "(e2e) owned-browser reveal probe");
await loadChatIntoHome(OWN_CHAT);
await waitForActiveConversation(OWN_CHAT);