feat(billing): 完成异步结算与请求执行闭环
统一任务成功、Attempt 与结算 Outbox 的事务边界,增加多实例安全结算、人工复核、请求幂等与执行租约。钱包决策使用九位精确金额,并通过审计保护约束保留流水事实;同时补充管理接口、指标与 PostgreSQL 集成测试。
This commit is contained in:
@@ -34,6 +34,11 @@ var gatewayOpenAIRequestExtensions = stringSet(
|
||||
"requestId", "request_id", "signal", "userMessage", "user_message", "platformId",
|
||||
"platform_id", "options", "enable_thinking", "thinking_budget_tokens", "enable_web_search",
|
||||
"modelType", "model_type", "capability", "capabilityType", "mode", "simulation", "testMode",
|
||||
"cacheAffinityKey", "cache_affinity_key", "simulationDurationMs", "simulationDurationSeconds",
|
||||
"simulationMinDurationMs", "simulationMaxDurationMs", "simulationMinDurationSeconds",
|
||||
"simulationMaxDurationSeconds", "simulationDurationMinMs", "simulationDurationMaxMs",
|
||||
"simulationDurationMinSeconds", "simulationDurationMaxSeconds", "simulationFailure",
|
||||
"simulationProfile", "simulationUsage",
|
||||
)
|
||||
|
||||
var gatewayResponsesRequestExtensions = stringSet("messages", "presence_penalty", "frequency_penalty")
|
||||
|
||||
@@ -60,6 +60,23 @@ func TestValidateOpenAIRequestParametersRejectsUnknownTopLevelField(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOpenAIRequestParametersAcceptsInternalSimulationAndAffinityFields(t *testing.T) {
|
||||
body := map[string]any{
|
||||
"model": "demo", "messages": []any{}, "simulation": true,
|
||||
"simulationDurationMs": 5, "simulationUsage": map[string]any{"inputTokens": 10},
|
||||
"cacheAffinityKey": "conversation-1",
|
||||
}
|
||||
if err := ValidateOpenAIRequestParameters("chat.completions", body); err != nil {
|
||||
t.Fatalf("expected documented gateway extensions to remain accepted, got %v", err)
|
||||
}
|
||||
filtered := FilterOpenAIChatRequestBody(body)
|
||||
for _, key := range []string{"simulation", "simulationDurationMs", "simulationUsage", "cacheAffinityKey"} {
|
||||
if _, ok := filtered[key]; ok {
|
||||
t.Fatalf("gateway-only field %q leaked upstream", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponsesFallbackMapsEquivalentCurrentParameters(t *testing.T) {
|
||||
body, err := ResponsesRequestToChat(map[string]any{
|
||||
"input": "hello", "store": false, "metadata": map[string]any{"trace": "1"},
|
||||
|
||||
@@ -36,6 +36,7 @@ type ResponseTurn struct {
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
AttemptID string
|
||||
Result map[string]any
|
||||
RequestID string
|
||||
Usage Usage
|
||||
|
||||
Reference in New Issue
Block a user