diff --git a/apps/web/tests/cua-optin.e2e.ts b/apps/web/tests/cua-optin.e2e.ts index 9cc9cf1f16..287a073493 100644 --- a/apps/web/tests/cua-optin.e2e.ts +++ b/apps/web/tests/cua-optin.e2e.ts @@ -8,8 +8,8 @@ import { readProfileManifest } from '@deepseek-ai/dsh-app-boot' import { SessionId } from '@deepseek-ai/dsh-session' import type {} from '@deepseek-ai/dsh-ptc-runtime' import type {} from '@deepseek-ai/dsh-agent-preset-registry' -import { expect, it } from 'vitest' -import { launchWebScaffold, type WebScaffold } from './scaffold.ts' +import { expect, it, vi } from 'vitest' +import { captureStableAria, compareOrRefreshGolden, launchWebScaffold, webSnapshotMode, type WebScaffold } from './scaffold.ts' import { connectFreshWorkspaceZh, ZH_BROWSER_LOCALE } from './support.ts' it.each([undefined, 'minimal'] as const)('adds CUA to PTC sessions while preserving default %s until the explicit persistent-runtime action', async (selectedDefault) => { @@ -54,9 +54,28 @@ it.each([undefined, 'minimal'] as const)('adds CUA to PTC sessions while preserv const toggle = card.getByRole('switch', { name: '启用 Computer Use', exact: true }) expect(await toggle.getAttribute('aria-checked')).toBe('false') expect(await card.textContent()).toContain('请切换到 PTC 模式') + const enabling = Promise.withResolvers() + const setEnabled = scaffold.ctx.pluginManager.setBundleEnabled.bind(scaffold.ctx.pluginManager) + let applying: ReturnType | undefined + // Hold the Host request so the pending UI does not depend on machine speed; release into the real operation. + const enableCall = vi.spyOn(scaffold.ctx.pluginManager, 'setBundleEnabled').mockImplementationOnce((name, enabled) => { + applying = enabling.promise.then(() => setEnabled(name, enabled)) + return applying + }) + try { + await toggle.click() + await card.getByRole('status', { name: '正在应用 Computer Use 的更改', exact: true }).waitFor() + expect(await toggle.isEnabled()).toBe(false) + await compareOrRefreshGolden(fileURLToPath(new URL('./expected/cua-permissions/enabling.expected.md', import.meta.url)), + await captureStableAria(page, '[data-plugin-package="@deepseek-ai/dsh-cua-bundle"]', scaffold.workspaceCwd), webSnapshotMode()) + } finally { + enabling.resolve(undefined) + enableCall.mockRestore() + await applying + } // Bundle transitions await native cleanup under the browser action deadline. - await toggle.click() await toggle.and(page.locator('[aria-checked="true"]')).waitFor({ state: 'visible' }) + await card.getByRole('status', { name: '正在应用 Computer Use 的更改', exact: true }).waitFor({ state: 'hidden' }) const setup = page.getByRole('dialog', { name: '使用 Computer Use 前需要设置', exact: true }) await setup.waitFor() expect(await setup.getByText('Computer Use 插件已开启,但暂时无法检测系统权限。请前往插件详情页查看原因并重试。', { exact: true }).count()).toBe(1) diff --git a/apps/web/tests/cua-permissions.e2e.ts b/apps/web/tests/cua-permissions.e2e.ts index e22fa09516..11701e191a 100644 --- a/apps/web/tests/cua-permissions.e2e.ts +++ b/apps/web/tests/cua-permissions.e2e.ts @@ -33,12 +33,13 @@ it.skipIf(process.platform !== 'darwin')('keeps system requests pending until fr icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAADElEQVQImWNgZGIGAAAOAAeCcsnOAAAAAElFTkSuQmCC' } await writeFile(state, JSON.stringify({ accessibility: false, screenRecording: false, launchApplication })) await writeFile(join(root, 'observe-helper'), '') - const fixturePatch = join(root, 'native-fixture.yml') - // Keep the helper override above bundle order changes when CUA is re-enabled. - await writeFile(fixturePatch, JSON.stringify([{ id: 'cua', config: { helperPath: helper } }])) + const fixtureBundle = join(root, 'fixture-bundle') + await mkdir(fixtureBundle) + await writeFile(join(fixtureBundle, 'package.json'), JSON.stringify({ name: 'cua-permission-fixture', version: '1.0.0', + dsh: { bundle: { patch: 'cordis.patch.yml' } } })) + await writeFile(join(fixtureBundle, 'cordis.patch.yml'), `- id: cua\n config: ${JSON.stringify({ helperPath: helper })}\n`) const scaffold = await launchWebScaffold({ - profile: { packages: [{ dir: bundle, enabled: true }] }, - extraOverlayPath: fixturePatch, + profile: { packages: [{ dir: bundle, enabled: true }, { dir: fixtureBundle, enabled: true }] }, }) resources.scaffold = scaffold await scaffold.ctx.settings.mutate('cua', [{ op: 'set', path: ['allowedApps'], diff --git a/apps/web/tests/expected/cua-permissions/enabling.expected.md b/apps/web/tests/expected/cua-permissions/enabling.expected.md new file mode 100644 index 0000000000..6059222749 --- /dev/null +++ b/apps/web/tests/expected/cua-permissions/enabling.expected.md @@ -0,0 +1,5 @@ +- listitem: + - button "查看 Computer Use": Computer Use + - text: 实验性 目前仅支持 macOS,Windows 支持正在开发中。为已有及新建 PTC 会话加载 Computer Use。请切换到 PTC 模式来使用,并授予辅助功能和屏幕录制权限。 + - status "正在应用 Computer Use 的更改" + - switch "启用 Computer Use" [disabled] diff --git a/apps/web/tests/plugin-manager.e2e.ts b/apps/web/tests/plugin-manager.e2e.ts index 4bdc097808..681366a3e6 100644 --- a/apps/web/tests/plugin-manager.e2e.ts +++ b/apps/web/tests/plugin-manager.e2e.ts @@ -298,7 +298,7 @@ describe('web e2e: plugin manager', () => { width: node.getBoundingClientRect().width, height: node.getBoundingClientRect().height, }))) - expect(blankActions).toEqual(Array.from({ length: 4 }, () => ({ children: 0, background: 'rgba(0, 0, 0, 0)', width: 36, height: 20 }))) + expect(blankActions).toEqual(Array.from({ length: 4 }, () => ({ children: 0, background: 'rgba(0, 0, 0, 0)', width: 58, height: 20 }))) if (shots !== undefined) { for (const colorScheme of ['light', 'dark'] as const) { await probe.emulateMedia({ colorScheme })