Skip to content

Commit add9a49

Browse files
committed
test: cover generated media delivery evidence fallback
1 parent a0ea07e commit add9a49

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/agents/pi-embedded-subscribe.tools.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,9 @@ export function extractMessagingToolSend(
554554
const provider = providerId ?? normalizeOptionalLowercaseString(providerHint) ?? "message";
555555
const to = normalizeTargetForProvider(provider, toRaw);
556556
const threadId = normalizeOptionalString(args.threadId);
557-
return to ? { tool: toolName, provider, accountId, to, threadId } : undefined;
557+
return to
558+
? { tool: toolName, provider, accountId, to, ...(threadId ? { threadId } : {}) }
559+
: undefined;
558560
}
559561
const providerId = normalizeChannelId(toolName);
560562
if (!providerId) {

src/agents/subagent-announce-delivery.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,58 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
12711271
);
12721272
});
12731273

1274+
it("does not fallback for generated media group completions when message tool evidence exists", async () => {
1275+
const callGateway = createGatewayMock({
1276+
result: {
1277+
payloads: [],
1278+
didSendViaMessagingTool: false,
1279+
messagingToolSentTargets: [
1280+
{
1281+
tool: "message",
1282+
provider: "slack",
1283+
accountId: "acct-1",
1284+
to: "channel:C123",
1285+
text: "The track is ready.",
1286+
mediaUrls: ["/tmp/generated-night-drive.mp3"],
1287+
},
1288+
],
1289+
},
1290+
});
1291+
const sendMessage = createSendMessageMock();
1292+
const result = await deliverSlackChannelAnnouncement({
1293+
callGateway,
1294+
sendMessage,
1295+
sessionId: "requester-session-channel",
1296+
isActive: false,
1297+
expectsCompletionMessage: true,
1298+
directIdempotencyKey: "announce-channel-media-message-tool-evidence",
1299+
sourceTool: "music_generate",
1300+
internalEvents: [
1301+
{
1302+
type: "task_completion",
1303+
source: "music_generation",
1304+
childSessionKey: "music_generate:task-123",
1305+
childSessionId: "task-123",
1306+
announceType: "music generation task",
1307+
taskLabel: "night-drive synthwave",
1308+
status: "ok",
1309+
statusLabel: "completed successfully",
1310+
result: "Generated 1 track.\nMEDIA:/tmp/generated-night-drive.mp3",
1311+
mediaUrls: ["/tmp/generated-night-drive.mp3"],
1312+
replyInstruction: "Deliver the generated music through the message tool.",
1313+
},
1314+
],
1315+
});
1316+
1317+
expect(result).toEqual(
1318+
expect.objectContaining({
1319+
delivered: true,
1320+
path: "direct",
1321+
}),
1322+
);
1323+
expect(sendMessage).not.toHaveBeenCalled();
1324+
});
1325+
12741326
it("does not fallback while generated media announce-agent run is still pending", async () => {
12751327
const callGateway = createGatewayMock({
12761328
runId: "video_generate:task-123:ok",

0 commit comments

Comments
 (0)