From 523e667b403966fcdb51136eda34b2c1c0cd7bcb Mon Sep 17 00:00:00 2001 From: Yige Date: Sun, 19 Jul 2026 21:47:10 +0800 Subject: [PATCH] fix(compute): enforce reasoning effort boundaries (#60) --- __tests__/validate.test.mjs | 36 ++++++++++++++++++++++++++++++++++ manifest.json | 2 +- schemas/model-spec.schema.json | 3 ++- schemas/provider.schema.json | 8 ++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/__tests__/validate.test.mjs b/__tests__/validate.test.mjs index 8963f45..ccd1b78 100644 --- a/__tests__/validate.test.mjs +++ b/__tests__/validate.test.mjs @@ -324,6 +324,14 @@ describe('provider schema 反例(防 PR #1 重演)', () => { assert.equal(validate(duplicate), false) }) + it('拒绝不在 supportedEfforts 中的 defaultEffort', () => { + const data = makeValidProvider() + data.models[0].extra = { + reasoning: { supportedEfforts: ['low'], defaultEffort: 'high' }, + } + assert.equal(validate(data), false) + }) + it('接受 defaultTemperature: 0.7(合法 number)', () => { const data = makeValidProvider() data.models[0].defaultTemperature = 0.7 @@ -373,6 +381,34 @@ describe('provider schema 反例(防 PR #1 重演)', () => { }) }) +describe('model-spec schema 接入面边界', () => { + const validate = compile('model-spec') + + it('拒绝在模型内在规格中声明 reasoning effort', () => { + const data = { + specs: [{ + id: 'gpt-test', + spec: { + extra: { + reasoning: { + supportedEfforts: ['low', 'high'], + defaultEffort: 'low', + }, + }, + }, + }], + } + assert.equal(validate(data), false) + }) + + it('仍允许模型内在扩展参数', () => { + const data = { + specs: [{ id: 'gpt-test', spec: { extra: { intrinsicBudgetHint: 8192 } } }], + } + assert.equal(validate(data), true, JSON.stringify(validate.errors)) + }) +}) + // ==================== Manifest schema ==================== describe('manifest schema', () => { diff --git a/manifest.json b/manifest.json index 1197159..4bc185b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "version": "1.0.0", - "presetDataVersion": 76, + "presetDataVersion": 77, "updatedAt": "2026-07-19", "description": "DesireCore 官方配置中心" } diff --git a/schemas/model-spec.schema.json b/schemas/model-spec.schema.json index b5d5b32..24c921f 100644 --- a/schemas/model-spec.schema.json +++ b/schemas/model-spec.schema.json @@ -98,7 +98,8 @@ }, "extra": { "type": "object", - "description": "模型特定附加配置(如 apiModelId 全名、推理预算等)。不含价格。", + "description": "模型内在附加配置(如 apiModelId 全名、推理预算等)。不含价格,也不得声明 Provider/接入面的 reasoning effort 能力。", + "not": { "required": ["reasoning"] }, "additionalProperties": true }, "releasedAt": { diff --git a/schemas/provider.schema.json b/schemas/provider.schema.json index 047bbc8..6f197d3 100644 --- a/schemas/provider.schema.json +++ b/schemas/provider.schema.json @@ -274,6 +274,14 @@ "description": "当前模型在此接入面的推荐显式默认档位,必须同时存在于 supportedEfforts。" } }, + "allOf": [ + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "minimal" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "minimal" } } } } }, + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "low" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "low" } } } } }, + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "medium" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "medium" } } } } }, + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "high" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "high" } } } } }, + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "xhigh" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "xhigh" } } } } }, + { "if": { "required": ["defaultEffort"], "properties": { "defaultEffort": { "const": "max" } } }, "then": { "properties": { "supportedEfforts": { "contains": { "const": "max" } } } } } + ], "additionalProperties": false } },