Files
next-tjwater-frontend/tests/browser/agent-artifact-download.e2e.ts
T
jiang 2d8506fea0
Generic Container CI/CD / test-build-publish (push) Successful in 2m9s
Frontend CI/CD / build-test-publish-and-deploy (push) Successful in 2m39s
feat: add project-aware agent workspace
2026-10-22 18:52:18 +08:00

44 lines
2.5 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { mockAgentApi } from "./support/mock-agent-api";
import { mockWorkbenchContext } from "./support/mock-workbench-context";
import { responsesFixture } from "./support/responses-fixture";
test("Agent export links download through the scoped client and preserve the conversation", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce" });
await mockWorkbenchContext(page, undefined, undefined, {}, [], { runtimeMode: "backend" });
await mockAgentApi(page);
const filename = "mcp-11111111-1111-1111-1111-111111111111.zip";
const path = `/api/v1/session/browser-session-1/files/${filename}`;
await page.route("**/api/v1/responses", (route) => {
if (route.request().method() === "OPTIONS") return route.fallback();
return route.fulfill({ headers: { "Access-Control-Allow-Origin": "*", "Content-Type": "text/event-stream" }, body: responsesFixture([
{ type: "start", messageId: "export-answer" }, { type: "text-start", id: "export-text" },
{ type: "text-delta", id: "export-text", delta: `[下载模型文件](${path}) [外部参考](https://example.com)` },
{ type: "text-end", id: "export-text" }, { type: "finish", finishReason: "stop" },
]) });
});
let projectHeader: string | undefined;
await page.route(`**${path}`, (route) => {
if (route.request().method() === "OPTIONS") return route.fallback();
projectHeader = route.request().headers()["x-project-id"];
return route.fulfill({ headers: { "Access-Control-Allow-Origin": "*", "Content-Type": "application/zip" }, body: "ZIP fixture" });
});
await page.goto("/", { waitUntil: "domcontentloaded" });
await page.getByRole("button", { name: /展开 Agent 助手面板/ }).click();
const panel = page.getByRole("complementary", { name: "Agent 命令面板" });
await panel.locator("textarea").fill("导出当前模型");
await panel.getByRole("button", { name: "发送 Agent 指令" }).click();
const link = panel.getByRole("link", { name: "下载模型文件" });
await expect(link).toBeVisible();
await expect(panel.getByRole("button", { name: "外部参考" })).toBeVisible();
const pageUrl = page.url();
const downloading = page.waitForEvent("download");
await link.focus();
await page.keyboard.press("Enter");
const file = await downloading;
expect(file.suggestedFilename()).toBe(filename);
expect(projectHeader).toBeTruthy();
expect(page.url()).toBe(pageUrl);
await expect(panel.locator("textarea")).toBeVisible();
});