From 19abbb2c1c3076aae7a56dca8deeae1e1a903b77 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 28 Jun 2026 07:33:07 +0200 Subject: [PATCH] test(coding-agent): align skill prompt role coverage --- .../test/session-messages.test.ts | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/test/session-messages.test.ts b/packages/coding-agent/test/session-messages.test.ts index 27b0fcfde..ed424732a 100644 --- a/packages/coding-agent/test/session-messages.test.ts +++ b/packages/coding-agent/test/session-messages.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "bun:test"; import { type AgentMessage, filterProviderReplayMessages } from "@oh-my-pi/pi-agent-core"; import type { ImageContent, Message, TextContent } from "@oh-my-pi/pi-ai"; import { inferCopilotInitiator } from "@oh-my-pi/pi-ai/providers/github-copilot-headers"; -import { convertToLlm, wrapSteeringForModel } from "@oh-my-pi/pi-coding-agent/session/messages"; +import { convertToLlm, SKILL_PROMPT_MESSAGE_TYPE, wrapSteeringForModel } from "@oh-my-pi/pi-coding-agent/session/messages"; function expectAttribution(message: Message | undefined, expected: "user" | "agent" | undefined): void { expect(message).toBeDefined(); @@ -240,12 +240,12 @@ describe("convertToLlm custom message mapping", () => { expect(converted[0].content.filter(content => content.type === "image")).toEqual([image]); }); - it("allows custom messages to opt into user attribution", () => { + it("keeps non-skill user-attributed custom messages on the developer role", () => { const messages: AgentMessage[] = [ { role: "custom", - customType: "skill-prompt", - content: "Run this skill with my arguments", + customType: "ultrathink-notice", + content: "User requested deeper reasoning", display: true, attribution: "user", timestamp: Date.now(), @@ -259,6 +259,31 @@ describe("convertToLlm custom message mapping", () => { expectAttribution(converted[0], "user"); expect(inferCopilotInitiator(converted)).toBe("user"); }); + + it("maps user-invoked skill prompts to the user role", () => { + const messages: AgentMessage[] = [ + { + role: "custom", + customType: SKILL_PROMPT_MESSAGE_TYPE, + content: "Run this skill with my arguments", + display: true, + attribution: "user", + timestamp: Date.now(), + }, + ]; + + const converted = convertToLlm(messages); + + expect(converted).toHaveLength(1); + expect(converted[0]?.role).toBe("user"); + expectAttribution(converted[0], "user"); + expect(inferCopilotInitiator(converted)).toBe("user"); + if (converted[0]?.role !== "user" || !Array.isArray(converted[0].content)) { + throw new Error("Expected user array content"); + } + const text = converted[0].content.find(content => content.type === "text")?.text ?? ""; + expect(text).toContain("Run this skill with my arguments"); + }); }); function getUserText(message: AgentMessage | undefined): string {