Relay turned Autopilot off (every /autopilot route renders the "not available" page), so the five upstream specs in e2e_tests/autopilot/ are skipped explicitly with that reason. New autopilot-unavailable.spec.ts (runs in the default suite) asserts /autopilot, /autopilot/sessions, /autopilot/sessions/new and a session URL answer 501 with the unavailable heading, and that the home sidebar has no Autopilot links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
421 lines
15 KiB
TypeScript
421 lines
15 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { v7 } from "uuid";
|
|
|
|
// Relay does not offer Autopilot: it depends on TensorZero's hosted Autopilot
|
|
// service, so every /autopilot route renders the "not available" page
|
|
// (app/routes/autopilot/layout.tsx) and these upstream session flows cannot
|
|
// run. Skipped explicitly; the unavailable page itself is covered by
|
|
// e2e_tests/autopilot-unavailable.spec.ts.
|
|
test.skip(
|
|
true,
|
|
"Autopilot is not available in Relay (/autopilot renders the unavailable page)",
|
|
);
|
|
|
|
test("should interrupt an active session", async ({ page }) => {
|
|
// Increase timeout for this test since it involves LLM responses
|
|
test.setTimeout(120000);
|
|
|
|
// Navigate to autopilot sessions
|
|
await page.goto("/autopilot/sessions");
|
|
|
|
// Wait for the page to load
|
|
await expect(
|
|
page.getByRole("heading", { name: "Autopilot Sessions" }),
|
|
).toBeVisible();
|
|
|
|
// Click to create a new session
|
|
await page.getByRole("button", { name: /new session/i }).click();
|
|
|
|
// Wait for the new session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/new/);
|
|
|
|
// Find the message textarea and type a message that will trigger tool calls
|
|
const messageInput = page.getByRole("textbox");
|
|
// We randomize this message so it misses the provider proxy cache and we have time to click the stop button
|
|
await messageInput.fill(
|
|
`What functions are available in my TensorZero config? ${v7()}`,
|
|
);
|
|
|
|
// Send the message
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// Wait for redirect to the actual session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// Wait for the stop button to appear (session is processing)
|
|
const stopButton = page.getByRole("button", {
|
|
name: /stop session/i,
|
|
});
|
|
await expect(stopButton).toBeVisible({ timeout: 30000 });
|
|
|
|
// Click the stop button
|
|
await stopButton.click();
|
|
|
|
// Verify the status update message appears in the event stream
|
|
await expect(page.getByText("Interrupted session")).toBeVisible({
|
|
timeout: 10000,
|
|
});
|
|
|
|
// Verify the send button reappears after interruption (session returns to idle)
|
|
const sendButton = page.getByRole("button", { name: /send message/i });
|
|
await expect(sendButton).toBeVisible({ timeout: 30000 });
|
|
|
|
// Verify the status indicator shows "Ready" (which is the label for "idle" status)
|
|
await expect(page.getByText("Ready")).toBeVisible({ timeout: 10000 });
|
|
|
|
// Verify no error message is shown - the session should be cleanly idle, not failed
|
|
await expect(page.getByText("Something went wrong")).not.toBeVisible();
|
|
});
|
|
|
|
test("should create a session, send a message, approve tool calls, and get a response", async ({
|
|
page,
|
|
}) => {
|
|
// Increase timeout for this test since it involves LLM responses
|
|
test.setTimeout(120000);
|
|
|
|
// Navigate to autopilot sessions
|
|
await page.goto("/autopilot/sessions");
|
|
|
|
// Wait for the page to load
|
|
await expect(
|
|
page.getByRole("heading", { name: "Autopilot Sessions" }),
|
|
).toBeVisible();
|
|
|
|
// Click to create a new session
|
|
await page.getByRole("button", { name: /new session/i }).click();
|
|
|
|
// Wait for the new session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/new/);
|
|
|
|
// Find the message textarea and type a message that triggers a non-whitelisted tool
|
|
// (delete_datapoints is not in the default whitelist, so it requires manual approval)
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
"Use the delete_datapoints tool to delete datapoint ID '00000000-0000-7000-0000-000000000000' from dataset 'foo'. Call the tool directly without using any other tools first.",
|
|
);
|
|
|
|
// Send the message (button has aria-label="Send message")
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
// Wait for redirect to the actual session page
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// Verify the message appears in the conversation
|
|
await expect(page.getByText("Use the delete_datapoints tool")).toBeVisible();
|
|
|
|
// Wait for the Approve button to appear (delete_datapoints is not whitelisted for auto-approval)
|
|
const approveButton = page.getByRole("button", { name: "Approve" }).first();
|
|
await expect(approveButton).toBeVisible({ timeout: 60000 });
|
|
|
|
// Approve the tool call
|
|
await approveButton.click();
|
|
|
|
// Verify the tool result appeared (confirming tool was approved and executed)
|
|
// The tool_result event renders as "Tool Call" with a "Success" status badge
|
|
await expect(page.getByText("Success").first()).toBeVisible({
|
|
timeout: 60000,
|
|
});
|
|
});
|
|
|
|
test.describe("Chat input validation", () => {
|
|
test("send button disabled when empty, enabled with text", async ({
|
|
page,
|
|
}) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
const textarea = page.getByRole("textbox");
|
|
const sendButton = page.getByRole("button", { name: "Send message" });
|
|
|
|
// Empty → disabled
|
|
await expect(sendButton).toBeDisabled();
|
|
|
|
// Whitespace only → still disabled
|
|
await textarea.fill(" ");
|
|
await expect(sendButton).toBeDisabled();
|
|
|
|
// Real text → enabled
|
|
await textarea.fill("Hello");
|
|
await expect(sendButton).toBeEnabled();
|
|
|
|
// Clear → disabled again
|
|
await textarea.fill("");
|
|
await expect(sendButton).toBeDisabled();
|
|
});
|
|
|
|
test("Shift+Enter inserts newline without sending", async ({ page }) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
const textarea = page.getByRole("textbox");
|
|
await textarea.fill("Line 1");
|
|
await textarea.press("Shift+Enter");
|
|
await textarea.type("Line 2");
|
|
|
|
// Should still be on new session page (not submitted)
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/new/);
|
|
await expect(textarea).toHaveValue("Line 1\nLine 2");
|
|
});
|
|
});
|
|
|
|
// Skipped: autopilot sidebar hard-disabled upstream in #7347
|
|
test.describe.skip("Autopilot New Session Button", () => {
|
|
test("should navigate to new session from existing session page", async ({
|
|
page,
|
|
}) => {
|
|
// 1. Go to autopilot sessions list
|
|
await page.goto("/autopilot/sessions");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 2. Click the first session in the table
|
|
const firstSessionLink = page
|
|
.locator("table a[href^='/autopilot/sessions/']")
|
|
.first();
|
|
await firstSessionLink.waitFor({ state: "visible" });
|
|
await firstSessionLink.click();
|
|
|
|
// 3. Wait for session page to load
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
// 4. Click "New Session" link in the header
|
|
const newSessionLink = page.getByRole("link", { name: "New Session" });
|
|
await newSessionLink.waitFor({ state: "visible" });
|
|
await newSessionLink.click();
|
|
|
|
// 5. Verify navigation to /autopilot/sessions/new and page stays there
|
|
await page.waitForURL("**/autopilot/sessions/new", { timeout: 10000 });
|
|
await page.waitForLoadState("networkidle");
|
|
expect(page.url()).toMatch(/\/autopilot\/sessions\/new$/);
|
|
});
|
|
});
|
|
|
|
test.describe("Scroll blur overlays", () => {
|
|
test("top fade is hidden on new session at rest", async ({ page }) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
const topFade = page.getByTestId("scroll-fade-top");
|
|
await expect(topFade).toHaveCSS("opacity", "0");
|
|
});
|
|
|
|
test("bottom fade is hidden on new session at rest", async ({ page }) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
const bottomFade = page.getByTestId("scroll-fade-bottom");
|
|
await expect(bottomFade).toHaveCSS("opacity", "0");
|
|
});
|
|
});
|
|
|
|
test.describe("YOLO mode", () => {
|
|
test("toggle is visible and defaults to off", async ({ page }) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
|
|
const yoloToggle = page
|
|
.locator("label")
|
|
.filter({ hasText: "YOLO Mode" })
|
|
.getByRole("switch");
|
|
await expect(yoloToggle).toBeVisible();
|
|
await expect(yoloToggle).toHaveAttribute("data-state", "unchecked");
|
|
});
|
|
|
|
test("reads persisted state from localStorage on page load", async ({
|
|
page,
|
|
}) => {
|
|
await page.goto("/autopilot/sessions/new");
|
|
await page.evaluate(() =>
|
|
localStorage.setItem("tensorzero-yolo-mode", "true"),
|
|
);
|
|
await page.reload();
|
|
|
|
const yoloToggle = page
|
|
.locator("label")
|
|
.filter({ hasText: "YOLO Mode" })
|
|
.getByRole("switch");
|
|
await expect(yoloToggle).toBeVisible();
|
|
await expect(yoloToggle).toHaveAttribute("data-state", "checked");
|
|
});
|
|
|
|
test("clicking toggle enables auto-approval of tool calls", async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(120000);
|
|
|
|
await page.goto("/autopilot/sessions/new");
|
|
|
|
const yoloLabel = page.locator("label").filter({ hasText: "YOLO Mode" });
|
|
const yoloToggle = yoloLabel.getByRole("switch");
|
|
await expect(yoloToggle).toBeVisible();
|
|
await yoloLabel.click();
|
|
await expect(yoloToggle).toHaveAttribute("data-state", "checked");
|
|
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
"What functions are available in my TensorZero config?",
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// "Success" badge appearing confirms tool was auto-approved and executed
|
|
await expect(page.getByText("Success").first()).toBeVisible({
|
|
timeout: 60000,
|
|
});
|
|
});
|
|
});
|
|
|
|
test.describe("Tool call authorization deduplication", () => {
|
|
test("spam-clicking Approve sends only one request", async ({ page }) => {
|
|
test.setTimeout(120000);
|
|
|
|
// Track requests by tool_call_event_id to scope assertion to the clicked tool call
|
|
const requestsByToolCallId = new Map<string, number>();
|
|
let firstToolCallId: string | null = null;
|
|
|
|
await page.route("**/events/authorize", async (route) => {
|
|
const body = route.request().postDataJSON();
|
|
const toolCallId = body?.tool_call_event_id;
|
|
if (toolCallId) {
|
|
if (!firstToolCallId) {
|
|
firstToolCallId = toolCallId;
|
|
}
|
|
requestsByToolCallId.set(
|
|
toolCallId,
|
|
(requestsByToolCallId.get(toolCallId) ?? 0) + 1,
|
|
);
|
|
}
|
|
await route.continue();
|
|
});
|
|
|
|
await page.goto("/autopilot/sessions/new");
|
|
|
|
// Use a non-whitelisted tool so the Approve button appears
|
|
// (delete_datapoints is not in the default whitelist)
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
"Use the delete_datapoints tool to delete datapoint ID '00000000-0000-7000-0000-000000000000' from dataset 'foo'. Call the tool directly without using any other tools first.",
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// Wait for Approve button to appear
|
|
const approveButton = page.getByRole("button", { name: "Approve" }).first();
|
|
await expect(approveButton).toBeVisible({ timeout: 60000 });
|
|
|
|
// Get button position before clicking - use mouse.click at fixed coordinates
|
|
// to avoid flakiness if the button is removed/disabled after first click
|
|
const boundingBox = await approveButton.boundingBox();
|
|
if (!boundingBox) {
|
|
throw new Error("Approve button bounding box not found");
|
|
}
|
|
const clickX = boundingBox.x + boundingBox.width / 2;
|
|
const clickY = boundingBox.y + boundingBox.height / 2;
|
|
|
|
// Spam-click at the fixed position rapidly
|
|
await Promise.all([
|
|
page.mouse.click(clickX, clickY),
|
|
page.mouse.click(clickX, clickY),
|
|
page.mouse.click(clickX, clickY),
|
|
]);
|
|
|
|
// Wait for request to complete
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Only count requests for the first tool call (the one we spam-clicked)
|
|
const requestCount = firstToolCallId
|
|
? (requestsByToolCallId.get(firstToolCallId) ?? 0)
|
|
: 0;
|
|
expect(
|
|
requestCount,
|
|
"Spam-clicking Approve should send only one request for the same tool call",
|
|
).toBe(1);
|
|
});
|
|
|
|
test("spam-clicking Reject sends only one request", async ({ page }) => {
|
|
test.setTimeout(120000);
|
|
|
|
// Track requests by tool_call_event_id to scope assertion to the clicked tool call
|
|
const requestsByToolCallId = new Map<string, number>();
|
|
let firstToolCallId: string | null = null;
|
|
|
|
await page.route("**/events/authorize", async (route) => {
|
|
const body = route.request().postDataJSON();
|
|
const toolCallId = body?.tool_call_event_id;
|
|
if (toolCallId) {
|
|
if (!firstToolCallId) {
|
|
firstToolCallId = toolCallId;
|
|
}
|
|
requestsByToolCallId.set(
|
|
toolCallId,
|
|
(requestsByToolCallId.get(toolCallId) ?? 0) + 1,
|
|
);
|
|
}
|
|
await route.continue();
|
|
});
|
|
|
|
await page.goto("/autopilot/sessions/new");
|
|
|
|
// Use a non-whitelisted tool so the Reject button appears
|
|
// (delete_datapoints is not in the default whitelist)
|
|
const messageInput = page.getByRole("textbox");
|
|
await messageInput.fill(
|
|
"Use the delete_datapoints tool to delete datapoint ID '00000000-0000-7000-0000-000000000000' from dataset 'foo'. Call the tool directly without using any other tools first.",
|
|
);
|
|
await page.getByRole("button", { name: "Send message" }).click();
|
|
|
|
await expect(page).toHaveURL(/\/autopilot\/sessions\/[a-f0-9-]+$/, {
|
|
timeout: 30000,
|
|
});
|
|
|
|
// Wait for Reject button to appear
|
|
const rejectButton = page.getByRole("button", { name: "Reject" }).first();
|
|
await expect(rejectButton).toBeVisible({ timeout: 60000 });
|
|
|
|
// Click Reject to show confirmation
|
|
await rejectButton.click();
|
|
|
|
// Wait for and spam-click the confirm button (button has aria-label="Confirm rejection")
|
|
const confirmButton = page
|
|
.getByRole("button", { name: "Confirm rejection" })
|
|
.first();
|
|
await expect(confirmButton).toBeVisible();
|
|
|
|
// Get button position before clicking - use mouse.click at fixed coordinates
|
|
// to avoid flakiness if the button is removed/disabled after first click
|
|
const boundingBox = await confirmButton.boundingBox();
|
|
if (!boundingBox) {
|
|
throw new Error("Confirm rejection button bounding box not found");
|
|
}
|
|
const clickX = boundingBox.x + boundingBox.width / 2;
|
|
const clickY = boundingBox.y + boundingBox.height / 2;
|
|
|
|
// Spam-click at the fixed position rapidly
|
|
await Promise.all([
|
|
page.mouse.click(clickX, clickY),
|
|
page.mouse.click(clickX, clickY),
|
|
page.mouse.click(clickX, clickY),
|
|
]);
|
|
|
|
// Wait for request to complete
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Only count requests for the first tool call (the one we spam-clicked)
|
|
const requestCount = firstToolCallId
|
|
? (requestsByToolCallId.get(firstToolCallId) ?? 0)
|
|
: 0;
|
|
expect(
|
|
requestCount,
|
|
"Spam-clicking Reject confirm should send only one request for the same tool call",
|
|
).toBe(1);
|
|
});
|
|
});
|