Skip to content

Commit 0698b52

Browse files
committed
fix(sdks): C++/C# demo 契约全量对齐——所有注册函数补 schema,fallback 不再污染共享契约
DB 全量审计(15:25 注册后)实证:除 player.* 外全部函数契约被 action fallback 形状污染(inventory.list/order.list/mail.list 等 collection_query 的 output 全为 {status,action})。六语言 demo 共享同一 (game,env,function_id) 契约槽位(last-writer-wins), C++/C# 的 schema 表只覆盖 player.* + 上轮补的 4 个 list——其余 注册函数仍落 fallback,重注册即覆盖正确契约。 Python/Java/JS 全量核对确认本就全覆盖(此前正则核对误报)。 本次 C++/C# 按 Go 基准补齐全部注册函数: - collection_query:items/total 形状(上轮已补) - item/action 函数:order{create,get,update,delete}/leaderboard {upsert,reset}/inventory{grant,consume}/mail{send,claim, batch_send}——单对象形状(order/entry/item/mail/reset/deleted)
1 parent 189284b commit 0698b52

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

sdks/cpp/examples/game_demo.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,30 @@ static std::pair<std::string, std::string> demo_schema_for(const std::string& id
7171
if (id == "player.update") return {player_fields_schema(true), player_out};
7272
if (id == "player.delete") return {id_required_in, "{\"type\":\"object\",\"properties\":{\"playerId\":" + std::string(SCHEMA_STR) + "}}"};
7373
if (id == "player.list") return {pagination_in, list_out};
74-
// 其余 collection_query 函数:与 Go demo 契约对齐(items/total 形状)。
75-
// 此前这些函数落到 action fallback({status,action}),六语言 demo
76-
// 共享同一契约槽位,C++ 注册会覆盖 Go 的正确 collection schema,
77-
// 导致页面发布校验 "/items,/total not found" 失败。
78-
if (id == "order.list") return {pagination_in, list_out};
79-
if (id == "leaderboard.list") return {pagination_in, list_out};
80-
if (id == "inventory.list") return {pagination_in, list_out};
81-
if (id == "mail.list") return {pagination_in, list_out};
74+
// 与 Go demo 契约逐一对齐。此前未列出的函数落到 action fallback
75+
//({status,action}),六语言 demo 共享同一契约槽位,fallback 注册
76+
// 会覆盖 Go 写入的正确 schema,导致页面发布校验
77+
// "/items,/total not found" 失败(DB 实证全量污染)。
78+
if (id == "order.list" || id == "leaderboard.list" ||
79+
id == "inventory.list" || id == "mail.list") return {pagination_in, list_out};
80+
if (id == "mail.batch_send") return {"{\"type\":\"object\",\"properties\":{\"mailIds\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}},\"title\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"},\"reward\":" + std::string(SCHEMA_OBJ) + "}}",
81+
"{\"type\":\"object\",\"properties\":{\"sent\":{\"type\":\"integer\"},\"failed\":{\"type\":\"integer\"}}}"};
82+
if (id == "leaderboard.reset") return {"{\"type\":\"object\",\"properties\":{}}",
83+
"{\"type\":\"object\",\"properties\":{\"reset\":{\"type\":\"boolean\"}}}"};
84+
if (id == "order.create") return {"{\"type\":\"object\",\"properties\":{\"id\":" + std::string(SCHEMA_STR) + ",\"playerId\":" + std::string(SCHEMA_STR) + ",\"productId\":" + std::string(SCHEMA_STR) + ",\"amount\":" + SCHEMA_INT + ",\"currency\":" + std::string(SCHEMA_STR) + ",\"status\":" + std::string(SCHEMA_STR) + ",\"channel\":" + std::string(SCHEMA_STR) + ",\"attributes\":" + std::string(SCHEMA_OBJ) + "}}",
85+
"{\"type\":\"object\",\"properties\":{\"order\":" + std::string(SCHEMA_OBJ) + "}}"};
86+
if (id == "order.get") return {"{\"type\":\"object\",\"properties\":{\"id\":" + std::string(SCHEMA_STR) + "},\"required\":[\"id\"]}",
87+
"{\"type\":\"object\",\"properties\":{\"order\":" + std::string(SCHEMA_OBJ) + "}}"};
88+
if (id == "order.update") return {"{\"type\":\"object\",\"properties\":{\"id\":" + std::string(SCHEMA_STR) + ",\"status\":" + std::string(SCHEMA_STR) + ",\"channel\":" + std::string(SCHEMA_STR) + ",\"amount\":" + SCHEMA_INT + "},\"required\":[\"id\"]}",
89+
"{\"type\":\"object\",\"properties\":{\"order\":" + std::string(SCHEMA_OBJ) + "}}"};
90+
if (id == "order.delete") return {"{\"type\":\"object\",\"properties\":{\"id\":" + std::string(SCHEMA_STR) + "},\"required\":[\"id\"]}",
91+
"{\"type\":\"object\",\"properties\":{\"deleted\":{\"type\":\"boolean\"}}}"};
92+
if (id == "leaderboard.upsert") return {"{\"type\":\"object\",\"properties\":{\"playerId\":" + std::string(SCHEMA_STR) + ",\"score\":" + SCHEMA_INT + "},\"required\":[\"playerId\"]}",
93+
"{\"type\":\"object\",\"properties\":{\"entry\":" + std::string(SCHEMA_OBJ) + "}}"};
94+
if (id == "inventory.grant" || id == "inventory.consume") return {"{\"type\":\"object\",\"properties\":{\"playerId\":" + std::string(SCHEMA_STR) + ",\"templateId\":" + std::string(SCHEMA_STR) + ",\"quantity\":" + SCHEMA_INT + "},\"required\":[\"playerId\",\"templateId\"]}",
95+
"{\"type\":\"object\",\"properties\":{\"item\":" + std::string(SCHEMA_OBJ) + "}}"};
96+
if (id == "mail.send" || id == "mail.claim") return {"{\"type\":\"object\",\"properties\":{\"playerId\":" + std::string(SCHEMA_STR) + ",\"mailId\":" + std::string(SCHEMA_STR) + "},\"required\":[\"playerId\"]}",
97+
"{\"type\":\"object\",\"properties\":{\"mail\":" + std::string(SCHEMA_OBJ) + "}}"};
8298
return {};
8399
}
84100

sdks/csharp/examples/GameDemo/Program.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,27 @@ static void EnrichDescriptor(FunctionDescriptor desc)
436436
"player.delete" => (BuildObj("{\"id\":" + SchemaStr + "}", new[] { "id" }), BuildObj("{\"playerId\":" + SchemaStr + "}")),
437437
"player.list" => (BuildObj("{\"page\":" + SchemaInt + ",\"pageSize\":" + SchemaInt + "}"),
438438
BuildObj("{\"items\":{\"type\":\"array\",\"items\":" + SchemaObj + "},\"total\":" + SchemaInt + "}")),
439-
// 其余 collection_query 函数与 Go demo 契约对齐(items/total):
440-
// 六语言共享同一契约槽位,action 形状 fallback 会覆盖正确
441-
// collection schema,导致页面发布校验失败。
439+
// 与 Go demo 契约逐一对齐(六语言共享同一契约槽位,fallback
440+
// 形状会覆盖其他 SDK 写入的正确 schema → 发布校验失败)。
442441
"order.list" or "leaderboard.list" or "mail.list"
443442
=> (BuildObj("{\"page\":" + SchemaInt + ",\"pageSize\":" + SchemaInt + "}"),
444443
BuildObj("{\"items\":{\"type\":\"array\",\"items\":" + SchemaObj + "},\"total\":" + SchemaInt + "}")),
445-
"inventory.list" => (BuildObj("{\"playerId\":" + SchemaStr + "}"),
444+
"inventory.list" => (BuildObj("{\"playerId\":" + SchemaStr + "}", new[] { "playerId" }),
446445
BuildObj("{\"items\":{\"type\":\"array\",\"items\":" + SchemaObj + "},\"total\":" + SchemaInt + "}")),
446+
"order.create" => (BuildObj("{\"id\":" + SchemaStr + ",\"playerId\":" + SchemaStr + ",\"productId\":" + SchemaStr + ",\"amount\":" + SchemaInt + ",\"currency\":" + SchemaStr + ",\"status\":" + SchemaStr + ",\"channel\":" + SchemaStr + ",\"attributes\":" + SchemaObj + "}"),
447+
BuildObj("{\"order\":" + SchemaObj + "}")),
448+
"order.get" or "order.update" => (BuildObj("{\"id\":" + SchemaStr + ",\"status\":" + SchemaStr + ",\"channel\":" + SchemaStr + ",\"amount\":" + SchemaInt + "}", new[] { "id" }),
449+
BuildObj("{\"order\":" + SchemaObj + "}")),
450+
"order.delete" => (BuildObj("{\"id\":" + SchemaStr + "}", new[] { "id" }),
451+
BuildObj("{\"deleted\":{\"type\":\"boolean\"}}")),
452+
"leaderboard.upsert" => (BuildObj("{\"playerId\":" + SchemaStr + ",\"score\":" + SchemaInt + "}", new[] { "playerId" }),
453+
BuildObj("{\"entry\":" + SchemaObj + "}")),
454+
"leaderboard.reset" => (BuildObj("{}"),
455+
BuildObj("{\"reset\":{\"type\":\"boolean\"}}")),
456+
"inventory.grant" or "inventory.consume" => (BuildObj("{\"playerId\":" + SchemaStr + ",\"templateId\":" + SchemaStr + ",\"quantity\":" + SchemaInt + "}", new[] { "playerId", "templateId" }),
457+
BuildObj("{\"item\":" + SchemaObj + "}")),
458+
"mail.send" or "mail.claim" => (BuildObj("{\"playerId\":" + SchemaStr + ",\"mailId\":" + SchemaStr + "}", new[] { "playerId" }),
459+
BuildObj("{\"mail\":" + SchemaObj + "}")),
447460
_ => (BuildObj("{}"), "{\"type\":\"object\",\"properties\":{\"status\":{\"type\":\"string\"},\"action\":{\"type\":\"string\"}}}"),
448461
};
449462

0 commit comments

Comments
 (0)