Skip to content

Commit 9fe5da6

Browse files
committed
refactor(arch): 移除废弃模块并优化服务层结构
- 移除废弃的 voiceCommandProcessor.ts(功能已迁移至 voiceCommand/) - 更新 digitalHuman.test.tsx 使用新的 VoiceCommandExecutor - 优化服务层文件结构,职责分明 测试:165 passed, typecheck 通过, lint 0 warnings
1 parent e07977a commit 9fe5da6

8 files changed

Lines changed: 70 additions & 452 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 架构深化:移除废弃模块、合并服务层
2+
3+
## 变更摘要
4+
5+
1. **移除废弃的 `voiceCommandProcessor.ts`**
6+
- 删除 `src/core/audio/voiceCommandProcessor.ts`(已标记 @deprecated
7+
- 删除 `src/__tests__/voiceCommandProcessor.test.ts`
8+
- 更新 `src/core/audio/index.ts` 停止导出废弃函数
9+
- 更新 `digitalHuman.test.tsx` 使用新的 `VoiceCommandExecutor`
10+
11+
2. **优化服务层文件结构**
12+
- 保持 4 文件结构(符合 react-refresh 要求)
13+
- 更新 `services.ts` 为清晰的重导出入口
14+
- 文件职责分明:
15+
- `servicesContext.ts`: Context 定义
16+
- `createServices.ts`: 服务工厂
17+
- `ServicesProvider.tsx`: React Provider
18+
- `serviceHooks.ts`: Hooks
19+
20+
## 影响范围
21+
22+
- `src/core/audio/`: 移除废弃模块
23+
- `src/core/services*.ts`: 结构优化
24+
- `src/__tests__/`: 测试更新
25+
26+
## 测试结果
27+
28+
- TypeScript 类型检查:通过
29+
- ESLint 检查:通过(0 warnings)
30+
- Vitest 测试:165 passed

src/__tests__/digitalHuman.test.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useDigitalHumanStore } from '../store/digitalHumanStore';
66
import { useChatSessionStore } from '../store/chatSessionStore';
77
import { useSystemStore } from '../store/systemStore';
88
import { TTSService, ASRService } from '../core/audio/audioService';
9-
import { processVoiceCommand } from '../core/audio/voiceCommandProcessor';
9+
import { createVoiceCommandExecutor } from '../core/voiceCommand';
1010
import { handleDialogueResponse } from '../core/dialogue/dialogueOrchestrator';
1111
import React from 'react';
1212

@@ -516,18 +516,29 @@ describe('ASRService', () => {
516516
expect(asrService).toBeDefined();
517517
});
518518

519-
it('voice command processor handles cancel mute correctly', () => {
520-
// Voice command processing is now in voiceCommandProcessor.ts
521-
// This test verifies the integration via processVoiceCommand
519+
it('voice command executor handles cancel mute correctly', () => {
520+
// Voice command processing now uses VoiceCommandExecutor
521+
// This test verifies the integration via createVoiceCommandExecutor
522522
useDigitalHumanStore.getState().setMuted(true);
523523

524-
const matched = processVoiceCommand('取消静音', {
525-
play: () => useDigitalHumanStore.getState().play(),
526-
pause: () => useDigitalHumanStore.getState().pause(),
527-
reset: () => useDigitalHumanStore.getState().reset(),
528-
setMuted: (m: boolean) => useDigitalHumanStore.getState().setMuted(m),
524+
const executor = createVoiceCommandExecutor({
525+
systemControls: {
526+
play: () => useDigitalHumanStore.getState().play(),
527+
pause: () => useDigitalHumanStore.getState().pause(),
528+
reset: () => useDigitalHumanStore.getState().reset(),
529+
setMuted: (m: boolean) => useDigitalHumanStore.getState().setMuted(m),
530+
},
531+
avatarControls: {
532+
setEmotion: () => {},
533+
setExpression: () => {},
534+
setAnimation: () => {},
535+
setBehavior: () => {},
536+
speak: () => {},
537+
},
529538
});
530539

540+
const matched = executor.execute('取消静音');
541+
531542
expect(matched).toBe(true);
532543
expect(useDigitalHumanStore.getState().isMuted).toBe(false);
533544
});

src/__tests__/voiceCommandProcessor.test.ts

Lines changed: 0 additions & 244 deletions
This file was deleted.

src/core/audio/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,3 @@ export type {
66
TTSCallbacks,
77
ASRStateAdapter,
88
} from './audioService';
9-
export {
10-
parseVoiceCommand,
11-
processVoiceCommand,
12-
executeVoiceCommandAction,
13-
} from './voiceCommandProcessor';
14-
export type { VoiceCommandAction, VoiceCommandResult } from './voiceCommandProcessor';

0 commit comments

Comments
 (0)