Preserve HTTP provider parameter numbers

This commit is contained in:
2026-11-25 17:25:38 +00:00
parent 6beddde313
commit fb6c1d3435
3 changed files with 40 additions and 19 deletions

View File

@@ -2,7 +2,7 @@
Prepared 2026-11-25 for a Luna coding agent.
Baseline: `e67633b9f48b42c5b0d14782c6e8e1d4c78fcdd5`.
Status: all stages not started.
Status: implementation in progress.
## Scope And Execution
@@ -35,6 +35,10 @@ handoff, upstream execution/admission, and native CLI inspection/reporting.
## 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.
**Files:** `internal/adapter/http/handler.go` and `handler_test.go`.

View File

@@ -56,6 +56,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body = http.MaxBytesReader(w, r.Body, h.options.MaxRequestBytes)
}
dec := json.NewDecoder(body)
dec.UseNumber()
dec.DisallowUnknownFields()
if err := dec.Decode(&req); err != nil {
if isRequestTooLarge(err) {

View File

@@ -1373,23 +1373,33 @@ func TestHandlerRejectsOverlongSessionIDAndNonStringReasoningEffort(t *testing.T
}
func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
r := &fakeRunner{result: &promptkit.RunResult{
Artifact: promptkit.Artifact{Body: []byte("ok")},
Validation: promptkit.ValidationResult{Status: promptkit.ValidationPassed, Mode: promptkit.ValidationBasic, IsValid: true},
EffectiveModelParams: promptkit.ExecutionTarget{Endpoint: "http://llm/v1", Model: "m1"},
}}
h := NewHandler(r)
observed := make(chan map[string]any, 1)
provider := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body map[string]any
decoder := json.NewDecoder(r.Body)
decoder.UseNumber()
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 := `{
"prompt_id": "prompt-1",
"inputs": {"transcript": {"type": "file", "uri": "./t.md"}},
"prompt_id": "p",
"model": {
"extra_params": {
"string_value": "enabled",
"number_value": 42,
"number_value": 9007199254740993,
"boolean_value": true,
"object_value": {"nested": "value", "count": 2},
"array_value": ["first", 3, false]
"null_value": null,
"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 {
t.Fatalf("expected 200, got %d body=%s", w.Code, w.Body.String())
}
if r.last.Execution == nil {
t.Fatal("expected execution override in run request")
var got map[string]any
select {
case got = <-observed:
default:
t.Fatal("provider did not receive a request")
}
want := map[string]any{
"string_value": "enabled",
"number_value": float64(42),
"number_value": json.Number("9007199254740993"),
"boolean_value": true,
"object_value": map[string]any{"nested": "value", "count": float64(2)},
"array_value": []any{"first", float64(3), false},
"null_value": nil,
"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) {
t.Fatalf("unexpected mapped extra_params:\ngot=%#v\nwant=%#v", r.last.Execution.ExtraParams, want)
for key, value := range 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)
}
}
}