Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243package protocol
import ( "encoding/json" "testing")
// These serialized writes exercise presence semantics that ordinary response// pointer types cannot represent, including nested merge patches.func TestPatchPresenceSurvivesSerialization(t *testing.T) { cases := []struct { name string patch any want string }{ {"omitted", SessionPatch{}, `{}`}, {"clear", SessionPatch{Name: ClearPatch[string](), ContextWindow: ClearPatch[int64]()}, `{"context_window":null,"name":null}`}, {"false and empty", SessionPatch{Fast: SetPatch(false), Name: SetNullablePatch("")}, `{"fast":false,"name":""}`}, {"zero", ProviderProfilePatch{ImageEdge: SetNullablePatch(int64(0))}, `{"image_edge":0}`}, {"empty collection", ProviderProfilePatch{AccountIDs: SetNullablePatch([]ID{})}, `{"account_ids":[]}`}, {"nested choices", SessionPatch{Selection: SetPatch(SelectionPatch{Extensions: SetNullablePatch(map[string]*bool{"off": new(false), "remove": nil})})}, `{"selection":{"extensions":{"off":false,"remove":null}}}`}, {"clear selection", SessionPatch{Selection: SetPatch(SelectionPatch{Extensions: ClearPatch[map[string]*bool]()})}, `{"selection":{"extensions":null}}`}, } for _, test := range cases { t.Run(test.name, func(t *testing.T) { data, err := json.Marshal(test.patch) if err != nil { t.Fatal(err) } if string(data) != test.want { t.Fatalf("got %s, want %s", data, test.want) } }) }}
func TestNonnullablePatchRejectsNilCollection(t *testing.T) { _, err := json.Marshal(MCPDefinitionPatch{Arguments: SetPatch[[]string](nil)}) if err == nil { t.Fatal("nonnullable arguments must not serialize as null") }}