Skip to content

Commit 4a3f210

Browse files
stephentoubCopilot
andauthored
Normalize skill context snapshots (#1269)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 81b7b01 commit 4a3f210

3 files changed

Lines changed: 48 additions & 10 deletions

File tree

test/harness/replayingCapiProxy.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,45 @@ describe("ReplayingCapiProxy", () => {
370370
expect(result.conversations[0].messages[0].content).toBe("Say hello.");
371371
});
372372

373+
test("strips skill metadata frontmatter from skill-context user messages", async () => {
374+
const skillDir = path.join(workDir, ".test_skills", "test-skill");
375+
const requestBody = JSON.stringify({
376+
messages: [
377+
{
378+
role: "user",
379+
content: `<skill-context name="test-skill">
380+
Base directory for this skill: ${skillDir}
381+
382+
---
383+
name: test-skill
384+
description: A test skill that adds a marker to responses
385+
---
386+
387+
# Test Skill Instructions
388+
389+
Always include PINEAPPLE_COCONUT_42.
390+
</skill-context>`,
391+
},
392+
],
393+
});
394+
const responseBody = JSON.stringify({
395+
choices: [{ message: { role: "assistant", content: "OK!" } }],
396+
});
397+
398+
const outputPath = await createProxy([
399+
{ url: "/chat/completions", requestBody, responseBody },
400+
]);
401+
402+
const result = await readYamlOutput(outputPath);
403+
expect(result.conversations[0].messages[0].content).toBe(`<skill-context name="test-skill">
404+
Base directory for this skill: ${workingDirPlaceholder}/.test_skills/test-skill
405+
406+
# Test Skill Instructions
407+
408+
Always include PINEAPPLE_COCONUT_42.
409+
</skill-context>`);
410+
});
411+
373412
test("applies tool result normalizers to tool response content", async () => {
374413
const requestBody = JSON.stringify({
375414
messages: [

test/harness/replayingCapiProxy.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ function transformOpenAIRequestMessage(
10321032
}
10331033

10341034
function normalizeUserMessage(content: string): string {
1035-
return content
1035+
return normalizeSkillContextFrontmatter(content)
10361036
.replace(/<current_datetime>.*?<\/current_datetime>/g, "")
10371037
.replace(/<reminder>[\s\S]*?<\/reminder>/g, "")
10381038
.replace(/<system_reminder>[\s\S]*?<\/system_reminder>/g, "")
@@ -1044,6 +1044,14 @@ function normalizeUserMessage(content: string): string {
10441044
.trim();
10451045
}
10461046

1047+
function normalizeSkillContextFrontmatter(content: string): string {
1048+
// Runtime versions may include or omit SKILL.md metadata in the prompt context.
1049+
return content.replace(
1050+
/(<skill-context\b[^>]*>\s*Base directory for this skill:[^\r\n]*(?:\r?\n)+)---\r?\n(?:(?!<\/skill-context>)[\s\S])*?\r?\n---(?:\r?\n)+/g,
1051+
"$1",
1052+
);
1053+
}
1054+
10471055
function normalizeLargeOutputFilepaths(result: string): string {
10481056
// Replaces filenames like 1774637043987-copilot-tool-output-tk7puw.txt with PLACEHOLDER-copilot-tool-output-PLACEHOLDER
10491057
return result

test/snapshots/skills/should_load_and_apply_skill_from_skilldirectories.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ conversations:
2323
Base directory for this skill: ${workdir}/.test_skills/test-skill
2424
2525
26-
---
27-
28-
name: test-skill
29-
30-
description: A test skill that adds a marker to responses
31-
32-
---
33-
34-
3526
# Test Skill Instructions
3627
3728

0 commit comments

Comments
 (0)