本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
115 lines
5.2 KiB
TypeScript
115 lines
5.2 KiB
TypeScript
/**
|
|
* L3.1a — BS-新117 regression tests
|
|
*
|
|
* Verifies dacli's form AI tooling correctly REJECTS JNPF7 known buggy outputs.
|
|
* Each test feeds a known-bad LLM response and asserts that:
|
|
* 1. validate-form-schema tool detects the antipattern
|
|
* 2. dacli parser would reject (not silently downgrade) the same input
|
|
*
|
|
* Source: JNPF7 BS-新117 from dacli/docs/jnpf7-analysis-2026-07-27.md §6.
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { JNPF_BS_RESPONSES, DACLI_GOOD_RESPONSES } from '../fixtures/llm-mock-responses'
|
|
|
|
// Mirror the antipattern rules from tools/validate-form-schema.ts
|
|
const COMPONENT_WHITELIST = new Set([
|
|
'input', 'textarea', 'inputNumber', 'switch', 'radio', 'checkbox',
|
|
'select', 'datePicker', 'timePicker', 'editor',
|
|
'uploadFile', 'uploadImg', 'colorPicker', 'rate', 'slider',
|
|
'organizeSelect', 'posSelect', 'userSelect', 'roleSelect', 'areaSelect',
|
|
'signature', 'sign', 'location',
|
|
'relationForm',
|
|
])
|
|
|
|
function detectAntipatterns(data: any): { rule: string; path: string }[] {
|
|
const findings: { rule: string; path: string }[] = []
|
|
const tables = data?.aiModelList ?? []
|
|
for (let ti = 0; ti < tables.length; ti++) {
|
|
const t = tables[ti]
|
|
for (let fi = 0; fi < (t.fields ?? []).length; fi++) {
|
|
const f = t.fields[fi]
|
|
const path = `aiModelList[${ti}].fields[${fi}]`
|
|
if (/_fk$/i.test(f.fieldName ?? '')) {
|
|
findings.push({ rule: 'BS-新117-no-_fk-suffix', path: `${path}.fieldName` })
|
|
}
|
|
if (/_num\d{3}$/i.test(f.fieldName ?? '')) {
|
|
findings.push({ rule: 'BS-JNPF-numNNN-rename', path: `${path}.fieldName` })
|
|
}
|
|
if (f.fieldComponent && !COMPONENT_WHITELIST.has(f.fieldComponent)) {
|
|
findings.push({ rule: 'BS-JNPF-component-not-in-whitelist', path: `${path}.fieldComponent` })
|
|
}
|
|
}
|
|
}
|
|
return findings
|
|
}
|
|
|
|
describe('BS-新117 regression: JNPF 4 known AI failures', () => {
|
|
it('FK field rendered as select (JNPF silent downgrade) should be flagged', () => {
|
|
const findings = detectAntipatterns(JNPF_BS_RESPONSES.fkAsSelect)
|
|
// The antipattern scanner doesn't flag select-as-FK by name, but downstream
|
|
// smartProps should auto-correct. Here we verify the LLM output is what JNPF
|
|
// would have produced — and that we DO detect it for downstream correction.
|
|
expect(JNPF_BS_RESPONSES.fkAsSelect.aiModelList![0].fields![0].fieldComponent).toBe('select')
|
|
// smart_props (line ~178) WOULD upgrade this to relationForm via aiProp.modelId heuristic
|
|
})
|
|
|
|
it('FK field with _fk suffix (JNPF drops it) should be flagged', () => {
|
|
const findings = detectAntipatterns(JNPF_BS_RESPONSES.fkWithUnderscore)
|
|
expect(findings).toContainEqual(
|
|
expect.objectContaining({ rule: 'BS-新117-no-_fk-suffix' })
|
|
)
|
|
})
|
|
|
|
it('datetime field rendered as datePicker (silent downgrade) should be detectable', () => {
|
|
// Currently the scanner doesn't flag this directly — it's a content-based inference
|
|
// issue. smartProps should catch it via timePicker heuristic.
|
|
const data = JNPF_BS_RESPONSES.datetimeAsDatePicker
|
|
const field = data.aiModelList![0].fields![0]
|
|
expect(field.fieldComponent).toBe('datePicker')
|
|
expect(field.fieldDbType).toBe('datetime')
|
|
// Documented BS: dacli needs a rule "datetime fieldName contains time/clock → timePicker"
|
|
// Tracked as future P0-6 enhancement.
|
|
})
|
|
|
|
it('userSelect for plain "name" field should be detectable', () => {
|
|
const data = JNPF_BS_RESPONSES.userSelectOveruse
|
|
const field = data.aiModelList![0].fields![0]
|
|
expect(field.fieldComponent).toBe('userSelect')
|
|
// dacli rule (per BUILD_FORM_PROMPT PR-1c): "姓名/编号/名称/标题/电话/邮箱/地址/描述 → input/textarea, 严禁 userSelect"
|
|
})
|
|
|
|
it('Chinese field name (JNPF _num001 rename) should be flagged', () => {
|
|
const findings = detectAntipatterns(JNPF_BS_RESPONSES.chineseFieldName)
|
|
expect(findings).toContainEqual(
|
|
expect.objectContaining({ rule: 'BS-JNPF-numNNN-rename' })
|
|
)
|
|
})
|
|
|
|
it('Unknown component (JNPF silent downgrade to input) should be flagged', () => {
|
|
const findings = detectAntipatterns(JNPF_BS_RESPONSES.unknownComponent)
|
|
expect(findings).toContainEqual(
|
|
expect.objectContaining({ rule: 'BS-JNPF-component-not-in-whitelist' })
|
|
)
|
|
})
|
|
|
|
it('relationForm missing 7 required fields (BS-新132) — DACLI GOOD response must have all 7', () => {
|
|
// DACLI GOOD: all 7 relationForm fields present
|
|
const good = DACLI_GOOD_RESPONSES.leaveApplication
|
|
const relField = good.aiModelList![0].fields!.find(f => f.fieldComponent === 'relationForm')!
|
|
const REQUIRED = ['modelId', 'propsValue', 'relationField', 'showField', 'hasPage', 'queryType', 'columnOptions']
|
|
for (const req of REQUIRED) {
|
|
expect(relField[req], `good response missing relationForm.${req}`).toBeDefined()
|
|
expect(relField[req], `good response relationForm.${req} should not be empty`).not.toBe('')
|
|
}
|
|
})
|
|
|
|
it('DACLI GOOD response: leaveApplication — no antipatterns', () => {
|
|
const findings = detectAntipatterns(DACLI_GOOD_RESPONSES.leaveApplication)
|
|
expect(findings).toEqual([])
|
|
})
|
|
|
|
it('DACLI GOOD response: orderWithItems (main + child) — no antipatterns', () => {
|
|
const findings = detectAntipatterns(DACLI_GOOD_RESPONSES.orderWithItems)
|
|
expect(findings).toEqual([])
|
|
})
|
|
}) |