1
0

node-half.spec.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /** Node half: registers the /api prefix route bridging to the api gateway. */
  2. import { EventEmitter, once } from 'node:events'
  3. import { createServer, request as httpRequest } from 'node:http'
  4. import { PassThrough, Readable } from 'node:stream'
  5. import { Context } from '@deepseek-ai/cordis'
  6. import { describe, expect, it } from 'vitest'
  7. import type { AddressInfo } from 'node:net'
  8. import type { IncomingMessage, ServerResponse } from 'node:http'
  9. import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api'
  10. import type { AttachmentStore } from '@deepseek-ai/dsh-attachment'
  11. import { RpcId, type ClientRequest } from '@deepseek-ai/dsh-host-apiproxy/api'
  12. import type { HttpServerService, WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver'
  13. import { API_PATH, apply, HOST_EVENTS_PATH, inject, MUX_EVENTS_PATH, type HostConnectionHandle } from '../src/index.ts'
  14. /** Structural httpServer fake recording both route registries. */
  15. function fakeHttpServer(
  16. routes: WebRoute[],
  17. upgrades: WebUpgradeRoute[],
  18. ): Pick<HttpServerService, 'register' | 'registerUpgrade' | 'tapIndex' | 'port'> {
  19. return {
  20. register(route) {
  21. if (routes.some(candidate => candidate.kind === route.kind && candidate.path === route.path)) {
  22. throw new Error(`duplicate route ${route.path}`)
  23. }
  24. routes.push(route)
  25. return () => { routes.splice(routes.indexOf(route), 1) }
  26. },
  27. registerUpgrade(route) {
  28. upgrades.push(route)
  29. return () => { upgrades.splice(upgrades.indexOf(route), 1) }
  30. },
  31. tapIndex: () => () => {},
  32. port: 0,
  33. }
  34. }
  35. /** Bodyless GET carrying the given headers (enough for the trust fence + bridge). */
  36. function fakeRequest(headers: Record<string, string>, url = `${API_PATH}/session.list`): IncomingMessage {
  37. const request = Readable.from([]) as unknown as IncomingMessage
  38. Object.assign(request, { url, method: 'GET', headers })
  39. return request
  40. }
  41. /** JSON POST carrying a complete client-request envelope. */
  42. function fakePost(headers: Record<string, string>, url: string, body: unknown): IncomingMessage {
  43. const request = Readable.from([Buffer.from(JSON.stringify(body))]) as unknown as IncomingMessage
  44. Object.assign(request, { url, method: 'POST', headers: { 'content-type': 'application/json', ...headers } })
  45. return request
  46. }
  47. /** Raw POST for malformed-body and media-type boundary cases. */
  48. function fakeRawPost(headers: Record<string, string>, url: string, body: string): IncomingMessage {
  49. const request = Readable.from([Buffer.from(body)]) as unknown as IncomingMessage
  50. Object.assign(request, { url, method: 'POST', headers })
  51. return request
  52. }
  53. /** Response recorder compatible with both the fence's short-circuit and the bridge. */
  54. function fakeResponse(): { response: ServerResponse; state: { status?: number; body?: unknown } } {
  55. const state: { status?: number; body?: unknown } = {}
  56. const chunks: Buffer[] = []
  57. const response = Object.assign(new EventEmitter(), {
  58. writableEnded: false,
  59. writeHead(value: number) { state.status = value; return this },
  60. write(value: string | Uint8Array) { chunks.push(Buffer.from(value)); return true },
  61. end(this: { writableEnded: boolean }, value?: unknown) {
  62. if (typeof value === 'string' || value instanceof Uint8Array) chunks.push(Buffer.from(value))
  63. else if (value !== undefined) throw new TypeError('fake response only accepts string or Uint8Array bodies')
  64. if (chunks.length > 0) state.body = Buffer.concat(chunks).toString()
  65. this.writableEnded = true
  66. return this
  67. },
  68. }) as unknown as ServerResponse
  69. return { response, state }
  70. }
  71. async function mounted(config?: { trustedHosts?: string[] }): Promise<{
  72. routes: WebRoute[]
  73. upgrades: WebUpgradeRoute[]
  74. dispose: () => Promise<void>
  75. }> {
  76. const ctx = new Context()
  77. const routes: WebRoute[] = []
  78. const upgrades: WebUpgradeRoute[] = []
  79. ctx.provide('httpServer', fakeHttpServer(routes, upgrades) as HttpServerService)
  80. ctx.provide('apiProxy', {} as unknown as ApiProxy)
  81. const fiber = ctx.plugin({ inject: [...inject], apply }, config)
  82. await fiber.await()
  83. return { routes, upgrades, dispose: () => fiber.dispose() }
  84. }
  85. describe('connection node half', () => {
  86. it('fails loud when the carrier cap cannot hold the configured image batch', () => {
  87. const ctx = new Context()
  88. const routes: WebRoute[] = []
  89. ctx.provide('httpServer', fakeHttpServer(routes, []) as HttpServerService)
  90. ctx.provide('attachments', {
  91. imageLimits: { maxMessageImageBytes: 20 * 1024 * 1024 },
  92. } as AttachmentStore)
  93. ctx.provide('apiProxy', {} as ApiProxy)
  94. expect(() => { apply(ctx, { maxRequestBodyBytes: 1024 }) })
  95. .toThrow(/must be at least .* aggregate image limit/)
  96. expect(routes).toHaveLength(0)
  97. })
  98. it('fails the load on a trustedHosts entry that is not a bare authority', async () => {
  99. const routes: WebRoute[] = []
  100. const upgrades: WebUpgradeRoute[] = []
  101. const ctx = new Context()
  102. ctx.provide('httpServer', fakeHttpServer(routes, upgrades) as HttpServerService)
  103. ctx.provide('apiProxy', {} as unknown as ApiProxy)
  104. const fiber = ctx.plugin({ inject: [...inject], apply }, { trustedHosts: ['harness.internal/path'] })
  105. await expect(fiber).rejects.toThrow(/not a bare host\[:port\] authority/)
  106. expect(routes).toHaveLength(0)
  107. expect(upgrades).toHaveLength(0)
  108. })
  109. it('registers one HTTP route plus one upgrade route per downlink and removes all three with the fiber', async () => {
  110. const { routes, upgrades, dispose } = await mounted()
  111. expect(routes).toHaveLength(1)
  112. expect(routes[0]).toMatchObject({ kind: 'prefix', path: API_PATH })
  113. expect(upgrades.map(route => route.path)).toEqual([MUX_EVENTS_PATH, HOST_EVENTS_PATH])
  114. await dispose()
  115. expect(routes).toHaveLength(0)
  116. expect(upgrades).toHaveLength(0)
  117. })
  118. it('requires WebSocket upgrade for network GETs to either event path', async () => {
  119. const { routes, dispose } = await mounted()
  120. for (const path of [MUX_EVENTS_PATH, HOST_EVENTS_PATH]) {
  121. const { response, state } = fakeResponse()
  122. await routes[0]!.handler(fakeRequest({ host: '127.0.0.1:3080' }, path), response)
  123. expect(state.status).toBe(426)
  124. expect(state.body).toBe('upgrade required')
  125. }
  126. await dispose()
  127. })
  128. it('rejects an untrusted WebSocket upgrade before protocol negotiation', async () => {
  129. const { upgrades, dispose } = await mounted()
  130. const socket = new PassThrough()
  131. const chunks: Buffer[] = []
  132. socket.on('data', (chunk: Buffer) => { chunks.push(chunk) })
  133. const ended = once(socket, 'end')
  134. await upgrades[0]!.handler(fakeRequest({
  135. host: 'harness.example', origin: 'http://harness.example', 'sec-fetch-site': 'same-origin',
  136. }, MUX_EVENTS_PATH), socket, Buffer.alloc(0))
  137. await ended
  138. expect(Buffer.concat(chunks).toString()).toContain('HTTP/1.1 403 Forbidden')
  139. await dispose()
  140. })
  141. it('refuses an untrusted Host on any /api path before the bridge runs', async () => {
  142. const { routes, dispose } = await mounted()
  143. const { response, state } = fakeResponse()
  144. await routes[0]!.handler(fakeRequest({
  145. host: 'harness.example', origin: 'http://harness.example', 'sec-fetch-site': 'same-origin',
  146. }), response)
  147. expect(state.status).toBe(403)
  148. expect(state.body).toBe('forbidden')
  149. await dispose()
  150. })
  151. it('pins privileged methods to loopback even for a declared trusted authority', async () => {
  152. const { routes, dispose } = await mounted({ trustedHosts: ['harness.example'] })
  153. // The privileged set: native dialogs plus the whole settings/credential
  154. // configuration plane, reads included, plus the one method that makes the
  155. // host fetch a caller-chosen URL. The same declared authority reaches
  156. // ordinary reads (carrier-level 404 from the empty proxy proves the fence
  157. // passed), but each privileged method stays loopback-only and 403s.
  158. for (const method of [
  159. 'host.pickDirectory', 'host.openPath',
  160. 'settings.describe', 'settings.openDocument', 'settings.update', 'settings.replace', 'settings.mutate',
  161. 'credentials.describe', 'credentials.set', 'credentials.unset',
  162. 'llm.discoverModels',
  163. // A composition names the plugins a session runs: reading one is
  164. // reconnaissance, and copy/remove/openDocument manage the roster and
  165. // drive the host desktop.
  166. 'agentPreset.read', 'agentPreset.copy', 'agentPreset.openDocument', 'agentPreset.remove',
  167. ]) {
  168. const denied = fakeResponse()
  169. await routes[0]!.handler(
  170. fakeRequest({ host: 'harness.example' }, `${API_PATH}/${method}`),
  171. denied.response,
  172. )
  173. expect(denied.state.status).toBe(403)
  174. expect(denied.state.body).toBe('forbidden')
  175. }
  176. const read = fakeResponse()
  177. await routes[0]!.handler(fakeRequest({ host: 'harness.example' }), read.response)
  178. expect(read.state.status).not.toBe(403)
  179. await dispose()
  180. })
  181. it('passes loopback and declared-authority requests through to the bridge', async () => {
  182. const { routes, dispose } = await mounted({ trustedHosts: ['harness.example:3080', '192.168.1.5'] })
  183. // Loopback, no browser markers (curl shape): the fence passes; the carrier
  184. // answers 404 for a GET unary path — proof the bridge ran.
  185. const loopback = fakeResponse()
  186. await routes[0]!.handler(fakeRequest({ host: '127.0.0.1:3080' }), loopback.response)
  187. expect(loopback.state.status).toBe(404)
  188. // LAN authority declared as a port-less IP literal — the shape the CLI
  189. // derives for `--host 0.0.0.0` — passes markerless curl on any port.
  190. const lan = fakeResponse()
  191. await routes[0]!.handler(fakeRequest({ host: '192.168.1.5:3080' }), lan.response)
  192. expect(lan.state.status).toBe(404)
  193. // Declared public authority, same-origin browser shape.
  194. const declared = fakeResponse()
  195. await routes[0]!.handler(fakeRequest({
  196. host: 'harness.example:3080', origin: 'http://harness.example:3080', 'sec-fetch-site': 'same-origin',
  197. }), declared.response)
  198. expect(declared.state.status).toBe(404)
  199. await dispose()
  200. })
  201. it('provides a disposable dedicated RPC channel without requiring apiProxy', async () => {
  202. const ctx = new Context()
  203. const routes: WebRoute[] = []
  204. ctx.provide('httpServer', fakeHttpServer(routes, []) as HttpServerService)
  205. const fiber = ctx.plugin({ inject: [...inject], apply })
  206. await fiber.await()
  207. expect(routes).toHaveLength(1)
  208. expect(routes[0]).toMatchObject({ kind: 'prefix', path: API_PATH })
  209. const connection = ctx.get('connection') as HostConnectionHandle
  210. const calls: unknown[] = []
  211. const remove = connection.rpc.handle('/rpc', async (endpoint, payload) => {
  212. calls.push({ endpoint, payload })
  213. return { ok: true, value: { accepted: true } }
  214. }, { authority: 'trusted-host' })
  215. const route = routes.find(candidate => candidate.path === '/rpc')
  216. expect(route).toBeDefined()
  217. const request: ClientRequest = {
  218. type: 'client-request',
  219. rpcId: RpcId('rpc-dedicated'),
  220. method: 'goals/create',
  221. payload: { args: { agentId: 'agent-1' } },
  222. }
  223. const result = fakeResponse()
  224. await route!.handler(fakePost({ host: '127.0.0.1:3080' }, '/rpc/goals/create', request), result.response)
  225. expect(result.state.status).toBe(200)
  226. expect(JSON.parse(String(result.state.body))).toEqual({
  227. type: 'server-response',
  228. rpcId: 'rpc-dedicated',
  229. result: { ok: true, value: { accepted: true } },
  230. })
  231. expect(calls).toEqual([{
  232. endpoint: 'goals/create',
  233. payload: { args: { agentId: 'agent-1' } },
  234. }])
  235. expect(() => connection.rpc.handle('/rpc', async () => ({ ok: true, value: null }), {
  236. authority: 'trusted-host',
  237. })).toThrow(/duplicate route/)
  238. await remove()
  239. expect(routes.map(candidate => candidate.path)).toEqual([API_PATH])
  240. await fiber.dispose()
  241. expect(routes).toHaveLength(0)
  242. })
  243. it('dispatches claimed /api endpoints before the API Proxy fallback and withdraws the claim', async () => {
  244. const ctx = new Context()
  245. const routes: WebRoute[] = []
  246. ctx.provide('httpServer', fakeHttpServer(routes, []) as HttpServerService)
  247. ctx.provide('apiProxy', {} as unknown as ApiProxy)
  248. const fiber = ctx.plugin({ inject: [...inject], apply }, { trustedHosts: ['harness.example'] })
  249. await fiber.await()
  250. const connection = ctx.get('connection') as HostConnectionHandle
  251. const calls: unknown[] = []
  252. const remove = connection.rpc.intercept(
  253. '/api',
  254. endpoint => endpoint === 'goals/create',
  255. async (endpoint, payload) => {
  256. calls.push({ endpoint, payload })
  257. return { ok: true, value: { accepted: true } }
  258. },
  259. { authority: 'trusted-host' },
  260. )
  261. expect(() => connection.rpc.intercept(
  262. '/api',
  263. () => true,
  264. async () => ({ ok: true, value: null }),
  265. { authority: 'trusted-host' },
  266. )).toThrow('already has an interceptor')
  267. expect(() => connection.rpc.intercept(
  268. '/rpc' as '/api',
  269. () => true,
  270. async () => ({ ok: true, value: null }),
  271. { authority: 'trusted-host' },
  272. )).toThrow('invalid shared RPC channel')
  273. const route = routes.find(candidate => candidate.path === API_PATH)!
  274. const request: ClientRequest = {
  275. type: 'client-request',
  276. rpcId: RpcId('rpc-shared'),
  277. method: 'goals/create',
  278. payload: { args: { agentId: 'agent-1' } },
  279. }
  280. const claimed = fakeResponse()
  281. await route.handler(fakePost({ host: '127.0.0.1:3080' }, '/api/goals/create', request), claimed.response)
  282. expect(JSON.parse(String(claimed.state.body))).toEqual({
  283. type: 'server-response',
  284. rpcId: 'rpc-shared',
  285. result: { ok: true, value: { accepted: true } },
  286. })
  287. expect(calls).toEqual([{
  288. endpoint: 'goals/create',
  289. payload: { args: { agentId: 'agent-1' } },
  290. }])
  291. const denied = fakeResponse()
  292. await route.handler(fakePost({ host: 'other.example' }, '/api/goals/create', request), denied.response)
  293. expect(denied.state).toMatchObject({ status: 403, body: 'forbidden' })
  294. expect(calls).toHaveLength(1)
  295. const unclaimed = fakeResponse()
  296. await route.handler(fakeRequest({ host: '127.0.0.1:3080' }, '/api/session.list'), unclaimed.response)
  297. expect(unclaimed.state.status).toBe(404)
  298. await remove()
  299. const withdrawn = fakeResponse()
  300. await route.handler(fakePost({ host: '127.0.0.1:3080' }, '/api/goals/create', request), withdrawn.response)
  301. expect(withdrawn.state.status).toBe(404)
  302. expect(calls).toHaveLength(1)
  303. const removeLoopback = connection.rpc.intercept(
  304. '/api',
  305. endpoint => endpoint === 'goals/create',
  306. async () => ({ ok: true, value: null }),
  307. { authority: 'loopback' },
  308. )
  309. const loopbackOnly = fakeResponse()
  310. await route.handler(fakePost({ host: 'harness.example' }, '/api/goals/create', request), loopbackOnly.response)
  311. expect(loopbackOnly.state.status).toBe(403)
  312. await removeLoopback()
  313. await fiber.dispose()
  314. })
  315. it('applies the configured trust fence and JSON envelope checks to generic channels', async () => {
  316. const ctx = new Context()
  317. const routes: WebRoute[] = []
  318. ctx.provide('httpServer', fakeHttpServer(routes, []) as HttpServerService)
  319. const fiber = ctx.plugin({ inject: [...inject], apply }, { trustedHosts: ['harness.example'] })
  320. await fiber.await()
  321. const connection = ctx.get('connection') as HostConnectionHandle
  322. const remove = connection.rpc.handle('/rpc', async (endpoint) => {
  323. if (endpoint === 'fail') throw new Error('handler broke')
  324. return { ok: true, value: null }
  325. }, {
  326. authority: 'trusted-host',
  327. })
  328. const route = routes.find(candidate => candidate.path === '/rpc')!
  329. const denied = fakeResponse()
  330. await route.handler(fakePost({ host: 'other.example' }, '/rpc/goals/create', {}), denied.response)
  331. expect(denied.state).toMatchObject({ status: 403, body: 'forbidden' })
  332. const methodMismatch = fakeResponse()
  333. await route.handler(fakePost({ host: 'harness.example' }, '/rpc/goals/create', {
  334. type: 'client-request', rpcId: 'rpc-bad', method: 'other', payload: {},
  335. }), methodMismatch.response)
  336. expect(JSON.parse(String(methodMismatch.state.body))).toMatchObject({
  337. rpcId: 'rpc-bad',
  338. result: { ok: false, error: { code: 'bad-request' } },
  339. })
  340. for (const [request, status] of [
  341. [fakeRequest({ host: 'harness.example' }, '/rpc/goals/create'), 404],
  342. [fakePost({ host: 'harness.example' }, '/outside/goals/create', {}), 404],
  343. [fakePost({ host: 'harness.example' }, '/rpc/goals//create', {}), 404],
  344. [fakeRawPost({ host: 'harness.example' }, '/rpc/goals/create', '{}'), 415],
  345. [fakeRawPost({ host: 'harness.example', 'content-type': 'text/plain' }, '/rpc/goals/create', '{}'), 415],
  346. [fakeRawPost({ host: 'harness.example', 'content-type': 'application/json; charset=utf-8' }, '/rpc/goals/create', '{'), 400],
  347. ] as const) {
  348. const response = fakeResponse()
  349. await route.handler(request, response.response)
  350. expect(response.state.status).toBe(status)
  351. }
  352. for (const [body, rpcId] of [
  353. [{ rpcId: 'retained-id' }, 'retained-id'],
  354. [{ rpcId: 42 }, 'invalid-request'],
  355. [null, 'invalid-request'],
  356. ] as const) {
  357. const response = fakeResponse()
  358. await route.handler(fakePost({ host: 'harness.example' }, '/rpc/goals/create', body), response.response)
  359. expect(JSON.parse(String(response.state.body))).toMatchObject({
  360. rpcId,
  361. result: { ok: false, error: { code: 'bad-request' } },
  362. })
  363. }
  364. const failed = fakeResponse()
  365. await route.handler(fakePost({ host: 'harness.example' }, '/rpc/fail', {
  366. type: 'client-request', rpcId: 'rpc-fail', method: 'fail', payload: {},
  367. }), failed.response)
  368. expect(failed.state).toMatchObject({ status: 500, body: 'handler failure: Error: handler broke' })
  369. expect(() => connection.rpc.handle('/api', async () => ({ ok: true, value: null }), {
  370. authority: 'loopback',
  371. })).toThrow('invalid or reserved RPC channel')
  372. expect(() => connection.rpc.handle('api3', async () => ({ ok: true, value: null }), {
  373. authority: 'loopback',
  374. })).toThrow('invalid or reserved RPC channel')
  375. const removeLoopback = connection.rpc.handle('/loopback', async () => ({ ok: true, value: null }), {
  376. authority: 'loopback',
  377. })
  378. const loopbackRoute = routes.find(candidate => candidate.path === '/loopback')!
  379. const publicResponse = fakeResponse()
  380. await loopbackRoute.handler(fakePost({ host: 'harness.example' }, '/loopback/read', {
  381. type: 'client-request', rpcId: 'rpc-public', method: 'read', payload: {},
  382. }), publicResponse.response)
  383. expect(publicResponse.state.status).toBe(403)
  384. await removeLoopback()
  385. await remove()
  386. await fiber.dispose()
  387. })
  388. })
  389. describe('connection node half over a real HTTP server', () => {
  390. /** Serve the registered prefix route from a real server and return its port. */
  391. async function serve(routes: WebRoute[]): Promise<{ port: number; close: () => Promise<void> }> {
  392. const server = createServer((request, response) => {
  393. void routes[0]!.handler(request, response)
  394. })
  395. await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve))
  396. const address = server.address() as AddressInfo
  397. return {
  398. port: address.port,
  399. close: () => new Promise<void>((resolve, reject) => {
  400. server.close((error) => {
  401. if (error === undefined || error === null) resolve()
  402. else reject(error)
  403. })
  404. }),
  405. }
  406. }
  407. /** One real request; `host` spoofs the authority the way a LAN client's browser would send it. */
  408. function call(port: number, method: string, host: string): Promise<number> {
  409. return new Promise((resolve, reject) => {
  410. const request = httpRequest(
  411. { host: '127.0.0.1', port, path: `${API_PATH}/${method}`, method: 'GET', headers: { host } },
  412. (response) => {
  413. response.resume()
  414. response.on('end', () => { resolve(response.statusCode ?? 0) })
  415. },
  416. )
  417. request.on('error', reject)
  418. request.end()
  419. })
  420. }
  421. it('answers a declared LAN authority with 403 on every configuration method, over real HTTP', async () => {
  422. // The fence's input is a real IncomingMessage parsed by Node from the
  423. // wire, not a hand-assembled object: the Host header a LAN browser sends
  424. // is exactly what decides loopback-only here, so the boundary is asserted
  425. // against the parse the server actually performs.
  426. const { routes, dispose } = await mounted({ trustedHosts: ['harness.example'] })
  427. const { port, close } = await serve(routes)
  428. try {
  429. // Reads are as privileged as writes: describe returns the exposed
  430. // configuration, and credentials.describe probes arbitrary env-var names.
  431. for (const method of [
  432. 'settings.describe', 'settings.openDocument', 'settings.update', 'settings.replace', 'settings.mutate',
  433. 'credentials.describe', 'credentials.set', 'credentials.unset',
  434. 'host.pickDirectory', 'host.openPath',
  435. // Carries a draft credential and turns the host into a fetcher for a
  436. // URL the caller picked: an anonymous LAN caller must not reach it.
  437. 'llm.discoverModels',
  438. 'agentPreset.read', 'agentPreset.copy', 'agentPreset.openDocument', 'agentPreset.remove',
  439. ]) {
  440. expect([method, await call(port, method, 'harness.example')]).toEqual([method, 403])
  441. }
  442. // The model catalog stays reachable for the same authority: a LAN
  443. // client's model picker needs it, and it carries no key or endpoint
  444. // state (404 is the empty proxy's carrier answer — the fence passed).
  445. // `agentPreset.list` joins the model catalog for the same reason: ids and
  446. // trust only, and a LAN client's preset picker needs it. `select` is
  447. // reachable too: `session.create` already takes an `agentPreset`, and the
  448. // deployment's own default already carries bash, so pinning the switch
  449. // would be a fence beside an open gate.
  450. for (const method of ['llm.providers', 'llm.models', 'agentPreset.list', 'agentPreset.select']) {
  451. expect([method, await call(port, method, 'harness.example')]).toEqual([method, 404])
  452. }
  453. // Loopback reaches everything, configuration included.
  454. expect(await call(port, 'settings.describe', `127.0.0.1:${String(port)}`)).toBe(404)
  455. } finally {
  456. await close()
  457. await dispose()
  458. }
  459. })
  460. })