Files
kandev/apps/web/e2e/tests/chat/mobile-clarification.spec.ts
T
nova28 c82668c789 feat(mcp): expose agent clarification questions and permission requests externally (#2875)
Co-authored-by: Vojtěch Biberle <vojtech.biberle@gmail.com>
Co-authored-by: nova28 <17953305+nova28@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
2026-08-22 15:39:40 +00:00

223 lines
8.4 KiB
TypeScript

import { test, expect } from "../../fixtures/test-base";
import { seedClarificationSession } from "../../helpers/clarification";
/**
* Mobile parity for the multiline custom clarification answer. On a coarse-pointer
* device Enter inserts a newline instead of submitting, and the send affordance is
* the inline "Send" button (there is no overlay Submit button for single-question
* bundles). Runs under the Pixel 5 `mobile-chrome` project.
*/
test.describe("Mobile clarification multiline answer", () => {
test.describe.configure({ retries: 1, timeout: 120_000 });
test("Auto-run ON does not bypass a pending clarification on mobile", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await seedClarificationSession(
testPage,
apiClient,
seedData,
"Mobile Clarify Composer Queue",
{ scenario: "clarification" },
);
await expect(session.clarificationOverlay()).toBeVisible({ timeout: 30_000 });
const composer = session.activeChat().getByTestId("chat-input-editor");
await expect(composer).toHaveAttribute("contenteditable", "true", { timeout: 30_000 });
await composer.pressSequentially("Queue this from phone 1", { timeout: 30_000 });
await expect(composer).toContainText("Queue this from phone 1");
await expect(session.clarificationOverlay()).toBeVisible();
await testPage.getByTestId("submit-message-button").tap();
await expect(testPage.getByTestId("queue-chip")).toBeVisible({ timeout: 10_000 });
await expect(session.clarificationOverlay()).toBeVisible();
await testPage.getByTestId("queue-chip").tap();
const panel = testPage.getByTestId("queued-ghost-list");
await expect(panel).toBeVisible();
const autoRun = panel.getByTestId("queue-auto-run");
await expect(autoRun).toHaveAttribute("data-state", "checked");
await autoRun.tap();
await expect(autoRun).toHaveAttribute("data-state", "unchecked");
await autoRun.tap();
await expect(autoRun).toHaveAttribute("data-state", "checked");
await expect(panel.getByTestId("queue-entry")).toHaveCount(1);
await expect(session.clarificationOverlay()).toBeVisible();
});
test("Enter inserts a newline and the Send button submits the multiline answer", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await seedClarificationSession(
testPage,
apiClient,
seedData,
"Mobile Clarify",
{
scenario: "clarification",
},
);
await expect(session.clarificationOverlay()).toBeVisible({ timeout: 30_000 });
const input = session.clarificationInput();
// Tap the apparent row surface, outside the textarea itself. The whole row
// is the mobile touch target and should transfer focus into the textarea.
await session.clarificationCustomInput().tap({ position: { x: 4, y: 4 } });
await expect(input).toBeFocused();
await input.pressSequentially("first line");
// On touch, Enter inserts a newline rather than submitting.
await input.press("Enter");
await input.pressSequentially("second line");
await expect(input).toHaveValue("first line\nsecond line");
// The overlay is still open — Enter did not submit.
await expect(session.clarificationOverlay()).toBeVisible();
// The inline Send button is the touch send affordance.
await expect(session.clarificationCustomSubmit()).toBeVisible();
await session.clarificationCustomSubmit().tap();
await expect(session.idleInput()).toBeVisible({ timeout: 30_000 });
await expect(session.chat).toContainText("first line");
await expect(session.chat).toContainText("second line");
await expect(session.chat).not.toContainText("linesecond line");
});
test("keeps the over-limit counter inside the phone viewport", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await seedClarificationSession(
testPage,
apiClient,
seedData,
"Mobile Clarify Limit",
{ scenario: "clarification" },
);
await expect(session.clarificationOverlay()).toBeVisible({ timeout: 30_000 });
await session.clarificationInput().fill("a".repeat(2001));
const counter = session.clarificationOverlay().getByTestId("clarification-input-rune-counter");
await expect(counter).toHaveAttribute("data-over-limit", "true");
const [counterBox, overlayBox] = await Promise.all([
counter.boundingBox(),
session.clarificationOverlay().boundingBox(),
]);
if (!counterBox || !overlayBox) {
throw new Error("expected mobile counter and overlay to have bounding boxes");
}
expect(counterBox.x).toBeGreaterThanOrEqual(overlayBox.x - 1);
expect(counterBox.x + counterBox.width).toBeLessThanOrEqual(
overlayBox.x + overlayBox.width + 1,
);
expect(
await testPage.evaluate(
() => document.documentElement.scrollWidth <= document.documentElement.clientWidth,
),
).toBe(true);
});
test("shows shared context once above the question on mobile", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await seedClarificationSession(
testPage,
apiClient,
seedData,
"Mobile Clarify Shared Context",
{ scenario: "clarification-multi" },
);
await expect(session.clarificationOverlay()).toBeVisible({ timeout: 30_000 });
const context = session.clarificationContext();
await expect(context).toHaveCount(1);
await expect(context).toHaveText(
"Picking the foundational stack.\n\nAnswer all three so we can move forward.",
);
await expect(context).not.toContainText(String.raw`\n`);
await expect(context).toHaveCSS("font-size", "13px");
await expect(context).toHaveCSS("margin-top", "12px");
await expect(context).toHaveCSS("padding", "0px");
await expect(context).toHaveCSS("border-width", "0px");
await expect(context).toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
await expect(
session.clarificationQuestionCards().getByTestId("clarification-context"),
).toHaveCount(0);
const [contextBox, overlayBox] = await Promise.all([
context.boundingBox(),
session.clarificationOverlay().boundingBox(),
]);
if (!contextBox || !overlayBox) {
throw new Error("expected mobile shared context and overlay to have bounding boxes");
}
expect(contextBox.x).toBeGreaterThanOrEqual(overlayBox.x - 1);
expect(contextBox.x + contextBox.width).toBeLessThanOrEqual(
overlayBox.x + overlayBox.width + 1,
);
expect(
await testPage.evaluate(
() => document.documentElement.scrollWidth <= document.documentElement.clientWidth,
),
).toBe(true);
await session.clarificationStep(1).tap();
await expect(session.clarificationStep(1)).toHaveAttribute("data-active", "true");
await expect(context).toHaveCount(1);
});
test("shows a loading spinner while batch answers submit on mobile", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await seedClarificationSession(
testPage,
apiClient,
seedData,
"Mobile Clarify Submit Feedback",
{ scenario: "clarification-multi" },
);
await expect(session.clarificationOverlay()).toBeVisible({ timeout: 30_000 });
await session.clarificationOption("PostgreSQL").tap();
await session.clarificationOption("Go").tap();
await session.clarificationOption("Docker").tap();
let releaseResponse = () => undefined;
const heldResponse = new Promise<void>((resolve) => {
releaseResponse = resolve;
});
await testPage.route("**/api/v1/clarification/*/respond", async (route) => {
await heldResponse;
await route.fulfill({ status: 200, contentType: "application/json", body: "{}" });
});
const submit = session.clarificationSubmit();
await expect(submit).toBeEnabled();
await submit.tap();
await expect(submit).toContainText("Submitting");
await expect(submit).toBeDisabled();
await expect(submit.locator('[role="status"]')).toBeVisible();
await expect(submit.locator('[role="status"]')).toHaveAttribute("aria-hidden", "true");
await expect(submit.locator("svg.tabler-icon-check")).toHaveCount(0);
await expect(
testPage.evaluate(
() => document.documentElement.scrollWidth <= document.documentElement.clientWidth,
),
).resolves.toBe(true);
releaseResponse();
await expect(session.clarificationOverlay()).not.toBeVisible({ timeout: 30_000 });
});
});