|
| 1 | +import { beforeEach, describe, expect, it } from "vitest"; |
| 2 | +import type { SkillSnapshot } from "../../agents/skills.js"; |
| 3 | +import type { CronJob } from "../types.js"; |
| 4 | +import { |
| 5 | + mockRunCronFallbackPassthrough, |
| 6 | + resetRunCronIsolatedAgentTurnHarness, |
| 7 | + runEmbeddedPiAgentMock, |
| 8 | +} from "./run.test-harness.js"; |
| 9 | + |
| 10 | +const { createCronPromptExecutor } = await import("./run-executor.js"); |
| 11 | + |
| 12 | +type ExecutorParams = Parameters<typeof createCronPromptExecutor>[0]; |
| 13 | +type AgentTurnPayload = Extract<CronJob["payload"], { kind: "agentTurn" }>; |
| 14 | + |
| 15 | +const agentPayload: AgentTurnPayload = { kind: "agentTurn", message: "do it" }; |
| 16 | + |
| 17 | +const job: CronJob = { |
| 18 | + id: "job-1", |
| 19 | + name: "silent delivery", |
| 20 | + enabled: true, |
| 21 | + createdAtMs: 0, |
| 22 | + updatedAtMs: 0, |
| 23 | + schedule: { kind: "every", everyMs: 60_000 }, |
| 24 | + sessionTarget: "isolated", |
| 25 | + wakeMode: "now", |
| 26 | + payload: agentPayload, |
| 27 | + delivery: { mode: "none" }, |
| 28 | + state: {}, |
| 29 | +}; |
| 30 | + |
| 31 | +function makeExecutorParams( |
| 32 | + overrides?: Partial<ExecutorParams>, |
| 33 | +): ExecutorParams { |
| 34 | + return { |
| 35 | + cfg: {}, |
| 36 | + cfgWithAgentDefaults: {}, |
| 37 | + job, |
| 38 | + agentId: "agent-1", |
| 39 | + agentDir: "/tmp/agent", |
| 40 | + agentSessionKey: "agent:agent-1:main", |
| 41 | + runSessionKey: "agent:agent-1:cron:job-1:run:run-1", |
| 42 | + workspaceDir: "/tmp/workspace", |
| 43 | + lane: "cron", |
| 44 | + resolvedVerboseLevel: "off", |
| 45 | + thinkLevel: undefined, |
| 46 | + timeoutMs: 60_000, |
| 47 | + messageChannel: undefined, |
| 48 | + suppressExecNotifyOnExit: true, |
| 49 | + senderIsOwner: true, |
| 50 | + allowEmptyAssistantReplyAsSilent: true, |
| 51 | + resolvedDelivery: {}, |
| 52 | + toolPolicy: { |
| 53 | + requireExplicitMessageTarget: false, |
| 54 | + disableMessageTool: true, |
| 55 | + forceMessageTool: false, |
| 56 | + }, |
| 57 | + skillsSnapshot: { prompt: "", skills: [] } satisfies SkillSnapshot, |
| 58 | + agentPayload, |
| 59 | + liveSelection: { provider: "openai", model: "gpt-5.5" }, |
| 60 | + cronSession: { |
| 61 | + storePath: "/tmp/store.json", |
| 62 | + store: {}, |
| 63 | + systemSent: false, |
| 64 | + isNewSession: true, |
| 65 | + previousSessionId: undefined, |
| 66 | + sessionEntry: { |
| 67 | + sessionId: "run-1", |
| 68 | + updatedAt: 0, |
| 69 | + systemSent: false, |
| 70 | + skillsSnapshot: undefined, |
| 71 | + }, |
| 72 | + }, |
| 73 | + abortReason: () => "aborted", |
| 74 | + ...overrides, |
| 75 | + }; |
| 76 | +} |
| 77 | + |
| 78 | +describe("createCronPromptExecutor silent delivery", () => { |
| 79 | + beforeEach(() => { |
| 80 | + resetRunCronIsolatedAgentTurnHarness(); |
| 81 | + mockRunCronFallbackPassthrough(); |
| 82 | + }); |
| 83 | + |
| 84 | + it("passes delivery.mode none through as empty assistant silent success", async () => { |
| 85 | + const executor = createCronPromptExecutor(makeExecutorParams()); |
| 86 | + |
| 87 | + await executor.runPrompt("do it"); |
| 88 | + |
| 89 | + const call = runEmbeddedPiAgentMock.mock.calls.at(-1)?.[0] as |
| 90 | + | { allowEmptyAssistantReplyAsSilent?: boolean } |
| 91 | + | undefined; |
| 92 | + expect(call?.allowEmptyAssistantReplyAsSilent).toBe(true); |
| 93 | + }); |
| 94 | +}); |
0 commit comments