






















@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
33import path from "node:path";
44import { beforeEach, describe, expect, it, vi } from "vitest";
55import * as modelThinkingDefault from "../agents/model-thinking-default.js";
6+import type { SessionEntry } from "../config/sessions.js";
67import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
78import {
89makeCfg,
@@ -21,10 +22,13 @@ import {
2122} from "./isolated-agent.turn-test-helpers.js";
2223import { setupRunCronIsolatedAgentTurnSuite } from "./isolated-agent/run.suite-helpers.js";
2324import {
25+dispatchCronDeliveryMock,
2426mockRunCronFallbackPassthrough,
2527runEmbeddedPiAgentMock,
2628updateSessionStoreMock,
2729} from "./isolated-agent/run.test-harness.js";
30+import { normalizeCronJobCreate } from "./normalize.js";
31+import type { CronJob } from "./types.js";
28322933setupRunCronIsolatedAgentTurnSuite();
3034@@ -148,7 +152,7 @@ describe("runCronIsolatedAgentTurn session identity", () => {
148152});
149153});
150154151-it("persists rotated transcript identity for session-bound cron runs", async () => {
155+it("persists rotated transcript identity for current-bound cron runs", async () => {
152156await withTempHome(async (home) => {
153157const deps = makeDeps();
154158const boundSessionKey = "agent:main:telegram:direct:42";
@@ -177,34 +181,35 @@ describe("runCronIsolatedAgentTurn session identity", () => {
177181},
178182},
179183});
180-updateSessionStoreMock.mockImplementation(async (_storePath, update) => {
181-const store = {
182-[boundSessionKey]: {
183-sessionId: "bound-session",
184-sessionFile: originalSessionFile,
185-updatedAt: Date.now(),
186-lastInteractionAt: Date.now() - 1_000,
187-systemSent: true,
188-},
189-};
184+updateSessionStoreMock.mockImplementation(async (targetStorePath, update) => {
185+const raw = await fs.readFile(targetStorePath, "utf-8");
186+const store = JSON.parse(raw) as Record<string, SessionEntry>;
190187update(store);
188+await fs.writeFile(targetStorePath, JSON.stringify(store, null, 2), "utf-8");
191189});
190+const currentBoundJob = normalizeCronJobCreate(
191+{
192+ ...makeJob(DEFAULT_AGENT_TURN_PAYLOAD),
193+sessionTarget: "current",
194+delivery: { mode: "none" },
195+},
196+{ sessionContext: { sessionKey: boundSessionKey } },
197+) as CronJob;
192198193199const res = await runCronIsolatedAgentTurn({
194200cfg: makeCfg(home, storePath),
195201 deps,
196-job: {
197- ...makeJob(DEFAULT_AGENT_TURN_PAYLOAD),
198-sessionTarget: `session:${boundSessionKey}`,
199-delivery: { mode: "none" },
200-},
202+job: currentBoundJob,
201203message: DEFAULT_MESSAGE,
202204sessionKey: boundSessionKey,
203205lane: "cron",
204206});
205207206208expect(res.status).toBe("ok");
207209expect(res.sessionId).toBe("bound-session-rotated");
210+expect(dispatchCronDeliveryMock.mock.calls.at(-1)?.[0]).toEqual(
211+expect.objectContaining({ sessionId: "bound-session-rotated" }),
212+);
208213209214const finalPersist = updateSessionStoreMock.mock.calls.at(-1);
210215expect(finalPersist?.[0]).toBe(storePath);
@@ -218,6 +223,13 @@ describe("runCronIsolatedAgentTurn session identity", () => {
218223usageFamilySessionIds: ["bound-session", "bound-session-rotated"],
219224}),
220225);
226+227+await expect(readSessionEntry(storePath, boundSessionKey)).resolves.toEqual(
228+expect.objectContaining({
229+sessionId: "bound-session-rotated",
230+sessionFile: rotatedSessionFile,
231+}),
232+);
221233});
222234});
223235此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。