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(e2e,parallel-chat): unbreak the test that's been blocking every PR's E2E since 2026-04-29

Louis Beaumontfabdba7ebc75
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 81526a080..3e3fe93aa 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -2039,6 +2039,46 @@ export function StandaloneChat({
useChatStore.getState().actions.setPanelSession(conversationId);
}, [conversationId]);
+ // E2E hook: expose a function to seed a user message into a session.
+ // Required by parallel-chat.spec.ts because `ensureAssistantPlaceholder`
+ // (added 2026-04-29 in e1f55023d) only creates an assistant bubble when
+ // the last message is `role: "user"`. Without a way to inject a user
+ // message, the test's pure pi_event-faking path can't materialize any
+ // assistant DOM and CI has been red on every PR since.
+ // Production impact: zero — only adds a non-functional reference on
+ // window. Not gated by env so the e2e build (which uses prod Next.js
+ // bundling) can reach it.
+ 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)}`;
+ useChatStore.getState().actions.appendMessage(sid, {
+ id,
+ role: "user",
+ content: text,
+ timestamp: Date.now(),
+ } as any);
+ // If the panel is currently rendering this session, mirror into
+ // local state so the placeholder check in the next text_delta sees
+ // a "user" tail. Production never needs this — sendPiMessage handles
+ // both store + local state in one shot.
+ if (sid === piSessionIdRef.current) {
+ setMessages((prev) => [
+ ...prev,
+ {
+ id,
+ role: "user",
+ content: text,
+ timestamp: Date.now(),
+ } as any,
+ ]);
+ }
+ };
+ return () => {
+ delete (window as any).__e2eSeedUserMessage;
+ };
+ }, []);
+
// Cross-window rename sync. The chat-store is window-local (zustand
// lives in each WebView's JS context), so a rename done in the /chat
// overlay would otherwise never reach the chat-sidebar in /home. The
diff --git a/apps/screenpipe-app-tauri/e2e/specs/parallel-chat.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/parallel-chat.spec.ts
index 3f5ab7be3..3226ddec4 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/parallel-chat.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/parallel-chat.spec.ts
@@ -69,9 +69,37 @@ async function switchToSession(id: string): Promise<void> {
await browser.pause(t(400));
}
+/** Seed a user message into a session via the e2e hook the chat panel
+ * exposes on `window.__e2eSeedUserMessage`. Required because
+ * `ensureAssistantPlaceholder` only creates an assistant bubble when the
+ * last message in the session is `role: "user"` (added 2026-04-29) — so
+ * faking pi_event with no preceding user message is a no-op. */
+async function seedUserMessage(sessionId: string, text: string): Promise<void> {
+ await browser.executeAsync(
+ (sid: string, txt: string, done: (v?: unknown) => void) => {
+ const g = globalThis as unknown as {
+ __e2eSeedUserMessage?: (sid: string, txt: string) => void;
+ };
+ if (typeof g.__e2eSeedUserMessage === "function") {
+ g.__e2eSeedUserMessage(sid, txt);
+ }
+ done();
+ },
+ sessionId,
+ text,
+ );
+ await browser.pause(t(100));
+}
+
/** Fake one Pi assistant turn for a session. Forges the same envelope
- * Rust emits: { sessionId, event }. */
+ * Rust emits: { sessionId, event }. Seeds a synthetic user message
+ * first because the panel's placeholder logic requires a user-message
+ * tail before it'll materialize an assistant bubble for streaming
+ * deltas. In production, `sendPiMessage` does this; in tests we do it
+ * via the `__e2eSeedUserMessage` hook. */
async function fakePiTurn(sessionId: string, fullText: string): Promise<void> {
+ await seedUserMessage(sessionId, `(e2e) prompt for: ${fullText}`);
+
await emitFromWebview('pi_event', {
sessionId,
event: { type: 'message_start', message: { role: 'assistant' } },