1 parent
a8f689e39c
commit
c340aec110
59 files changed
+1108
-1590
No files matched your search
@@ -17,11 +17,11 @@ const USER_PATCH = '- id: permission\n config:\n defaultPreset: danger-full-
|
||||
* patch path, the initiating agent, and one of the two settings generations.
|
||||
*/
|
||||
async function makeContext({ settings: generation = '0.2' } = {}) {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'geek2api-wiring-'))
|
||||
const dir = await mkdtemp(join(tmpdir(), 'infstarapi-wiring-'))
|
||||
const patchPath = join(dir, 'cordis.patch.yml')
|
||||
await writeFile(patchPath, USER_PATCH)
|
||||
|
||||
const values = { searchProvider: 'default', searchBackend: 'claude' }
|
||||
const values = { searchProvider: 'default', searchBackend: 'gpt' }
|
||||
const seen = { updates: [], configured: [], listeners: new Map(), handler: undefined, section: undefined }
|
||||
const providers = new Map()
|
||||
const dshSearch = { id: 'deepseek-official', available: () => true, search: async () => ({ sources: [{ url: 'https://dsh.example/' }], truncated: false }) }
|
||||
@@ -38,7 +38,7 @@ async function makeContext({ settings: generation = '0.2' } = {}) {
|
||||
options: { id: 'web', config: { searchProvider: 'deepseek-official', fetchProvider: 'http' } },
|
||||
fiber: { config: { searchProvider: 'codex-subscription-auto', fetchProvider: 'http' } },
|
||||
}
|
||||
let modelProvider = 'geek2api'
|
||||
let modelProvider = 'infstarapi'
|
||||
const session = { id: 'session-1', requestContext: () => ({ provider: modelProvider }) }
|
||||
const services = {
|
||||
profileContext: { patchPath },
|
||||
@@ -75,7 +75,7 @@ async function makeContext({ settings: generation = '0.2' } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
const fiber = { entry: { options: { id: 'geek2api' } } }
|
||||
const fiber = { entry: { options: { id: 'infstarapi' } } }
|
||||
const ctx = {
|
||||
credentials: fakeCredentials(),
|
||||
attachments: undefined,
|
||||
@@ -123,7 +123,7 @@ const settle = () => new Promise(resolve => { setTimeout(resolve, 20) })
|
||||
test('the search preference fields are part of the plugin Config', () => {
|
||||
const resolved = new Config({})
|
||||
assert.equal(fieldValue(resolved.searchProvider), 'default')
|
||||
assert.equal(fieldValue(resolved.searchBackend), 'claude')
|
||||
assert.equal(fieldValue(resolved.searchBackend), 'gpt')
|
||||
assert.throws(() => new Config({ searchProvider: 'everything' }))
|
||||
})
|
||||
|
||||
@@ -133,8 +133,8 @@ test('DSH 0.2: both providers register, and the panel switches routing through t
|
||||
apply(env.ctx, env.config)
|
||||
await settle()
|
||||
|
||||
assert.ok(env.providers.has('geek2api'))
|
||||
assert.ok(env.providers.has('geek2api-auto'))
|
||||
assert.ok(env.providers.has('infstarapi'))
|
||||
assert.ok(env.providers.has('infstarapi-auto'))
|
||||
// The Geek2API panel is the editor; the generated page is hidden for this fiber.
|
||||
assert.deepEqual(env.seen.configured, [{ presentation: { auto: false }, owner: env.ctx.fiber }])
|
||||
assert.equal(typeof env.seen.listeners.get('loader/volatile-update'), 'function')
|
||||
@@ -142,7 +142,7 @@ test('DSH 0.2: both providers register, and the panel switches routing through t
|
||||
const initial = await env.seen.handler('search/status', {})
|
||||
assert.equal(initial.ok, true)
|
||||
assert.equal(initial.value.searchProvider, 'default')
|
||||
assert.equal(initial.value.searchBackend, 'claude')
|
||||
assert.equal(initial.value.searchBackend, 'gpt')
|
||||
assert.equal(initial.value.writable, true)
|
||||
assert.equal(initial.value.available, true)
|
||||
assert.deepEqual(initial.value.effective, { base: 'deepseek-official', runtime: 'codex-subscription-auto' })
|
||||
@@ -152,12 +152,12 @@ test('DSH 0.2: both providers register, and the panel switches routing through t
|
||||
const auto = await env.seen.handler('search/update', { searchProvider: 'auto' })
|
||||
assert.equal(auto.ok, true)
|
||||
// DSH 0.2 writes a volatile field of the plugin's own row.
|
||||
assert.deepEqual(env.seen.updates, [{ id: 'geek2api', patch: { searchProvider: 'auto' } }])
|
||||
assert.deepEqual(env.seen.updates, [{ id: 'infstarapi', patch: { searchProvider: 'auto' } }])
|
||||
assert.equal(auto.value.searchProvider, 'auto')
|
||||
assert.deepEqual(auto.value.applied, { state: 'applied', fallback: 'deepseek-official' })
|
||||
const patched = await readFile(env.patchPath, 'utf8')
|
||||
assert.ok(patched.startsWith(USER_PATCH))
|
||||
assert.match(patched, /- id: web\n {2}config:\n {4}fetchProvider: http\n {4}searchProvider: geek2api-auto\n/u)
|
||||
assert.match(patched, /- id: web\n {2}config:\n {4}fetchProvider: http\n {4}searchProvider: infstarapi-auto\n/u)
|
||||
|
||||
const backend = await env.seen.handler('search/update', { searchBackend: 'gpt' })
|
||||
assert.equal(backend.value.searchBackend, 'gpt')
|
||||
@@ -175,10 +175,10 @@ test('DSH 0.2: a volatile change made elsewhere is followed without a restart',
|
||||
t.after(env.cleanup)
|
||||
apply(env.ctx, env.config)
|
||||
await settle()
|
||||
env.values.searchProvider = 'geek2api'
|
||||
env.values.searchProvider = 'infstarapi'
|
||||
env.seen.listeners.get('loader/volatile-update')([['searchProvider']])
|
||||
await settle()
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: geek2api\n/u)
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: infstarapi\n/u)
|
||||
})
|
||||
|
||||
test('DSH 0.1.5: the preference lives in the installed section and its change hook reconciles', async t => {
|
||||
@@ -186,13 +186,13 @@ test('DSH 0.1.5: the preference lives in the installed section and its change ho
|
||||
t.after(env.cleanup)
|
||||
apply(env.ctx, {})
|
||||
await settle()
|
||||
assert.equal(env.seen.section.ns, 'geek2api')
|
||||
const updated = await env.seen.handler('search/update', { searchProvider: 'geek2api', searchBackend: 'gpt' })
|
||||
assert.equal(env.seen.section.ns, 'infstarapi')
|
||||
const updated = await env.seen.handler('search/update', { searchProvider: 'infstarapi', searchBackend: 'gpt' })
|
||||
assert.equal(updated.ok, true)
|
||||
assert.deepEqual(env.seen.updates, [{ id: 'geek2api', patch: { searchProvider: 'geek2api', searchBackend: 'gpt' } }])
|
||||
assert.equal(updated.value.searchProvider, 'geek2api')
|
||||
assert.deepEqual(env.seen.updates, [{ id: 'infstarapi', patch: { searchProvider: 'infstarapi', searchBackend: 'gpt' } }])
|
||||
assert.equal(updated.value.searchProvider, 'infstarapi')
|
||||
assert.equal(updated.value.searchBackend, 'gpt')
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: geek2api\n/u)
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: infstarapi\n/u)
|
||||
})
|
||||
|
||||
test('the registered providers search with ring keys and route by the initiating model', async t => {
|
||||
@@ -208,26 +208,26 @@ test('the registered providers search with ring keys and route by the initiating
|
||||
globalThis.fetch = async (url, init) => {
|
||||
// Every probe answers alike, so the configured order decides the host.
|
||||
if (String(url).endsWith('/health')) return { ok: false, status: 503 }
|
||||
requests.push({ url, key: new Headers(init.headers).get('x-api-key') })
|
||||
requests.push({ url, key: new Headers(init?.headers ?? (typeof url === 'string' ? undefined : url.headers)).get('authorization') })
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
content: [
|
||||
{ type: 'web_search_tool_result', content: [{ type: 'web_search_result', url: 'https://geek2api.example/', title: 'Geek2API result' }] },
|
||||
{ type: 'text', text: 'summary' },
|
||||
output: [
|
||||
{ type: 'web_search_call', status: 'completed', action: { type: 'search', query: 'q', sources: [{ type: 'url', url: 'https://infstarapi.example/', title: 'InfStarAPI result' }] } },
|
||||
{ type: 'message', content: [{ type: 'output_text', text: 'summary', annotations: [] }] },
|
||||
],
|
||||
}),
|
||||
}
|
||||
}
|
||||
t.after(() => { globalThis.fetch = original })
|
||||
|
||||
const direct = await env.providers.get('geek2api').search({ query: 'q' })
|
||||
assert.equal(direct.sources[0].url, 'https://geek2api.example/')
|
||||
assert.deepEqual(requests, [{ url: `${DEFAULT_API_HOST}/v1/messages`, key: 'sk-search-key-0001' }])
|
||||
const direct = await env.providers.get('infstarapi').search({ query: 'q' })
|
||||
assert.equal(direct.sources[0].url, 'https://infstarapi.example/')
|
||||
assert.deepEqual(requests, [{ url: `${DEFAULT_API_HOST}/v1/responses`, key: 'Bearer sk-search-key-0001' }])
|
||||
|
||||
const auto = env.providers.get('geek2api-auto')
|
||||
assert.equal((await auto.search({ query: 'q' })).sources[0].url, 'https://geek2api.example/')
|
||||
const auto = env.providers.get('infstarapi-auto')
|
||||
assert.equal((await auto.search({ query: 'q' })).sources[0].url, 'https://infstarapi.example/')
|
||||
env.setModelProvider('anthropic')
|
||||
assert.equal((await auto.search({ query: 'q' })).sources[0].url, 'https://dsh.example/')
|
||||
assert.equal(requests.length, 2, 'the non-Geek2API request never reached the gateway')
|
||||
@@ -252,12 +252,12 @@ test('patch writes run inside DSH\'s reload lock, and unlocked when that lock re
|
||||
const before = locked
|
||||
await env.seen.handler('search/update', { searchProvider: 'auto' })
|
||||
assert.equal(locked, before + 1)
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: geek2api-auto\n/u)
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: infstarapi-auto\n/u)
|
||||
|
||||
nested = true
|
||||
const updated = await env.seen.handler('search/update', { searchProvider: 'geek2api' })
|
||||
const updated = await env.seen.handler('search/update', { searchProvider: 'infstarapi' })
|
||||
assert.equal(updated.value.applied.state, 'applied')
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: geek2api\n/u)
|
||||
assert.match(await readFile(env.patchPath, 'utf8'), /searchProvider: infstarapi\n/u)
|
||||
})
|
||||
|
||||
test('a profile without the web service keeps its route and reports search unavailable', async t => {
|
||||
@@ -268,5 +268,5 @@ test('a profile without the web service keeps its route and reports search unava
|
||||
apply(env.ctx, env.config)
|
||||
const status = await env.seen.handler('search/status', {})
|
||||
assert.equal(status.value.available, false)
|
||||
assert.equal(env.providers.has('geek2api'), false)
|
||||
assert.equal(env.providers.has('infstarapi'), false)
|
||||
})
|
||||
Reference in new issue
Block a user