
























@@ -1,6 +1,8 @@
11import { afterEach, beforeEach, describe, expect, it } from "vitest";
22import {
33clearFastTestEnv,
4+getCliSessionIdMock,
5+isCliProviderMock,
46loadRunCronIsolatedAgentTurn,
57makeCronSession,
68makeCronSessionEntry,
@@ -17,6 +19,7 @@ import {
1719runEmbeddedPiAgentMock,
1820runWithModelFallbackMock,
1921updateSessionStoreMock,
22+runCliAgentMock,
2023} from "./run.test-harness.js";
21242225const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
@@ -67,6 +70,16 @@ function makeSuccessfulRunResult(provider = "google", model = "gemini-2.0-flash"
6770};
6871}
697273+function createDeferred<T = void>() {
74+let resolve!: (value: T | PromiseLike<T>) => void;
75+let reject!: (reason?: unknown) => void;
76+const promise = new Promise<T>((res, rej) => {
77+resolve = res;
78+reject = rej;
79+});
80+return { promise, resolve, reject };
81+}
82+7083// ---------- tests ----------
71847285describe("runCronIsolatedAgentTurn — cron model override forwarding (#58065)", () => {
@@ -187,6 +200,74 @@ describe("runCronIsolatedAgentTurn — cron model override forwarding (#58065)",
187200);
188201});
189202203+it("does not mark CLI cron runs as model-started before CLI session resolution", async () => {
204+isCliProviderMock.mockReturnValue(true);
205+runWithModelFallbackMock.mockImplementation(async ({ provider, model, run }) => {
206+const result = await run(provider, model);
207+return { result, provider, model, attempts: [] };
208+});
209+resolveCronSessionMock.mockReturnValue(
210+makeCronSession({
211+sessionEntry: makeCronSessionEntry({
212+model: undefined,
213+modelProvider: undefined,
214+}),
215+isNewSession: false,
216+}),
217+);
218+const getCliSessionStarted = createDeferred();
219+const releaseCliSessionLookup = createDeferred<string | undefined>();
220+getCliSessionIdMock.mockImplementation(async () => {
221+getCliSessionStarted.resolve();
222+return await releaseCliSessionLookup.promise;
223+});
224+runCliAgentMock.mockImplementation(async ({ onExecutionPhase }) => {
225+onExecutionPhase?.({
226+phase: "model_call_started",
227+provider: "google",
228+model: "gemini-2.0-flash",
229+firstModelCallStarted: true,
230+});
231+return {
232+payloads: [{ text: "summary done" }],
233+meta: { agentMeta: { usage: { input: 10, output: 20 } } },
234+};
235+});
236+const phases: unknown[] = [];
237+238+const runPromise = runCronIsolatedAgentTurn(
239+makeParams({
240+job: makeJob({ sessionTarget: "session:existing-cron-session" }),
241+onExecutionPhase: (info: unknown) => phases.push(info),
242+}),
243+);
244+245+await getCliSessionStarted.promise;
246+expect(phases).not.toContainEqual(
247+expect.objectContaining({
248+phase: "model_call_started",
249+firstModelCallStarted: true,
250+}),
251+);
252+253+releaseCliSessionLookup.resolve("previous-cli-session");
254+const result = await runPromise;
255+256+expect(result.status).toBe("ok");
257+expect(runCliAgentMock).toHaveBeenCalledWith(
258+expect.objectContaining({
259+cliSessionId: "previous-cli-session",
260+onExecutionPhase: expect.any(Function),
261+}),
262+);
263+expect(phases).toContainEqual(
264+expect.objectContaining({
265+phase: "model_call_started",
266+firstModelCallStarted: true,
267+}),
268+);
269+});
270+190271it("validates cron thinking with catalog reasoning metadata", async () => {
191272resolveAllowedModelRefMock.mockImplementation(() => ({
192273ref: { provider: "ollama", model: "qwen3:0.6b" },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。