connection binds the web transport: it injects httpServer + apiProxy and registers toFetchHandler(ctx.apiProxy) under the /api prefix (the node:http to fetch bridge moves in from the webserver, keeping the res-close disconnect detection and drain/close backpressure waits). hmr owns dev reload: a stat-poll watch per graph row driven by clientModuleHost.onGraphChanged, rebuilt(id) on content change, and the /plugins/events SSE route (GET/HEAD guarded); frame types are single-sourced in events.ts shared by both halves.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/** Node half: registers the /api prefix route bridging to the api gateway. */
|
|
import { Context } from 'cordis'
|
|
import { describe, expect, it } from 'vitest'
|
|
import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api'
|
|
import type { HttpServerService, WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
import { API_PATH, apply, inject } from '../src/index.ts'
|
|
|
|
describe('connection node half', () => {
|
|
it('registers the /api prefix route and removes it with the fiber', async () => {
|
|
const ctx = new Context()
|
|
const routes: WebRoute[] = []
|
|
// Structural fake: the plugin only touches register(); the service class
|
|
// carries private state a literal cannot (and need not) reproduce.
|
|
const httpServer: Pick<HttpServerService, 'register' | 'tapIndex' | 'port'> = {
|
|
register(route) {
|
|
routes.push(route)
|
|
return () => { routes.splice(routes.indexOf(route), 1) }
|
|
},
|
|
tapIndex: () => () => {},
|
|
port: 0,
|
|
}
|
|
ctx.provide('httpServer', httpServer as HttpServerService)
|
|
ctx.provide('apiProxy', {} as unknown as ApiProxy)
|
|
|
|
const fiber = ctx.plugin({ inject: [...inject], apply })
|
|
await fiber.await()
|
|
expect(routes).toHaveLength(1)
|
|
expect(routes[0]).toMatchObject({ kind: 'prefix', path: API_PATH })
|
|
|
|
await fiber.dispose()
|
|
expect(routes).toHaveLength(0)
|
|
})
|
|
})
|