Skip to content

Commit b6a7751

Browse files
xumapleclaude
andcommitted
Add Nexus integration test coverage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a98d422 commit b6a7751

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

tests/contrib/langsmith/test_integration.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
from typing import Any
88
from unittest.mock import MagicMock
99

10+
import nexusrpc.handler
1011
import pytest
1112
from langsmith import traceable, tracing_context
1213

13-
from temporalio import activity, common, workflow
14+
from temporalio import activity, common, nexus, workflow
1415
from temporalio.client import Client, WorkflowFailureError
1516
from temporalio.contrib.langsmith import LangSmithPlugin
1617
from temporalio.exceptions import ApplicationError
1718
from temporalio.testing import WorkflowEnvironment
1819
from tests.contrib.langsmith.conftest import InMemoryRunCollector, dump_runs
1920
from tests.helpers import new_worker
21+
from tests.helpers.nexus import make_nexus_endpoint_name
2022

2123
# ---------------------------------------------------------------------------
2224
# Shared @traceable functions and activities
@@ -64,6 +66,29 @@ async def run(self) -> str:
6466
)
6567

6668

69+
@workflow.defn
70+
class SimpleNexusWorkflow:
71+
@workflow.run
72+
async def run(self, input: str) -> str:
73+
return await workflow.execute_activity(
74+
traceable_activity,
75+
start_to_close_timeout=timedelta(seconds=10),
76+
)
77+
78+
79+
@nexusrpc.handler.service_handler
80+
class NexusService:
81+
@nexus.workflow_run_operation
82+
async def run_operation(
83+
self, ctx: nexus.WorkflowRunOperationContext, input: str
84+
) -> nexus.WorkflowHandle[str]:
85+
return await ctx.start_workflow(
86+
SimpleNexusWorkflow.run,
87+
input,
88+
id=f"nexus-wf-{ctx.request_id}",
89+
)
90+
91+
6792
# ---------------------------------------------------------------------------
6893
# Simple/basic workflows and activities
6994
# ---------------------------------------------------------------------------
@@ -113,7 +138,17 @@ async def run(self) -> str:
113138
TraceableActivityWorkflow.run,
114139
id=f"child-{workflow.info().workflow_id}",
115140
)
116-
# 4. Wait for signal
141+
# 4. Nexus operation
142+
nexus_client = workflow.create_nexus_client(
143+
endpoint=make_nexus_endpoint_name(workflow.info().task_queue),
144+
service=NexusService,
145+
)
146+
nexus_handle = await nexus_client.start_operation(
147+
operation=NexusService.run_operation,
148+
input="test-input",
149+
)
150+
await nexus_handle
151+
# 5. Wait for signal
117152
await workflow.wait_condition(lambda: self._signal_received)
118153
# 5. Wait for update to complete
119154
await workflow.wait_condition(lambda: self._complete)
@@ -449,8 +484,14 @@ async def user_pipeline() -> str:
449484
temporal_client,
450485
ComprehensiveWorkflow,
451486
TraceableActivityWorkflow,
487+
SimpleNexusWorkflow,
452488
activities=[nested_traceable_activity, traceable_activity],
489+
nexus_service_handlers=[NexusService()],
453490
) as worker:
491+
await env.create_nexus_endpoint(
492+
make_nexus_endpoint_name(worker.task_queue),
493+
worker.task_queue,
494+
)
454495
handle = await temporal_client.start_workflow(
455496
ComprehensiveWorkflow.run,
456497
id=f"comprehensive-{uuid.uuid4()}",
@@ -489,6 +530,13 @@ async def user_pipeline() -> str:
489530
" StartActivity:traceable_activity",
490531
" RunActivity:traceable_activity",
491532
" inner_llm_call",
533+
" StartNexusOperation:NexusService/run_operation",
534+
" RunStartNexusOperationHandler:NexusService/run_operation",
535+
" StartWorkflow:SimpleNexusWorkflow",
536+
" RunWorkflow:SimpleNexusWorkflow",
537+
" StartActivity:traceable_activity",
538+
" RunActivity:traceable_activity",
539+
" inner_llm_call",
492540
" QueryWorkflow:my_query",
493541
" HandleQuery:my_query",
494542
" SignalWorkflow:my_signal",
@@ -517,8 +565,14 @@ async def user_pipeline() -> str:
517565
temporal_client,
518566
ComprehensiveWorkflow,
519567
TraceableActivityWorkflow,
568+
SimpleNexusWorkflow,
520569
activities=[nested_traceable_activity, traceable_activity],
570+
nexus_service_handlers=[NexusService()],
521571
) as worker:
572+
await env.create_nexus_endpoint(
573+
make_nexus_endpoint_name(worker.task_queue),
574+
worker.task_queue,
575+
)
522576
handle = await temporal_client.start_workflow(
523577
ComprehensiveWorkflow.run,
524578
id=f"comprehensive-no-runs-{uuid.uuid4()}",
@@ -547,6 +601,7 @@ async def user_pipeline() -> str:
547601
" outer_chain",
548602
" inner_llm_call",
549603
" inner_llm_call",
604+
" inner_llm_call",
550605
]
551606
assert hierarchy == expected, (
552607
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"

tests/contrib/langsmith/test_plugin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
from tests.contrib.langsmith.conftest import dump_runs
1414
from tests.contrib.langsmith.test_integration import (
1515
ComprehensiveWorkflow,
16+
NexusService,
17+
SimpleNexusWorkflow,
1618
TraceableActivityWorkflow,
1719
_make_client_and_collector,
1820
nested_traceable_activity,
1921
traceable_activity,
2022
)
2123
from tests.helpers import new_worker
24+
from tests.helpers.nexus import make_nexus_endpoint_name
2225

2326

2427
class TestPluginConstruction:
@@ -60,8 +63,14 @@ async def user_pipeline() -> str:
6063
temporal_client,
6164
ComprehensiveWorkflow,
6265
TraceableActivityWorkflow,
66+
SimpleNexusWorkflow,
6367
activities=[nested_traceable_activity, traceable_activity],
68+
nexus_service_handlers=[NexusService()],
6469
) as worker:
70+
await env.create_nexus_endpoint(
71+
make_nexus_endpoint_name(worker.task_queue),
72+
worker.task_queue,
73+
)
6574
handle = await temporal_client.start_workflow(
6675
ComprehensiveWorkflow.run,
6776
id=f"plugin-comprehensive-{uuid.uuid4()}",
@@ -100,6 +109,13 @@ async def user_pipeline() -> str:
100109
" StartActivity:traceable_activity",
101110
" RunActivity:traceable_activity",
102111
" inner_llm_call",
112+
" StartNexusOperation:NexusService/run_operation",
113+
" RunStartNexusOperationHandler:NexusService/run_operation",
114+
" StartWorkflow:SimpleNexusWorkflow",
115+
" RunWorkflow:SimpleNexusWorkflow",
116+
" StartActivity:traceable_activity",
117+
" RunActivity:traceable_activity",
118+
" inner_llm_call",
103119
" QueryWorkflow:my_query",
104120
" HandleQuery:my_query",
105121
" SignalWorkflow:my_signal",

0 commit comments

Comments
 (0)