From 4a041e16f06d1f6f98ac2cac10b56eb5b8c3f4ce Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Sun, 14 Jun 2026 14:30:53 +0800 Subject: [PATCH] =?UTF-8?q?test(effort):=20=E8=A1=A5=20computeConfirmOutco?= =?UTF-8?q?me=20=E5=88=86=E6=94=AF=E6=B5=8B=E8=AF=95=EF=BC=88=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=20mockApply=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../__tests__/effortPanelState.test.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/components/EffortPanel/__tests__/effortPanelState.test.ts b/src/components/EffortPanel/__tests__/effortPanelState.test.ts index 8760cd4e3..d9347e1db 100644 --- a/src/components/EffortPanel/__tests__/effortPanelState.test.ts +++ b/src/components/EffortPanel/__tests__/effortPanelState.test.ts @@ -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 ') +})