1818from temporalio .client import Client
1919from temporalio .nexus import WorkflowRunOperationContext , workflow_run_operation
2020from temporalio .nexus ._operation_handlers import WorkflowRunOperationHandler
21+ from temporalio .nexus ._token import OperationToken , OperationTokenType
2122from temporalio .testing import WorkflowEnvironment
2223from temporalio .worker import Worker
2324from tests .helpers .nexus import make_nexus_endpoint_name
@@ -48,7 +49,7 @@ async def start(
4849 handle = await tctx .start_workflow (
4950 EchoWorkflow .run ,
5051 input .value ,
51- id = str ( uuid . uuid4 ()) ,
52+ id = input . value ,
5253 )
5354 return StartOperationResultAsync (handle .to_token ())
5455
@@ -78,7 +79,7 @@ async def op(
7879 return await ctx .start_workflow (
7980 EchoWorkflow .run ,
8081 input .value ,
81- id = str ( uuid . uuid4 ()) ,
82+ id = input . value ,
8283 )
8384
8485
@@ -146,13 +147,14 @@ async def test_workflow_run_operation(
146147 nexus_service_handlers = [service_handler_cls ()],
147148 workflows = [CallerWorkflow , EchoWorkflow ],
148149 ):
150+ input_value = str (uuid .uuid4 ())
149151 result = await client .execute_workflow (
150152 CallerWorkflow .run ,
151- args = [Input (value = "test" ), service_defn .name , task_queue ],
153+ args = [Input (value = input_value ), service_defn .name , task_queue ],
152154 id = str (uuid .uuid4 ()),
153155 task_queue = task_queue ,
154156 )
155- assert result == "test"
157+ assert result == input_value
156158
157159
158160async def test_request_deadline_is_accessible_in_workflow_run_operation (
@@ -173,9 +175,10 @@ async def test_request_deadline_is_accessible_in_workflow_run_operation(
173175 nexus_service_handlers = [service_handler ],
174176 workflows = [RequestDeadlineWorkflow , EchoWorkflow ],
175177 ):
178+ input_value = str (uuid .uuid4 ())
176179 await client .execute_workflow (
177180 RequestDeadlineWorkflow .run ,
178- args = [Input (value = "test" ), task_queue ],
181+ args = [Input (value = input_value ), task_queue ],
179182 task_queue = task_queue ,
180183 id = str (uuid .uuid4 ()),
181184 )
@@ -186,3 +189,43 @@ async def test_request_deadline_is_accessible_in_workflow_run_operation(
186189 "request_deadline should be set in WorkflowRunOperationContext"
187190 )
188191 assert deadline .tzinfo is timezone .utc , "request_deadline should be in utc"
192+
193+
194+ async def test_workflow_run_operation_includes_token_in_callback (
195+ client : Client ,
196+ env : WorkflowEnvironment ,
197+ ):
198+ if env .supports_time_skipping :
199+ pytest .skip ("Nexus tests don't work with time-skipping server" )
200+
201+ task_queue = str (uuid .uuid4 ())
202+ await env .create_nexus_endpoint (make_nexus_endpoint_name (task_queue ), task_queue )
203+ async with Worker (
204+ client ,
205+ task_queue = task_queue ,
206+ nexus_service_handlers = [SubclassingHappyPath ()],
207+ workflows = [CallerWorkflow , EchoWorkflow ],
208+ ):
209+ input_value = str (uuid .uuid4 ())
210+ result = await client .execute_workflow (
211+ CallerWorkflow .run ,
212+ args = [Input (value = input_value ), "SubclassingHappyPath" , task_queue ],
213+ id = str (uuid .uuid4 ()),
214+ task_queue = task_queue ,
215+ )
216+ assert result == input_value
217+
218+ target_handle = client .get_workflow_handle (input_value )
219+
220+ desc = await target_handle .describe ()
221+ token = desc .raw_description .callbacks [0 ].callback .nexus .header [
222+ "nexus-operation-token"
223+ ]
224+
225+ expected_token = OperationToken (
226+ type = OperationTokenType .WORKFLOW ,
227+ namespace = client .namespace ,
228+ workflow_id = target_handle .id ,
229+ ).encode ()
230+
231+ assert token == expected_token
0 commit comments