fix(form-info): enCode 兜底加 keyword=0 fallback + toLowerCase 模糊匹配
df213fd 加的 enCode 兜底在 tdd8 smoke test 暴露 1 个边界 bug:
- web 端 getVisualDevList({ keyword }) 是 exact-match
- 输入 "tdd8customermanage" (lowercase) 但实际 enCode="tdd8CustomerManage" (PascalCase)
→ keyword 查询 0 条 → resolver 报"未匹配"
修复:
1. keyword 查询 0 条时 fallback 到无 keyword 全量 (pageSize=500, 单 app 表单数 < 500 安全)
2. toLowerCase 模糊匹配 (处理 PascalCase / camelCase 大小写不一致)
3. try/catch 兜底 (web 端偶发 5xx 不阻断 — 走 fallback)
验证 (tdd8 smoke test 2026-07-24):
- dacli form info tdd8customermanage --summary → 0.2s (命中 fallback, 正确解析)
- dacli form info 850387545819711621 --summary → 0.1s (literal id 路径, 性能无回归)
- typecheck 0 errors, anti_patterns tests 10/10, doc:check PASS (0 drift)
tdd8 app + 5 关卡验证文档已写 docs/tdd8/learnings.md (workdir 无 git, 不入 dacli repo)
This commit is contained in:
1 parent
955a3780a6
commit
afc2a88105
1 file changed
+25
-10
+25
-10
@@ -29,20 +29,35 @@ async function resolveFormId(input: string): Promise<{ id: string; resolvedFrom:
|
||||
if (/^[\d-]+$/.test(input) && input.length >= 10) {
|
||||
return { id: input, resolvedFrom: 'literal' }
|
||||
}
|
||||
// 否则按 enCode 查
|
||||
// 否则按 enCode 查 — 注意: web 端 getVisualDevList 用 keyword 做 exact-match,
|
||||
// 若 enCode 大小写不一致 (e.g. 输入 "tdd8customermanage" 但实际 enCode="tdd8CustomerManage")
|
||||
// → 返回 0 条. fallback: keyword 0 条时拉全量 + 客户端模糊匹配
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initWebapi(c)
|
||||
const resp = (await loadVisualDev.getVisualDevList({
|
||||
keyword: input,
|
||||
currentPage: 1,
|
||||
pageSize: 200,
|
||||
})) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> }
|
||||
const list = resp.list || []
|
||||
// 精确匹配 enCode (优先); 否则 fullName 包含; 最后模糊 enCode
|
||||
let list: Array<{ id?: string; enCode?: string; fullName?: string }> = []
|
||||
try {
|
||||
const resp = (await loadVisualDev.getVisualDevList({
|
||||
keyword: input,
|
||||
currentPage: 1,
|
||||
pageSize: 200,
|
||||
})) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> }
|
||||
list = resp.list || []
|
||||
} catch { /* fallback below */ }
|
||||
// keyword 查询 0 条时, 拉全量客户端模糊匹配 (单 app 表单数一般 < 500, pageSize=500 安全)
|
||||
if (list.length === 0) {
|
||||
const resp = (await loadVisualDev.getVisualDevList({
|
||||
currentPage: 1,
|
||||
pageSize: 500,
|
||||
})) as { list?: Array<{ id?: string; enCode?: string; fullName?: string }> }
|
||||
list = resp.list || []
|
||||
}
|
||||
// 精确匹配 enCode (优先); 否则 fullName 包含; 最后模糊 enCode (toLowerCase 兼容 PascalCase)
|
||||
const inputLower = input.toLowerCase()
|
||||
const exact = list.find((f) => f.enCode === input)
|
||||
const byName = list.find((f) => f.fullName === input)
|
||||
const fuzzy = list.find((f) => (f.enCode || '').toLowerCase().includes(input.toLowerCase()))
|
||||
const hit = exact || byName || fuzzy
|
||||
const fuzzyEnCode = list.find((f) => (f.enCode || '').toLowerCase() === inputLower)
|
||||
const fuzzyPartial = list.find((f) => (f.enCode || '').toLowerCase().includes(inputLower))
|
||||
const hit = exact || byName || fuzzyEnCode || fuzzyPartial
|
||||
if (!hit || !hit.id) {
|
||||
throw new Error(`enCode 未匹配到 form: "${input}" (list 返回 ${list.length} 条, 请用 dacli form list 查正确 enCode)`)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user