Files
paseo/packages/app/e2e/support/helpers/assistant-fork.ts
T
Mohamed BoudraandGitHub 5a30affd7f Skip unrelated required checks without losing their names (#2542)
* fix(ci): skip unrelated required checks cleanly

Matrix jobs had to start no-op runners to preserve interpolated required-check names. Static named jobs let GitHub report genuine skipped conclusions while keeping those names stable.

* fix(ci): gate changes to install patching script

* fix(ci): route cross-package test contracts narrowly

* fix(ci): keep routed contracts merge-blocking

* fix(server): exclude nested test utilities from builds

* fix(ci): cover app-owned native and browser domains

* refactor(ci): align tests with runtime domains

Own browser specs, desktop specs, and Electron-only app code by stable directories so PR routing does not depend on filename conventions. Keep desktop integration coverage inside the required desktop check.

* fix(ci): keep routing and desktop suites isolated

The routing regression must run before dependency installation, and desktop Vitest must not collect Playwright-owned specs.

* fix(ci): isolate desktop e2e runtime

* perf(test): isolate Playwright workers

* perf(test): parallelize Playwright within specs

* fix(test): keep Playwright file scheduling

* fix(test): share dynamic Metro fixture

* fix(test): preserve own-host restart fixtures

* fix(ci): preserve routed contracts after rebase

* Stabilize Playwright wheel-scroll assertions
2026-08-02 00:56:05 +08:00

115 lines
3.9 KiB
TypeScript

import { expect, type Page } from "@playwright/test";
import { scrollAgentChatToBottom } from "./agent-bottom-anchor";
import { getE2EDaemonPort } from "./daemon-port";
type WebSocketMessage = string | Buffer;
interface SessionMessage {
type?: unknown;
payload?: unknown;
}
interface ForkContextResponsePayload {
attachment?: { text?: unknown } | null;
}
function readSessionMessage(message: WebSocketMessage): SessionMessage | null {
if (typeof message !== "string") return null;
try {
const envelope = JSON.parse(message) as { type?: unknown; message?: SessionMessage };
return envelope.type === "session" ? (envelope.message ?? null) : envelope;
} catch {
return null;
}
}
export function observeForkAttachment(page: Page): {
waitForText: () => Promise<string>;
} {
const attachmentTexts: string[] = [];
const daemonPortMarker = `:${getE2EDaemonPort()}`;
page.on("websocket", (socket) => {
if (!socket.url().includes(daemonPortMarker)) return;
socket.on("framereceived", ({ payload }) => {
const message = readSessionMessage(payload);
if (message?.type === "agent.fork_context.response") {
const response = (message.payload ?? {}) as ForkContextResponsePayload;
attachmentTexts.push(String(response.attachment?.text ?? ""));
}
});
});
return {
async waitForText() {
await expect.poll(() => attachmentTexts.length, { timeout: 30_000 }).toBeGreaterThan(0);
const text = attachmentTexts.at(-1);
if (text === undefined) {
throw new Error("Expected a chat history attachment from the fork");
}
return text;
},
};
}
function inFlightTurn(page: Page) {
return page.getByTestId("turn-working-indicator");
}
async function openForkMenu(page: Page, trigger: ReturnType<Page["getByRole"]>): Promise<void> {
await trigger.click();
await expect(page.getByRole("button", { name: "Fork in a new tab" })).toBeVisible({
timeout: 10_000,
});
}
export async function openMostRecentAssistantForkMenu(page: Page): Promise<void> {
await expect
.poll(
async () => {
await scrollAgentChatToBottom(page);
return page.getByRole("button", { name: "Fork chat" }).count();
},
{ timeout: 30_000 },
)
.toBeGreaterThan(0);
const trigger = page.getByRole("button", { name: "Fork chat" }).last();
await expect(trigger).toBeVisible({ timeout: 30_000 });
await openForkMenu(page, trigger);
}
export async function forkMostRecentAssistantTurnToNewTab(page: Page): Promise<void> {
await openMostRecentAssistantForkMenu(page);
await page.getByRole("button", { name: "Fork in a new tab" }).click();
}
export async function expectInFlightForkAvailable(page: Page): Promise<void> {
const trigger = inFlightTurn(page).getByRole("button", { name: "Fork chat" });
await expect(trigger).toHaveCount(1, { timeout: 30_000 });
await expect(trigger).toBeVisible();
}
export async function forkInFlightTurnToNewTab(page: Page): Promise<void> {
const trigger = inFlightTurn(page).getByRole("button", { name: "Fork chat" });
await openForkMenu(page, trigger);
await page.getByRole("button", { name: "Fork in a new tab" }).click();
}
export async function forkMostRecentAssistantTurnToNewWorkspace(page: Page): Promise<void> {
await openMostRecentAssistantForkMenu(page);
await page.getByRole("button", { name: "Fork in a new workspace" }).click();
}
export async function expectChatHistoryAttachment(page: Page): Promise<void> {
const attachment = page.getByRole("button", { name: "Open chat history attachment" }).first();
await expect(attachment).toBeVisible({ timeout: 30_000 });
await expect(attachment).toContainText("Chat history");
}
export async function expectLiveAssistantText(page: Page, text: string): Promise<void> {
await expect(inFlightTurn(page)).toBeVisible({ timeout: 30_000 });
await expect(page.getByTestId("assistant-message").last()).toContainText(text, {
timeout: 60_000,
});
}