mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
113 lines
3.1 KiB
Go
113 lines
3.1 KiB
Go
// Helper methods for the nexusoperations_test package.
|
|
package nexusoperations_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
historypb "go.temporal.io/api/history/v1"
|
|
"go.temporal.io/sdk/converter"
|
|
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
|
|
"github.com/hanzoai/tasks/common"
|
|
"github.com/hanzoai/tasks/components/nexusoperations"
|
|
"github.com/hanzoai/tasks/service/history/hsm"
|
|
"github.com/hanzoai/tasks/service/history/hsm/hsmtest"
|
|
"github.com/hanzoai/tasks/service/history/workflow"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
type fakeEnv struct {
|
|
node *hsm.Node
|
|
}
|
|
|
|
func (s fakeEnv) Access(ctx context.Context, ref hsm.Ref, accessType hsm.AccessType, accessor func(*hsm.Node) error) error {
|
|
return accessor(s.node)
|
|
}
|
|
|
|
func (fakeEnv) Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
var _ hsm.Environment = fakeEnv{}
|
|
|
|
func newRegistry(t *testing.T) *hsm.Registry {
|
|
t.Helper()
|
|
reg := hsm.NewRegistry()
|
|
require.NoError(t, workflow.RegisterStateMachine(reg))
|
|
require.NoError(t, nexusoperations.RegisterStateMachines(reg))
|
|
require.NoError(t, nexusoperations.RegisterEventDefinitions(reg))
|
|
return reg
|
|
}
|
|
|
|
func newRoot(t *testing.T, backend *hsmtest.NodeBackend) *hsm.Node {
|
|
reg := hsm.NewRegistry()
|
|
require.NoError(t, workflow.RegisterStateMachine(reg))
|
|
require.NoError(t, nexusoperations.RegisterStateMachines(reg))
|
|
root, err := hsm.NewRoot(reg, workflow.StateMachineType, root{}, make(map[string]*persistencespb.StateMachineMap), backend)
|
|
require.NoError(t, err)
|
|
return root
|
|
}
|
|
|
|
func newOperationNode(t *testing.T, backend *hsmtest.NodeBackend, event *historypb.HistoryEvent) *hsm.Node {
|
|
root := newRoot(t, backend)
|
|
token, err := hsm.GenerateEventLoadToken(event)
|
|
require.NoError(t, err)
|
|
node, err := nexusoperations.AddChild(root, fmt.Sprintf("%d", event.EventId), event, token)
|
|
require.NoError(t, err)
|
|
return node
|
|
}
|
|
|
|
type root struct{}
|
|
|
|
func (root) IsWorkflowExecutionRunning() bool {
|
|
return true
|
|
}
|
|
|
|
func (root) IsTransitionHistoryEnabled() bool {
|
|
return false
|
|
}
|
|
|
|
func mustNewScheduledEvent(schedTime time.Time, defaults *historypb.NexusOperationScheduledEventAttributes) *historypb.HistoryEvent {
|
|
if defaults == nil {
|
|
defaults = &historypb.NexusOperationScheduledEventAttributes{}
|
|
}
|
|
attrs := common.CloneProto(defaults)
|
|
if attrs.EndpointId == "" {
|
|
attrs.EndpointId = "endpoint-id"
|
|
}
|
|
if attrs.Endpoint == "" {
|
|
attrs.Endpoint = "endpoint"
|
|
}
|
|
if attrs.Service == "" {
|
|
attrs.Service = "service"
|
|
}
|
|
if attrs.Operation == "" {
|
|
attrs.Operation = "operation"
|
|
}
|
|
if attrs.Input == nil {
|
|
conv := converter.GetDefaultDataConverter()
|
|
payload, err := conv.ToPayload("input")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
attrs.Input = payload
|
|
}
|
|
if attrs.RequestId == "" {
|
|
attrs.RequestId = uuid.NewString()
|
|
}
|
|
|
|
return &historypb.HistoryEvent{
|
|
EventType: enumspb.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
|
|
EventId: 1,
|
|
EventTime: timestamppb.New(schedTime),
|
|
Attributes: &historypb.HistoryEvent_NexusOperationScheduledEventAttributes{
|
|
NexusOperationScheduledEventAttributes: attrs,
|
|
},
|
|
}
|
|
}
|