fix: classify upstream failures and prevent empty billed responses
This commit is contained in:
1 parent
b455d8d79f
commit
9acc69d4c7
28 files changed
+1449
-131
No files matched your search
@@ -1,9 +1,53 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { buildModelCatalog, setGroupSelection } from '../src/services/model-catalog.ts'
|
||||
import { buildModelCatalog, providerCapabilityLabel, setGroupSelection, summarizeModelCatalog } from '../src/services/model-catalog.ts'
|
||||
import { usePagination } from '../src/composables/usePagination.ts'
|
||||
|
||||
test('catalog summary distinguishes published models, ready models, ready routes, and missing prices', () => {
|
||||
const definitions = [
|
||||
'available', 'legacy-ready', 'no-routes', 'pricing-only', 'billing-only',
|
||||
'execution-only', 'unavailable-provider', 'orphan-provider', 'disabled-route',
|
||||
].map(id => ({ id, status: 'active' }))
|
||||
definitions.push({ id: 'hidden', status: 'disabled' })
|
||||
const providers = [{ id: 'live', status: 'active' }, { id: 'offline', status: 'disabled' }]
|
||||
const route = (id, logicalModelId, overrides = {}) => ({
|
||||
id, logicalModelId, providerId: 'live', status: 'active',
|
||||
pricingConfigured: true, billingReady: true, executionReady: true, ...overrides,
|
||||
})
|
||||
const routes = [
|
||||
route('ready-a', 'available'),
|
||||
route('ready-b', 'available'),
|
||||
route('legacy-ready', 'legacy-ready', { billingReady: undefined, executionReady: undefined }),
|
||||
route('unconfigured', 'available', { pricingConfigured: undefined }),
|
||||
route('unpriced', 'pricing-only', { pricingConfigured: false }),
|
||||
route('billing-blocked', 'billing-only', { billingReady: false }),
|
||||
route('execution-blocked', 'execution-only', { executionReady: false }),
|
||||
route('offline', 'unavailable-provider', { providerId: 'offline' }),
|
||||
route('offline-unpriced', 'unavailable-provider', { providerId: 'offline', pricingConfigured: false }),
|
||||
route('orphan-provider', 'orphan-provider', { providerId: 'missing' }),
|
||||
route('disabled', 'disabled-route', { status: 'disabled' }),
|
||||
route('disabled-unpriced', 'disabled-route', { status: 'disabled', pricingConfigured: false }),
|
||||
route('hidden', 'hidden'),
|
||||
route('hidden-unpriced', 'hidden', { pricingConfigured: false }),
|
||||
route('orphan-definition', 'missing'),
|
||||
]
|
||||
|
||||
assert.deepEqual(summarizeModelCatalog(definitions, routes, providers), {
|
||||
publishedModels: 9, readyModels: 2, readyRoutes: 3, unpricedRoutes: 2,
|
||||
})
|
||||
})
|
||||
|
||||
test('published models remain counted when no routes or providers can serve them', () => {
|
||||
const definitions = [{ id: 'published', status: 'active' }, { id: 'hidden', status: 'disabled' }]
|
||||
assert.deepEqual(summarizeModelCatalog(definitions, [], []), {
|
||||
publishedModels: 1, readyModels: 0, readyRoutes: 0, unpricedRoutes: 0,
|
||||
})
|
||||
assert.deepEqual(summarizeModelCatalog([], [], []), {
|
||||
publishedModels: 0, readyModels: 0, readyRoutes: 0, unpricedRoutes: 0,
|
||||
})
|
||||
})
|
||||
|
||||
test('published models without enabled routes remain visible and duplicate routes are grouped', () => {
|
||||
const definitions = Array.from({ length: 315 }, (_, i) => ({ id: `m${i}`, status: 'active' }))
|
||||
const routes = [{ id: 'a', logicalModelId: 'm0', status: 'active' }, { id: 'b', logicalModelId: 'm0', status: 'active' }, { id: 'c', logicalModelId: 'm1', status: 'disabled' }]
|
||||
@@ -14,6 +58,13 @@ test('published models without enabled routes remain visible and duplicate route
|
||||
assert.equal(catalog.at(-1).definition.id, 'm314')
|
||||
})
|
||||
|
||||
test('provider capability summary deduplicates route types and remains bounded', () => {
|
||||
assert.equal(providerCapabilityLabel(['text', 'text', 'multimodal', '3d']), '文本 · 多模态 · 3D')
|
||||
assert.equal(providerCapabilityLabel(['text', 'code', 'image', 'audio', 'video']), '文本 · 代码 · 图像 等 5 类')
|
||||
assert.equal(providerCapabilityLabel(['unknown', 'unknown']), '其他')
|
||||
assert.equal(providerCapabilityLabel([]), '待配置能力')
|
||||
})
|
||||
|
||||
test('selecting and removing another model preserves existing exact group grants', () => {
|
||||
let grants = ['model-a/relay-1', 'legacy-unavailable']
|
||||
grants = setGroupSelection(grants, ['model-b/relay-2'], true)
|
||||
|
||||
Reference in new issue
Block a user