From afaa9ad828cd9c31afbccd70cdb8c04474cc1143 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Tue, 28 Jul 2026 22:36:35 +0800 Subject: [PATCH] style: satisfy the eslint lane on the plan surfaces Drop the assertions eslint proved unnecessary (getByRole gains the element type parameter instead, keeping tsc satisfied), declare the injected setPlanMode as a function property (the seat face is this-free), and narrow the fixture's command args without String()'s object stringification arm. --- packages/client/connection/src/client/fixture.ts | 3 ++- packages/client/ui-plan/src/client/index.ts | 2 +- .../client/ui-plan/tests/plan-mode-control.spec.tsx | 12 ++++++------ .../ui-question/tests/question-composer.spec.tsx | 2 +- packages/plan/plan-mode/tests/projection.spec.ts | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/client/connection/src/client/fixture.ts b/packages/client/connection/src/client/fixture.ts index effdd6db6e..e27f6afa71 100644 --- a/packages/client/connection/src/client/fixture.ts +++ b/packages/client/connection/src/client/fixture.ts @@ -314,7 +314,8 @@ function foldPlan(log: readonly SessionEvent[]): { active: boolean; pending: boo for (const event of log) { const item = event as unknown as { type: string; data?: Record } if (item.type === 'command/run' && item.data?.['name'] === 'plan') { - wanted = String(item.data['args'] ?? '').trim() !== 'off' + const args = item.data['args'] + wanted = (typeof args === 'string' ? args : '').trim() !== 'off' } else if (item.type === 'plan/mode') { active = item.data?.['active'] === true wanted = null diff --git a/packages/client/ui-plan/src/client/index.ts b/packages/client/ui-plan/src/client/index.ts index 4165a130db..d799d33632 100644 --- a/packages/client/ui-plan/src/client/index.ts +++ b/packages/client/ui-plan/src/client/index.ts @@ -23,7 +23,7 @@ export interface PlanModeControlInjected { * @param active - whether plan mode should be active from the next boundary. * @returns null on admitted execution; a user-visible failure line otherwise. */ - setPlanMode(active: boolean): Promise + setPlanMode: (active: boolean) => Promise } /** diff --git a/packages/client/ui-plan/tests/plan-mode-control.spec.tsx b/packages/client/ui-plan/tests/plan-mode-control.spec.tsx index 9c5fd1b2b6..bc41f8a775 100644 --- a/packages/client/ui-plan/tests/plan-mode-control.spec.tsx +++ b/packages/client/ui-plan/tests/plan-mode-control.spec.tsx @@ -34,7 +34,7 @@ describe('PlanModeControl', () => { cleanup() setup({ active: false, pending: false }) expect(screen.getByTitle('当前为默认模式')).toBeTruthy() - const select = screen.getByRole('combobox', { name: '协作模式' }) as HTMLSelectElement + const select = screen.getByRole('combobox', { name: '协作模式' }) expect(select.value).toBe('default') expect(document.getElementById(select.getAttribute('aria-describedby') ?? '')?.textContent) .toBe('当前为默认模式') @@ -49,7 +49,7 @@ describe('PlanModeControl', () => { cleanup() setup({ active: true, pending: true }) expect(screen.getByText('默认 · 待生效')).toBeTruthy() - const defaultSelect = screen.getByRole('combobox') as HTMLSelectElement + const defaultSelect = screen.getByRole('combobox') expect(defaultSelect.value).toBe('default') expect(document.getElementById(defaultSelect.getAttribute('aria-describedby') ?? '')?.textContent) .toBe('当前为计划模式;默认模式将在下一次模型请求时生效') @@ -59,7 +59,7 @@ describe('PlanModeControl', () => { let resolve!: (value: string | null) => void const setPlanMode = vi.fn(() => new Promise((done) => { resolve = done })) const { store } = setup({ active: false, pending: false }, setPlanMode) - const select = screen.getByRole('combobox', { name: '协作模式' }) as HTMLSelectElement + const select = screen.getByRole('combobox', { name: '协作模式' }) expect(select.disabled).toBe(false) fireEvent.change(select, { target: { value: 'plan' } }) expect(setPlanMode).toHaveBeenCalledWith(true) @@ -69,7 +69,7 @@ describe('PlanModeControl', () => { store.set({ value: { active: false, pending: true } }) resolve(null) await waitFor(() => { - expect((screen.getByRole('combobox') as HTMLSelectElement).disabled).toBe(false) + expect(screen.getByRole('combobox').disabled).toBe(false) }) expect(screen.getByText('计划 · 待生效')).toBeTruthy() // Re-selecting the effective target is a no-op. @@ -79,7 +79,7 @@ describe('PlanModeControl', () => { it('disables under the locked owner prop', () => { setup({ active: false, pending: false }, vi.fn(), true) - expect((screen.getByRole('combobox') as HTMLSelectElement).disabled).toBe(true) + expect(screen.getByRole('combobox').disabled).toBe(true) }) it('surfaces admission and transport failures without changing the confirmed mode', async () => { @@ -94,7 +94,7 @@ describe('PlanModeControl', () => { fireEvent.change(screen.getByRole('combobox'), { target: { value: 'plan' } }) expect(await screen.findByTitle('network down')).toBeTruthy() - expect((screen.getByRole('combobox') as HTMLSelectElement).disabled).toBe(false) + expect(screen.getByRole('combobox').disabled).toBe(false) fireEvent.change(screen.getByRole('combobox'), { target: { value: 'plan' } }) expect(await screen.findByTitle('socket closed')).toBeTruthy() diff --git a/packages/client/ui-question/tests/question-composer.spec.tsx b/packages/client/ui-question/tests/question-composer.spec.tsx index 8db82deffa..7df9f2bde9 100644 --- a/packages/client/ui-question/tests/question-composer.spec.tsx +++ b/packages/client/ui-question/tests/question-composer.spec.tsx @@ -119,7 +119,7 @@ describe('QuestionComposer', () => { detail: '# 实施计划\n\n- **先验证**现状\n- 修改 `QuestionComposer`', options: [{ label: '批准' }], }], - } as PendingWait<'question'>['payload'], + }, vi.fn(), ) const view = render() diff --git a/packages/plan/plan-mode/tests/projection.spec.ts b/packages/plan/plan-mode/tests/projection.spec.ts index dbd6d5a733..7c69417e58 100644 --- a/packages/plan/plan-mode/tests/projection.spec.ts +++ b/packages/plan/plan-mode/tests/projection.spec.ts @@ -42,7 +42,7 @@ async function harness(withPlanMode: boolean): Promise { return { ctx, session, - values: () => ctx.sessionProjections.snapshot(session).values as Record, + values: () => ctx.sessionProjections.snapshot(session).values, } } @@ -124,7 +124,7 @@ describe('plan projection unit', () => { const cold = await harness(true) for (const event of bench.session.events) { if (event.type === 'command/run' || event.type === 'plan/mode') { - cold.session.append(event.type, event.data as never) + cold.session.append(event.type, event.data) } } expect(cold.values().plan).toEqual({ active: false, pending: true })