test(coding-agent): align skill prompt role coverage

This commit is contained in:
can1357
2026-06-28 07:33:07 +02:00
parent 2de341246c
commit 19abbb2c1c
@@ -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 {