aaron-y-chen commented on code in PR #75700:
URL: https://github.com/apache/airflow/pull/75700#discussion_r4531667291


##########
go-sdk/pkg/execution/messages_test.go:
##########
@@ -542,6 +544,93 @@ func TestAPIErrorFromFrame(t *testing.T) {
        })
 }
 
+// marshalCompactBody encodes body with each integer in the fewest bytes, as 
the
+// supervisor's msgpack packer does.
+func marshalCompactBody(t *testing.T, body any) msgpack.RawMessage {
+       t.Helper()
+       var buf bytes.Buffer
+       enc := msgpack.NewEncoder(&buf)
+       enc.UseCompactInts(true)
+       require.NoError(t, enc.Encode(body))
+       return buf.Bytes()
+}
+
+func TestDecodeBodyNormalizesNumbers(t *testing.T) {
+       cases := []struct {
+               name  string
+               value any
+               want  any
+       }{
+               {name: "positive fixint", value: 7, want: int64(7)},
+               {name: "uint8", value: 200, want: int64(200)},
+               {name: "uint16", value: 500, want: int64(500)},
+               {name: "uint32", value: 70000, want: int64(70000)},
+               {name: "uint64 up to max int64", value: uint64(math.MaxInt64), 
want: int64(math.MaxInt64)},
+               {
+                       name:  "uint64 above max int64",
+                       value: uint64(math.MaxInt64) + 1,
+                       want:  uint64(math.MaxInt64) + 1,
+               },
+               {name: "negative fixint", value: -1, want: int64(-1)},
+               {name: "int8", value: -100, want: int64(-100)},
+               {name: "int16", value: -129, want: int64(-129)},
+               {name: "int32", value: -32769, want: int64(-32769)},
+               {name: "float32", value: float32(1.25), want: float64(1.25)},
+               {
+                       name: "nested in maps and arrays",
+                       value: map[string]any{
+                               "rows":    7,
+                               "batches": []any{200, "eu", nil, 
map[string]any{"ratio": float32(0.5)}},
+                       },
+                       want: map[string]any{
+                               "rows":    int64(7),
+                               "batches": []any{int64(200), "eu", nil, 
map[string]any{"ratio": float64(0.5)}},
+                       },
+               },
+       }
+       for _, tc := range cases {
+               t.Run(tc.name, func(t *testing.T) {
+                       raw := marshalCompactBody(t, map[string]any{
+                               "type":  "XComResult",
+                               "key":   "return_value",
+                               "value": tc.value,
+                       })
+                       var result genmodels.XComResult
+                       require.NoError(t, decodeBody(raw, &result))
+                       assert.Equal(t, tc.want, result.Value)
+               })
+       }
+}
+
+func TestDecodeStartupDetailsNormalizesConfNumbers(t *testing.T) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to