c3f3b822f1
- Use CF Workers AI bge-base-en-v1.5 for embeddings - Deploy stores capability embedding in KV - Query uses cosine similarity (find) and MMR (explore) - Query embedding cached in KV (1h TTL) - Fallback to string matching for capabilities without embeddings - Mock embedding service for unit tests
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { createMockKv, createMockCfApi, MockEmbeddingService } from './setup.js'
|
|
import { WorkerPool } from '../src/backend/worker-pool.js'
|
|
|
|
describe('S5: 调用不存在的能力', () => {
|
|
let mockKv: KVNamespace
|
|
let mockCf: ReturnType<typeof createMockCfApi>
|
|
let mockEmbed: MockEmbeddingService
|
|
let pool: WorkerPool
|
|
|
|
beforeEach(() => {
|
|
mockKv = createMockKv()
|
|
mockCf = createMockCfApi()
|
|
mockEmbed = new MockEmbeddingService()
|
|
pool = new WorkerPool(mockKv, mockCf.cfApi, mockEmbed as any)
|
|
})
|
|
|
|
it('should return 404 for nonexistent capability', async () => {
|
|
const req = new Request('https://sigil.shazhou.workers.dev/run/nonexistent')
|
|
const resp = await pool.invoke('nonexistent', req)
|
|
expect(resp.status).toBe(404)
|
|
})
|
|
|
|
it('should return error JSON body', async () => {
|
|
const req = new Request('https://sigil.shazhou.workers.dev/run/nonexistent')
|
|
const resp = await pool.invoke('nonexistent', req)
|
|
const body = await resp.json() as { error: string }
|
|
expect(body.error).toBeTruthy()
|
|
})
|
|
|
|
it('should not call deployWorker for nonexistent', async () => {
|
|
const req = new Request('https://sigil.shazhou.workers.dev/run/nonexistent')
|
|
await pool.invoke('nonexistent', req)
|
|
expect(mockCf.deployCalls()).toHaveLength(0)
|
|
})
|
|
})
|