import { expect, test, type Page } from '@playwright/test'; test.skip(true, '2.0.0 S5 单人版已移除市场、handoff 或多用户前端入口,本 spec 隔离保留待恢复'); /** * 已安装知识库停用/恢复端到端(真实后端,MSW off)。 * * 覆盖 G 链路:进 /knowledge →「从市场安装的」Tab → 已安装 KB →「停用」(disable→binding_status=disabled) * →「恢复」(restore→binding_status=active)。 * 关键:真后端 installed 状态存 muse_knowledge_binding.binding_status;list 映射 disabled→'disabled'、else→'installed', * studio normalizeKnowledgeStatus 据此判 active/disabled。 * 幂等:global-setup 每轮复位 binding binding_status='active'(开局 active→先显示停用)。 */ const TOKEN = 'test1'; async function seedToken(page: Page): Promise { await page.addInitScript((t) => { window.localStorage.setItem('accessToken', t); window.localStorage.setItem('tenantId', '1'); }, TOKEN); } test('用户停用/恢复已安装知识库(真实后端)', async ({ page }) => { await seedToken(page); page.on('dialog', (d) => d.accept()); // 停用走 window.confirm,自动接受 await page.goto('/knowledge'); // 切到「从市场安装的」Tab。 await page.getByRole('button', { name: '从市场安装的' }).click(); // 等已安装 KB 卡片(global-setup 复位为 active→显示停用按钮)。 const disableBtn = page.getByRole('button', { name: /停用已安装知识库/ }); await expect(disableBtn.first()).toBeVisible({ timeout: 15_000 }); // 1) 停用 → disable(binding_status→disabled)→「已停用」+ 恢复按钮。 const disableResp = page.waitForResponse( (r) => /\/installed-knowledge-bases\/\d+\/disable/.test(r.url()) && r.request().method() === 'POST' ); await disableBtn.first().click(); expect((await disableResp).status()).toBe(200); await expect(page.getByText('已停用').first()).toBeVisible({ timeout: 10_000 }); await expect(page.getByRole('button', { name: /恢复已安装知识库/ }).first()).toBeVisible({ timeout: 10_000 }); // 2) 恢复 → restore(binding_status→active→list status=installed→normalize active)→「已启用」+ 停用按钮。 const restoreResp = page.waitForResponse( (r) => /\/installed-knowledge-bases\/\d+\/restore/.test(r.url()) && r.request().method() === 'POST' ); await page.getByRole('button', { name: /恢复已安装知识库/ }).first().click(); expect((await restoreResp).status()).toBe(200); await expect(page.getByText('已启用').first()).toBeVisible({ timeout: 10_000 }); await expect(page.getByRole('button', { name: /停用已安装知识库/ }).first()).toBeVisible({ timeout: 10_000 }); });