Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions proxy/system_nexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ func TestSystemPayloadRejectsMissingMessageType(t *testing.T) {
require.ErrorContains(t, err, "missing")
}

func TestLegacyMarkedPayloadRetainsExistingBehavior(t *testing.T) {
result := &common.Payload{
Data: []byte("legacy-result"),
Metadata: map[string][]byte{
SystemPayloadMetadataKey: []byte(systemPayloadMarkerValue),
"encoding": []byte("json/plain"),
},
}
attrs := &history.NexusOperationCompletedEventAttributes{Result: result}

var seen []string
err := VisitPayloads(context.Background(), attrs, VisitPayloadsOptions{
Visitor: func(_ *VisitPayloadsContext, payloads []*common.Payload) ([]*common.Payload, error) {
for _, payload := range payloads {
seen = append(seen, string(payload.Data))
}
return payloads, nil
},
})
require.NoError(t, err)
require.Equal(t, []string{"legacy-result"}, seen)
}

func TestUnmarkedPayloadRetainsExistingBehavior(t *testing.T) {
cmd := &command.Command{
Attributes: &command.Command_ScheduleNexusOperationCommandAttributes{
Expand Down
10 changes: 8 additions & 2 deletions proxy/system_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ func visitSystemPayload(
return false, nil
}

if encoding := string(payload.GetMetadata()["encoding"]); encoding != binaryProtobufEncoding {
encoding := string(payload.GetMetadata()["encoding"])
messageType := string(payload.GetMetadata()["messageType"])
// Older servers mark ordinary system Nexus result payloads without a message type.
// Keep visiting those as ordinary payloads rather than treating them as envelopes.
if messageType == "" && encoding != binaryProtobufEncoding {
return false, nil
}
if encoding != binaryProtobufEncoding {
return true, fmt.Errorf("system payload must be encoded as %s but got %q", binaryProtobufEncoding, encoding)
}

messageType := string(payload.GetMetadata()["messageType"])
if messageType == "" {
return true, fmt.Errorf("system payload is missing the messageType metadata")
}
Expand Down
Loading