@@ -3,8 +3,10 @@ package temporal
33import (
44 "testing"
55
6+ "github.com/Websoft9/waterflow/pkg/dsl"
67 "github.com/Websoft9/waterflow/pkg/dsl/node"
78 "github.com/stretchr/testify/assert"
9+ "go.uber.org/zap"
810 "go.uber.org/zap/zaptest"
911)
1012
@@ -16,10 +18,134 @@ func TestNewActivities(t *testing.T) {
1618 assert .NotNil (t , activities )
1719 assert .NotNil (t , activities .logger )
1820 assert .NotNil (t , activities .nodeRegistry )
21+ assert .NotNil (t , activities .nodeTracker )
22+ }
23+
24+ func TestActivities_Structure (t * testing.T ) {
25+ logger := zap .NewNop ()
26+ registry := node .NewRegistry ()
27+
28+ t .Run ("activities_has_required_fields" , func (t * testing.T ) {
29+ activities := NewActivities (logger , registry )
30+
31+ // Verify all fields are initialized
32+ assert .NotNil (t , activities .logger , "logger should be initialized" )
33+ assert .NotNil (t , activities .nodeRegistry , "nodeRegistry should be initialized" )
34+ assert .NotNil (t , activities .nodeTracker , "nodeTracker should be initialized" )
35+ })
36+ }
37+
38+ func TestExecuteStepInput_Structure (t * testing.T ) {
39+ t .Run ("input_serialization" , func (t * testing.T ) {
40+ // Test that ExecuteStepInput only contains serializable types
41+ input := ExecuteStepInput {
42+ WorkflowName : "test-workflow" ,
43+ JobName : "test-job" ,
44+ StepName : "test-step" ,
45+ StepUses : "exec/shell@v1" ,
46+ StepWith : map [string ]interface {}{
47+ "command" : "echo hello" ,
48+ },
49+ StepEnv : map [string ]string {
50+ "FOO" : "bar" ,
51+ },
52+ StepIf : "success()" ,
53+ Context : & dsl.SerializableEvalContext {
54+ Workflow : map [string ]interface {}{"name" : "test" },
55+ Job : map [string ]interface {}{"name" : "job1" },
56+ Steps : map [string ]interface {}{},
57+ Vars : map [string ]interface {}{"key" : "value" },
58+ Env : map [string ]string {"ENV" : "test" },
59+ Matrix : map [string ]interface {}{},
60+ Runner : map [string ]interface {}{},
61+ Inputs : map [string ]interface {}{},
62+ Secrets : map [string ]string {},
63+ Needs : map [string ]interface {}{},
64+ },
65+ }
66+
67+ // Verify all fields are set
68+ assert .Equal (t , "test-workflow" , input .WorkflowName )
69+ assert .Equal (t , "test-job" , input .JobName )
70+ assert .Equal (t , "test-step" , input .StepName )
71+ assert .Equal (t , "exec/shell@v1" , input .StepUses )
72+ assert .NotNil (t , input .StepWith )
73+ assert .NotNil (t , input .StepEnv )
74+ assert .Equal (t , "success()" , input .StepIf )
75+ assert .NotNil (t , input .Context )
76+ })
77+ }
78+
79+ func TestStepResult_Structure (t * testing.T ) {
80+ t .Run ("result_status_types" , func (t * testing.T ) {
81+ // Test different status types
82+ statuses := []string {"success" , "failure" , "skipped" , "timeout" }
83+
84+ for _ , status := range statuses {
85+ result := & StepResult {
86+ Status : status ,
87+ Outputs : map [string ]string {"output1" : "value1" },
88+ Error : "" ,
89+ DurationMs : 1234 ,
90+ }
91+
92+ assert .Equal (t , status , result .Status )
93+ assert .NotNil (t , result .Outputs )
94+ assert .GreaterOrEqual (t , result .DurationMs , int64 (0 ))
95+ }
96+ })
97+
98+ t .Run ("result_with_error" , func (t * testing.T ) {
99+ result := & StepResult {
100+ Status : "failure" ,
101+ Outputs : map [string ]string {},
102+ Error : "execution failed" ,
103+ DurationMs : 5678 ,
104+ }
105+
106+ assert .Equal (t , "failure" , result .Status )
107+ assert .NotEmpty (t , result .Error )
108+ assert .Equal (t , "execution failed" , result .Error )
109+ })
110+ }
111+
112+ func TestSerializableEvalContext_Reconstruction (t * testing.T ) {
113+ t .Run ("context_round_trip" , func (t * testing.T ) {
114+ // Create serializable context
115+ serializable := & dsl.SerializableEvalContext {
116+ Workflow : map [string ]interface {}{"name" : "test-wf" },
117+ Job : map [string ]interface {}{"name" : "test-job" , "status" : "success" },
118+ Steps : map [string ]interface {}{},
119+ Vars : map [string ]interface {}{"var1" : "value1" },
120+ Env : map [string ]string {"ENV1" : "envvalue1" },
121+ Matrix : map [string ]interface {}{"os" : "linux" },
122+ Runner : map [string ]interface {}{"name" : "runner1" },
123+ Inputs : map [string ]interface {}{"input1" : "inputvalue1" },
124+ Secrets : map [string ]string {"SECRET1" : "secretvalue1" },
125+ Needs : map [string ]interface {}{"job1" : map [string ]interface {}{"result" : "success" }},
126+ }
127+
128+ // Convert to EvalContext
129+ evalCtx := serializable .ToEvalContext ()
130+
131+ // Verify all data fields are preserved
132+ assert .Equal (t , "test-wf" , evalCtx .Workflow ["name" ])
133+ assert .Equal (t , "test-job" , evalCtx .Job ["name" ])
134+ assert .Equal (t , "value1" , evalCtx .Vars ["var1" ])
135+ assert .Equal (t , "envvalue1" , evalCtx .Env ["ENV1" ])
136+ assert .Equal (t , "linux" , evalCtx .Matrix ["os" ])
137+
138+ // Verify functions are reconstructed
139+ assert .NotNil (t , evalCtx .Len )
140+ assert .NotNil (t , evalCtx .Upper )
141+ assert .NotNil (t , evalCtx .Lower )
142+ assert .NotNil (t , evalCtx .Success )
143+ assert .NotNil (t , evalCtx .Failure )
144+ })
19145}
20146
21147// Note: ExecuteStepActivity error handling tests (NonRetryableError) are covered
22- // in workflow_test.go TestToTemporalRetryPolicy_NonRetryableErrorTypes which验证
148+ // in workflow_test.go TestToTemporalRetryPolicy_NonRetryableErrorTypes which validates
23149// the NonRetryableErrorTypes list configuration.
24150//
25151// Full integration tests with actual node execution require a real Temporal server
0 commit comments