From e7c4bcef2be75b61e8d5fa7ea319375f1a935a25 Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Tue, 8 Sep 2026 22:00:10 -0700 Subject: [PATCH] test(native-chat): make the structured session test harness type-portable --- pnpm-lock.yaml | 19 ++++++++++++ ...tiveChatStructuredSession.test-harness.tsx | 29 ++++++++++--------- .../NativeChatStructuredSession.test.tsx | 1 - 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7add63b397b..baf05a74084 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,9 @@ importers: .: configDependencies: {} packageManagerDependencies: + '@pnpm/exe': + specifier: 12.0.0 + version: 12.0.0 pnpm: specifier: 12.0.0 version: 12.0.0 @@ -56,6 +59,11 @@ packages: cpu: [x64] os: [win32] + '@pnpm/exe@12.0.0': + resolution: {integrity: sha512-405vw2qYPPghNxoPRt2cvkGtGNU5gnInDcIe5TztQxe73yUZLqFJN/jCJFGs1xbVaIWDXEVuQ71P8npFZeatZQ==} + engines: {node: '>=18.*'} + hasBin: true + pnpm@12.0.0: resolution: {integrity: sha512-ni49w5EZlYaNyUuBdcIXwn6VQI+gO0oidJd48rNPdzt3zdOznt6BcbIvzVO+ajU0Lp+smUimjvWN9kiM6Jp+Zw==} engines: {node: '>=18.*'} @@ -87,6 +95,17 @@ snapshots: '@pnpm/exe.win32-x64@12.0.0': optional: true + '@pnpm/exe@12.0.0': + optionalDependencies: + '@pnpm/exe.darwin-arm64': 12.0.0 + '@pnpm/exe.darwin-x64': 12.0.0 + '@pnpm/exe.linux-arm64': 12.0.0 + '@pnpm/exe.linux-arm64-musl': 12.0.0 + '@pnpm/exe.linux-x64': 12.0.0 + '@pnpm/exe.linux-x64-musl': 12.0.0 + '@pnpm/exe.win32-arm64': 12.0.0 + '@pnpm/exe.win32-x64': 12.0.0 + pnpm@12.0.0: optionalDependencies: '@pnpm/exe.darwin-arm64': 12.0.0 diff --git a/src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx b/src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx index 37d5ba57bd7..d7d2bb1f119 100644 --- a/src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx +++ b/src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx @@ -1,10 +1,13 @@ -import React, { forwardRef, useImperativeHandle } from 'react' -import { vi } from 'vitest' +import { forwardRef, useImperativeHandle } from 'react' +import { vi, type Mock } from 'vitest' import type { AgentJournalRenderItem } from '../../../../shared/agent-session-journal-types' import type { AgentSessionBackgroundTask } from '../../../../shared/agent-session-wire' import type { NativeChatQuestionCardProps } from './NativeChatQuestionCard' import type { NativeChatLaunchSeed } from './native-chat-composer-types' +// Why: a named spy type keeps the harness's inferred return type portable across the test files. +type StructuredSessionSpy = Mock + /** * Shared mock state and `vi.mock` factories for the NativeChatStructuredSession test files. * Load it through `await vi.hoisted(async () => (await import(...)).createStructuredSessionMocks())` @@ -12,8 +15,8 @@ import type { NativeChatLaunchSeed } from './native-chat-composer-types' */ export function createStructuredSessionMocks() { const mocks = { - call: vi.fn(), - fileLinkClick: vi.fn(), + call: vi.fn() as StructuredSessionSpy, + fileLinkClick: vi.fn() as StructuredSessionSpy, mode: 'static' as 'static' | 'outbox', status: 'ready' as 'idle' | 'loading' | 'ready' | 'error', messages: null as null | unknown[], @@ -30,14 +33,14 @@ export function createStructuredSessionMocks() { }, questionCardProps: null as NativeChatQuestionCardProps | null, promptItems: [] as AgentJournalRenderItem[], - respond: vi.fn(), - handlePasteEvent: vi.fn(), - pasteFromClipboard: vi.fn(), + respond: vi.fn() as StructuredSessionSpy, + handlePasteEvent: vi.fn() as StructuredSessionSpy, + pasteFromClipboard: vi.fn() as StructuredSessionSpy, submissions: [] as unknown[], monitoringBackgroundTasks: false, supportsBackgroundTaskStop: false, backgroundTasks: [] as AgentSessionBackgroundTask[], - stopBackgroundTask: vi.fn() + stopBackgroundTask: vi.fn() as StructuredSessionSpy } const moduleFactories = { @@ -81,7 +84,7 @@ export function createStructuredSessionMocks() { error: outbox.error, hasOlder: false, loadingOlder: false, - loadOlder: vi.fn(), + loadOlder: vi.fn() as StructuredSessionSpy, prompts: mocks.promptItems, outbox: outbox.outbox, blockedClientMessageId: outbox.blockedClientMessageId, @@ -92,7 +95,7 @@ export function createStructuredSessionMocks() { supportsBackgroundTaskStop: mocks.supportsBackgroundTaskStop, backgroundTasks: mocks.backgroundTasks, turnId: null, - cancel: vi.fn(), + cancel: vi.fn() as StructuredSessionSpy, stopBackgroundTask: (taskId?: string) => mocks.stopBackgroundTask(props.sessionId, taskId), respond: mocks.respond, @@ -112,11 +115,11 @@ export function createStructuredSessionMocks() { ], optionSurface: { getSnapshot: () => [], - setOption: vi.fn(), - invokeAction: vi.fn(), + setOption: vi.fn() as StructuredSessionSpy, + invokeAction: vi.fn() as StructuredSessionSpy, subscribe: () => () => {} }, - setStructuredOption: vi.fn() + setStructuredOption: vi.fn() as StructuredSessionSpy } } } diff --git a/src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx b/src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx index b440dccaf02..17bd7f71ac5 100644 --- a/src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx +++ b/src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx @@ -1,7 +1,6 @@ // @vitest-environment happy-dom import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' -import React from 'react' import { afterEach, describe, expect, it, vi } from 'vitest' import { decodeAgentSessionQuestionAnswers } from '../../../../shared/agent-session-question-answer' import { useAppStore } from '@/store'