diff --git a/__tests__/validate.test.mjs b/__tests__/validate.test.mjs index 12a5380..79ca963 100644 --- a/__tests__/validate.test.mjs +++ b/__tests__/validate.test.mjs @@ -110,6 +110,20 @@ describe('真实数据全量校验', () => { assert.equal(routed.every((spec) => Array.isArray(spec.spec.capabilities)), true) }) + it('智能路由三档必须完整唯一,且每档从自身开始回退', () => { + const indexPath = join(ROOT, 'compute', 'model-specs', '_index.json') + const index = JSON.parse(readFileSync(indexPath, 'utf8')) + const validate = compile('model-specs-index') + + const duplicateTier = structuredClone(index) + duplicateTier.routingTiers[1] = structuredClone(duplicateTier.routingTiers[0]) + assert.equal(validate(duplicateTier), false) + + const wrongFirstFallback = structuredClone(index) + wrongFirstFallback.routingTiers[0].fallbackOrder = ['balanced', 'flagship', 'lightweight'] + assert.equal(validate(wrongFirstFallback), false) + }) + it('Provider 与 coding plan 的 _index.json 应通过 providers-index schema', () => { const r1 = validateFile(join(ROOT, 'compute', 'providers', '_index.json'), validators) const r2 = validateFile(join(ROOT, 'compute', 'coding-plans', '_index.json'), validators) diff --git a/schemas/model-specs-index.schema.json b/schemas/model-specs-index.schema.json index c9b8909..81537b1 100644 --- a/schemas/model-specs-index.schema.json +++ b/schemas/model-specs-index.schema.json @@ -42,10 +42,47 @@ "description": "该档位缺少可用候选时的量级降级/升级顺序,首项必须等于 id。" } }, + "allOf": [ + { + "if": { "properties": { "id": { "const": "flagship" } }, "required": ["id"] }, + "then": { "properties": { "fallbackOrder": { "items": [{ "const": "flagship" }] } } } + }, + { + "if": { "properties": { "id": { "const": "balanced" } }, "required": ["id"] }, + "then": { "properties": { "fallbackOrder": { "items": [{ "const": "balanced" }] } } } + }, + { + "if": { "properties": { "id": { "const": "lightweight" } }, "required": ["id"] }, + "then": { "properties": { "fallbackOrder": { "items": [{ "const": "lightweight" }] } } } + } + ], "additionalProperties": false }, "description": "智能路由量级定义与回退策略。" } }, + "allOf": [ + { + "properties": { + "routingTiers": { + "contains": { "type": "object", "properties": { "id": { "const": "flagship" } }, "required": ["id"] } + } + } + }, + { + "properties": { + "routingTiers": { + "contains": { "type": "object", "properties": { "id": { "const": "balanced" } }, "required": ["id"] } + } + } + }, + { + "properties": { + "routingTiers": { + "contains": { "type": "object", "properties": { "id": { "const": "lightweight" } }, "required": ["id"] } + } + } + } + ], "additionalProperties": false }