本节基于当前 tests/ 与脚本配置,给出 NaviGo 的测试与评估总结。
tests/
├── unit/
│ ├── agents/
│ ├── security/
│ └── tools/
├── integration/
│ ├── api.chat-endpoint.test.ts
│ ├── api.frontend-route.test.ts
│ ├── api.plan-endpoint.test.ts
│ └── graph.plan-flow.test.ts
├── redteam/
│ └── guardrails.redteam.test.ts
├── evals/
│ └── travel-planner.eval.ts
└── helpers/
└── fake-model.ts
tests/unit/agents/budget.agent.test.tstests/unit/agents/itinerary.agent.test.tstests/unit/agents/risk-guard.agent.test.tstests/unit/agents/form-completer.agent.test.tstests/unit/agents/requirement-parser.agent.test.tstests/unit/security/guardrails.test.tstests/unit/tools/http.test.ts目标:验证单模块逻辑正确性与错误路径。
tests/integration/graph.plan-flow.test.tstests/integration/api.plan-endpoint.test.tstests/integration/api.frontend-route.test.tstests/integration/api.chat-endpoint.test.ts目标:验证完整图流程、API 路由(含聊天与恢复)、静态资源与状态持久化读取行为。
tests/redteam/guardrails.redteam.test.ts目标:验证护栏对已知攻击向量(注入、越狱、homoglyph、零宽字符、间接注入、上下文操纵)的检测能力,并记录盲区。
tests/evals/travel-planner.eval.ts目标:验证“最终计划完整性”基线;该用例对 LANGSMITH_API_KEY 做环境门控。
| 模块 | 已有验证点(来自测试代码) |
|---|---|
requirement-parser.agent.ts |
自然语言字段提取、缺失字段过滤 |
form-completer.agent.ts |
完整表单组装、待澄清问题生成 |
risk-guard.agent.ts |
注入命中与非命中分支、LLM 扫描与规则扫描合并、风险标记写入 |
itinerary.agent.ts |
LLM 行程生成、往返航班集成、天气风险传导、未知城市锚点 fallback |
budget.agent.ts |
超预算/预算内分支及风险标记 |
guardrails.ts |
prompt injection / unsafe output 检测、零宽字符与 homoglyph 归一化 |
tools/common/http.ts |
query 组装、超时中断与错误映射 |
graph/builder.ts + routes.ts |
全链路执行、按状态推进节点、聊天恢复、线程恢复 |
| API 路由 | POST /plan、POST /plan/chat、POST /plan/chat/resume、GET /plan/:threadId 行为与状态读取 |
测试大量使用:
FakeStructuredChatModelcreateInMemoryCheckpointer()因此单元与集成测试不依赖真实外部 API,结果稳定。
测试夹具普遍通过 schema(如 UserRequestSchema.parse(...))构造,保证与生产输入契约一致。
集成测试关注的是状态图执行结果(finalPlan、snapshot、thread 恢复、chat resume),而不是内部实现细节,适合保障重构安全。
tests/redteam/guardrails.redteam.test.ts 对已知盲区(如变体动词、复数形式)仅做信息性日志,不阻断构建,避免假阳性影响开发节奏,同时保留安全审计线索。
tests/evals/travel-planner.eval.ts 的基线评分由四项组成:
通过条件:completenessScore >= 4。
这属于“结构完整性”评估,适合作为最低质量门槛。
以下为建议项(当前仓库未完整实现):
npm run test:unit
npm run test:integration
npm run test:eval
npm run test
npm run acceptance
Red-team 测试(需要 OPENAI_API_KEY 以运行 LLM 生成变体,静态对抗样本无需):
npx vitest run tests/redteam/
其中 acceptance 会在满足环境变量时追加 live CLI 场景验证。
基于现有测试代码可确认:
同时,当前 eval 仍以结构完整性为主,若用于更高可靠性场景,建议补齐语义质量、安全鲁棒性量化评分与性能回归三类评估。