/** 真实浏览器与隔离库:方法库、检索与版本绑定的维护旅程。 */ import { readFileSync } from "node:fs"; import { expect, test } from "@playwright/test"; test.use({ trace: "off" }); // @muse-case {"case_id":"NC-w20-browser","environment":"真实隔离库 + Chrome","given":"隔离浏览器环境与已启用绑定方法","when":"浏览方法库与版本绑定页并执行混合检索","then":["清单与类型过滤可见","检索命中并标注绑定","绑定固定版本可见"],"contract":"docs/系统架构/新版设计/模块设计/B04-知识方法.md"} test("NC-w20-browser:方法库与绑定旅程", async ({ page }, info) => { if (!process.env.MUSE_WORKBENCH_URL || !process.env.MUSE_AUTHOR_PASSWORD_FILE) throw new Error("需要明确的隔离后端和作者口令文件。"); const workId = process.env.MUSE_WORK_ID!; if (!workId) throw new Error("需要预置作品编号。"); const consoleErrors: string[] = []; page.on("pageerror", (error) => consoleErrors.push(String(error))); await page.goto("/"); await page .getByLabel("访问口令") .fill(readFileSync(process.env.MUSE_AUTHOR_PASSWORD_FILE, "utf8").trim()); await page.getByRole("button", { name: "进入工作台" }).click(); // 方法库页:类型过滤、方法清单、索引状态与混合检索。 await page.goto(`/methods?work=${workId}`); const 清单 = page.locator('section[aria-label="方法清单"]'); await expect(清单.getByText(/1 张卡/)).toBeVisible({ timeout: 15_000 }); await expect(清单.getByRole("button", { name: /叙事技法/ })).toBeVisible(); await expect(清单.getByText(/契诃夫之枪/)).toBeVisible(); const 索引 = page.locator('section[aria-label="索引状态"]'); await expect(索引.getByText("新鲜")).toBeVisible(); const 检索 = page.locator('section[aria-label="混合检索"]'); await 检索.locator("input").fill("埋设 引爆"); await expect(检索.getByText(/契诃夫之枪/)).toBeVisible(); await expect(检索.getByText(/已绑定本书/)).toBeVisible(); await page.screenshot({ path: `${info.outputDir}/方法库页.png`, fullPage: true }); // 版本绑定页:绑定清单呈现固定版本。 await page.goto(`/works/${workId}/methods`); const 绑定 = page.locator('section[aria-label="绑定清单"]'); await expect(绑定.getByText(/1 条生效/)).toBeVisible({ timeout: 15_000 }); await expect(绑定.getByText(/契诃夫之枪/)).toBeVisible(); await expect(绑定.getByText(/v1/)).toBeVisible(); await page.screenshot({ path: `${info.outputDir}/版本绑定页.png`, fullPage: true }); expect( consoleErrors.filter((文本) => !文本.includes("favicon")), "页面不得出现控制台错误", ).toEqual([]); });