test(dacli): form-lint 单测 T1.6-T1.9 (use*Permission, CLI 行为, tdss 真数据回归)

This commit is contained in:
ssw committed 2026-06-14 19:45:07 +08:00
1 parent 7edf55bc88
commit 546c79fdca
2 files changed
+62 -3

No files matched your search

+14 -2
View File
@@ -26,7 +26,13 @@ interface LintReport {
}
function lintScript(scriptPath: string): { forms: FormDef[]; issues: BlindspotIssue[] } {
const src = readFileSync(scriptPath, 'utf-8')
let src: string
try {
src = readFileSync(scriptPath, 'utf-8')
} catch {
log.warn(`文件不可读: ${scriptPath}, 跳过`)
return { forms: [], issues: [] }
}
const forms = parsePythonForms(src)
const issues: BlindspotIssue[] = []
for (const f of forms) {
@@ -42,7 +48,13 @@ function lintScript(scriptPath: string): { forms: FormDef[]; issues: BlindspotIs
}
function lintDesign(designPath: string): { blocks: CmdBlock[]; issues: BlindspotIssue[]; blockIssues: string[] } {
const src = readFileSync(designPath, 'utf-8')
let src: string
try {
src = readFileSync(designPath, 'utf-8')
} catch {
log.warn(`文件不可读: ${designPath}, 跳过`)
return { blocks: [], issues: [], blockIssues: [] }
}
const blocks = parseDesignHtml(src)
const blockIssues: string[] = []
for (const b of blocks) {
+48 -1
View File
@@ -3,7 +3,23 @@
*/
import { describe, it, expect } from 'vitest'
import { parsePythonForms, parseDesignHtml } from '../../src/commands/form/_parsers.ts'
import { checkBs31, checkBs32 } from '../../src/commands/form/_blindspots.ts'
import { checkBs31, checkBs32, checkBs23 } from '../../src/commands/form/_blindspots.ts'
import { execFileSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const CLI = resolve(__dirname, '../../src/cli.ts')
function runDacli(args: string[]): { stdout: string; exitCode: number } {
try {
const stdout = execFileSync('npx', ['tsx', CLI, ...args], { encoding: 'utf-8', timeout: 30_000, cwd: resolve(__dirname, '../..') })
return { stdout, exitCode: 0 }
} catch (e) {
const err = e as { stdout?: Buffer | string; status?: number }
return { stdout: err.stdout?.toString() || '', exitCode: err.status || 1 }
}
}
const FIXTURE_SCRIPT = `
FORMS = [
@@ -93,4 +109,35 @@ describe('checkBs32', () => {
const issues = checkBs32(JSON.stringify(formData))
expect(issues).toEqual([])
})
})
describe('checkBs23 (use*Permission)', () => {
it('T1.6 缺 useBtnPermission → BS-23 FAIL', () => {
const cd = JSON.stringify({ useColumnPermission: false, useFormPermission: false, useDataPermission: false })
const issues = checkBs23(cd)
expect(issues.some(i => i.message.includes('useBtnPermission'))).toBe(true)
})
it('T1.6b 4 个齐 → PASS', () => {
const cd = JSON.stringify({ useBtnPermission: false, useColumnPermission: false, useFormPermission: false, useDataPermission: false })
expect(checkBs23(cd)).toEqual([])
})
})
describe('lint CLI 行为', () => {
it('T1.8 解析错误 Python 脚本 → 友好报错 (exit 0 但 forms=0)', () => {
const r = runDacli(['form', 'lint', '--from-script=/tmp/not_a_python_file.txt'])
// 不抛 stack, 输出含 '未找到 FORMS' 或 'forms=0'
expect(r.stdout).toMatch(/解析 0 form/)
})
it('T1.9 跑真 tdss 数据 → 全 PASS exit 0', () => {
const r = runDacli([
'form', 'lint',
'--from-script=/home/ubuntu/ccWorkDir/docs/tdss/scripts/03_forms.py',
'--from-design=/home/ubuntu/ccWorkDir/docs/tdss/design-jnpf.html',
])
expect(r.exitCode).toBe(0)
expect(r.stdout).toMatch(/解析 14 form/)
})
})