Compare commits

...
Author SHA1 Message Date
Garry TanandMastra Code c07c8e8930 fix(test): repair typecheck failures in admin-sse and lifecycle tests (#3598, #3599)
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: Mastra Code (anthropic/claude-opus-4-6) <noreply@mastra.ai>
2026-07-29 16:39:13 -07:00
3 changed files with 13 additions and 10 deletions
+6 -3
View File
@@ -57,8 +57,10 @@ import { registerCleanup } from '../core/process-cleanup.ts';
*/
export const HEALTH_TIMEOUT_MS = 3000;
type HttpServerLifecycle = Pick<HttpServer, 'listening' | 'once' | 'off' | 'close'>;
type SignalSource = Pick<NodeJS.Process, 'once' | 'off'>;
/** Exported so tests can type their structural fakes exactly (#3599). */
export type HttpServerLifecycle = Pick<HttpServer, 'listening' | 'once' | 'off' | 'close'>;
/** Exported so tests can type their structural fakes exactly (#3599). */
export type SignalSource = Pick<NodeJS.Process, 'once' | 'off'>;
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<Response, 'setHeader' | 'flushHeaders' | 'write'>;
/** Exported so tests can type their structural fakes exactly (#3598). */
export type AdminSseResponse = Pick<Response, 'setHeader' | 'flushHeaders' | 'write'>;
/**
* Complete the admin EventSource handshake immediately.
+2 -2
View File
@@ -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'],
+5 -5
View File
@@ -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 () => {};
},