package handler import ( "bytes" "net/http" "net/http/httptest" "testing" ) // TestWriteMeasuredJSONByteIdenticalToWriteJSON locks the load-bearing assumption // behind the F2 claim-observability patch: swapping writeJSON for writeMeasuredJSON // at the /tasks/claim response sites must not change a single byte on the wire. // // writeJSON encodes via json.NewEncoder(w).Encode (which appends a trailing // newline); writeMeasuredJSON marshals via json.Marshal and appends the newline // by hand. Both HTML-escape by default, so the emitted bytes must match for every // input. This table-driven test fails closed if that invariant ever drifts, so the // "no wire-behavior change" claim is provable rather than reasoned. func TestWriteMeasuredJSONByteIdenticalToWriteJSON(t *testing.T) { type skill struct { Name string `json:"name"` Description string `json:"description"` Files map[string]string `json:"files"` } type claimResp struct { ID string `json:"id"` Name string `json:"name"` Skills []skill `json:"skills"` Args []string `json:"args"` } cases := []struct { name string v any }{ {"nil", nil}, {"no_task", map[string]any{"task": nil}}, {"empty_map", map[string]any{}}, {"empty_slice", []string{}}, {"scalar_string", "plain string"}, {"scalar_bool", true}, {"numbers", map[string]any{"i": 42, "f": 3.5, "neg": -17, "big": 1234567890123}}, {"html_escapable", map[string]any{"s": `a & "c" 'd'