node-half.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /** Node half: registers the /api prefix route bridging to the api gateway. */
  2. import { Context } from 'cordis'
  3. import { describe, expect, it } from 'vitest'
  4. import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api'
  5. import type { HttpServerService, WebRoute } from '@deepseek-ai/dsh-host-webserver'
  6. import { API_PATH, apply, inject } from '../src/index.ts'
  7. describe('connection node half', () => {
  8. it('registers the /api prefix route and removes it with the fiber', async () => {
  9. const ctx = new Context()
  10. const routes: WebRoute[] = []
  11. // Structural fake: the plugin only touches register(); the service class
  12. // carries private state a literal cannot (and need not) reproduce.
  13. const httpServer: Pick<HttpServerService, 'register' | 'tapIndex' | 'port'> = {
  14. register(route) {
  15. routes.push(route)
  16. return () => { routes.splice(routes.indexOf(route), 1) }
  17. },
  18. tapIndex: () => () => {},
  19. port: 0,
  20. }
  21. ctx.provide('httpServer', httpServer as HttpServerService)
  22. ctx.provide('apiProxy', {} as unknown as ApiProxy)
  23. const fiber = ctx.plugin({ inject: [...inject], apply })
  24. await fiber.await()
  25. expect(routes).toHaveLength(1)
  26. expect(routes[0]).toMatchObject({ kind: 'prefix', path: API_PATH })
  27. await fiber.dispose()
  28. expect(routes).toHaveLength(0)
  29. })
  30. })