diff --git a/src/Netclaw.Actors.Tests/Sessions/LlmSessionIntegrationTests.cs b/src/Netclaw.Actors.Tests/Sessions/LlmSessionIntegrationTests.cs index 7436518f..41e2b293 100644 --- a/src/Netclaw.Actors.Tests/Sessions/LlmSessionIntegrationTests.cs +++ b/src/Netclaw.Actors.Tests/Sessions/LlmSessionIntegrationTests.cs @@ -1417,11 +1417,27 @@ await sessionManager.Ask(new JoinSession }, TimeSpan.FromSeconds(3), cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(sessionId, ack.SessionId); - await AwaitAssertAsync(() => - { - Assert.Equal(1, _fakeChatClient.CallCount); - return Task.CompletedTask; - }, TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(100), cancellationToken: TestContext.Current.CancellationToken); + + // Poll until the turn is fully persisted. Checking CallCount alone is not + // sufficient — the in-memory journal persists asynchronously, so TurnCount + // can still be 0 at the moment CallCount first reaches 1. CallCount is + // intentionally NOT asserted inside the retry loop: if retries push it above + // the expected value, a strict equality check would loop forever rather than + // failing fast. Assert it once after the loop, when the actor is idle. + // JoinSession is idempotent for the same subscriber (Dictionary keyed by + // IActorRef), so repeated calls with the witness probe are safe. + var witness = CreateTestProbe("passivation-witness"); + await AwaitAssertAsync(async () => + { + var peek = await sessionManager.Ask(new JoinSession + { + SessionId = sessionId, + Subscriber = witness, + Filter = OutputFilter.TextOnly + }, TimeSpan.FromSeconds(1), cancellationToken: TestContext.Current.CancellationToken); + Assert.Equal(1, peek.TurnCount); + }, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(100), cancellationToken: TestContext.Current.CancellationToken); + Assert.Equal(1, _fakeChatClient.CallCount); var rejoined = await sessionManager.Ask(new JoinSession { diff --git a/src/Netclaw.Actors.Tests/Sessions/LlmSessionTestBase.cs b/src/Netclaw.Actors.Tests/Sessions/LlmSessionTestBase.cs index 4a9eba9e..59e6c83f 100644 --- a/src/Netclaw.Actors.Tests/Sessions/LlmSessionTestBase.cs +++ b/src/Netclaw.Actors.Tests/Sessions/LlmSessionTestBase.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Netclaw.Actors.Hosting; +using Netclaw.Actors.Jobs; using Netclaw.Configuration; namespace Netclaw.Actors.Tests.Sessions; @@ -30,6 +31,8 @@ protected sealed override void ConfigureServices(HostBuilderContext context, ISe { services.AddSingleton(new FakeCapabilityResolver()); services.AddTestNetclawPaths(); + services.AddSingleton(SecurityPolicyDefaults.Resolve(null)); + services.AddSingleton(); ConfigureSessionServices(services); services.AddLlmSessionCompositeRecords(); }