@@ -11,25 +11,6 @@ import (
1111 "github.com/stretchr/testify/require"
1212)
1313
14- // decodeAnyToType converts an any value (which is map[string]interface{} after JSON decode)
15- // back to the expected type T by re-encoding to JSON and decoding into T.
16- func decodeAnyToType [T any ](value any ) (T , error ) {
17- var result T
18- if value == nil {
19- return result , nil
20- }
21- // Re-encode the any value to JSON
22- jsonBytes , err := json .Marshal (value )
23- if err != nil {
24- return result , fmt .Errorf ("failed to marshal any value: %w" , err )
25- }
26- // Decode JSON into the expected type T
27- if err := json .Unmarshal (jsonBytes , & result ); err != nil {
28- return result , fmt .Errorf ("failed to unmarshal into type T: %w" , err )
29- }
30- return result , nil
31- }
32-
3314// testAllSerializationPaths tests workflow recovery and verifies all read paths.
3415// This is the unified test function that exercises:
3516// 1. Workflow recovery: starts a workflow, blocks it, recovers it, then verifies completion
@@ -116,13 +97,17 @@ func testAllSerializationPaths[T any](
11697 if len (steps ) > 0 {
11798 lastStep := steps [len (steps )- 1 ]
11899 if isNilExpected {
119- assert .Nil (t , lastStep .Output , "Step output should be nil" )
100+ // Should be an empty string
101+ assert .Equal (t , "" , lastStep .Output , "Step output should be an empty string" )
120102 } else {
121103 require .NotNil (t , lastStep .Output )
122- // GetWorkflowSteps returns any (map[string]interface{} after JSON decode)
123- // We need to re-encode to JSON and decode into type T
124- decodedOutput , err := decodeAnyToType [T ](lastStep .Output )
125- require .NoError (t , err , "Failed to decode step output to type T" )
104+ // GetWorkflowSteps returns a string (base64-decoded JSON)
105+ // Unmarshal the JSON string into type T
106+ strValue , ok := lastStep .Output .(string )
107+ require .True (t , ok , "Step output should be a string" )
108+ var decodedOutput T
109+ err := json .Unmarshal ([]byte (strValue ), & decodedOutput )
110+ require .NoError (t , err , "Failed to unmarshal step output to type T" )
126111 assert .Equal (t , expectedOutput , decodedOutput , "Step output should match expected output" )
127112 }
128113 assert .Nil (t , lastStep .Error )
@@ -138,18 +123,28 @@ func testAllSerializationPaths[T any](
138123 require .Len (t , wfs , 1 )
139124 wf := wfs [0 ]
140125 if isNilExpected {
141- assert .Nil (t , wf .Input , "Workflow input should be nil" )
142- assert .Nil (t , wf .Output , "Workflow output should be nil" )
126+ // Should be an empty string
127+ assert .Equal (t , "" , wf .Input , "Workflow input should be an empty string" )
128+ assert .Equal (t , "" , wf .Output , "Workflow output should be an empty string" )
143129 } else {
144130 require .NotNil (t , wf .Input )
145131 require .NotNil (t , wf .Output )
146132
147- // ListWorkflows returns any (map[string]interface{} after JSON decode)
148- // We need to re-encode to JSON and decode into type T
149- decodedInput , err := decodeAnyToType [T ](wf .Input )
150- require .NoError (t , err , "Failed to decode workflow input to type T" )
151- decodedOutput , err := decodeAnyToType [T ](wf .Output )
152- require .NoError (t , err , "Failed to decode workflow output to type T" )
133+ // ListWorkflows returns strings (base64-decoded JSON)
134+ // Unmarshal the JSON strings into type T
135+ inputStr , ok := wf .Input .(string )
136+ require .True (t , ok , "Workflow input should be a string" )
137+ outputStr , ok := wf .Output .(string )
138+ require .True (t , ok , "Workflow output should be a string" )
139+
140+ var decodedInput T
141+ err := json .Unmarshal ([]byte (inputStr ), & decodedInput )
142+ require .NoError (t , err , "Failed to unmarshal workflow input to type T" )
143+
144+ var decodedOutput T
145+ err = json .Unmarshal ([]byte (outputStr ), & decodedOutput )
146+ require .NoError (t , err , "Failed to unmarshal workflow output to type T" )
147+
153148 assert .Equal (t , input , decodedInput , "Workflow input should match input" )
154149 assert .Equal (t , expectedOutput , decodedOutput , "Workflow output should match expected output" )
155150 }
0 commit comments