feat(coding): complete PI conversation UI
This commit is contained in:
@@ -53,8 +53,10 @@ async function disableCodingEventSource(page: Page): Promise<void> {
|
||||
async function installCodingFirstChatHost(
|
||||
electronApp: ElectronApplication,
|
||||
hostConnection: HostConnection,
|
||||
featureComplete = false,
|
||||
): Promise<void> {
|
||||
await electronApp.evaluate(async (_, connection) => {
|
||||
await electronApp.evaluate(async (_, payload) => {
|
||||
const { connection, featureComplete } = payload;
|
||||
const { ipcMain } = process.mainModule!.require('electron') as typeof import('electron');
|
||||
type MainState = {
|
||||
captured: CapturedRequest[];
|
||||
@@ -133,6 +135,16 @@ async function installCodingFirstChatHost(
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
const secondConversation = {
|
||||
...conversation,
|
||||
id: 'conversation-pi-second',
|
||||
title: 'Second Conversation',
|
||||
updatedAt: '2026-08-23T23:59:00.000Z',
|
||||
model: featureComplete
|
||||
? { accountId: 'account-e2e', modelId: 'model-b', thinkingLevel: 'low' }
|
||||
: null,
|
||||
modelResolution: featureComplete ? 'resolved' : 'required',
|
||||
};
|
||||
const snapshot = {
|
||||
schemaVersion: 1,
|
||||
conversation: {
|
||||
@@ -142,13 +154,52 @@ async function installCodingFirstChatHost(
|
||||
title: conversation.title,
|
||||
model: { model: null, modelResolution: 'required' },
|
||||
},
|
||||
nodes: featureComplete ? [{
|
||||
kind: 'subagent',
|
||||
id: 'subagent-e2e',
|
||||
runId: 'run-e2e-feature',
|
||||
details: {
|
||||
schema: 'subagent.v1',
|
||||
dispatchId: 'dispatch-e2e',
|
||||
mode: 'parallel',
|
||||
tasks: [
|
||||
{ taskId: 'task-reader', agentId: 'reader', toolProfile: 'read-only', status: 'complete', summary: 'Read complete' },
|
||||
{ taskId: 'task-builder', agentId: 'builder', toolProfile: 'coding', status: 'running' },
|
||||
],
|
||||
},
|
||||
}] : [],
|
||||
run: featureComplete ? { status: 'running', runId: 'run-e2e-feature', mode: 'prompt' } : { status: 'idle' },
|
||||
queue: { items: featureComplete ? [{ id: 'queue-e2e', clientRequestId: 'request-queued', mode: 'follow-up', text: 'Queued follow-up', attachmentIds: [] }] : [] },
|
||||
context: featureComplete
|
||||
? { usedTokens: 256, contextWindow: 4096, compaction: 'idle' }
|
||||
: { usedTokens: 0, contextWindow: 0, compaction: 'idle' },
|
||||
pendingInteractions: featureComplete ? [{
|
||||
id: 'interaction-e2e',
|
||||
conversationId: conversation.id,
|
||||
runId: 'run-e2e-feature',
|
||||
kind: 'confirm',
|
||||
title: '允许继续?',
|
||||
message: '确认当前实现方向。',
|
||||
status: 'pending',
|
||||
}] : [],
|
||||
worker: { status: 'ready', generation: 1 },
|
||||
cursor: { workerGeneration: 1, seq: 0 },
|
||||
};
|
||||
const secondSnapshot = {
|
||||
...snapshot,
|
||||
conversation: {
|
||||
...snapshot.conversation,
|
||||
id: secondConversation.id,
|
||||
title: secondConversation.title,
|
||||
model: {
|
||||
model: secondConversation.model,
|
||||
modelResolution: secondConversation.modelResolution,
|
||||
},
|
||||
},
|
||||
nodes: [],
|
||||
run: { status: 'idle' },
|
||||
queue: { items: [] },
|
||||
context: { usedTokens: 0, contextWindow: 0, compaction: 'idle' },
|
||||
pendingInteractions: [],
|
||||
worker: { status: 'ready', generation: 1 },
|
||||
cursor: { workerGeneration: 1, seq: 0 },
|
||||
};
|
||||
const respond = (json: unknown, status = 200) => ({
|
||||
ok: true,
|
||||
@@ -227,21 +278,43 @@ async function installCodingFirstChatHost(
|
||||
if (path === '/api/coding/projects') {
|
||||
return respond({ projects: [project], activeProjectId: project.id });
|
||||
}
|
||||
if (path === '/api/provider-accounts') {
|
||||
return respond(featureComplete ? [{
|
||||
id: 'account-e2e',
|
||||
vendorId: 'custom',
|
||||
label: 'E2E account',
|
||||
authMode: 'api_key',
|
||||
model: 'model-a',
|
||||
fallbackModels: ['model-b'],
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}] : []);
|
||||
}
|
||||
if (path === '/api/provider-accounts/key-info') return respond([]);
|
||||
if (path === '/api/provider-vendors') return respond(featureComplete ? [{ id: 'custom', name: 'Custom' }] : []);
|
||||
if (path === '/api/provider-accounts/default') return respond({ accountId: featureComplete ? 'account-e2e' : null });
|
||||
if (path === `/api/coding/projects/config?projectId=${project.id}`) {
|
||||
return respond({ snapshot: { project, config, knowledgeFiles: [] } });
|
||||
}
|
||||
if (path === `/api/coding/projects/conversations?projectId=${project.id}`) {
|
||||
return respond({ conversations: [] });
|
||||
return respond({ conversations: featureComplete ? [conversation, secondConversation] : [] });
|
||||
}
|
||||
if (path === '/api/coding/projects/conversations' && method === 'POST') {
|
||||
return respond({ conversation }, 201);
|
||||
}
|
||||
if (path === `/api/coding/conversations/${conversation.id}/snapshot`) {
|
||||
state.snapshotPending = true;
|
||||
await new Promise<void>((resolve) => { state.releaseSnapshot = resolve; });
|
||||
state.snapshotPending = false;
|
||||
if (!featureComplete) {
|
||||
state.snapshotPending = true;
|
||||
await new Promise<void>((resolve) => { state.releaseSnapshot = resolve; });
|
||||
state.snapshotPending = false;
|
||||
}
|
||||
return respond({ snapshot });
|
||||
}
|
||||
if (path === `/api/coding/conversations/${secondConversation.id}/snapshot`) {
|
||||
return respond({ snapshot: secondSnapshot });
|
||||
}
|
||||
if (path === `/api/coding/conversations/${conversation.id}/prompt` && method === 'POST') {
|
||||
return respond({
|
||||
acceptance: {
|
||||
@@ -253,6 +326,33 @@ async function installCodingFirstChatHost(
|
||||
},
|
||||
}, 202);
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/(abort|compact|recover)$/.test(path) && method === 'POST') {
|
||||
return respond({});
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/model$/.test(path) && method === 'POST') {
|
||||
return respond({ model: { model: body?.model, modelResolution: 'resolved' } });
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/thinking$/.test(path) && method === 'POST') {
|
||||
return respond({ model: snapshot.conversation.model });
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/fork$/.test(path) && method === 'POST') {
|
||||
return respond({ conversation: { ...conversation, id: 'conversation-forked', title: 'Feature UI branch' } }, 201);
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+$/.test(path) && method === 'PATCH') {
|
||||
return respond({ conversation: { ...conversation, ...(body?.title ? { title: body.title } : {}), unread: body?.unread === true, archivedAt: body?.archived === true ? now : null } });
|
||||
}
|
||||
if (/^\/api\/coding\/interactions\/[^/]+\/respond$/.test(path) && method === 'POST') {
|
||||
return respond({});
|
||||
}
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/changes$/.test(path)) {
|
||||
return respond({ changes: { conversationId: conversation.id, runId: 'run-e2e-feature', git: true, baselineHead: 'head-e2e', files: [{ path: 'src/app.ts', status: 'modified', diff: '+feature UI' }] } });
|
||||
}
|
||||
if (path === '/api/coding/files/status') return respond({ files: [{ path: 'src/app.ts', name: 'app.ts', type: 'file', status: 'modified' }] });
|
||||
if (path.startsWith('/api/coding/files/content?')) return respond({ file: { path: 'src/app.ts', content: 'export const app = true;', truncated: false } });
|
||||
if (path.startsWith('/api/coding/files/find?')) return respond({ files: [{ path: 'src/app.ts', name: 'app.ts', type: 'file' }] });
|
||||
if (path.startsWith('/api/coding/skills')) return respond({ skills: [{ id: 'research', name: 'Research', description: 'Inspect sources', selected: true }] });
|
||||
if (/^\/api\/coding\/conversations\/[^/]+\/commands$/.test(path)) return respond({ commands: [{ name: 'review', title: 'Review', description: 'Review changes', source: 'makelore' }] });
|
||||
if (path === '/api/coding/runtime/diagnostics') return respond({ runtime: { revision: { provider: 1, resources: 1 }, workers: [{ conversationId: conversation.id, generation: 1, state: 'running', stage: 'running' }] } });
|
||||
if (path.startsWith('/api/opencode/status')) {
|
||||
return respond({ state: 'stopped', port: null, url: null });
|
||||
}
|
||||
@@ -272,7 +372,7 @@ async function installCodingFirstChatHost(
|
||||
}
|
||||
return respond({ success: false, error: `Unhandled E2E route: ${method} ${path}` }, 404);
|
||||
});
|
||||
}, hostConnection);
|
||||
}, { connection: hostConnection, featureComplete });
|
||||
}
|
||||
|
||||
async function readState(electronApp: ElectronApplication): Promise<{
|
||||
@@ -385,3 +485,62 @@ test('first PI Conversation is editable under 500 ms and submits before runtime
|
||||
await releaseSnapshot(electronApp);
|
||||
}
|
||||
});
|
||||
|
||||
test('PI feature UI isolates Conversations and exposes queue, interaction, model, subagent, and project tools', async ({
|
||||
launchElectronApp,
|
||||
}) => {
|
||||
const electronApp = await launchElectronApp({ skipSetup: true });
|
||||
let page = await getStableWindow(electronApp);
|
||||
const hostConnection = await page.evaluate(async () => ({
|
||||
token: await window.electron.ipcRenderer.invoke('hostapi:token') as string,
|
||||
baseUrl: await window.electron.ipcRenderer.invoke('hostapi:base-url') as string,
|
||||
}));
|
||||
await installCodingFirstChatHost(electronApp, hostConnection, true);
|
||||
await disableCodingEventSource(page);
|
||||
|
||||
try {
|
||||
await page.reload();
|
||||
page = await getStableWindow(electronApp);
|
||||
await page.getByTestId('ai-module-option-programming').click();
|
||||
await expect(page.getByTestId('main-layout')).toBeVisible();
|
||||
await page.evaluate(() => { window.location.hash = '/opencode-chat'; });
|
||||
|
||||
await expect(page.getByTestId('coding-conversation-header')).toContainText('生成中');
|
||||
await expect(page.getByTestId('coding-conversation-header')).toContainText('队列 1');
|
||||
await expect(page.getByText('并行子任务')).toBeVisible();
|
||||
await expect(page.getByText('允许继续?')).toBeVisible();
|
||||
await page.getByRole('button', { name: '确认', exact: true }).click();
|
||||
|
||||
const mode = page.getByRole('combobox', { name: '消息发送方式' });
|
||||
await mode.selectOption('follow-up');
|
||||
await expect(mode).toHaveValue('follow-up');
|
||||
|
||||
const model = page.getByRole('combobox', { name: '当前对话模型' });
|
||||
await model.selectOption(JSON.stringify(['account-e2e', 'model-b']));
|
||||
await page.getByRole('button', { name: '中止' }).click();
|
||||
|
||||
await page.getByRole('button', { name: '打开编程工具' }).click();
|
||||
await expect(page.getByRole('dialog')).toContainText('编程工具');
|
||||
await page.getByRole('tab', { name: '命令' }).click();
|
||||
await page.getByRole('button', { name: /\/review/ }).click();
|
||||
await expect(page.getByRole('textbox')).toHaveValue('/review ');
|
||||
|
||||
await page.getByRole('button', { name: 'Second Conversation' }).first().click();
|
||||
await expect(page.getByTestId('coding-conversation-header')).toContainText('Second Conversation');
|
||||
await expect(page.getByRole('combobox', { name: '当前对话模型' })).toHaveValue(
|
||||
JSON.stringify(['account-e2e', 'model-b']),
|
||||
);
|
||||
await expect(page.getByRole('textbox')).toHaveValue('');
|
||||
|
||||
await expect(page.getByText(/分享|取消分享|回滚|恢复回滚|待办|全局运行时/)).toHaveCount(0);
|
||||
const state = await readState(electronApp);
|
||||
expect(state.captured.some((request) => request.path.endsWith('/model') && request.method === 'POST')).toBe(true);
|
||||
expect(state.captured.some((request) => request.path.endsWith('/abort') && request.method === 'POST')).toBe(true);
|
||||
expect(state.captured.some((request) => request.path.includes('/interactions/') && request.path.endsWith('/respond'))).toBe(true);
|
||||
expect(state.captured.some((request) => request.path.endsWith('/commands'))).toBe(true);
|
||||
expect(state.captured.some((request) => request.path.endsWith('/changes'))).toBe(true);
|
||||
expect(state.captured.every((request) => !request.path.includes('/api/opencode/share'))).toBe(true);
|
||||
} finally {
|
||||
await releaseSnapshot(electronApp);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user