test(effort): 补 computeConfirmOutcome 分支测试(注入 mockApply)

- ultracode → kind=ultracode-hint,不调 applyFn
- low → kind=apply,message/effortUpdate 来自 applyFn
- applyFn 返回无 effortUpdate 时 outcome.effortUpdate 为 undefined
- CANCEL_MESSAGE / ULTRACODE_HINT 常量

Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-06-14 14:30:53 +08:00
parent 10cf60989a
commit 4a041e16f0

View File

@@ -1,9 +1,13 @@
import { describe, expect, test } from 'bun:test'
import {
CANCEL_MESSAGE,
type ApplyFn,
ULTRACODE_HINT,
END_POSITION,
HOME_POSITION,
PANEL_POSITIONS,
type PanelPosition,
computeConfirmOutcome,
getInitialCursor,
isUltracode,
moveLeft,
@@ -99,3 +103,57 @@ describe('effortPanelState', () => {
expect(p).toBe('xhigh')
})
})
describe('computeConfirmOutcome', () => {
const mockApply: ApplyFn = cursor => ({
message: `applied:${cursor}`,
effortUpdate: { value: cursor },
})
test('ultracode → kind=ultracode-hint含 /ultracode 引导', () => {
const out = computeConfirmOutcome('ultracode', mockApply)
expect(out.kind).toBe('ultracode-hint')
if (out.kind === 'ultracode-hint') {
expect(out.message).toBe(ULTRACODE_HINT)
expect(out.message).toContain('/ultracode')
}
})
test('ultracode 不调 applyFn不会被副作用触发', () => {
let called = false
const spy: ApplyFn = c => {
called = true
return { message: `applied:${c}` }
}
computeConfirmOutcome('ultracode', spy)
expect(called).toBe(false)
})
test('low → kind=applymessage 来自 applyFneffortUpdate 透传', () => {
const out = computeConfirmOutcome('low', mockApply)
expect(out.kind).toBe('apply')
if (out.kind === 'apply') {
expect(out.message).toBe('applied:low')
expect(out.effortUpdate?.value).toBe('low')
}
})
test('high → apply 路径不调 ultracode 分支', () => {
const out = computeConfirmOutcome('high', mockApply)
expect(out.kind).toBe('apply')
})
test('applyFn 返回无 effortUpdate 时outcome.effortUpdate 为 undefined', () => {
const noUpdate: ApplyFn = c => ({ message: `applied:${c}` })
const out = computeConfirmOutcome('medium', noUpdate)
expect(out.kind).toBe('apply')
if (out.kind === 'apply') {
expect(out.effortUpdate).toBeUndefined()
}
})
})
test('常量字符串', () => {
expect(CANCEL_MESSAGE).toBe('Effort unchanged.')
expect(ULTRACODE_HINT).toContain('/ultracode <context>')
})