File tree Expand file tree Collapse file tree
temporal-spring-ai/src/test/java/io/temporal/springai/replay Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import io .temporal .springai .activity .ChatModelActivityImpl ;
1313import io .temporal .springai .chat .TemporalChatClient ;
1414import io .temporal .springai .model .ActivityChatModel ;
15+ import io .temporal .testing .TestEnvironmentOptions ;
1516import io .temporal .testing .TestWorkflowEnvironment ;
1617import io .temporal .testing .WorkflowReplayer ;
1718import io .temporal .worker .Worker ;
19+ import io .temporal .worker .WorkerFactoryOptions ;
1820import io .temporal .workflow .Workflow ;
1921import io .temporal .workflow .WorkflowInterface ;
2022import io .temporal .workflow .WorkflowMethod ;
@@ -48,7 +50,15 @@ class ActivityToolSideEffectTest {
4850
4951 @ BeforeEach
5052 void setUp () {
51- testEnv = TestWorkflowEnvironment .newInstance ();
53+ // WorkflowCacheSize(0) forces the worker to replay from history on every workflow task
54+ // instead of resuming from in-memory cached state — the regime in which a missing
55+ // Workflow.sideEffect wrap or an un-guarded in-workflow mutation would actually bite.
56+ testEnv =
57+ TestWorkflowEnvironment .newInstance (
58+ TestEnvironmentOptions .newBuilder ()
59+ .setWorkerFactoryOptions (
60+ WorkerFactoryOptions .newBuilder ().setWorkflowCacheSize (0 ).build ())
61+ .build ());
5262 client = testEnv .getWorkflowClient ();
5363 addActivity = new AddActivityImpl ();
5464 }
Original file line number Diff line number Diff line change 88import io .temporal .common .WorkflowExecutionHistory ;
99import io .temporal .springai .activity .ChatModelActivityImpl ;
1010import io .temporal .springai .model .ActivityChatModel ;
11+ import io .temporal .testing .TestEnvironmentOptions ;
1112import io .temporal .testing .TestWorkflowEnvironment ;
1213import io .temporal .testing .WorkflowReplayer ;
1314import io .temporal .worker .Worker ;
15+ import io .temporal .worker .WorkerFactoryOptions ;
1416import io .temporal .workflow .WorkflowInterface ;
1517import io .temporal .workflow .WorkflowMethod ;
1618import java .util .List ;
@@ -43,7 +45,16 @@ class ChatModelSideEffectTest {
4345
4446 @ BeforeEach
4547 void setUp () {
46- testEnv = TestWorkflowEnvironment .newInstance ();
48+ // WorkflowCacheSize(0) forces the worker to replay from history on every workflow task
49+ // instead of resuming from in-memory cached state, which is what we actually need to
50+ // assert side-effect safety: any un-wrapped side effect in workflow code would run on
51+ // each replay and bump the counter.
52+ testEnv =
53+ TestWorkflowEnvironment .newInstance (
54+ TestEnvironmentOptions .newBuilder ()
55+ .setWorkerFactoryOptions (
56+ WorkerFactoryOptions .newBuilder ().setWorkflowCacheSize (0 ).build ())
57+ .build ());
4758 client = testEnv .getWorkflowClient ();
4859 model = new CountingChatModel ("pong" );
4960 }
Original file line number Diff line number Diff line change 1010import io .temporal .springai .chat .TemporalChatClient ;
1111import io .temporal .springai .model .ActivityChatModel ;
1212import io .temporal .springai .tool .SideEffectTool ;
13+ import io .temporal .testing .TestEnvironmentOptions ;
1314import io .temporal .testing .TestWorkflowEnvironment ;
1415import io .temporal .testing .WorkflowReplayer ;
1516import io .temporal .worker .Worker ;
17+ import io .temporal .worker .WorkerFactoryOptions ;
1618import io .temporal .workflow .WorkflowInterface ;
1719import io .temporal .workflow .WorkflowMethod ;
1820import java .util .List ;
@@ -51,7 +53,15 @@ class SideEffectToolReplayTest {
5153 @ BeforeEach
5254 void setUp () {
5355 CALL_COUNT .set (0 );
54- testEnv = TestWorkflowEnvironment .newInstance ();
56+ // WorkflowCacheSize(0) forces the worker to replay from history on every workflow task.
57+ // This is exactly the regime a missing Workflow.sideEffect wrap would fail in: every
58+ // tick the @Tool body would run again and bump the counter past 1.
59+ testEnv =
60+ TestWorkflowEnvironment .newInstance (
61+ TestEnvironmentOptions .newBuilder ()
62+ .setWorkerFactoryOptions (
63+ WorkerFactoryOptions .newBuilder ().setWorkflowCacheSize (0 ).build ())
64+ .build ());
5565 client = testEnv .getWorkflowClient ();
5666 }
5767
You can’t perform that action at this time.
0 commit comments