来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
61 lines
3.5 KiB
TypeScript
61 lines
3.5 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
|
||
/**
|
||
* AI 助手悬浮球:流式进度接入(P2b-7,2026-09-23)。
|
||
*
|
||
* 文案边界(`.cursor/rules/frontend-copy-changes.mdc` + 开发者 2026-09-23 指示):
|
||
* **只动 AI 助手自己的进度行,其它业务页面一律不碰、不新增小字**。
|
||
* 进度行只显示工具名(既有 `TOOL_LABELS` + 经批准的 `assistant.progress.tool.*` 25 条),
|
||
* 不新增任何前后缀句子;没有名字的工具不显示;无进度时与改前一致(仍是「处理中…」)。
|
||
*/
|
||
describe('OrderEntryIntakeFab 流式进度', () => {
|
||
const src = readFileSync(path.join(__dirname, 'OrderEntryIntakeFab.tsx'), 'utf8');
|
||
|
||
it('走 requestAssistantChat(流式优先 + 自动回退),不再直接 fetch /chat', () => {
|
||
expect(src).toContain("import { requestAssistantChat } from '../copilot/assistantChatStream';");
|
||
expect(src).toContain('const { payload } = await requestAssistantChat({');
|
||
expect(src).toContain('onProgress: (event) => {');
|
||
// 旧的直连 /chat 写法必须消失(回退逻辑收敛到 copilot 模块,避免两条路径漂移)
|
||
expect(src).not.toContain("fetch(buildApiUrl('/mcp/order-entry/chat')");
|
||
});
|
||
|
||
it('进度标签:既有 TOOL_LABELS 优先,其次经批准的 assistant.progress.tool.*,都不露裸工具名', () => {
|
||
expect(src).toContain('function progressLabelFor(name: string, t: (key: string) => string): string {');
|
||
expect(src).toContain('return TOOL_LABELS[raw] || assistantProgressToolLabel(t, raw);');
|
||
// 渲染行格式不变:只把工具名拼起来,不加「正在执行:」这类前后缀
|
||
expect(src).toContain("{progressLabels.length ? progressLabels.join('、') : '处理中…'}");
|
||
expect(src).not.toContain('progress.running');
|
||
});
|
||
|
||
it('进度文案只在助手范围内:词条落在 assistant 命名空间,且没有其它页面引用', () => {
|
||
expect(src).toContain("import { assistantProgressToolLabel } from '../i18n/assistantLabel';");
|
||
const label = readFileSync(path.join(__dirname, '..', 'i18n', 'assistantLabel.ts'), 'utf8');
|
||
expect(label).toContain('assistant.progress.tool.${raw}');
|
||
});
|
||
|
||
it('进度写入受会话代次守卫(过期进度不得写进新会话)', () => {
|
||
const progressBlock = src.slice(
|
||
src.indexOf('onProgress: (event) => {'),
|
||
src.indexOf('if (gen !== conversationGen.current) return; // 会话已切换:丢弃过期响应')
|
||
);
|
||
expect(progressBlock).toContain('if (gen !== conversationGen.current) return;');
|
||
expect(progressBlock).toContain('setProgressLabels(');
|
||
});
|
||
|
||
it('进度只在本次请求期间显示(开始清空、finally 清空)', () => {
|
||
expect(src).toContain('setProgressLabels([]);');
|
||
const resets = src.match(/setProgressLabels\(\[\]\);/g) || [];
|
||
expect(resets.length).toBeGreaterThanOrEqual(2);
|
||
expect(src).toMatch(/setLoading\(false\);\s*\n\s*setProgressLabels\(\[\]\);/);
|
||
});
|
||
|
||
it('回退路径仍然可用:错误分支与既有提示不变', () => {
|
||
// 非 2xx 的说明由 copilot 模块抛出,FAB 只负责展示(既有 catch 不改)
|
||
expect(src).toContain("setError(err instanceof Error ? err.message : '助手失败');");
|
||
// 失败也不会把进度条卡住:finally 里既复位 loading 也清空进度
|
||
expect(src).toMatch(/if \(gen === conversationGen\.current\) \{\s*\n\s*setLoading\(false\);\s*\n\s*setProgressLabels\(\[\]\);/);
|
||
});
|
||
});
|