|
| 1 | +import { Value } from "typebox/value"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import type { AgentInternalEvent } from "../../../agents/internal-events.js"; |
| 4 | +import { AgentParamsSchema } from "./agent.js"; |
| 5 | + |
| 6 | +function makeAgentParamsWithInternalEvent(event: AgentInternalEvent) { |
| 7 | + return { |
| 8 | + message: "A music generation task finished. Process the completion update now.", |
| 9 | + sessionKey: "agent:main:discord:channel:1456744319972282449", |
| 10 | + internalEvents: [event], |
| 11 | + idempotencyKey: "music_generate:task-123:ok", |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +const musicCompletionEvent: AgentInternalEvent = { |
| 16 | + type: "task_completion", |
| 17 | + source: "music_generation", |
| 18 | + childSessionKey: "music_generate:task-123", |
| 19 | + childSessionId: "task-123", |
| 20 | + announceType: "music generation task", |
| 21 | + taskLabel: "OpenClaw release anthem", |
| 22 | + status: "ok", |
| 23 | + statusLabel: "completed successfully", |
| 24 | + result: "Generated 1 track.", |
| 25 | + attachments: [ |
| 26 | + { |
| 27 | + type: "audio", |
| 28 | + path: "/tmp/openclaw/generated-release-anthem.mp3", |
| 29 | + mimeType: "audio/mpeg", |
| 30 | + name: "generated-release-anthem.mp3", |
| 31 | + }, |
| 32 | + ], |
| 33 | + mediaUrls: ["/tmp/openclaw/generated-release-anthem.mp3"], |
| 34 | + replyInstruction: "Deliver the generated music.", |
| 35 | +}; |
| 36 | + |
| 37 | +describe("AgentParamsSchema", () => { |
| 38 | + it("accepts generated music attachments on internal completion events", () => { |
| 39 | + const params = makeAgentParamsWithInternalEvent(musicCompletionEvent); |
| 40 | + |
| 41 | + expect(Value.Check(AgentParamsSchema, params)).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + it("keeps task completion internal events strict", () => { |
| 45 | + const params = makeAgentParamsWithInternalEvent({ |
| 46 | + ...musicCompletionEvent, |
| 47 | + unexpected: true, |
| 48 | + } as AgentInternalEvent); |
| 49 | + |
| 50 | + expect(Value.Check(AgentParamsSchema, params)).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it("rejects malformed generated attachment entries on internal events", () => { |
| 54 | + const params = makeAgentParamsWithInternalEvent({ |
| 55 | + ...musicCompletionEvent, |
| 56 | + attachments: [null], |
| 57 | + } as unknown as AgentInternalEvent); |
| 58 | + |
| 59 | + expect(Value.Check(AgentParamsSchema, params)).toBe(false); |
| 60 | + }); |
| 61 | +}); |
0 commit comments