Preserve HTTP provider parameter numbers
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Prepared 2026-11-25 for a Luna coding agent.
|
Prepared 2026-11-25 for a Luna coding agent.
|
||||||
Baseline: `e67633b9f48b42c5b0d14782c6e8e1d4c78fcdd5`.
|
Baseline: `e67633b9f48b42c5b0d14782c6e8e1d4c78fcdd5`.
|
||||||
Status: all stages not started.
|
Status: implementation in progress.
|
||||||
|
|
||||||
## Scope And Execution
|
## Scope And Execution
|
||||||
|
|
||||||
@@ -35,6 +35,10 @@ handoff, upstream execution/admission, and native CLI inspection/reporting.
|
|||||||
|
|
||||||
## Stage 1: Preserve HTTP Provider Numbers
|
## Stage 1: Preserve HTTP Provider Numbers
|
||||||
|
|
||||||
|
**Status: complete.** The provider-boundary test exposed rounding before the
|
||||||
|
decoder change and passes with lossless JSON numbers. The optional model-mapping
|
||||||
|
cleanup was left unchanged.
|
||||||
|
|
||||||
**Finding:** 2; optional adjacent cleanup from 17.
|
**Finding:** 2; optional adjacent cleanup from 17.
|
||||||
**Files:** `internal/adapter/http/handler.go` and `handler_test.go`.
|
**Files:** `internal/adapter/http/handler.go` and `handler_test.go`.
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
body = http.MaxBytesReader(w, r.Body, h.options.MaxRequestBytes)
|
body = http.MaxBytesReader(w, r.Body, h.options.MaxRequestBytes)
|
||||||
}
|
}
|
||||||
dec := json.NewDecoder(body)
|
dec := json.NewDecoder(body)
|
||||||
|
dec.UseNumber()
|
||||||
dec.DisallowUnknownFields()
|
dec.DisallowUnknownFields()
|
||||||
if err := dec.Decode(&req); err != nil {
|
if err := dec.Decode(&req); err != nil {
|
||||||
if isRequestTooLarge(err) {
|
if isRequestTooLarge(err) {
|
||||||
|
|||||||
@@ -1373,23 +1373,33 @@ func TestHandlerRejectsOverlongSessionIDAndNonStringReasoningEffort(t *testing.T
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
|
func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
|
||||||
r := &fakeRunner{result: &promptkit.RunResult{
|
observed := make(chan map[string]any, 1)
|
||||||
Artifact: promptkit.Artifact{Body: []byte("ok")},
|
provider := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Validation: promptkit.ValidationResult{Status: promptkit.ValidationPassed, Mode: promptkit.ValidationBasic, IsValid: true},
|
var body map[string]any
|
||||||
EffectiveModelParams: promptkit.ExecutionTarget{Endpoint: "http://llm/v1", Model: "m1"},
|
decoder := json.NewDecoder(r.Body)
|
||||||
}}
|
decoder.UseNumber()
|
||||||
h := NewHandler(r)
|
if err := decoder.Decode(&body); err != nil {
|
||||||
|
t.Errorf("decode provider request: %v", err)
|
||||||
|
http.Error(w, "invalid request", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
observed <- body
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}]}`))
|
||||||
|
}))
|
||||||
|
defer provider.Close()
|
||||||
|
h := newRetryHandler(t, provider.URL, intPointer(0), 1, intPointer(0))
|
||||||
|
|
||||||
reqBody := `{
|
reqBody := `{
|
||||||
"prompt_id": "prompt-1",
|
"prompt_id": "p",
|
||||||
"inputs": {"transcript": {"type": "file", "uri": "./t.md"}},
|
|
||||||
"model": {
|
"model": {
|
||||||
"extra_params": {
|
"extra_params": {
|
||||||
"string_value": "enabled",
|
"string_value": "enabled",
|
||||||
"number_value": 42,
|
"number_value": 9007199254740993,
|
||||||
"boolean_value": true,
|
"boolean_value": true,
|
||||||
"object_value": {"nested": "value", "count": 2},
|
"null_value": null,
|
||||||
"array_value": ["first", 3, false]
|
"object_value": {"nested": "value", "array": [9007199254740993, {"count": 9007199254740993}]},
|
||||||
|
"array_value": ["first", 3, false, null]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
@@ -1401,18 +1411,24 @@ func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
|
|||||||
if w.Code != http.StatusOK {
|
if w.Code != http.StatusOK {
|
||||||
t.Fatalf("expected 200, got %d body=%s", w.Code, w.Body.String())
|
t.Fatalf("expected 200, got %d body=%s", w.Code, w.Body.String())
|
||||||
}
|
}
|
||||||
if r.last.Execution == nil {
|
var got map[string]any
|
||||||
t.Fatal("expected execution override in run request")
|
select {
|
||||||
|
case got = <-observed:
|
||||||
|
default:
|
||||||
|
t.Fatal("provider did not receive a request")
|
||||||
}
|
}
|
||||||
want := map[string]any{
|
want := map[string]any{
|
||||||
"string_value": "enabled",
|
"string_value": "enabled",
|
||||||
"number_value": float64(42),
|
"number_value": json.Number("9007199254740993"),
|
||||||
"boolean_value": true,
|
"boolean_value": true,
|
||||||
"object_value": map[string]any{"nested": "value", "count": float64(2)},
|
"null_value": nil,
|
||||||
"array_value": []any{"first", float64(3), false},
|
"object_value": map[string]any{"nested": "value", "array": []any{json.Number("9007199254740993"), map[string]any{"count": json.Number("9007199254740993")}}},
|
||||||
|
"array_value": []any{"first", json.Number("3"), false, nil},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(r.last.Execution.ExtraParams, want) {
|
for key, value := range want {
|
||||||
t.Fatalf("unexpected mapped extra_params:\ngot=%#v\nwant=%#v", r.last.Execution.ExtraParams, want)
|
if actual, ok := got[key]; !ok || !reflect.DeepEqual(actual, value) {
|
||||||
|
t.Errorf("provider parameter %s = %#v (present %t), want %#v", key, actual, ok, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user