/** * tests/e2e/baseline/developSystem/regression.spec.ts * * developSystem baseline 回归测试 (API 层 0 错): * - switchapp 切到 developSystem * - 拿 form list * - 对每张表单跑 info 验证 schema 完整 * - 汇总 PASS / FAIL * * 跑法: * npx playwright test tests/e2e/baseline/developSystem/regression.spec.ts */ import { test, expect } from '@playwright/test' import { execSync } from 'node:child_process' const APP_CODE = 'developSystem' interface FormRow { id: string; enCode: string; fullName: string; type: number; webType?: string } function dacli(args: string): string { return execSync(`npx tsx src/cli.ts ${args}`, { encoding: 'utf-8', cwd: process.cwd(), }) } test.describe.configure({ mode: 'serial' }) test(`switchapp ${APP_CODE} 成功`, () => { // switchapp --force 在 client.ts:fromToken 里被读 forceLogin dacli(`switchapp --appCode=${APP_CODE}`) const st = dacli(`status`) expect(st).toContain(APP_CODE) }) test('developSystem form list 返回 25+ 张 (v0.6 真总数 29)', () => { const out = dacli(`form list --limit=200 --json`) const json = JSON.parse(out) as { list: FormRow[] } // v0.6 修 dacli list bug 后真总数 29 (vs v0.5 误报 20 — 旧版走 /list 强制 enableFlow=1) expect(json.list.length, `developSystem form 真总数应 ≥25, 实际 ${json.list.length}`).toBeGreaterThanOrEqual(25) }) test('每张 form info 都能拿到完整 schema', () => { const out = dacli(`form list --limit=200 --json`) const json = JSON.parse(out) as { list: FormRow[] } const forms = json.list || [] const results: { enCode: string; ok: boolean; err?: string }[] = [] for (const f of forms) { try { const infoOut = dacli(`form info ${f.id}`) const info = JSON.parse(infoOut) as { fullName: string; formData: string | null; tables?: string } if (!info.fullName) throw new Error('fullName 缺失') // formData 可能是 null (视图) / 对象 (新格式) / 数组 (旧格式) — 都接受 if (info.formData) { const formData = JSON.parse(info.formData) as { fields?: unknown[] } | unknown[] if (Array.isArray(formData)) { // 接受 } else if (formData && typeof formData === 'object') { const fields = (formData as { fields?: unknown[] }).fields if (fields !== undefined && !Array.isArray(fields)) { throw new Error('formData.fields 非数组') } } else { throw new Error('formData 既非对象也非数组') } } results.push({ enCode: f.enCode, ok: true }) } catch (e) { results.push({ enCode: f.enCode, ok: false, err: (e as Error).message }) } } const okCount = results.filter((r) => r.ok).length const failCount = results.length - okCount console.log(` ✓ PASS: ${okCount}/${results.length}`) if (failCount > 0) { console.log(' ✗ FAIL:') for (const r of results.filter((x) => !x.ok)) console.log(` - ${r.enCode}: ${r.err}`) } expect(failCount, `${failCount} 张表单 info 失败`).toBe(0) }) test('workSystem form list 同样通 (真总数 85)', () => { dacli(`switchapp --appCode=workSystem`) const out = dacli(`form list --limit=200 --json`) const json = JSON.parse(out) as { list: FormRow[] } expect(json.list.length).toBeGreaterThanOrEqual(80) })