From c6dc0adf26a2d20df1147d2ec87c8922ca86d410 Mon Sep 17 00:00:00 2001 From: Time Attakc <89218912+time-attack@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:12:08 -0700 Subject: [PATCH] fix(test): repair typecheck failures in admin-sse and lifecycle tests (#3598, #3599) (#3610) Export AdminSseResponse, HttpServerLifecycle, and SignalSource from serve-http.ts so test fakes can reference them. Cast structural fakes through `as unknown as T` where the fake return types (EventEmitter, plain object) cannot structurally match the full Node/Express originals. Co-authored-by: Garry Tan Co-authored-by: Mastra Code (anthropic/claude-opus-4-6) --- src/commands/serve-http.ts | 9 ++++++--- test/admin-sse-handshake.test.ts | 4 ++-- test/serve-http-lifecycle.test.ts | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/commands/serve-http.ts b/src/commands/serve-http.ts index 75c7b6a8e..412115ece 100644 --- a/src/commands/serve-http.ts +++ b/src/commands/serve-http.ts @@ -57,8 +57,10 @@ import { registerCleanup } from '../core/process-cleanup.ts'; */ export const HEALTH_TIMEOUT_MS = 3000; -type HttpServerLifecycle = Pick; -type SignalSource = Pick; +/** Exported so tests can type their structural fakes exactly (#3599). */ +export type HttpServerLifecycle = Pick; +/** Exported so tests can type their structural fakes exactly (#3599). */ +export type SignalSource = Pick; type CleanupRegistrar = typeof registerCleanup; /** @@ -200,7 +202,8 @@ export type ProbeHealthResult = | { ok: true; status: 200; body: { status: 'ok'; version: string; engine: string; [k: string]: unknown } } | { ok: false; status: 503; body: { error: 'service_unavailable'; error_description: string } }; -type AdminSseResponse = Pick; +/** Exported so tests can type their structural fakes exactly (#3598). */ +export type AdminSseResponse = Pick; /** * Complete the admin EventSource handshake immediately. diff --git a/test/admin-sse-handshake.test.ts b/test/admin-sse-handshake.test.ts index b78a0802c..ca5626a2d 100644 --- a/test/admin-sse-handshake.test.ts +++ b/test/admin-sse-handshake.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'bun:test'; -import { openAdminSseStream } from '../src/commands/serve-http.ts'; +import { openAdminSseStream, type AdminSseResponse } from '../src/commands/serve-http.ts'; describe('admin SSE handshake', () => { test('flushes a protocol-valid comment immediately after the headers', () => { @@ -19,7 +19,7 @@ describe('admin SSE handshake', () => { calls.push(`write:${String(chunk)}`); return true; }, - }); + } as unknown as AdminSseResponse); expect(headers).toEqual(new Map([ ['Content-Type', 'text/event-stream'], diff --git a/test/serve-http-lifecycle.test.ts b/test/serve-http-lifecycle.test.ts index 52c556a03..7bbefa25d 100644 --- a/test/serve-http-lifecycle.test.ts +++ b/test/serve-http-lifecycle.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from 'bun:test'; import { EventEmitter } from 'events'; -import { waitForHttpServerLifecycle } from '../src/commands/serve-http.ts'; +import { waitForHttpServerLifecycle, type HttpServerLifecycle } from '../src/commands/serve-http.ts'; class FakeHttpServer extends EventEmitter { listening = true; @@ -25,8 +25,8 @@ describe('HTTP server lifecycle', () => { let deregistered = false; let resolved = false; - const lifecycle = waitForHttpServerLifecycle(server, { - signals, + const lifecycle = waitForHttpServerLifecycle(server as unknown as HttpServerLifecycle, { + signals: signals as unknown as NodeJS.Process, register(_name, fn) { cleanup = fn; return () => { deregistered = true; }; @@ -49,8 +49,8 @@ describe('HTTP server lifecycle', () => { const server = new FakeHttpServer(); const signals = new EventEmitter(); - const lifecycle = waitForHttpServerLifecycle(server, { - signals, + const lifecycle = waitForHttpServerLifecycle(server as unknown as HttpServerLifecycle, { + signals: signals as unknown as NodeJS.Process, register() { return () => {}; },