package wire_test import ( "encoding/json" "errors" "testing" "amadan.net/oficina/equipo/internal/wire" ) // Warm (protocol 24) is the instance asking the person's primary to warm // their Assistant now that they opened Base. It is a command like any // other (durable, acked), and Encode refuses it below 24: an older // runner's strict decoder would close the stream on it. func TestEncodeWarmBelow24(t *testing.T) { if wire.ProtocolWarm != 24 || wire.ProtocolCurrent != wire.ProtocolDesign || wire.Spoken(99) != 38 { t.Fatalf("protocols %d %d", wire.ProtocolWarm, wire.ProtocolCurrent) } f, err := wire.NewFrame("c1", wire.FrameWarm, wire.WarmCommand{Person: "ana@example.com"}) if err != nil { t.Fatal(err) } if !f.Durable() { t.Fatal("a warm command is not durable") } body, err := f.Decode() if w, ok := body.(*wire.WarmCommand); err != nil || !ok || w.Person != "ana@example.com" { t.Fatalf("decode %+v %v", body, err) } if _, err := (wire.Frame{ID: "c2", Type: wire.FrameWarm, Data: json.RawMessage(`{"person":"a","more":1}`)}).Decode(); err == nil { t.Fatal("an unknown warm field decoded") } for _, p := range []int{wire.Protocol1, wire.Protocol2, wire.ProtocolAssistant, wire.ProtocolJobs, wire.ProtocolGlance} { if _, err := wire.Encode(f, p); !errors.Is(err, wire.ErrProtocol) { t.Fatalf("a warm encoded at protocol %d: %v", p, err) } } if got, err := wire.Encode(f, wire.ProtocolWarm); err != nil || string(got.Data) != string(f.Data) { t.Fatalf("at 24 %s %v", got.Data, err) } }