跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

mobile-transcript-smoke.mjs

97 行 · 3.7 KB历史下载
1// Reads the one-time URL from stdin. Run by TestMobileTranscriptInBrowser.
2import assert from "node:assert/strict";
3import { mkdir } from "node:fs/promises";
4import path from "node:path";
5const parts = [];
6for await (const chunk of process.stdin) parts.push(chunk);
7const entry = Buffer.concat(parts).toString().trim();
8const engine = process.env.CAGE_TEST_MOBILE_BROWSER;
9const playwright = await import(
10 process.env.CAGE_PLAYWRIGHT_MODULE || "playwright"
11);
12const browser = await playwright[engine].launch();
13try {
14 const page = await browser.newPage({
15 viewport: { width: 390, height: 844 },
16 isMobile: true,
17 hasTouch: true,
18 colorScheme: "dark",
19 });
20 const errors = [];
21 page.on("pageerror", (e) => errors.push(e.message));
22 await page.goto(entry);
23 await page.getByRole("button", { name: "宣传片制作", exact: true }).click();
24 await page.getByRole("heading", { name: "交付文件" }).waitFor();
25 assert.equal(
26 await page.locator(".markdown strong").first().innerText(),
27 "以后维护",
28 );
29 assert.equal(await page.getByRole("table").count(), 1);
30 assert.equal(await page.getByRole("checkbox", { checked: true }).count(), 1);
31 const transcript = page.getByRole("region", { name: "会话消息" });
32 assert(await transcript.evaluate((el) => el.scrollWidth <= el.clientWidth));
33 const call = page.locator("summary").filter({ hasText: "2 次工具调用" });
34 await call.click();
35 await page.getByText("检查帧率", { exact: true }).waitFor();
36 await call.click();
37 const task = page.locator("summary").filter({ hasText: "后台任务" });
38 assert.equal(await task.count(), 1);
39 await task.focus();
40 await page.keyboard.press("Enter");
41 await page.getByText("fixture-id", { exact: true }).waitFor();
42 await task.click();
43 const capture = process.env.CAGE_TEST_MOBILE_CAPTURE;
44 if (capture) {
45 await mkdir(capture, { recursive: true });
46 await page.screenshot({
47 path: path.join(capture, engine + "-transcript.png"),
48 });
49 }
50 await page.getByRole("button", { name: /封面.*查看图片/ }).click();
51 await page.waitForFunction(
52 () => document.querySelector(".project-media img")?.naturalWidth > 0,
53 );
54 await page.getByRole("button", { name: /成片.*加载视频/ }).click();
55 await page.waitForFunction(
56 () => document.querySelector("video")?.videoWidth > 0,
57 );
58 const video = page.locator("video");
59 await video.evaluate(async (el) => {
60 el.muted = true;
61 await el.play();
62 });
63 await page.waitForFunction(
64 () => document.querySelector("video")?.currentTime > 0,
65 );
66 await video.evaluate((el) => el.pause());
67 if (capture)
68 await page.screenshot({ path: path.join(capture, engine + "-media.png") });
69 await page.getByRole("button", { name: /成片.*收起/ }).click();
70 assert.equal(await video.count(), 0);
71 await page.getByRole("button", { name: /缺失.*查看图片/ }).click();
72 await page.getByText(/未找到媒体文件/).waitFor();
73 await page.reload();
74 await page.getByRole("heading", { name: "交付文件" }).waitFor();
75 assert.equal(await page.locator("video").count(), 0);
76 const opened = page.waitForRequest(
77 (r) =>
78 r.method() === "POST" &&
79 new URL(r.url()).pathname === "/api/mobile/browser/open",
80 );
81 await page.getByRole("link", { name: "查看网页" }).click();
82 assert.equal((await opened).postDataJSON().url, "https://example.org/demo");
83 assert.deepEqual(errors, []);
84 console.log(
85 engine +
86 " Markdown, tool history, task notice, image decode, video playback, retry affordance, reload and remote link passed",
87 );
88} catch (error) {
89 throw Error(
90 String(error).replace(
91 /link-bootstrap#[\w-]+/g,
92 "link-bootstrap#[redacted]",
93 ),
94 );
95} finally {
96 await browser.close();
97}