

























@@ -28,6 +28,22 @@ function createDueMainJob(params: { now: number; wakeMode: CronJob["wakeMode"] }
2828};
2929}
303031+function createDueIsolatedAgentJob(params: { now: number }): CronJob {
32+return {
33+id: "isolated-agent-job",
34+agentId: "finn",
35+name: "isolated agent job",
36+enabled: true,
37+createdAtMs: params.now - 60_000,
38+updatedAtMs: params.now - 60_000,
39+schedule: { kind: "every", everyMs: 60_000, anchorMs: params.now - 60_000 },
40+sessionTarget: "isolated",
41+wakeMode: "now",
42+payload: { kind: "agentTurn", message: "run isolated cron" },
43+state: { nextRunAtMs: params.now - 1 },
44+};
45+}
46+3147afterEach(() => {
3248resetTaskRegistryForTests();
3349});
@@ -108,6 +124,49 @@ describe("cron service timer seam coverage", () => {
108124timeoutSpy.mockRestore();
109125});
110126127+it("records isolated cron task runs against the backing cron session", async () => {
128+const { storePath } = await makeStorePath();
129+const now = Date.parse("2026-03-23T12:00:00.000Z");
130+const enqueueSystemEvent = vi.fn();
131+const requestHeartbeat = vi.fn();
132+const runIsolatedAgentJob = vi.fn(async () => ({
133+status: "ok" as const,
134+summary: "done",
135+sessionKey: "agent:finn:cron:isolated-agent-job:run:run-1",
136+}));
137+138+await writeCronStoreSnapshot({
139+ storePath,
140+jobs: [createDueIsolatedAgentJob({ now })],
141+});
142+143+const state = createCronServiceState({
144+ storePath,
145+cronEnabled: true,
146+log: logger,
147+nowMs: () => now,
148+ enqueueSystemEvent,
149+ requestHeartbeat,
150+ runIsolatedAgentJob,
151+});
152+153+await onTimer(state);
154+155+expect(runIsolatedAgentJob).toHaveBeenCalledWith(
156+expect.objectContaining({
157+job: expect.objectContaining({ id: "isolated-agent-job" }),
158+message: "run isolated cron",
159+}),
160+);
161+const task = findTaskByRunId(`cron:isolated-agent-job:${now}`);
162+if (!task) {
163+throw new Error("expected isolated cron task ledger record");
164+}
165+expect(task.childSessionKey).toBe("agent:finn:cron:isolated-agent-job");
166+expect(task.status).toBe("succeeded");
167+expect(task.terminalSummary).toBe("done");
168+});
169+111170it("keeps scheduler progress when task ledger creation fails", async () => {
112171const { storePath } = await makeStorePath();
113172const now = Date.parse("2026-03-23T12:00:00.000Z");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。