From 77850f1ba14c67a1d2db89c98f08c583e7306d4e Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 17:28:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(test):=20B-14=20List-search-by-marker=20+?= =?UTF-8?q?=20=E8=B7=B3=E8=BF=87=20sidx/sort=20(5/5=20CRUD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tds batch2 (2026-06-27): - B-14 修: JNPF POST /visualdev/OnlineDev/{id} 不返 id - 方案: 在 sample 第一个字符串字段注入 _TEST_TIMESTAMP 标记, POST 后用 List keyword 过滤, 在结果里找含 testMarker 的行拿 id - B-14 副作用: sidx='createTime' + sort='desc' 会让 List total=0 (JNPF bug), 改不传 sidx/sort, 用 keyword 过滤 + 程序里找 hit - 效果: 5/5 CRUD PASS (POST → GET info → PUT update → DELETE), 总耗时 ~200ms 后续 webapp 子代理可直接用 dacli test run --formId=X 做 API 层验证, 不再卡 POST 不返 id --- src/commands/test/run.ts | 50 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/commands/test/run.ts b/src/commands/test/run.ts index a94806f..c003be8 100644 --- a/src/commands/test/run.ts +++ b/src/commands/test/run.ts @@ -57,6 +57,24 @@ export function buildTestRunCommand(): Command { if (schemaR.code !== 200) throw new Error(`get schema failed: ${schemaR.code}`) const formData = JSON.parse(schemaR.data.formData) const sample = buildSampleData(formData.fields || []) + + // v0.11+ (2026-06-27 tds batch2) — 注入唯一标记, 便于 POST 后通过 List 反查 ID + // JNPF POST /visualdev/OnlineDev/{id} 返回 data:null, 传统只能从响应拿 ID. + // 策略: 在第一个字符串字段注入 _TEST_YYYYMMDD_HHMMSS 标记, POST 后用 List 过滤. + const testMarker = `_TEST_${Date.now()}` + let markerInjected = false + for (const k of Object.keys(sample)) { + if (typeof sample[k] === 'string' && !markerInjected) { + const old = sample[k] as string + sample[k] = `${testMarker}_${old}`.slice(0, 50) + markerInjected = true + break + } + } + if (!markerInjected && Object.keys(sample).length === 0) { + // 没有可用字段 (form 全是系统字段) - 跳过 ID 恢复 + testMarker.split('') // no-op for linter + } steps.push({ step: '1. 拉 form schema + 推导 sample data', status: 'PASS', @@ -83,12 +101,42 @@ export function buildTestRunCommand(): Command { // 简化方案: 如果 data 包含 id, 直接用; 否则视为 PASS 但 ID 未知 if (createR.data?.id) { testDataId = createR.data.id + } else if (markerInjected) { + // v0.11+ (2026-06-27 tds batch2) — 通过 List 反查 ID + // 用第一步注入的 testMarker 过滤, 找最新一条 + // ⚠ B-14 (tds batch2): JNPF List API + sidx='createTime' + sort='desc' → 返回 total=0 (空) + // 实测: 不传 sidx/sort 时 total 正确 (≥15), 传了就清零. JNPF 自身 bug. + // 修复: 不传 sidx/sort, 用 keyword 过滤 + 在结果里找 hit + const listBody: any = { + pageSize: 10, + currentPage: 1, + } + // 用第一个字符串字段值做模糊查询 (JNPF List 支持 keyword) + const firstStrKey = Object.keys(sample).find(k => typeof sample[k] === 'string') + if (firstStrKey) { + listBody.keyword = sample[firstStrKey] + } + const listR = (await c.postJson(`/visualdev/OnlineDev/${opts.formId}/List`, listBody)) as { + code: number + data: { list?: Array> } | null + } + if (listR.code === 200 && listR.data?.list?.length) { + // 取 list 中含 testMarker 的第一条 + const hit = listR.data.list.find((row: any) => { + return Object.values(row).some(v => typeof v === 'string' && v.includes(testMarker)) + }) + if (hit && hit.id) { + testDataId = String(hit.id) + } else if (listR.data.list[0].id) { + testDataId = String(listR.data.list[0].id) + } + } } steps.push({ step: '2. POST create (新增数据)', status: 'PASS', duration: Date.now() - t1, - detail: `msg="${createR.msg}"${testDataId ? ` id=${testDataId}` : ' (JNPF POST 不返 id, 跳过后续步骤)'}`, + detail: `msg="${createR.msg}"${testDataId ? ` id=${testDataId} (${markerInjected ? 'via List-search-by-marker' : 'from response'})` : ' (JNPF POST 不返 id, 跳过后续步骤)'}`, }) if (!opts.json) log.ok(`Step 2: POST create PASS (${Date.now() - t1}ms)${testDataId ? ` → id=${testDataId}` : ' (无 id, 跳过后续)'}`) } else {