Files
dacli/tests/test-ai-refactored.ts
T
ssw 5473fd4c6b verify: Task 6 端到端走通 (直连 AI → JNPF form create)
新增:
- tests/test-e2e-direct-ai-buildformdata.ts: 完整 e2e 测试
  (直连 AI → buildFormData → POST create API → 反查 → 发布)
  注: 因 type=1 form 需要 dbLinkId 配置正确, 走简化路径;
  实际端到端通过 'dacli form create --ai' 命令验证 (用 ANTHROPIC_* env)

端到端验证结果 (formId=839789894598394629 enCode=bookInfo):
- ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropic
- ANTHROPIC_MODEL=MiniMax-M3
- AI 返回 4 字段 (input/switch/datePicker)
- dacli form create --ai 自动建表单 (state=0, type=4 视图)
- jxcj 应用的 form list 能看到这个 form

关键发现:
- 'Database exception' 是因为 dbLinkId 错 (用 '0' 主库 vs 业务库 ID)
- dacli form create --ai 内部仍走 _simplify, 丢 AI 的 component 类型
- 这正是 Task 7 瘦身要解决: buildFormData 替代 _simplify
2026-06-25 11:25:51 +08:00

26 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 验证 _ai.ts 改造后的双路径
// 用 env 强制走直连 AI(不依赖 JNPF backend)
import { callAiForm, printAiFormResult } from '../src/commands/form/_ai.ts';
// 凭据从环境变量读(不入文件、不入 git)
if (!process.env.ANTHROPIC_BASE_URL) {
console.error('❌ 请设置 ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN / ANTHROPIC_MODEL');
process.exit(1);
}
console.log('配置: BASE_URL=' + process.env.ANTHROPIC_BASE_URL + ' MODEL=' + process.env.ANTHROPIC_MODEL);
console.log('走路径 1: 直连 AI (ANTHROPIC_* 已设)');
console.log();
const r = await callAiForm('做一个客户管理表:姓名、电话、客户类型(个人/企业)、备注');
printAiFormResult(r);
console.log('\n✅ 验证 _ai.ts 直连 AI 路径走通');
// 验证主子表
console.log('\n=== 第二个测试: 主子表 ===');
const r2 = await callAiForm('做一个商城订单管理。主表存订单(订单号、客户姓名、订单状态未付款/已付款/已发货),子表存订单商品明细(商品名称、商品数量)');
printAiFormResult(r2);
console.log('\n✅ 主子表也走通');