mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
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:
@@ -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=apply,message 来自 applyFn,effortUpdate 透传', () => {
|
||||
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>')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user