Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/harness/replayingCapiProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,45 @@ describe("ReplayingCapiProxy", () => {
expect(result.conversations[0].messages[0].content).toBe("Say hello.");
});

test("strips skill metadata frontmatter from skill-context user messages", async () => {
const skillDir = path.join(workDir, ".test_skills", "test-skill");
const requestBody = JSON.stringify({
messages: [
{
role: "user",
content: `<skill-context name="test-skill">
Base directory for this skill: ${skillDir}

---
name: test-skill
description: A test skill that adds a marker to responses
---

# Test Skill Instructions

Always include PINEAPPLE_COCONUT_42.
</skill-context>`,
},
],
});
const responseBody = JSON.stringify({
choices: [{ message: { role: "assistant", content: "OK!" } }],
});

const outputPath = await createProxy([
{ url: "/chat/completions", requestBody, responseBody },
]);

const result = await readYamlOutput(outputPath);
expect(result.conversations[0].messages[0].content).toBe(`<skill-context name="test-skill">
Base directory for this skill: ${workingDirPlaceholder}/.test_skills/test-skill

# Test Skill Instructions

Always include PINEAPPLE_COCONUT_42.
</skill-context>`);
});

test("applies tool result normalizers to tool response content", async () => {
const requestBody = JSON.stringify({
messages: [
Expand Down
10 changes: 9 additions & 1 deletion test/harness/replayingCapiProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ function transformOpenAIRequestMessage(
}

function normalizeUserMessage(content: string): string {
return content
return normalizeSkillContextFrontmatter(content)
.replace(/<current_datetime>.*?<\/current_datetime>/g, "")
.replace(/<reminder>[\s\S]*?<\/reminder>/g, "")
.replace(/<system_reminder>[\s\S]*?<\/system_reminder>/g, "")
Expand All @@ -1044,6 +1044,14 @@ function normalizeUserMessage(content: string): string {
.trim();
}

function normalizeSkillContextFrontmatter(content: string): string {
// Runtime versions may include or omit SKILL.md metadata in the prompt context.
return content.replace(
/(<skill-context\b[^>]*>\s*Base directory for this skill:[^\r\n]*(?:\r?\n)+)---\r?\n(?:(?!<\/skill-context>)[\s\S])*?\r?\n---(?:\r?\n)+/g,
"$1",
);
}

function normalizeLargeOutputFilepaths(result: string): string {
// Replaces filenames like 1774637043987-copilot-tool-output-tk7puw.txt with PLACEHOLDER-copilot-tool-output-PLACEHOLDER
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ conversations:
Base directory for this skill: ${workdir}/.test_skills/test-skill
---
name: test-skill
description: A test skill that adds a marker to responses
---
# Test Skill Instructions
Expand Down
Loading