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
|
using Agent.Core.Tasks;
namespace Agent.Core.Tests;
public sealed class TaskRegistryTests
{
[Fact]
public void NewTaskGetsUniqueTaskAndSessionIds()
{
var registry = new TaskRegistry();
TaskSnapshot first = registry.Enqueue("one", null, null);
TaskSnapshot second = registry.Enqueue("two", null, 0.2);
Assert.NotEqual(first.TaskId, second.TaskId);
Assert.NotEqual(first.SessionId, second.SessionId);
Assert.Equal(AgentTaskState.Queued, first.State);
}
[Fact]
public void UnknownSessionIsRejected()
{
var registry = new TaskRegistry();
Assert.Throws<KeyNotFoundException>(() => registry.Enqueue("request", Guid.NewGuid(), null));
}
[Fact]
public void TerminalTaskCannotTransition()
{
var registry = new TaskRegistry();
TaskSnapshot task = registry.Enqueue("request", null, null);
Assert.True(registry.Transition(task.TaskId, AgentTaskState.Planning));
Assert.True(registry.Transition(task.TaskId, AgentTaskState.Running));
Assert.True(registry.Transition(task.TaskId, AgentTaskState.Completed));
Assert.False(registry.Transition(task.TaskId, AgentTaskState.Running));
}
}
|