Files
tasks/common/testing/updateutils/update.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

140 lines
4.3 KiB
Go

package updateutils
import (
"github.com/stretchr/testify/require"
commandpb "go.temporal.io/api/command/v1"
enumspb "go.temporal.io/api/enums/v1"
failurepb "go.temporal.io/api/failure/v1"
protocolpb "go.temporal.io/api/protocol/v1"
updatepb "go.temporal.io/api/update/v1"
"github.com/hanzoai/tasks/common/payloads"
"github.com/hanzoai/tasks/common/testing/protoutils"
"github.com/hanzoai/tasks/common/testing/testvars"
)
type (
UpdateUtils struct {
t require.TestingT
}
helper interface {
Helper()
}
)
func New(t require.TestingT) UpdateUtils {
return UpdateUtils{
t: t,
}
}
func (u UpdateUtils) UpdateAcceptCommands(tv *testvars.TestVars) []*commandpb.Command {
if th, ok := u.t.(helper); ok {
th.Helper()
}
return []*commandpb.Command{{
CommandType: enumspb.COMMAND_TYPE_PROTOCOL_MESSAGE,
Attributes: &commandpb.Command_ProtocolMessageCommandAttributes{ProtocolMessageCommandAttributes: &commandpb.ProtocolMessageCommandAttributes{
MessageId: tv.MessageID() + "_update-accepted",
}},
}}
}
func (u UpdateUtils) UpdateCompleteCommands(tv *testvars.TestVars) []*commandpb.Command {
if th, ok := u.t.(helper); ok {
th.Helper()
}
return []*commandpb.Command{
{
CommandType: enumspb.COMMAND_TYPE_PROTOCOL_MESSAGE,
Attributes: &commandpb.Command_ProtocolMessageCommandAttributes{ProtocolMessageCommandAttributes: &commandpb.ProtocolMessageCommandAttributes{
MessageId: tv.MessageID() + "_update-completed",
}},
},
}
}
func (u UpdateUtils) UpdateAcceptCompleteCommands(tv *testvars.TestVars) []*commandpb.Command {
if th, ok := u.t.(helper); ok {
th.Helper()
}
return append(u.UpdateAcceptCommands(tv), u.UpdateCompleteCommands(tv)...)
}
func (u UpdateUtils) UpdateAcceptMessages(tv *testvars.TestVars, updRequestMsg *protocolpb.Message) []*protocolpb.Message {
if th, ok := u.t.(helper); ok {
th.Helper()
}
updRequest := protoutils.UnmarshalAny[*updatepb.Request](u.t, updRequestMsg.GetBody())
return []*protocolpb.Message{
{
Id: tv.MessageID() + "_update-accepted",
ProtocolInstanceId: updRequest.GetMeta().GetUpdateId(),
SequencingId: nil,
Body: protoutils.MarshalAny(u.t, &updatepb.Acceptance{
AcceptedRequestMessageId: updRequestMsg.GetId(),
AcceptedRequestSequencingEventId: updRequestMsg.GetEventId(),
AcceptedRequest: updRequest,
}),
},
}
}
func (u UpdateUtils) UpdateCompleteMessages(tv *testvars.TestVars, updRequestMsg *protocolpb.Message) []*protocolpb.Message {
if th, ok := u.t.(helper); ok {
th.Helper()
}
updRequest := protoutils.UnmarshalAny[*updatepb.Request](u.t, updRequestMsg.GetBody())
return []*protocolpb.Message{
{
Id: tv.MessageID() + "_update-completed",
ProtocolInstanceId: updRequest.GetMeta().GetUpdateId(),
SequencingId: nil,
Body: protoutils.MarshalAny(u.t, &updatepb.Response{
Meta: updRequest.GetMeta(),
Outcome: &updatepb.Outcome{
Value: &updatepb.Outcome_Success{
Success: payloads.EncodeString("success-result-of-" + updRequest.GetMeta().GetUpdateId()),
},
},
}),
},
}
}
func (u UpdateUtils) UpdateAcceptCompleteMessages(tv *testvars.TestVars, updRequestMsg *protocolpb.Message) []*protocolpb.Message {
if th, ok := u.t.(helper); ok {
th.Helper()
}
return append(
u.UpdateAcceptMessages(tv, updRequestMsg),
u.UpdateCompleteMessages(tv, updRequestMsg)...)
}
func (u UpdateUtils) UpdateRejectMessages(tv *testvars.TestVars, updRequestMsg *protocolpb.Message) []*protocolpb.Message {
if th, ok := u.t.(helper); ok {
th.Helper()
}
updRequest := protoutils.UnmarshalAny[*updatepb.Request](u.t, updRequestMsg.GetBody())
return []*protocolpb.Message{
{
Id: tv.MessageID() + "_update-rejected",
ProtocolInstanceId: updRequest.GetMeta().GetUpdateId(),
SequencingId: nil,
Body: protoutils.MarshalAny(u.t, &updatepb.Rejection{
RejectedRequestMessageId: updRequestMsg.GetId(),
RejectedRequestSequencingEventId: updRequestMsg.GetEventId(),
RejectedRequest: updRequest,
Failure: &failurepb.Failure{
Message: "rejection-of-" + updRequest.GetMeta().GetUpdateId(),
FailureInfo: &failurepb.Failure_ApplicationFailureInfo{ApplicationFailureInfo: &failurepb.ApplicationFailureInfo{}},
},
}),
},
}
}