On native App the eager TTS request delayed the answer bubble: the message was created in `preparing` state, so the text stayed behind a voice line that was still waiting on a round trip. Skip the preload when `isNativeAppRuntime()`, marking the voice `unavailable` so the text and citations render immediately. The existing `unavailable` branch already exposes a play button that calls `toggleAnswerSpeech`, so voice stays reachable on demand instead of being dropped. H5 keeps preloading. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
59 lines
2.7 KiB
JavaScript
59 lines
2.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
|
|
const source = async (path) => readFile(new URL(path, import.meta.url), 'utf8');
|
|
|
|
test('问数字师傅统一使用 Agent 文本与媒体入口', async () => {
|
|
const [service, page] = await Promise.all([
|
|
source('../src/services/agent.ts'),
|
|
source('../src/pages/user/sop/index.vue')
|
|
]);
|
|
|
|
assert.match(service, /\/api\/aihr\/agent\/messages'/);
|
|
assert.match(service, /\/api\/aihr\/agent\/messages\/media/);
|
|
assert.doesNotMatch(service, /toolCode/);
|
|
assert.doesNotMatch(service, /\/api\/knowledge\/query/);
|
|
assert.match(page, /askAgent/);
|
|
assert.match(page, /askAgentWithMedia/);
|
|
assert.doesNotMatch(page, /await searchKnowledge\(/);
|
|
assert.doesNotMatch(page, /await queryKnowledgeTool\(/);
|
|
});
|
|
|
|
test('Agent 响应按结构化状态渲染来源、澄清和确认动作', async () => {
|
|
const [types, service, page] = await Promise.all([
|
|
source('../src/types/api.ts'),
|
|
source('../src/services/agent.ts'),
|
|
source('../src/pages/user/sop/index.vue')
|
|
]);
|
|
|
|
assert.match(types, /export type AgentStatus = 'COMPLETED' \| 'NEEDS_INPUT' \| 'NEEDS_CONFIRMATION'/);
|
|
assert.match(types, /sourceSummary\?: AgentSourceSummary\[\]/);
|
|
assert.match(types, /agentDraftId\?: string/);
|
|
assert.match(service, /status === 'NO_EVIDENCE'/);
|
|
assert.match(service, /agentDraftId: response\.actionDraft\.draftId/);
|
|
assert.match(page, /agent-source-chip/);
|
|
assert.match(page, /msg\.result\.agentStatus === 'NEEDS_INPUT'/);
|
|
assert.match(page, /consentWebResearch/);
|
|
assert.doesNotMatch(page, /result\.answer\.(?:includes|match|startsWith)/);
|
|
});
|
|
|
|
test('原生 App 立即显示 Agent 文字回答,语音仅按需生成', async () => {
|
|
const page = await source('../src/pages/user/sop/index.vue');
|
|
|
|
assert.match(page, /const shouldPreloadVoice = Boolean\(spoken\) && !isNativeAppRuntime\(\)/);
|
|
assert.match(page, /voiceStatus: shouldPreloadVoice \? 'preparing' : 'unavailable'/);
|
|
assert.match(page, /if \(shouldPreloadVoice\) void prepareVoice\(pending\.id, spoken\)/);
|
|
});
|
|
|
|
test('Agent 确认卡通过不透明 draftId 调用动作端点', async () => {
|
|
const [assistantService, card] = await Promise.all([
|
|
source('../src/services/personal-assistant.ts'),
|
|
source('../src/components/chat/MemoryCandidateCard.vue')
|
|
]);
|
|
|
|
assert.match(assistantService, /\/api\/aihr\/agent\/actions\/\$\{encodeURIComponent\(String\(candidateRef\)\)\}\/confirm/);
|
|
assert.match(assistantService, /\/api\/aihr\/agent\/actions\/\$\{encodeURIComponent\(String\(candidateRef\)\)\}\/dismiss/);
|
|
assert.match(card, /props\.candidate\.agentDraftId \|\| props\.candidate\.id/);
|
|
});
|