import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron'; test.describe('Project Plugin Center', () => { test('enables selection without configuring Data Service or duplicating project IDs', async ({ launchElectronApp }) => { const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-project-plugins-e2e-')); const app = await launchElectronApp({ skipSetup: true }); try { await app.evaluate(({ ipcMain }, selectedPath) => { ipcMain.removeHandler('dialog:open'); ipcMain.handle('dialog:open', async () => ({ canceled: false, filePaths: [selectedPath] })); }, projectPath); const page = await getStableWindow(app); await page.getByTestId('ai-module-option-programming').click(); await page.getByTestId('sidebar-create-project').click(); await page.getByRole('button', { name: '选择路径' }).click(); await page.getByRole('button', { name: '确认创建' }).click(); await expect(page.getByTestId('project-configuration-page')).toBeVisible(); await app.evaluate(({ ipcMain }) => { const state = { enabled: false, dataServiceCalls: 0, localProjectId: '' }; (globalThis as typeof globalThis & { __projectPluginE2E?: typeof state }).__projectPluginE2E = state; ipcMain.removeHandler('hostapi:fetch'); ipcMain.handle('hostapi:fetch', async (_event, request: { path?: string; method?: string }) => { const requestPath = request.path ?? ''; if (requestPath.startsWith('/api/works/data-service/')) { state.dataServiceCalls += 1; return { ok: false, error: { message: 'Enable must not configure Data Service' } }; } if (requestPath.startsWith('/api/coding/plugins')) { if (request.method === 'PUT') state.enabled = true; else state.localProjectId = new URL(requestPath, 'https://makelore.local').searchParams.get('projectId') ?? ''; return { ok: true, data: { status: 200, ok: true, json: { schemaVersion: 1, project: { localProjectId: state.localProjectId, durableProjectId: '11111111-1111-4111-8111-111111111111' }, policyStatus: 'current', unknownPluginIds: [], items: [{ id: 'makelore.data-service', version: '1.0.0', displayName: '开发数据服务', description: '为当前项目提供数据。', contractVersion: 1, requiresBackend: true, enabled: state.enabled, state: state.enabled ? 'configuration_required' : 'disabled', backend: { status: 'unconfigured' }, skills: [{ id: 'data-service', assignedAgentIds: [] }], capabilities: [{ id: 'data-service.control', operations: [{ id: 'inspect', billing: { mode: 'included', availability: 'available', notice: 'Fixed quotas apply' }, tool: null }] }], settingsSurface: 'data-service', }], } } }; } return { ok: false, error: { message: `Unexpected Host API request: ${requestPath}` } }; }); }); await page.getByTestId('sidebar-nav-project-plugins').click(); await expect(page.getByTestId('project-plugins-page')).toBeVisible(); await expect(page.getByText('当前包含,不按单次调用扣点')).toBeVisible(); const localProjectId = await app.evaluate(() => ( (globalThis as typeof globalThis & { __projectPluginE2E?: { localProjectId: string } }).__projectPluginE2E?.localProjectId )); expect(localProjectId).toBeTruthy(); await expect(page.getByText(localProjectId as string)).toHaveCount(0); await expect(page.getByText('11111111-1111-4111-8111-111111111111')).toHaveCount(0); await page.getByRole('button', { name: '启用到项目开发数据服务' }).click(); await expect(page.getByRole('article').getByText('待配置')).toBeVisible(); await expect(page.getByRole('button', { name: '创建开发数据空间' })).toBeDisabled(); const dataServiceCalls = await app.evaluate(() => ( (globalThis as typeof globalThis & { __projectPluginE2E?: { dataServiceCalls: number } }).__projectPluginE2E?.dataServiceCalls )); expect(dataServiceCalls).toBe(0); } finally { await closeElectronApp(app); await rm(projectPath, { recursive: true, force: true }); } }); });