feat: frozen schema + CI validation to prevent client-breaking data

引入 frozen JSON Schema 契约(schemas/)和自动校验,作为已发布客户端的兼容防线。

背景:
PR #1 把 reasoning 模型 defaultTemperature/defaultTopP 写为 null,已发布客户端
schema 严格 number → readComputeConfig 校验失败 → sync 死锁。详见 desirecore PR #471。

本次新增:
- schemas/provider.schema.json: 镜像 desirecore d185299(fix #471 之前)的 strict
  computeProviderSchema/providerModelSchema,禁止 null/string/未知字段
- schemas/{manifest,service-map,pricing,providers-index}.schema.json: 配套契约
- scripts/validate.mjs: 扫所有数据文件自动校验
- __tests__/validate.test.mjs: 28 个测试,含 PR #1 反例的回归测试
- .github/workflows/validate.yml: PR/push 自动跑 validate + test

未来新增字段流程:
1. 先在 desirecore 主仓升级 schema 接受新字段
2. 发布新客户端,等用户升级
3. 再更新本仓库 frozen schema 和数据

否则老客户端因 additionalProperties: false 拒绝未知字段而死锁。
This commit is contained in:
2026-04-25 21:09:23 +08:00
parent 10465e3570
commit bd448f6c43
11 changed files with 902 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://desirecore.net/schemas/config-center/manifest.schema.json",
"title": "ConfigCenterManifest",
"description": "manifest.json 数据契约。客户端通过 presetDataVersion 判断是否合并更新。",
"type": "object",
"required": ["version", "presetDataVersion", "updatedAt"],
"properties": {
"version": {
"type": "string",
"description": "配置中心格式版本semver如 1.0.0",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"presetDataVersion": {
"type": "integer",
"description": "预置数据版本号(递增整数)。客户端运行时通过此字段决定是否合并新数据。每次内容变更必须递增。",
"minimum": 1
},
"updatedAt": {
"type": "string",
"description": "最后更新日期YYYY-MM-DD 格式",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
},
"description": {
"type": "string",
"description": "仓库说明"
}
},
"additionalProperties": false
}