Browse Source

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.
imccyu 2 months ago
parent
commit
afaa9ad828

+ 2 - 1
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<string, unknown> }
     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

+ 1 - 1
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<string | null>
+  setPlanMode: (active: boolean) => Promise<string | null>
 }
 
 /**

+ 6 - 6
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<HTMLSelectElement>('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<HTMLSelectElement>('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<string | null>((done) => { resolve = done }))
     const { store } = setup({ active: false, pending: false }, setPlanMode)
-    const select = screen.getByRole('combobox', { name: '协作模式' }) as HTMLSelectElement
+    const select = screen.getByRole<HTMLSelectElement>('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<HTMLSelectElement>('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<HTMLSelectElement>('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<HTMLSelectElement>('combobox').disabled).toBe(false)
 
     fireEvent.change(screen.getByRole('combobox'), { target: { value: 'plan' } })
     expect(await screen.findByTitle('socket closed')).toBeTruthy()

+ 1 - 1
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(<QuestionComposer matched={carrier} interactions={[carrier]} {...kit} />)

+ 2 - 2
packages/plan/plan-mode/tests/projection.spec.ts

@@ -42,7 +42,7 @@ async function harness(withPlanMode: boolean): Promise<Bench> {
   return {
     ctx,
     session,
-    values: () => ctx.sessionProjections.snapshot(session).values as Record<string, unknown>,
+    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 })