From b70dc9dc6d90124ee63eea04bfe73ab06129bd62 Mon Sep 17 00:00:00 2001 From: liangxu Date: Sun, 12 Jul 2026 11:55:13 +0800 Subject: [PATCH] test(qwen-adapter): cover tab-container placeholder handling Add query-level cases asserting an internal placeholder yields `unknown`/`qwen_incomplete_response`, and that a resolved sibling field is used as the answer when another field is still a placeholder. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../src/main/adapters/qwen.test.ts | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/apps/desktop-client/src/main/adapters/qwen.test.ts b/apps/desktop-client/src/main/adapters/qwen.test.ts index 98324dd..fa2f1ce 100644 --- a/apps/desktop-client/src/main/adapters/qwen.test.ts +++ b/apps/desktop-client/src/main/adapters/qwen.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' -import { __qwenTestUtils } from './qwen' +import type { AdapterContext } from './base' +import { __qwenTestUtils, qwenAdapter } from './qwen' const { extractQuestionText } = __qwenTestUtils @@ -15,3 +16,81 @@ describe('qwen adapter helpers', () => { ) }) }) + +describe('qwen adapter query result validation', () => { + it('does not submit an internal tab-container placeholder as a successful answer', async () => { + const page = { + waitForLoadState: async () => undefined, + url: () => 'https://www.qianwen.com/chat/demo', + goto: async () => undefined, + evaluate: async () => ({ + ok: true as const, + url: 'https://www.qianwen.com/chat/demo', + question: { + model: 'Qwen', + deepSearch: '1', + enableSearch: true, + cardText: '测试问题', + }, + answer: { + reqId: 'req-1', + status: 'finish', + content: { + multiLoadIframe: { + content: '[(tab_container_1)]', + }, + searchResults: [{ url: 'https://example.com/source', title: '来源' }], + }, + extraInfo: null, + communication: null, + }, + }), + } + const context = { + playwright: { page, browser: {} }, + reportProgress: () => undefined, + } as unknown as AdapterContext + + const result = await qwenAdapter.query(context, { question_text: '测试问题' }) + + expect(result.status).toBe('unknown') + expect(result.error?.code).toBe('qwen_incomplete_response') + }) + + it('uses a resolved fallback answer when another content field is still a placeholder', async () => { + const page = { + waitForLoadState: async () => undefined, + url: () => 'https://www.qianwen.com/chat/demo', + goto: async () => undefined, + evaluate: async () => ({ + ok: true as const, + url: 'https://www.qianwen.com/chat/demo', + question: { + model: 'Qwen', + deepSearch: '1', + enableSearch: true, + cardText: '测试问题', + }, + answer: { + reqId: 'req-2', + status: 'finish', + content: { + multiLoadIframe: { content: '[(tab_container_1)]' }, + barIframe: { content: '这是完整答案。' }, + }, + extraInfo: null, + communication: null, + }, + }), + } + const context = { + playwright: { page, browser: {} }, + reportProgress: () => undefined, + } as unknown as AdapterContext + + const result = await qwenAdapter.query(context, { question_text: '测试问题' }) + + expect(result.status).toBe('succeeded') + expect(result.payload?.answer).toBe('这是完整答案。') + }) +})