85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import type { AntiPattern } from '../../src/commands/_anti_patterns'
|
|
import { ANTI_PATTERNS, enrichHelp } from '../../src/commands/_anti_patterns'
|
|
import type { DacliHelp } from '../../src/core/help'
|
|
|
|
describe('AntiPattern interface', () => {
|
|
it('should accept all 6 required fields', () => {
|
|
const p: AntiPattern = {
|
|
id: 'AP-test-1',
|
|
severity: 'P0',
|
|
wrong: 'wrong way',
|
|
right: 'right way',
|
|
rationale: 'because AI defaults to wrong',
|
|
source: 'drift/R17',
|
|
}
|
|
expect(p.id).toBe('AP-test-1')
|
|
expect(p.severity).toBe('P0')
|
|
})
|
|
})
|
|
|
|
describe('ANTI_PATTERNS[form create]', () => {
|
|
it('should have at least 8 entries', () => {
|
|
expect(ANTI_PATTERNS['form create'].length).toBeGreaterThanOrEqual(8)
|
|
})
|
|
|
|
it('all entries should have unique IDs', () => {
|
|
const ids = ANTI_PATTERNS['form create'].map(p => p.id)
|
|
const uniqueIds = new Set(ids)
|
|
expect(uniqueIds.size).toBe(ids.length)
|
|
})
|
|
|
|
it('should include AP-fc-1 (FK relation form required)', () => {
|
|
const p = ANTI_PATTERNS['form create'].find(p => p.id === 'AP-fc-1')
|
|
expect(p).toBeDefined()
|
|
expect(p?.severity).toBe('P0')
|
|
expect(p?.wrong).toContain('FK')
|
|
expect(p?.right).toContain('relationForm')
|
|
})
|
|
})
|
|
|
|
describe('ANTI_PATTERNS total count', () => {
|
|
it('should have at least 25 entries across all groups', () => {
|
|
const total = Object.values(ANTI_PATTERNS).reduce((sum, arr) => sum + arr.length, 0)
|
|
expect(total).toBeGreaterThanOrEqual(25)
|
|
})
|
|
|
|
it('all entries across all groups should have unique IDs', () => {
|
|
const allIds = Object.values(ANTI_PATTERNS).flat().map(p => p.id)
|
|
const uniqueIds = new Set(allIds)
|
|
expect(uniqueIds.size).toBe(allIds.length)
|
|
})
|
|
})
|
|
|
|
describe('enrichHelp', () => {
|
|
it('should merge ANTI_PATTERNS into DacliHelp pitfalls', () => {
|
|
const local: DacliHelp = { purpose: 'test' }
|
|
const enriched = enrichHelp('form create', local)
|
|
expect(enriched.pitfalls).toBeDefined()
|
|
expect(enriched.pitfalls!.length).toBeGreaterThanOrEqual(8)
|
|
})
|
|
|
|
it('should preserve local pitfalls and append ANTI_PATTERNS', () => {
|
|
const local: DacliHelp = {
|
|
purpose: 'test',
|
|
pitfalls: [{ wrong: 'local wrong', right: 'local right', severity: 'P0' }],
|
|
}
|
|
const enriched = enrichHelp('form create', local)
|
|
expect(enriched.pitfalls![0]).toEqual({ wrong: 'local wrong', right: 'local right', severity: 'P0' })
|
|
expect(enriched.pitfalls!.length).toBeGreaterThan(1)
|
|
})
|
|
|
|
it('should populate relatedRefs from crossRefs', () => {
|
|
const enriched = enrichHelp('form create', { purpose: 'test' })
|
|
expect(enriched.relatedRefs).toBeDefined()
|
|
expect(enriched.relatedRefs!.some(r => r.includes('decisions/0001'))).toBe(true)
|
|
})
|
|
|
|
it('should return original help if command key not in ANTI_PATTERNS', () => {
|
|
const local: DacliHelp = { purpose: 'unknown command' }
|
|
const enriched = enrichHelp('nonexistent command', local)
|
|
expect(enriched.pitfalls).toBeUndefined()
|
|
expect(enriched.purpose).toBe('unknown command')
|
|
})
|
|
})
|