94 lines
3.2 KiB
TypeScript
94 lines
3.2 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { renderDacliHelp } from '../../src/core/help'
|
|
import type { DacliHelp } from '../../src/core/help'
|
|
|
|
describe('DacliHelp interface', () => {
|
|
it('should accept the 4 new fields', () => {
|
|
const help: DacliHelp = {
|
|
purpose: 'test',
|
|
pitfalls: [{ wrong: 'wrong way', right: 'right way', severity: 'P0' }],
|
|
bestPractices: ['use --autoRelease'],
|
|
decisionTree: 'when A do B',
|
|
relatedRefs: ['docs/decisions/0001.md'],
|
|
}
|
|
expect(help.pitfalls).toHaveLength(1)
|
|
expect(help.bestPractices).toContain('use --autoRelease')
|
|
expect(help.decisionTree).toBe('when A do B')
|
|
expect(help.relatedRefs).toContain('docs/decisions/0001.md')
|
|
})
|
|
})
|
|
|
|
describe('renderDacliHelp', () => {
|
|
it('should render Pitfalls section when provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
pitfalls: [{ wrong: 'wrong', right: 'right', severity: 'P0' }],
|
|
})
|
|
expect(out).toContain('Pitfalls (踩过的坑)')
|
|
expect(out).toContain('❌ wrong')
|
|
expect(out).toContain('✅ right')
|
|
expect(out).toContain('[P0]')
|
|
})
|
|
|
|
it('should render Best Practices section when provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
bestPractices: ['use --autoRelease', 'read --help first'],
|
|
})
|
|
expect(out).toContain('Best Practices:')
|
|
expect(out).toContain('• use --autoRelease')
|
|
expect(out).toContain('• read --help first')
|
|
})
|
|
|
|
it('should render Decision Tree section when provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
decisionTree: 'simple → --ai; complex → --tables',
|
|
})
|
|
expect(out).toContain('Decision Tree (何时用 vs 何时不用)')
|
|
expect(out).toContain('simple → --ai')
|
|
})
|
|
|
|
it('should render Related Refs section when provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
relatedRefs: ['dacli/docs/decisions/0001-fk-relation-form-required.md'],
|
|
})
|
|
expect(out).toContain('Related Refs:')
|
|
expect(out).toContain('dacli/docs/decisions/0001-fk-relation-form-required.md')
|
|
})
|
|
|
|
it('should omit sections when fields are empty', () => {
|
|
const out = renderDacliHelp({ purpose: 'Create a form' })
|
|
expect(out).not.toContain('Pitfalls')
|
|
expect(out).not.toContain('Best Practices')
|
|
expect(out).not.toContain('Decision Tree')
|
|
expect(out).not.toContain('Related Refs')
|
|
})
|
|
})
|
|
|
|
describe('renderDacliHelp pitfalls rationale', () => {
|
|
it('should render rationale as intermediate → line when provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
pitfalls: [{
|
|
wrong: 'wrong way',
|
|
right: 'right way',
|
|
rationale: 'AI defaults to wrong',
|
|
severity: 'P0',
|
|
}],
|
|
})
|
|
expect(out).toContain('→ AI defaults to wrong')
|
|
expect(out).toContain('❌ wrong way [P0]')
|
|
expect(out).toContain('✅ right way')
|
|
})
|
|
|
|
it('should omit rationale line when not provided', () => {
|
|
const out = renderDacliHelp({
|
|
purpose: 'Create a form',
|
|
pitfalls: [{ wrong: 'wrong', right: 'right', severity: 'P0' }],
|
|
})
|
|
expect(out).not.toContain('→')
|
|
})
|
|
})
|