fix: resolve apiProxy via ctx.get for /model (v0.3.2)

Cordis throws on ctx.apiProxy without inject; use ctx.get and declare apiProxy inject so catalog and model APIs work under dsh web.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
owo
2026-08-14 20:20:55 +08:00
co-authored by Cursor
parent f433cce24d
commit 5dbe833205
18 changed files with 209 additions and 35 deletions
+25
View File
@@ -0,0 +1,25 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { resolveApiProxy } from '../src/apiproxy.ts'
test('resolveApiProxy uses ctx.get and avoids bare ctx.apiProxy', () => {
const api = { sessions: {} }
let touchedBare = false
const ctx = {
get(name: string) {
return name === 'apiProxy' ? api : undefined
},
get apiProxy() {
touchedBare = true
throw new Error('cannot get property "apiProxy" without inject')
},
}
assert.equal(resolveApiProxy(ctx as any), api)
assert.equal(touchedBare, false)
})
test('resolveApiProxy falls back to own-property mock', () => {
const api = { sessions: {} }
const ctx = { apiProxy: api }
assert.equal(resolveApiProxy(ctx as any), api)
})