feat(vscode-ide-companion): cherry-pick ACP compatibility improvements from PR #2195

- Add extractSessionListItems() utility for robust ACP response parsing
- Refactor getSessionList() and getSessionListPaged() to use the new utility
- Add openNewChatTabCommand to create new session when opening chat tab
- Add comprehensive test coverage for session list extraction

Co-authored-by: ZZAoYe <zzbuaoye@gmail.com>
This commit is contained in:
yiliang114 2026-03-09 16:11:26 +08:00
parent 2334386b69
commit b26e21f71d
5 changed files with 198 additions and 24 deletions

View file

@ -0,0 +1,98 @@
/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, expect, it, vi } from 'vitest';
import {
extractSessionListItems,
QwenAgentManager,
} from './qwenAgentManager.js';
vi.mock('vscode', () => ({
window: {
showInformationMessage: vi.fn(),
showWarningMessage: vi.fn(),
showErrorMessage: vi.fn(),
},
}));
describe('extractSessionListItems', () => {
it('reads ACP session arrays from the sessions field', () => {
const items = extractSessionListItems({
sessions: [{ sessionId: 'session-1' }],
});
expect(items).toEqual([{ sessionId: 'session-1' }]);
});
it('reads ACP session arrays from the legacy items field', () => {
const items = extractSessionListItems({
items: [{ sessionId: 'session-2' }],
});
expect(items).toEqual([{ sessionId: 'session-2' }]);
});
it('returns empty array for invalid responses', () => {
expect(extractSessionListItems(null)).toEqual([]);
expect(extractSessionListItems(undefined)).toEqual([]);
expect(extractSessionListItems('string')).toEqual([]);
expect(extractSessionListItems({})).toEqual([]);
expect(extractSessionListItems({ sessions: 'not-array' })).toEqual([]);
});
it('prefers sessions over items when both exist', () => {
const items = extractSessionListItems({
sessions: [{ sessionId: 'from-sessions' }],
items: [{ sessionId: 'from-items' }],
});
expect(items).toEqual([{ sessionId: 'from-sessions' }]);
});
});
describe('QwenAgentManager session list compatibility', () => {
it('maps paged ACP session lists returned via items', async () => {
const manager = new QwenAgentManager();
const listSessions = vi.fn().mockResolvedValue({
items: [
{
sessionId: 'session-3',
prompt: 'Fix sidebar history',
mtime: 1772114825468.5825,
cwd: '/workspace/qwen-code',
},
],
});
(
manager as unknown as {
connection: { listSessions: typeof listSessions };
}
).connection = { listSessions };
const page = await manager.getSessionListPaged({ size: 20 });
expect(listSessions).toHaveBeenCalledWith({ size: 20 });
expect(page).toEqual({
sessions: [
{
id: 'session-3',
sessionId: 'session-3',
title: 'Fix sidebar history',
name: 'Fix sidebar history',
startTime: undefined,
lastUpdated: 1772114825468.5825,
messageCount: 0,
projectHash: undefined,
filePath: undefined,
cwd: '/workspace/qwen-code',
},
],
nextCursor: undefined,
hasMore: false,
});
});
});