Cron: isolate active-model delivery tests

This commit is contained in:
Gustavo Madeira Santana
2026-03-16 11:39:15 +00:00
parent ccba943738
commit d6aa9b516e
5 changed files with 37 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import "./isolated-agent.mocks.js";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
import * as modelSelection from "../agents/model-selection.js";
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
import type { CliDeps } from "../cli/deps.js";
@@ -72,6 +73,7 @@ async function runTelegramAnnounceTurn(params: {
describe("runCronIsolatedAgentTurn", () => {
beforeEach(() => {
vi.spyOn(modelSelection, "resolveThinkingDefault").mockReturnValue(undefined);
setupIsolatedAgentTurnMocks({ fast: true });
});

View File

@@ -1,6 +1,7 @@
import "./isolated-agent.mocks.js";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { loadModelCatalog } from "../agents/model-catalog.js";
import * as modelSelection from "../agents/model-selection.js";
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
import { createCliDeps, mockAgentPayloads } from "./isolated-agent.delivery.test-helpers.js";
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
@@ -125,6 +126,7 @@ async function expectInvalidModel(home: string, model: string) {
describe("cron model formatting and precedence edge cases", () => {
beforeEach(() => {
vi.spyOn(modelSelection, "resolveThinkingDefault").mockReturnValue(undefined);
vi.mocked(runEmbeddedPiAgent).mockClear();
vi.mocked(loadModelCatalog).mockResolvedValue([]);
});

View File

@@ -1,6 +1,7 @@
import "./isolated-agent.mocks.js";
import fs from "node:fs/promises";
import { beforeEach, describe, expect, it, vi } from "vitest";
import * as modelSelection from "../agents/model-selection.js";
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
import type { CliDeps } from "../cli/deps.js";
import {
@@ -261,6 +262,7 @@ async function assertExplicitTelegramTargetDelivery(params: {
describe("runCronIsolatedAgentTurn", () => {
beforeEach(() => {
vi.spyOn(modelSelection, "resolveThinkingDefault").mockReturnValue(undefined);
setupIsolatedAgentTurnMocks();
});

View File

@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { loadModelCatalog } from "../agents/model-catalog.js";
import * as modelSelection from "../agents/model-selection.js";
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
import type { CliDeps } from "../cli/deps.js";
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
@@ -15,6 +16,10 @@ import {
} from "./isolated-agent.test-harness.js";
import type { CronJob } from "./types.js";
let resolveThinkingDefaultSpy: ReturnType<
typeof vi.spyOn<typeof modelSelection, "resolveThinkingDefault">
>;
function makeDeps(): CliDeps {
return {
sendMessageSlack: vi.fn(),
@@ -163,6 +168,9 @@ async function runStoredOverrideAndExpectModel(params: {
describe("runCronIsolatedAgentTurn", () => {
beforeEach(() => {
resolveThinkingDefaultSpy = vi
.spyOn(modelSelection, "resolveThinkingDefault")
.mockReturnValue(undefined);
vi.mocked(runEmbeddedPiAgent).mockClear();
vi.mocked(loadModelCatalog).mockResolvedValue([]);
});
@@ -503,16 +511,9 @@ describe("runCronIsolatedAgentTurn", () => {
});
});
it("defaults thinking to low for reasoning-capable models", async () => {
it("passes through the resolved default thinking level", async () => {
await withTempHome(async (home) => {
vi.mocked(loadModelCatalog).mockResolvedValueOnce([
{
id: "claude-opus-4-5",
name: "Opus 4.5",
provider: "anthropic",
reasoning: true,
},
]);
resolveThinkingDefaultSpy.mockReturnValueOnce("low");
await runCronTurn(home, {
jobPayload: DEFAULT_AGENT_TURN_PAYLOAD,

View File

@@ -171,6 +171,27 @@ async function resolveCronDeliveryContext(params: {
deliveryContract: IsolatedDeliveryContract;
}) {
const deliveryPlan = resolveCronDeliveryPlan(params.job);
if (!deliveryPlan.requested) {
const resolvedDelivery = {
ok: false as const,
channel: undefined,
to: undefined,
accountId: undefined,
threadId: undefined,
mode: "implicit" as const,
error: new Error("cron delivery not requested"),
};
return {
deliveryPlan,
deliveryRequested: false,
resolvedDelivery,
toolPolicy: resolveCronToolPolicy({
deliveryRequested: false,
resolvedDelivery,
deliveryContract: params.deliveryContract,
}),
};
}
const resolvedDelivery = await resolveDeliveryTarget(params.cfg, params.agentId, {
channel: deliveryPlan.channel ?? "last",
to: deliveryPlan.to,