import { afterEach, describe, expect, it, vi } from 'vitest' import { createMcpSession, type Server } from './session.ts' const session = createMcpSession() /** The two parts of a tmcp server the session reads. */ const serverFor = (clientName?: string) => { const progress = vi.fn() session.bind({ progress, ctx: { sessionInfo: { clientInfo: { name: clientName, version: '1.0.0' } } } } as unknown as Server) return progress } describe('session', () => { afterEach(() => { session.bind(null) }) it('sends progress through the bound server', () => { const progress = serverFor('Cursor') session.progress({ progress: 1, total: 3, message: 'plugin-ts completed in 14ms' }) expect(progress).toHaveBeenCalledWith(1, 3, 'plugin-ts completed in 14ms') }) it('tells Claude Code apart from other clients by the name it registers', () => { for (const name of ['claude-code', 'Claude Code']) { serverFor(name) expect(session.isClaudeCode()).toBe(true) } serverFor('claude-ai') expect(session.isClaudeCode()).toBe(false) }) it('answers false for a client that sends no name', () => { serverFor(undefined) expect(session.isClaudeCode()).toBe(false) }) it('does nothing when no server is bound, as when a test calls a tool directly', () => { expect(() => session.progress({ progress: 1, total: 1, message: 'Writing 1 files' })).not.toThrow() expect(session.isClaudeCode()).toBe(false) }) })