feat: 实现采购运行时规格解析 (#255)

This commit is contained in:
chengma
2026-08-17 17:20:07 +08:00
parent a699ec8132
commit de36cfd0b5
10 changed files with 1347 additions and 42 deletions
+24
View File
@@ -1,9 +1,16 @@
package api
import (
"bytes"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
"cmautobuy/admin/model"
"cmautobuy/admin/service"
)
func TestTaskPayload_包含不可变执行模式(t *testing.T) {
@@ -12,3 +19,20 @@ func TestTaskPayload_包含不可变执行模式(t *testing.T) {
t.Fatalf("execution_mode=%v", payload["execution_mode"])
}
}
func TestResolvePurchaseSpec_请求体上限在进入数据库前拒绝(t *testing.T) {
gin.SetMode(gin.TestMode)
router := gin.New()
Register(router, nil, nil, service.AIEndpointPolicy{})
body := bytes.Repeat([]byte("x"), service.MaxPurchaseSpecResolutionBodyBytes+1)
request := httptest.NewRequest(http.MethodPost,
"/api/v1/client/tasks/cg255/spec-resolution", bytes.NewReader(body))
request.Header.Set("X-Client-Id", "CLIENT-255")
request.Header.Set("Idempotency-Key", "spec-resolution-v1:"+strings.Repeat("0", 64))
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, request)
if recorder.Code != http.StatusBadRequest || !strings.Contains(recorder.Body.String(), `"code":"INVALID_BODY"`) {
t.Fatalf("status=%d body=%s", recorder.Code, recorder.Body.String())
}
}