diff --git a/tests/integration/drift/tc-c-deep.spec.ts b/tests/integration/drift/tc-c-deep.spec.ts new file mode 100644 index 0000000..7d87c93 --- /dev/null +++ b/tests/integration/drift/tc-c-deep.spec.ts @@ -0,0 +1,142 @@ +/** + * tc-c-deep.spec.ts — TC-C v0.21+ 加深 8 关卡自动化 (2026-07-12) + * + * 目的: 在 TC-C 层 (静态) 多发现 50% 漂移, 减少 TC-B 浏览器层重排雷. + * + * 8 关卡 (4 v0.11g+ + 4 v0.21+): + * 1. form 编辑字段 ⊆ API 字段 + * 2. form 列表字段 ⊆ API 字段 + * 3. 必填字段 vmodel 完整性 + * 4. columnList 列配置完整性 (字段名匹配 API) + * 5. **v0.21+** jnpfKey 有效性 (web FormGenerator 白名单) + * 6. **v0.21+** 字典绑定有效性 (dictionaryType 在 dict 表存在) + * 7. **v0.21+** formItem label 完整性 (非空 + 唯一) + * 8. **v0.21+** 必填 vs 控件类型 (必填不能在 switch/button/table 容器) + * + * 实测 (workSystem, 2026-07-12): + * - hesuanjiancedengji: 8/8 ✓ + * - testcustomer: 7/8 (字典 038d293f 失效) + * - testreceivable: 6/8 (columnList 错配子表字段) + * - yaofangguanli: 8/8 ✓ + * - baomingguanli: 6/8 (columnList 错配子表字段) + * + * 跑法: npx vitest run tests/integration/drift/tc-c-deep.spec.ts + * 集成: 可入 CI (无需浏览器) + */ + +import { describe, it, expect, beforeAll } from 'vitest' +import { execSync, execFile } from 'child_process' +import { promisify } from 'util' +import { existsSync } from 'fs' +import { resolve } from 'path' + +const execFileP = promisify(execFile) +const DACLI_ROOT = resolve(__dirname, '../../../') + +// 5 form 测试目标 (workSystem) +const FORMS = [ + { enCode: 'hesuanjiancedengji', formId: '469038006062344581', expectPass: 8 }, + { enCode: 'testcustomer', formId: '468842471892247429', expectPass: 7 }, + { enCode: 'testreceivable', formId: '468826463014018501', expectPass: 6 }, + { enCode: 'yaofangguanli', formId: '468849844170057541', expectPass: 8 }, + { enCode: 'baomingguanli', formId: '468848215723140933', expectPass: 6 }, +] + +interface RenderResult { + module: string + page: string + status: 'PASS' | 'FAIL' + missing: string[] +} + +interface RenderOutput { + module: string + totalPages: number + pass: number + fail: number + results: RenderResult[] +} + +async function runRender(formId: string): Promise { + // execFile (Promise) 比 execSync 稳定, FAIL render 也输出 JSON + try { + const r = await execFileP('npx', ['tsx', 'src/cli.ts', 'test', 'render', '--module=form', `--formId=${formId}`, '--json'], { + cwd: DACLI_ROOT, + maxBuffer: 50 * 1024 * 1024, + }) + return JSON.parse(r.stdout) + } catch (e: any) { + // FAIL render exit code=1, stdout 仍含 JSON + const stdout = e.stdout || '' + if (stdout) return JSON.parse(stdout) + throw new Error(`render ${formId} 完全失败: ${e.message}`) + } +} + +describe('TC-C v0.21+ 加深 8 关卡 (静态 webapi 分析, 不依赖浏览器)', () => { + beforeAll(() => { + const tokenFile = `${process.env.HOME}/.dacli-token/token.json` + if (!existsSync(tokenFile)) { + throw new Error(`dacli 未登录, 请先: cd ${DACLI_ROOT} && npx tsx src/cli.ts app login --appCode=workSystem`) + } + }) + + describe.each(FORMS)('form $enCode (formId=$formId)', ({ enCode, formId, expectPass }) => { + let output: RenderOutput + + beforeAll(async () => { + output = await runRender(formId) + }, 60000) + + it(`总通过数 = ${expectPass} (baseline 已知状态)`, () => { + expect(output.pass).toBe(expectPass) + }) + + it(`失败数 = ${8 - expectPass}`, () => { + expect(output.fail).toBe(8 - expectPass) + }) + + const expectedPages = [ + 'form 编辑表单', + 'form 列表', + '必填字段 vmodel', + 'columnList 列配置完整性', + 'jnpfKey 有效性 (web FormGenerator 白名单)', + '字典绑定有效性 (dictionaryType 在 dict 表存在)', + 'formItem label 完整性', + '必填字段 vs 控件类型', + ] + + it.each(expectedPages)('关卡 "%s" 存在且状态有值', (pageName) => { + const page = output.results.find((p) => p.page === pageName) + expect(page).toBeDefined() + expect(['PASS', 'FAIL']).toContain(page!.status) + }) + }) + + describe('已知漂移 (baseline 真实问题, 待修复)', () => { + it('testcustomer: 字典 038d293f... 在 dict 表失效', async () => { + const out = await runRender('468842471892247429') + const dictPage = out.results.find((p) => p.page.includes('字典绑定')) + expect(dictPage).toBeDefined() + expect(dictPage!.missing.some((m) => m.includes('038d293f'))).toBe(true) + }) + + it('testreceivable: columnList 错配子表字段 (tableField107-F_*)', async () => { + const out = await runRender('468826463014018501') + const colPage = out.results.find((p) => p.page.includes('columnList 列配置')) + expect(colPage).toBeDefined() + expect(colPage!.missing.some((m) => m.includes('tableField107-F_'))).toBe(true) + }) + + it('baomingguanli: columnList 错配子表字段 (tableField111-selectField107)', async () => { + const out = await runRender('468848215723140933') + const colPage = out.results.find((p) => p.page.includes('columnList 列配置')) + expect(colPage).toBeDefined() + expect(colPage!.missing.some((m) => m.includes('tableField111-selectField107'))).toBe(true) + }) + }) + + // 回归保护: 主 describe.each 已用 expectPass=8 覆盖 (hesuanjiancedengji/yaofangguanli) + // 删去冗余 describe, 避免并发 token 冲突 +}) \ No newline at end of file