chore: prepare GoodBuddy 0.8.2
Cross-platform packages / Validate source (push) Waiting to run
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, macos, macos-15-intel) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / Publish GitHub Release (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
Cross-platform packages / Validate source (push) Waiting to run
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, macos, macos-15-intel) (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
Cross-platform packages / Publish GitHub Release (push) Blocked by required conditions
Cross-platform packages / ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
classifyEmbeddingError,
|
||||
EmbeddingOperationError,
|
||||
toEmbeddingOperationError
|
||||
} from './embedding-errors'
|
||||
|
||||
describe('embedding error classification', () => {
|
||||
it.each([
|
||||
[new Error('Embedding request failed with HTTP 404'), 'model_not_found'],
|
||||
[new Error('unknown model vendor/embed-v9'), 'model_not_found'],
|
||||
[{ status: 401 }, 'authentication'],
|
||||
[new Error('Incorrect API key provided'), 'authentication'],
|
||||
[{ statusCode: 429 }, 'rate_limited'],
|
||||
[new Error('request ETIMEDOUT'), 'timeout'],
|
||||
[new TypeError('fetch failed'), 'network'],
|
||||
[{ code: 503 }, 'provider_unavailable']
|
||||
])('classifies %p as %s', (error, code) => {
|
||||
expect(classifyEmbeddingError(error).code).toBe(code)
|
||||
})
|
||||
|
||||
it('distinguishes explicit cancellation from timeout aborts', () => {
|
||||
const abort = new Error('The operation was aborted')
|
||||
abort.name = 'AbortError'
|
||||
expect(classifyEmbeddingError(abort).code).toBe('cancelled')
|
||||
expect(
|
||||
classifyEmbeddingError(abort, { timedOut: true }).code
|
||||
).toBe('cancelled')
|
||||
expect(
|
||||
classifyEmbeddingError(new Error('request stopped'), {
|
||||
timedOut: true
|
||||
}).code
|
||||
).toBe('timeout')
|
||||
})
|
||||
|
||||
it('never returns provider bodies, credentials, endpoints or nested causes', () => {
|
||||
const secret =
|
||||
'sk-secret-value https://vectors.example/v1 {"private":"document"}'
|
||||
const source = Object.assign(new Error(secret), {
|
||||
status: 401,
|
||||
response: {
|
||||
body: secret,
|
||||
headers: { authorization: `Bearer ${secret}` }
|
||||
},
|
||||
cause: new Error(secret)
|
||||
})
|
||||
|
||||
const result = classifyEmbeddingError(source)
|
||||
const serialized = JSON.stringify(result)
|
||||
expect(result).toEqual({
|
||||
code: 'authentication',
|
||||
message: '向量服务身份验证失败。',
|
||||
retryable: false,
|
||||
remedy: '请检查访问密钥是否有效以及是否具备调用向量模型的权限。'
|
||||
})
|
||||
expect(serialized).not.toContain('secret')
|
||||
expect(serialized).not.toContain('vectors.example')
|
||||
expect(serialized).not.toContain('private')
|
||||
})
|
||||
|
||||
it('wraps unknown errors in a safe serializable operation error', () => {
|
||||
const wrapped = toEmbeddingOperationError(
|
||||
new Error('raw provider payload with token')
|
||||
)
|
||||
expect(wrapped).toBeInstanceOf(EmbeddingOperationError)
|
||||
expect(wrapped.toSafeError()).toEqual({
|
||||
code: 'unknown',
|
||||
message: '向量操作失败。',
|
||||
retryable: false,
|
||||
remedy: '请检查向量服务配置后重试。'
|
||||
})
|
||||
expect(JSON.stringify(wrapped.toSafeError())).not.toContain('token')
|
||||
expect(toEmbeddingOperationError(wrapped)).toBe(wrapped)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user