Файли
openidea/e2e/agentComposerClick.spec.ts
T
l0ng-ai b20e7c0817 feat(agents): place image attachments inline in prompts (#7477)
Pasting, dropping or choosing an image in the agent composer inserts an [Image #n] label at the caret with a hover preview; deleting the label removes the attachment (undo restores it), and the prompt is sent as text and image blocks in label order (Copilot gets numbered references plus attachments).

Fixes #7336
2026-12-02 16:31:38 +08:00

136 рядки
5.1 KiB
TypeScript

import type { Page } from "@playwright/test";
import type { AgentTask } from "../src/bindings";
import { expect, test } from "./fixtures";
const task: AgentTask = {
id: "composer-click",
title: "Composer click task",
provider: "codex",
status: "ready",
isolation: "local",
model: null,
cwd: "/dev/acme-api",
branch: null,
base: null,
baseCommit: null,
error: null,
createdMs: 0,
updatedMs: 0,
config: [],
commands: [],
usage: null,
queue: [],
};
async function openTask(page: Page) {
await page.evaluate(async (task) => {
// These modules must load in the browser's Vite realm, not Playwright's Node process.
const storePath = "/src/features/agents/store.ts";
const ipcPath = "/src/platform/ipc.ts";
const store = await import(storePath);
const { commands } = await import(ipcPath);
commands.agentChanges = async () => ({ status: "ok", data: [] });
store.useAgents.setState({
loaded: true,
error: null,
providers: [],
tasks: new Map([[task.id, task]]),
entries: new Map([[task.id, [{ type: "agent", text: "Reply" }]]]),
composers: new Map(),
unread: new Set(),
docked: null,
homeOpen: false,
sessionLocation: "editor",
});
store.openTask(task.id);
}, task);
}
// Every row of the text area, down to the toolbar row, puts the caret in the message.
test("clicking anywhere in the composer's text area focuses the message", async ({ workbench: page }) => {
await openTask(page);
const box = page.getByRole("textbox", { name: "Message", exact: true }).filter({ visible: true });
await expect(box).toBeVisible();
const composer = page.locator("[class*='_composer_']:visible").filter({ has: box });
const bar = composer.locator("[class*='_bar_']");
const frame = (await composer.boundingBox())!;
const barTop = (await bar.boundingBox())!.y;
const history = page.locator("[class*='_stream_']:visible");
const missed: number[] = [];
for (let y = Math.ceil(frame.y) + 1; y < barTop; y++) {
await history.click({ position: { x: 12, y: 12 } });
await expect(box).not.toBeFocused();
await page.mouse.click(frame.x + frame.width / 2, y);
if (!(await box.evaluate((element) => element === document.activeElement))) missed.push(y - frame.y);
}
expect(missed).toEqual([]);
await page.keyboard.type("typed");
await expect(box).toHaveText("typed");
});
test("composer images stay at the caret, preview inline, and send in label order", async ({ workbench: page }) => {
await openTask(page);
await page.evaluate(async () => {
const ipcPath = "/src/platform/ipc.ts";
const { commands } = await import(ipcPath);
commands.agentPrompt = async (_task: string, prompt: unknown) => {
sessionStorage.setItem("composer-image-prompt", JSON.stringify(prompt));
return { status: "ok", data: null };
};
});
const box = page.getByRole("textbox", { name: "Message", exact: true }).filter({ visible: true });
const composer = page.locator("[class*='_composer_']:visible").filter({ has: box });
const png = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jQp0AAAAASUVORK5CYII=";
const dropOrPaste = (type: "paste" | "drop", name: string) =>
box.evaluate(
(el, { type, name, png }) => {
const data = new DataTransfer();
data.items.add(new File([Uint8Array.from(atob(png), (c) => c.charCodeAt(0))], name, { type: "image/png" }));
const event =
type === "paste"
? new ClipboardEvent(type, { clipboardData: data, bubbles: true, cancelable: true })
: new DragEvent(type, { dataTransfer: data, bubbles: true, cancelable: true });
el.dispatchEvent(event);
},
{ type, name, png },
);
await box.click();
await page.keyboard.insertText("left right");
for (const _char of "right") {
// oxlint-disable-next-line no-await-in-loop -- move the caret one character at a time
await box.press("ArrowLeft");
}
await dropOrPaste("paste", "first.png");
await expect(box).toHaveText("left [Image #1]right");
await box.getByText("[Image #1]", { exact: true }).hover();
await expect(page.getByRole("img", { name: "first.png" })).toBeVisible();
await box.press("Backspace");
await expect(box).toHaveText("left right");
await box.press("Meta+z");
await expect(box).toHaveText("left [Image #1]right");
await box.press("Backspace");
await expect(box).toHaveText("left right");
await composer.locator('input[type="file"]').setInputFiles({
name: "second.png",
mimeType: "image/png",
buffer: Buffer.from(png, "base64"),
});
await expect(box).toHaveText("left [Image #2]right");
await box.press("Home");
await dropOrPaste("drop", "third.png");
await expect(box).toHaveText("[Image #3]left [Image #2]right");
await page.getByRole("button", { name: "Send", exact: true }).filter({ visible: true }).click();
await expect
.poll(() => page.evaluate(() => JSON.parse(sessionStorage.getItem("composer-image-prompt") ?? "null")))
.toMatchObject({
text: "[Image #3]left [Image #2]right",
images: [
{ inlineNumber: 3, name: "third.png" },
{ inlineNumber: 2, name: "second.png" },
],
});
});