-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCommandsTests.cs
More file actions
138 lines (118 loc) · 4.2 KB
/
CommandsTests.cs
File metadata and controls
138 lines (118 loc) · 4.2 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.SDK.Test.Harness;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.SDK.Test;
public class CommandsTests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "commands", output)
{
[Fact]
public async Task Session_With_Commands_Creates_Successfully()
{
var session = await CreateSessionAsync(new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
Commands =
[
new CommandDefinition { Name = "deploy", Description = "Deploy the app", Handler = _ => Task.CompletedTask },
new CommandDefinition { Name = "rollback", Handler = _ => Task.CompletedTask },
],
});
// Session should be created successfully with commands
Assert.NotNull(session);
Assert.NotNull(session.SessionId);
await session.DisposeAsync();
}
[Fact]
public async Task Session_With_Commands_Resumes_Successfully()
{
var session1 = await CreateSessionAsync();
var sessionId = session1.SessionId;
var session2 = await ResumeSessionAsync(sessionId, new ResumeSessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
Commands =
[
new CommandDefinition { Name = "deploy", Description = "Deploy", Handler = _ => Task.CompletedTask },
],
});
Assert.NotNull(session2);
Assert.Equal(sessionId, session2.SessionId);
await session2.DisposeAsync();
}
[Fact]
public void CommandDefinition_Has_Required_Properties()
{
var cmd = new CommandDefinition
{
Name = "deploy",
Description = "Deploy the app",
Handler = _ => Task.CompletedTask,
};
Assert.Equal("deploy", cmd.Name);
Assert.Equal("Deploy the app", cmd.Description);
Assert.NotNull(cmd.Handler);
}
[Fact]
public void CommandContext_Has_All_Properties()
{
var ctx = new CommandContext
{
SessionId = "session-1",
Command = "/deploy production",
CommandName = "deploy",
Args = "production",
};
Assert.Equal("session-1", ctx.SessionId);
Assert.Equal("/deploy production", ctx.Command);
Assert.Equal("deploy", ctx.CommandName);
Assert.Equal("production", ctx.Args);
}
[Fact]
public async Task Session_With_No_Commands_Creates_Successfully()
{
var session = await CreateSessionAsync(new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
});
Assert.NotNull(session);
await session.DisposeAsync();
}
[Fact]
public async Task Session_Config_Commands_Are_Cloned()
{
var config = new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
Commands =
[
new CommandDefinition { Name = "deploy", Handler = _ => Task.CompletedTask },
],
};
var clone = config.Clone();
Assert.NotNull(clone.Commands);
Assert.Single(clone.Commands!);
Assert.Equal("deploy", clone.Commands![0].Name);
// Verify collections are independent
clone.Commands!.Add(new CommandDefinition { Name = "rollback", Handler = _ => Task.CompletedTask });
Assert.Single(config.Commands!);
}
[Fact]
public void Resume_Config_Commands_Are_Cloned()
{
var config = new ResumeSessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
Commands =
[
new CommandDefinition { Name = "deploy", Handler = _ => Task.CompletedTask },
],
};
var clone = config.Clone();
Assert.NotNull(clone.Commands);
Assert.Single(clone.Commands!);
Assert.Equal("deploy", clone.Commands![0].Name);
}
}