browser-manifest.test.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. import { readFileSync } from "node:fs";
  2. import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
  3. import { tmpdir } from "node:os";
  4. import { join, resolve } from "node:path";
  5. import { describe, expect, it } from "vitest";
  6. import type { BrowserInfo } from "../src/browser-client/index.js";
  7. import {
  8. BrowserApiPolicy,
  9. createBrowserApiProxy,
  10. loadBrowserApiManifest,
  11. } from "../src/browser-client/index.js";
  12. import { loadBrowserDocumentation } from "../src/browser-client/documentation.js";
  13. import { NodeReplSession } from "../src/repl/node-repl-session.js";
  14. const docsRoot = resolve(process.cwd(), "../browser-use-plugin/docs");
  15. const skillPath = resolve(process.cwd(), "../browser-use-plugin/skills/control-browser/SKILL.md");
  16. const overviewPath = resolve(docsRoot, "overview.md");
  17. const workflowPath = resolve(docsRoot, "workflow.md");
  18. const playwrightPath = resolve(docsRoot, "playwright.md");
  19. const repoRoot = resolve(process.cwd(), "../../../..");
  20. const runtimeBoundarySpecPath = resolve(
  21. repoRoot,
  22. "docs/browser-use/browser-use-plugin-runtime-boundary.md",
  23. );
  24. const runtimeSemanticsSpecPath = resolve(
  25. repoRoot,
  26. "docs/browser-use/2026-07-12-browser-use-codex-runtime-semantics-alignment-spec.md",
  27. );
  28. const phaseOneSpecPath = resolve(
  29. repoRoot,
  30. "docs/browser-use/2026-07-09-browser-use-codex-alignment-phase1-spec.md",
  31. );
  32. const testerSkillPath = resolve(
  33. process.cwd(),
  34. "../browser-use-plugin/skills/web-gui-tester/SKILL.md",
  35. );
  36. const iab: BrowserInfo = {
  37. id: "iab-runtime-1",
  38. generation: 3,
  39. type: "iab",
  40. name: "IAB",
  41. capabilities: { browser: [], tab: [{ id: "dom-cua", description: "DOM" }] },
  42. apiSupportOverrides: {
  43. "BrowserUser.claimTab": true,
  44. "Tabs.finalize": true,
  45. "Tab.markDeliverable": true,
  46. "Tab.markHandoff": true,
  47. },
  48. };
  49. describe("browser capability manifest", () => {
  50. it("keeps Browser Use runtime-boundary and matcher specs aligned with the shipped contract", () => {
  51. const runtimeBoundary = readFileSync(runtimeBoundarySpecPath, "utf8");
  52. const runtimeSemantics = readFileSync(runtimeSemanticsSpecPath, "utf8");
  53. const phaseOneSpec = readFileSync(phaseOneSpecPath, "utf8");
  54. expect(runtimeBoundary).toContain("物理发布载体");
  55. expect(runtimeBoundary).toContain("enabled === false");
  56. expect(runtimeBoundary).toContain("runtimeFeatures.browserUse");
  57. expect(runtimeBoundary).not.toContain("nodeRepl: true");
  58. expect(runtimeBoundary).not.toContain("不携带 runtime asset");
  59. expect(runtimeSemantics).toContain("guidance 都允许 `RegExp`");
  60. expect(runtimeSemantics).toContain("跨 Realm RegExp");
  61. expect(runtimeSemantics).not.toContain("guidance 禁止 RegExp");
  62. expect(phaseOneSpec).toContain("状态:历史阶段规格");
  63. expect(phaseOneSpec).not.toContain("关闭时两者都不可见");
  64. expect(phaseOneSpec).not.toContain("browser.tabs.selected()");
  65. });
  66. it("web GUI tester stays agnostic to the browser automation tooling available in the session", () => {
  67. const skill = readFileSync(testerSkillPath, "utf8");
  68. expect(skill).toContain("whatever browser automation tooling the session actually provides");
  69. expect(skill).toContain("This skill defines the testing methodology only");
  70. expect(skill).toContain("Cross-validate code and visuals");
  71. expect(skill).not.toContain("browser-use:control-browser");
  72. expect(skill).not.toContain("agent.browsers");
  73. expect(skill).not.toContain("tab.playwright.domSnapshot()");
  74. expect(skill).not.toContain("nodeRepl.emitImage(await tab.screenshot())");
  75. expect(skill).not.toMatch(
  76. /\bpage\.(?:click|fill|goto|screenshot|evaluate|on|context|keyboard|mouse)\b/u,
  77. );
  78. expect(skill).not.toContain("page.on(");
  79. expect(skill).toContain("Browser screenshot saved to: <absolute path>");
  80. });
  81. it("keeps included examples executable without cross-cell Browser bindings", async () => {
  82. const overview = readFileSync(overviewPath, "utf8");
  83. const workflow = readFileSync(workflowPath, "utf8");
  84. const firstWorkflowCell = /```js\r?\n([\s\S]*?)\r?\n```/u.exec(workflow)?.[1];
  85. expect(firstWorkflowCell).toBeTruthy();
  86. expect(overview).not.toContain("globalThis.browser");
  87. expect(overview).not.toContain("globalThis.tab");
  88. expect(overview).toContain("fresh kernel");
  89. expect(workflow).not.toContain("globalThis.browser");
  90. expect(workflow).not.toContain("globalThis.tab");
  91. expect(overview).not.toContain("browser.tabs.selected()");
  92. expect(workflow).toMatch(/\bconst browser = await agent\.browsers/u);
  93. if (!firstWorkflowCell) return;
  94. const browser = {
  95. tabs: {
  96. list: async () => [
  97. {
  98. id: "tab-1",
  99. title: "Example",
  100. url: "https://example.com/",
  101. viewport: { width: 1280, height: 720 },
  102. },
  103. ],
  104. },
  105. };
  106. const session = new NodeReplSession({
  107. injectedGlobals: () => ({
  108. agent: { browsers: { getDefault: async () => browser } },
  109. }),
  110. restrictProcess: true,
  111. });
  112. try {
  113. const first = await session.run(firstWorkflowCell);
  114. expect(first.error).toBeUndefined();
  115. expect(first.result).toContain('"id": "tab-1"');
  116. } finally {
  117. session.dispose();
  118. }
  119. });
  120. it("browser skill keeps BrowserControl continuity while rebuilding JavaScript bindings", () => {
  121. const skill = readFileSync(skillPath, "utf8");
  122. expect(skill).toContain("mcp__node_repl__js");
  123. expect(skill).toContain("every `js` call runs in a fresh JavaScript kernel");
  124. expect(skill).toContain("Persistent BrowserControl tabs are the continuity boundary");
  125. expect(skill).not.toContain("mcp__browser_use__");
  126. expect(skill).not.toContain("context_handle");
  127. });
  128. it("preserves pre-upgrade Browser Use guidance outside the fresh-kernel substitutions", () => {
  129. const skill = readFileSync(skillPath, "utf8");
  130. const bootstrapSource = /## Bootstrap[\s\S]*?```js\r?\n([\s\S]*?)\r?\n```/u.exec(skill)?.[1];
  131. expect(skill).toContain("The tool has no `command` parameter.");
  132. expect(skill).toContain("Headless is a CDP launch mode, not a backend type.");
  133. expect(skill).toContain("Reuse the latest relevant snapshot until it becomes stale.");
  134. expect(skill).toMatch(
  135. /An internal SDK validation or a list hidden inside the same\s+cell does not count as model inspection\./u,
  136. );
  137. expect(skill).toContain("Do not navigate to the same URL again");
  138. expect(skill).toMatch(
  139. /Do not close research\/source tabs merely because the\s+turn is ending\./u,
  140. );
  141. expect(skill).toContain(
  142. "If the user asked for screenshots, include the emitted images in your final response.",
  143. );
  144. expect(bootstrapSource).toBeTruthy();
  145. expect(bootstrapSource).not.toContain("agent.browsers.getDefault()");
  146. expect(bootstrapSource).not.toContain("agent.browsers.get(");
  147. expect(bootstrapSource).not.toContain("agent.browsers.getForUrl(");
  148. });
  149. it("browser skill resolves its client from the host-provided plugin root", () => {
  150. const skill = readFileSync(skillPath, "utf8");
  151. expect(skill).toContain("process.env.ZCODE_PLUGIN_ROOT");
  152. expect(skill).toContain("process.env.CLAUDE_PLUGIN_ROOT");
  153. expect(skill).toContain('await import("node:path")');
  154. expect(skill).toContain('await import("node:url")');
  155. expect(skill).toContain('join(browserPluginRoot, "scripts", "browser-client.mjs")');
  156. expect(skill).toContain("pathToFileURL");
  157. expect(skill).not.toContain("<plugin root>");
  158. expect(skill).not.toContain("skills/control-browser/scripts/browser-client.mjs");
  159. });
  160. it("executes the browser skill bootstrap with the host-provided plugin root", async () => {
  161. const skill = readFileSync(skillPath, "utf8");
  162. const bootstrapSource = /## Bootstrap[\s\S]*?```js\r?\n([\s\S]*?)\r?\n```/u.exec(skill)?.[1];
  163. expect(bootstrapSource).toBeTruthy();
  164. if (!bootstrapSource) return;
  165. const pluginRoot = await mkdtemp(join(tmpdir(), "zcode-browser-skill-"));
  166. const previousPluginRoot = process.env.ZCODE_PLUGIN_ROOT;
  167. let session: NodeReplSession | undefined;
  168. try {
  169. await mkdir(join(pluginRoot, "scripts"), { recursive: true });
  170. await writeFile(
  171. join(pluginRoot, "scripts", "browser-client.mjs"),
  172. [
  173. "export async function setupBrowserRuntime({ globals }) {",
  174. " globals.agent = { browsers: { ready: true, getDefault: async () => ({}) } };",
  175. "}",
  176. ].join("\n"),
  177. "utf8",
  178. );
  179. process.env.ZCODE_PLUGIN_ROOT = pluginRoot;
  180. session = new NodeReplSession({ restrictProcess: true });
  181. // 修复原因:生产 Skill 的 base directory 位于 skills/control-browser,必须证明模板只信任宿主根目录。
  182. const bootstrapResult = await session.run(bootstrapSource);
  183. expect(bootstrapResult.error).toBeUndefined();
  184. const readyResult = await session.run("globalThis.agent?.browsers?.ready");
  185. expect(readyResult.error).toBeUndefined();
  186. expect(readyResult.result).toBe("true");
  187. } finally {
  188. session?.dispose();
  189. if (previousPluginRoot === undefined) {
  190. delete process.env.ZCODE_PLUGIN_ROOT;
  191. } else {
  192. process.env.ZCODE_PLUGIN_ROOT = previousPluginRoot;
  193. }
  194. await rm(pluginRoot, { force: true, recursive: true });
  195. }
  196. });
  197. it("exposes the Playwright wait member in runtime policy and effective documentation", () => {
  198. const manifest = loadBrowserApiManifest(docsRoot);
  199. const policy = new BrowserApiPolicy(manifest, iab);
  200. const runtime = createBrowserApiProxy({ waitForTimeout: () => "ok" }, "PlaywrightAPI", policy);
  201. expect(runtime.waitForTimeout()).toBe("ok");
  202. expect("waitForTimeout" in runtime).toBe(true);
  203. const documentation = loadBrowserDocumentation(docsRoot, undefined, iab);
  204. expect(documentation).toContain("url(): Promise<string | undefined>");
  205. expect(documentation).toContain("playwright: PlaywrightAPI");
  206. expect(documentation).toContain("waitForTimeout(timeoutMs: number)");
  207. expect(documentation).toContain('waitForEvent(event: "download"');
  208. expect(documentation).toContain("Construct locators only from the latest relevant domSnapshot");
  209. expect(documentation).toContain("If the latest snapshot already contains the target");
  210. expect(documentation).toContain("execute JavaScript in the page context");
  211. expect(documentation).not.toContain("read-only evaluate");
  212. expect(documentation).not.toContain("Possible side-effect in debug-evaluate");
  213. expect(documentation).toContain("capped at 3000ms");
  214. expect(documentation).toContain("do not wait on that locator");
  215. expect(documentation).toContain("do not loop over guessed URL variants");
  216. expect(documentation).toContain("accepts a plain string or `RegExp`");
  217. expect(documentation).toContain("RegExp values created in the node_repl VM realm");
  218. expect(documentation).toContain("already-loaded page can satisfy that waiter");
  219. expect(documentation).toContain("ambient UI state, not a browser-selection instruction");
  220. expect(documentation).toContain("nodeRepl.emitImage(await tab.screenshot())");
  221. expect(documentation).toContain("Never use tab.screenshot() as the final expression");
  222. expect(documentation).not.toContain('waitForEvent(event: "filechooser"');
  223. expect(documentation).not.toContain("setFiles(files");
  224. expect(documentation).not.toContain("elementInfo(options:");
  225. expect(documentation).not.toContain("elementScreenshot(options:");
  226. expect(documentation).not.toContain("downloadMedia(options: CuaDownloadMediaOptions");
  227. expect(documentation).not.toContain("downloadMedia(options: DomDownloadMediaOptions");
  228. });
  229. it("browser skill keeps snapshot-first discovery while allowing evaluate page scripts", () => {
  230. const skill = readFileSync(skillPath, "utf8");
  231. expect(skill).toContain(
  232. "If that snapshot already contains the target, act from its facts directly",
  233. );
  234. expect(skill).toContain("do not write `evaluate()` code to rediscover related elements");
  235. expect(skill).toContain("execute JavaScript in the page context");
  236. expect(skill).not.toContain("read-only evaluate");
  237. expect(skill).not.toContain("Possible side-effect in debug-evaluate");
  238. });
  239. it("requires an explicit DOMContentLoaded wait after every new-URL goto", () => {
  240. const skill = readFileSync(skillPath, "utf8");
  241. const overview = readFileSync(overviewPath, "utf8");
  242. const workflow = readFileSync(workflowPath, "utf8");
  243. const playwright = readFileSync(playwrightPath, "utf8");
  244. const manifest = loadBrowserApiManifest(docsRoot);
  245. const documentation = loadBrowserDocumentation(docsRoot, undefined, iab);
  246. const fallbackDocumentation = loadBrowserDocumentation(undefined, undefined, iab);
  247. const requiredGuidance =
  248. 'After every successful `tab.goto(url)`, explicitly call `await tab.playwright.waitForLoadState({ state: "domcontentloaded" })` before the first title, URL, or DOM observation.';
  249. const explicitWait = 'await tab.playwright.waitForLoadState({ state: "domcontentloaded" });';
  250. expect(manifest.semantics?.navigationWait).toContain(requiredGuidance);
  251. for (const guidance of [
  252. skill,
  253. overview,
  254. workflow,
  255. playwright,
  256. documentation,
  257. fallbackDocumentation,
  258. ]) {
  259. expect(guidance).toContain(requiredGuidance);
  260. expect(guidance).toContain("3000ms");
  261. expect(guidance).not.toContain(
  262. 'tab.goto(url)` and `tab.playwright.waitForLoadState({ state: "networkidle" })',
  263. );
  264. }
  265. for (const example of [overview, workflow]) {
  266. const gotoIndex = example.indexOf('await tab.goto("https://example.com");');
  267. const waitIndex = example.indexOf(explicitWait, gotoIndex);
  268. const observationIndex = example.indexOf("await tab.playwright.domSnapshot();", waitIndex);
  269. expect(gotoIndex).toBeGreaterThanOrEqual(0);
  270. expect(waitIndex).toBeGreaterThan(gotoIndex);
  271. expect(observationIndex).toBeGreaterThan(waitIndex);
  272. }
  273. });
  274. it("browser guidance observes both tab registries in one cell before deciding a popup action effect", () => {
  275. const skill = readFileSync(skillPath, "utf8");
  276. const manifest = loadBrowserApiManifest(docsRoot);
  277. const documentation = loadBrowserDocumentation(docsRoot, undefined, iab);
  278. const fallbackDocumentation = loadBrowserDocumentation(undefined, undefined, iab);
  279. const troubleshootingDocumentation = loadBrowserDocumentation(
  280. docsRoot,
  281. "browser-troubleshooting",
  282. iab,
  283. );
  284. const tabClaimingDocumentation = loadBrowserDocumentation(docsRoot, "tab-claiming-iab", iab);
  285. expect(manifest.semantics?.actionResultObservation).toContain(
  286. "read `browser.tabs.list()` and `browser.user.openTabs()` unconditionally in the same observation cell",
  287. );
  288. for (const guidance of [skill, documentation, fallbackDocumentation]) {
  289. expect(guidance).toContain(
  290. "A snapshot-proven heading or visible text does not need a `link` or `button` role to be clicked.",
  291. );
  292. expect(guidance).toContain(
  293. "Do not replace a snapshot-proven `heading` with a guessed `link` role.",
  294. );
  295. expect(guidance).toContain("one state-changing action per observation cycle");
  296. expect(guidance).toContain("An unchanged source-tab URL does not prove the click failed.");
  297. expect(guidance).toContain(
  298. "When an action may open a popup/new tab and the source tab does not show the expected effect, read `browser.tabs.list()` and `browser.user.openTabs()` unconditionally in the same observation cell.",
  299. );
  300. expect(guidance).toContain(
  301. "Judge an action by whether its expected effect appeared, not by whether `browser.tabs.list()` is non-empty.",
  302. );
  303. expect(guidance).toContain(
  304. "An existing source tab or unrelated controlled tab is not an action effect.",
  305. );
  306. expect(guidance).toContain(
  307. "Return `{ controlledTabs, userTabs }` as that cell's final result so the model makes one decision from both lists.",
  308. );
  309. expect(guidance).toContain(
  310. "Do not return the controlled list first or decide whether to query user tabs from its contents.",
  311. );
  312. expect(guidance).not.toContain("Return each list in a dedicated JS call");
  313. expect(guidance).not.toContain("lists in separate observation calls");
  314. expect(guidance).not.toContain(
  315. "inspect `browser.tabs.list()` and then `browser.user.openTabs()` before clicking again",
  316. );
  317. }
  318. expect(fallbackDocumentation).toContain("every Browser Use call starts in a fresh kernel");
  319. expect(fallbackDocumentation).toContain(
  320. "const browser = await agent.browsers.getDefault()",
  321. );
  322. expect(fallbackDocumentation).not.toContain("globalThis.browser");
  323. expect(fallbackDocumentation).not.toContain("globalThis.tab");
  324. for (const guidance of [troubleshootingDocumentation, tabClaimingDocumentation]) {
  325. expect(guidance).toContain(
  326. "When an action may open a popup/new tab and the source tab does not show the expected effect, read",
  327. );
  328. expect(guidance).toContain(
  329. "`browser.tabs.list()` and `browser.user.openTabs()` unconditionally in the same observation cell.",
  330. );
  331. expect(guidance).toContain(
  332. "{ controlledTabs, userTabs }` as that cell's final result so the model makes one decision from both lists",
  333. );
  334. expect(guidance).not.toContain("separate observation");
  335. }
  336. });
  337. it("IAB effective docs include capability-gated tab lifecycle and recovery guidance", () => {
  338. const documentation = loadBrowserDocumentation(docsRoot, undefined, iab);
  339. expect(documentation).toContain("# User Tab Claiming");
  340. expect(documentation).toContain("# Tab Cleanup");
  341. expect(documentation).toContain("# Tab Lifecycle Marks");
  342. expect(documentation).toContain("# All-Tabs Cleanup Guidance");
  343. expect(documentation).toContain("browser.tabs.get(info.id)");
  344. expect(documentation).toContain("Before every logical tab operation batch");
  345. expect(documentation).toContain("dedicated JS call");
  346. expect(documentation).toContain("same-cell hidden list does not count as model inspection");
  347. expect(documentation).toContain("background session never steals the foreground UI");
  348. expect(documentation).toContain("active?: boolean");
  349. expect(documentation).toContain("viewport: BrowserViewportSize");
  350. expect(loadBrowserDocumentation(undefined, undefined, iab)).toContain(
  351. "viewport: BrowserViewportSize",
  352. );
  353. expect(documentation).toContain("validates, binds, and activates a tab");
  354. expect(documentation).toContain("omission from `keep` do not close a tab");
  355. expect(documentation).not.toContain("unlisted temporary tabs are cleaned up");
  356. expect(documentation).not.toContain("preserves only the final active agent tab");
  357. expect(documentation).not.toContain("# Browser Interaction Troubleshooting");
  358. expect(loadBrowserDocumentation(docsRoot, "browser-troubleshooting", iab)).toContain(
  359. "Do not retry the same",
  360. );
  361. expect(loadBrowserDocumentation(docsRoot, "viewport", iab)).toContain(
  362. "responsive mode uses DPR 1",
  363. );
  364. });
  365. it("non-IAB effective docs do not include IAB-only tab lifecycle documents", () => {
  366. const documentation = loadBrowserDocumentation(docsRoot, undefined, {
  367. ...iab,
  368. id: "extension-1",
  369. type: "extension",
  370. });
  371. expect(documentation).not.toContain("# User Tab Claiming");
  372. expect(documentation).not.toContain("# Tab Lifecycle Marks");
  373. expect(documentation).not.toContain("# All-Tabs Cleanup Guidance");
  374. });
  375. it("connection override can hide a common member from runtime and docs", () => {
  376. const manifest = loadBrowserApiManifest(docsRoot);
  377. const descriptor = {
  378. ...iab,
  379. apiSupportOverrides: { "PlaywrightAPI.waitForTimeout": false },
  380. };
  381. const policy = new BrowserApiPolicy(manifest, descriptor);
  382. const runtime = createBrowserApiProxy(
  383. { waitForTimeout: () => "unexpected" },
  384. "PlaywrightAPI",
  385. policy,
  386. );
  387. expect(runtime.waitForTimeout).toBeUndefined();
  388. expect("waitForTimeout" in runtime).toBe(false);
  389. expect(loadBrowserDocumentation(docsRoot, undefined, descriptor)).not.toContain(
  390. "waitForTimeout(timeoutMs: number)",
  391. );
  392. });
  393. it("hides tab lifecycle finalization from IAB and managed CDP object graphs", () => {
  394. const manifest = loadBrowserApiManifest(docsRoot);
  395. for (const type of ["iab", "cdp"] as const) {
  396. const policy = new BrowserApiPolicy(manifest, {
  397. ...iab,
  398. type,
  399. apiSupportOverrides: {},
  400. });
  401. const runtime = createBrowserApiProxy({ finalize: () => "unexpected" }, "Tab", policy);
  402. expect(policy.supports("Tab", "finalize")).toBe(false);
  403. expect(runtime.finalize).toBeUndefined();
  404. expect("finalize" in runtime).toBe(false);
  405. }
  406. });
  407. it("keeps browser and tab capability requirements isolated", () => {
  408. const manifest = loadBrowserApiManifest(docsRoot);
  409. const scopedManifest = {
  410. ...manifest,
  411. objects: {
  412. ...manifest.objects,
  413. Scoped: {
  414. members: [
  415. {
  416. name: "browserOnly",
  417. kind: "method" as const,
  418. signature: "browserOnly()",
  419. requiresCapabilities: ["browser:shared"],
  420. },
  421. {
  422. name: "tabOnly",
  423. kind: "method" as const,
  424. signature: "tabOnly()",
  425. requiresCapabilities: ["tab:shared"],
  426. },
  427. ],
  428. },
  429. },
  430. };
  431. const policy = new BrowserApiPolicy(scopedManifest, {
  432. ...iab,
  433. capabilities: { browser: [], tab: [{ id: "shared", description: "tab only" }] },
  434. });
  435. expect(policy.supports("Scoped", "browserOnly")).toBe(false);
  436. expect(policy.supports("Scoped", "tabOnly")).toBe(true);
  437. });
  438. it("keeps manifest command mappings inside the browser command contract", () => {
  439. const manifest = loadBrowserApiManifest(docsRoot);
  440. const knownCommands = new Set([
  441. "navigate",
  442. "back",
  443. "forward",
  444. "reload",
  445. "snapshot",
  446. "screenshot",
  447. "getState",
  448. "click",
  449. "type",
  450. "press",
  451. "scroll",
  452. "hover",
  453. "select",
  454. "check",
  455. "drag",
  456. "elementInfo",
  457. "evaluate",
  458. "getDialog",
  459. "handleDialog",
  460. "finalize",
  461. "close",
  462. "list",
  463. "newTab",
  464. "nameSession",
  465. "claimTab",
  466. "listUserTabs",
  467. "finalizeTabs",
  468. "markDeliverable",
  469. "markHandoff",
  470. "browserViewportSet",
  471. "browserViewportReset",
  472. "recordingStart",
  473. "recordingStatus",
  474. "recordingCancel",
  475. "playwrightWaitForTimeout",
  476. "playwright",
  477. ]);
  478. for (const object of Object.values(manifest.objects)) {
  479. for (const member of object.members) {
  480. if (member.command) expect(knownCommands.has(member.command), member.command).toBe(true);
  481. }
  482. }
  483. });
  484. it("manifest 枚举 common Playwright 全对象图", () => {
  485. const manifest = loadBrowserApiManifest(docsRoot);
  486. expect(manifest.version).toBe(11);
  487. expect(manifest.objects.PlaywrightAPI.members).toHaveLength(16);
  488. expect(manifest.objects.PlaywrightLocator.members).toHaveLength(32);
  489. expect(manifest.objects.PlaywrightFrameLocator.members).toHaveLength(7);
  490. expect(manifest.objects.PlaywrightDownload.members.map((member) => member.name)).toEqual([
  491. "path",
  492. ]);
  493. expect(manifest.objects.PlaywrightFileChooser.members.map((member) => member.name)).toEqual([
  494. "isMultiple",
  495. "setFiles",
  496. ]);
  497. });
  498. });