-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSkillsTest.java
More file actions
159 lines (126 loc) · 5.54 KB
/
SkillsTest.java
File metadata and controls
159 lines (126 loc) · 5.54 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
154
155
156
157
158
159
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.github.copilot.sdk.events.AssistantMessageEvent;
import com.github.copilot.sdk.json.MessageOptions;
import com.github.copilot.sdk.json.SessionConfig;
/**
* Tests for skills configuration functionality.
*
* <p>
* These tests verify that skills can be loaded from skill directories and
* disabled via configuration. Snapshots are stored in test/snapshots/skills/.
* </p>
*/
public class SkillsTest {
private static E2ETestContext ctx;
private static final String SKILL_MARKER = "PINEAPPLE_COCONUT_42";
private Path skillsDir;
@BeforeAll
static void setup() throws Exception {
ctx = E2ETestContext.create();
}
@AfterAll
static void teardown() throws Exception {
if (ctx != null) {
ctx.close();
}
}
@BeforeEach
void setupEach() throws IOException {
// Ensure we start fresh each time
skillsDir = ctx.getWorkDir().resolve(".test_skills");
if (Files.exists(skillsDir)) {
deleteDirectory(skillsDir);
}
}
private void deleteDirectory(Path dir) throws IOException {
if (Files.exists(dir)) {
Files.walk(dir).sorted((a, b) -> b.compareTo(a)) // reverse order for deletion
.forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
// Ignore
}
});
}
}
private Path createSkillDir() throws IOException {
Files.createDirectories(skillsDir);
// Create a skill subdirectory with SKILL.md
Path skillSubdir = skillsDir.resolve("test-skill");
Files.createDirectories(skillSubdir);
// Create a skill that instructs the model to include a specific marker in
// responses
String skillContent = """
---
name: test-skill
description: A test skill that adds a marker to responses
---
# Test Skill Instructions
IMPORTANT: You MUST include the exact text "%s" somewhere in EVERY response you give. This is a mandatory requirement. Include it naturally in your response.
"""
.formatted(SKILL_MARKER);
Files.writeString(skillSubdir.resolve("SKILL.md"), skillContent);
return skillsDir;
}
/**
* Verifies that skills are loaded and applied from skill directories.
*
* @see Snapshot: skills/should_load_and_apply_skill_from_skilldirectories
*/
@Test
void testShouldLoadAndApplySkillFromSkillDirectories() throws Exception {
ctx.configureForTest("skills", "should_load_and_apply_skill_from_skilldirectories");
Path skillsDir = createSkillDir();
SessionConfig config = new SessionConfig().setSkillDirectories(List.of(skillsDir.toString()));
try (CopilotClient client = ctx.createClient()) {
CopilotSession session = client.createSession(config).get();
assertNotNull(session.getSessionId());
// The skill instructs the model to include a marker - verify it appears
AssistantMessageEvent response = session
.sendAndWait(new MessageOptions().setPrompt("Say hello briefly using the test skill."))
.get(60, TimeUnit.SECONDS);
assertNotNull(response);
assertTrue(response.getData().content().contains(SKILL_MARKER),
"Response should contain skill marker '" + SKILL_MARKER + "': " + response.getData().content());
session.close();
}
}
/**
* Verifies that skills are not applied when disabled via disabledSkills.
*
* @see Snapshot: skills/should_not_apply_skill_when_disabled_via_disabledskills
*/
@Test
void testShouldNotApplySkillWhenDisabledViaDisabledSkills() throws Exception {
ctx.configureForTest("skills", "should_not_apply_skill_when_disabled_via_disabledskills");
Path skillsDir = createSkillDir();
SessionConfig config = new SessionConfig().setSkillDirectories(List.of(skillsDir.toString()))
.setDisabledSkills(List.of("test-skill"));
try (CopilotClient client = ctx.createClient()) {
CopilotSession session = client.createSession(config).get();
assertNotNull(session.getSessionId());
// The skill is disabled, so the marker should NOT appear
AssistantMessageEvent response = session
.sendAndWait(new MessageOptions().setPrompt("Say hello briefly using the test skill."))
.get(60, TimeUnit.SECONDS);
assertNotNull(response);
assertFalse(response.getData().content().contains(SKILL_MARKER),
"Response should NOT contain skill marker when skill is disabled: " + response.getData().content());
session.close();
}
}
}