From 31466bd17baa76749498d503a412c70841500201 Mon Sep 17 00:00:00 2001 From: Rogee Date: Thu, 8 Oct 2026 12:52:09 +0800 Subject: [PATCH] Keep standalone task schema aligned with explicit TTS protocol --- contracts/schema/README.md | 2 +- contracts/schema/http-task-detail.schema.json | 5 ++++ contracts/schema_consistency_test.go | 30 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 contracts/schema_consistency_test.go diff --git a/contracts/schema/README.md b/contracts/schema/README.md index aa238d2..edb497b 100644 --- a/contracts/schema/README.md +++ b/contracts/schema/README.md @@ -2,7 +2,7 @@ 此目录提供五类 HTTP 响应和六类 MQ 消息的独立校验入口,使用 JSON Schema Draft 2020-12。重复且约束相同的结构通过相对 `$ref` 引用 `common.schema.json`,仅单个入口使用的结构保留在该入口的 `$defs` 中。 -本次仅新增文件,不替换或删除 `contracts/local/` 的原文件,不修改现有程序的校验入口、嵌入资源或来源清单。程序仍使用原有 Schema;此目录尚未接入运行或发布流程,不构成外部 SaaS 签收。 +此目录不替换或删除 `contracts/local/` 的原文件,不修改现有程序的校验入口、嵌入资源或来源清单。现行定义仍以 `contracts/local/` 和 `docs/thirds/saas-dispatcher.md` 为准,拆分副本必须随其同步;单元测试核对任务 TTS 定义完全一致,防止协议字段等内容漂移。程序仍使用原有 Schema;此目录尚未接入运行或发布流程,不构成外部 SaaS 签收。 ## HTTP 响应 diff --git a/contracts/schema/http-task-detail.schema.json b/contracts/schema/http-task-detail.schema.json index b438569..f902aed 100644 --- a/contracts/schema/http-task-detail.schema.json +++ b/contracts/schema/http-task-detail.schema.json @@ -302,12 +302,17 @@ "additionalProperties": false, "required": [ "provider_id", + "protocol", "model", "voice", "language_type", "format" ], "properties": { + "protocol": { + "enum": ["dashscope_tts_http", "dashscope_task_websocket"], + "$comment": "Task selects the protocol; never infer it from model names or endpoint availability." + }, "provider_id": { "type": "string", "minLength": 1 diff --git a/contracts/schema_consistency_test.go b/contracts/schema_consistency_test.go new file mode 100644 index 0000000..d52eca3 --- /dev/null +++ b/contracts/schema_consistency_test.go @@ -0,0 +1,30 @@ +package contracts_test + +import ( + "encoding/json" + "os" + "reflect" + "testing" +) + +func TestStandaloneTaskTTSMatchesCurrentContract(t *testing.T) { + load := func(path string) map[string]any { + t.Helper() + body, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + var schema map[string]any + if err = json.Unmarshal(body, &schema); err != nil { + t.Fatal(err) + } + return schema + } + current := load("local/config-read.schema.json") + exported := load("schema/http-task-detail.schema.json") + expected := current["$defs"].(map[string]any)["tts"] + actual := exported["$defs"].(map[string]any)["tts"] + if !reflect.DeepEqual(expected, actual) { + t.Fatal("standalone task TTS schema has drifted from contracts/local; update the exported copy, not the runtime contract") + } +}