Testing Strategy

自动化测试策略

每次实施后的必经检查站
保证代码正确、逻辑正确、运行正确

🔗

测试跟着实施走

每个 Phase 包含对应测试任务

🚦

先测后进

全绿后才开始下一个 Phase

📋

两层验证

自动化 + 手动清单

🎯

最小覆盖

只测关键逻辑和边界

当前测试状态

56
tests passing
4
test suites
0.6s
total runtime
0
failures
☁️ 云端 API
Jest + supertest
T
health.test.js 3
T
process.test.js 18
T
filter.test.js 22
T
notes.test.js 13
H
helpers/mock-responses.js 6 fixtures
📱 iOS 端
XCTest(Phase 1 起)
待 Phase 1 建立
Core Data in-memory store
Mock LocationManager
Mock SpeechRecognizer

测试套件详情

点击卡片展开查看所有测试用例

health.test.js 3 tests
基础连通性 — 健康检查、CORS、预检
GET /health
returns ok status with service info
returns correct CORS headers
handles OPTIONS preflight
filter.test.js 22 tests
地点过滤纯逻辑 — 关键词匹配、购物意图识别
preserves LOCATION triggers
keeps triggers with location keyword (去超市)
keeps triggers with shopping intent (没了)
keeps triggers with shopping intent (快没了)
keeps triggers with shopping intent (用完了)
keeps triggers with LLM display_text keyword
removes LOCATION triggers
strips LOCATION with no keywords
preserves non-LOCATION triggers
multi-memory + keyword coverage
keeps all when any text matches
strips all when no keywords
+ 11 keyword coverage tests
process.test.js 18 tests
核心业务逻辑 — LLM 调用(mock)、解析、降级
input validation
rejects missing text / empty / whitespace / non-string
successful processing
ACTION (买盐), THOUGHT (content+themes)
multi-item, TIME trigger, PERSON trigger
KNOWLEDGE type
edge cases
JSON markdown code block fallback
location filter integration
500 error with fallback memory
LLM call parameters
system prompt, time context, temperature, trim
notes.test.js 13 tests
Notes CRUD — 创建、读取、删除、默认值、截断
GET /notes
empty array / existing notes
POST /notes
all fields, defaults (匿名, idea)
valid tags, rejects empty, truncation
newest first ordering
DELETE /notes/:id
deletes existing / 404 for missing

Mock 响应库

Anthropic SDK 被 jest.mock() 拦截,所有 LLM 调用不触及真实 API

Fixture 类型 场景 触发器
RESPONSE_BUY_SALT ACTION 购物 — 盐没了 LOCATION: supermarket
RESPONSE_MULTI_ITEM ACTION×2 多条拆分 — 盐 + 酱油 LOCATION×2
RESPONSE_THOUGHT THOUGHT 想法 + content + themes
RESPONSE_MEETING ACTION 开会 — 明天三点 TIME
RESPONSE_PERSON_TRIGGER ACTION 见人 — 问老张合同 PERSON: 老张
RESPONSE_KNOWLEDGE KNOWLEDGE 信息 — 护照位置

每次实施的测试流程

🌿
开分支
创建 feature branch
git checkout -b
跑基线
确认现有测试全绿
npm test
写代码 + 测试
同步写功能和测试
npm run test:watch
🧪
全量测试
完整测试套件
npm test
📋
手动验证
按清单逐条检查
📦
提交
全绿才提交
git commit
⚠️ 失败处理
测试红了 → 不提交,先修复
新功能没有测试 → 补测试后再提交
手动验证发现问题 → 写自动化测试重现 → 修复 → 确认全绿

各 Phase 测试要求

0
测试基建 已完成
☁️ API 侧
Jest + supertest 安装
server.js 可导入(require.main === module)
mock-responses.js fixtures(6 种场景)
4 个测试文件,56 tests 全绿
1
编码上下文 待实施
☁️ API 侧新增测试
上下文字段在 request body 中传递
processWithRetry 将上下文注入 LLM messages
响应中包含 context 元数据
📱 iOS 侧测试
Core Location 权限请求模拟
编码上下文组装逻辑
Core Data 存储 + 读取 context 字段
👁️ 手动验证
模拟器录入记忆 → API 请求含上下文
Core Data 查看存储的 context JSON
2a
Gateway 路由 待实施
☁️ API 侧新增测试
关键词命中 → 快速路径(不调 LLM)
无匹配 → LLM 常规路径
快速路径响应格式一致性
路由决策日志输出
👁️ 手动验证
"盐没了" 走快速路径 < 100ms
"我觉得远程办公更好" 走 LLM
日志显示路由选择
2b
图式 + Heartbeat 待实施
☁️ API 侧
图式匹配:已有图式走预填充
图式涌现:第 N 条同模式创建图式
Heartbeat 合并/降权逻辑
📱 iOS 侧
ThoughtThread 实体 CRUD
线索检测(3+ 同主题 → 形成线索)
线索通知触发
👁️ 手动验证
5 条购物 → 图式涌现
第 6 条走快速路径
3
检索重建 待实施
☁️ API 侧
检索请求:上下文 → 相关记忆
排序:上下文匹配度 > 时间
📱 iOS 侧
地理围栏触发 → 检索关联记忆
检索结果排序 + 展示
👁️ 手动验证
超市位置模拟 → 推送购物清单
4
渐进演化 待实施
📊 性能基准测试
LLM 调用频率(与基线对比)
端到端延迟对比
图式命中率统计