-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreAIGameEntryPointEditModeTests.cs
More file actions
153 lines (129 loc) · 4.9 KB
/
CoreAIGameEntryPointEditModeTests.cs
File metadata and controls
153 lines (129 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CoreAI.Ai;
using CoreAI.Composition;
using CoreAI.Logging;
using NUnit.Framework;
namespace CoreAI.Tests.EditMode
{
[TestFixture]
public sealed class CoreAIGameEntryPointEditModeTests
{
[SetUp]
public void SetUp()
{
CoreAIAgent.Reset();
CoreAIGameEntryPoint.ResetInitializationGuardForTests();
CoreAIGameEntryPoint.AutoBootstrap = false;
}
[TearDown]
public void TearDown()
{
CoreAIAgent.Reset();
CoreAIGameEntryPoint.ResetInitializationGuardForTests();
CoreAIGameEntryPoint.AutoBootstrap = false;
}
[Test]
public void Start_FirstEntryPoint_InitializesCoreAiFacade()
{
TestLogger logger = new();
StubOrchestrator orchestrator = new();
AgentMemoryPolicy policy = new();
StubMemoryStore memoryStore = new();
CoreAIGameEntryPoint entryPoint = new(logger, orchestrator, policy, memoryStore);
entryPoint.Start();
Assert.AreSame(orchestrator, CoreAIAgent.Orchestrator);
Assert.AreSame(policy, CoreAIAgent.Policy);
Assert.AreSame(memoryStore, CoreAIAgent.MemoryStore);
Assert.AreEqual(0, logger.WarnCount);
entryPoint.Dispose();
}
[Test]
public void Start_SecondEntryPoint_IsSkippedAndDoesNotOverrideFacade()
{
TestLogger logger1 = new();
StubOrchestrator orchestrator1 = new();
AgentMemoryPolicy policy1 = new();
StubMemoryStore memoryStore1 = new();
CoreAIGameEntryPoint first = new(logger1, orchestrator1, policy1, memoryStore1);
TestLogger logger2 = new();
StubOrchestrator orchestrator2 = new();
AgentMemoryPolicy policy2 = new();
StubMemoryStore memoryStore2 = new();
CoreAIGameEntryPoint second = new(logger2, orchestrator2, policy2, memoryStore2);
first.Start();
second.Start();
Assert.AreSame(orchestrator1, CoreAIAgent.Orchestrator);
Assert.AreSame(policy1, CoreAIAgent.Policy);
Assert.AreSame(memoryStore1, CoreAIAgent.MemoryStore);
// Duplicate-start is reported via Debug (not Warn) to keep the console quiet
// when additive scenes / tests legitimately spin up a second LifetimeScope.
Assert.AreEqual(1, logger2.DebugCount, "Duplicate start should be reported exactly once via Debug.");
Assert.AreEqual(0, logger2.WarnCount, "Duplicate start must not emit a Warning.");
first.Dispose();
second.Dispose();
}
private sealed class TestLogger : ILog
{
public int DebugCount { get; private set; }
public int WarnCount { get; private set; }
public void Debug(string message, string tag = null)
{
DebugCount++;
}
public void Info(string message, string tag = null)
{
}
public void Warn(string message, string tag = null)
{
WarnCount++;
}
public void Error(string message, string tag = null)
{
}
}
private sealed class StubOrchestrator : IAiOrchestrationService
{
public Task<string> RunTaskAsync(AiTaskRequest task, CancellationToken cancellationToken = default)
{
return Task.FromResult(string.Empty);
}
public async IAsyncEnumerable<LlmStreamChunk> RunStreamingAsync(
AiTaskRequest task,
[System.Runtime.CompilerServices.EnumeratorCancellation]
CancellationToken cancellationToken = default)
{
yield return new LlmStreamChunk { IsDone = true };
await Task.CompletedTask;
}
public void CancelTasks(string cancellationScope)
{
}
}
private sealed class StubMemoryStore : IAgentMemoryStore
{
public bool TryLoad(string roleId, out AgentMemoryState state)
{
state = null;
return false;
}
public void Save(string roleId, AgentMemoryState state)
{
}
public void Clear(string roleId)
{
}
public void ClearChatHistory(string roleId)
{
}
public void AppendChatMessage(string roleId, string role, string content, bool persistToDisk = true)
{
}
public ChatMessage[] GetChatHistory(string roleId, int maxMessages = 0)
{
return System.Array.Empty<ChatMessage>();
}
}
}
}