



















@@ -9,8 +9,12 @@ vi.mock("../../agents/auth-profiles/source-check.js", () => ({
99import {
1010clearFastTestEnv,
1111loadRunCronIsolatedAgentTurn,
12+makeCronSession,
13+makeCronSessionEntry,
1214resetRunCronIsolatedAgentTurnHarness,
15+resolveCronSessionMock,
1316restoreFastTestEnv,
17+runWithModelFallbackMock,
1418} from "./run.test-harness.js";
15191620const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
@@ -126,4 +130,55 @@ describe("runCronIsolatedAgentTurn diagnostic events", () => {
126130127131expect(events).toEqual([]);
128132});
133+134+it("emits final lifecycle events under the adopted run session id", async () => {
135+resolveCronSessionMock.mockReturnValue(
136+makeCronSession({
137+sessionEntry: makeCronSessionEntry({
138+sessionId: "fallback-run-session",
139+sessionFile: "/tmp/fallback-run-session.jsonl",
140+}),
141+}),
142+);
143+runWithModelFallbackMock.mockResolvedValue({
144+result: {
145+payloads: [{ text: "test output" }],
146+meta: {
147+agentMeta: {
148+sessionId: "persisted-run-session",
149+sessionFile: "/tmp/persisted-run-session.jsonl",
150+usage: { input: 10, output: 20 },
151+},
152+},
153+},
154+provider: "openai",
155+model: "gpt-5.4",
156+});
157+158+const events: EventRecord[] = [];
159+const unsubscribe = onDiagnosticEvent((evt) => {
160+const e = evt as EventRecord;
161+if (
162+e.type === "message.queued" ||
163+e.type === "session.state" ||
164+e.type === "message.processed"
165+) {
166+events.push(e);
167+}
168+});
169+170+try {
171+const result = await runCronIsolatedAgentTurn(makeParams());
172+expect(result.status).toBe("ok");
173+} finally {
174+unsubscribe();
175+}
176+177+expect(events).toMatchObject([
178+{ type: "message.queued", sessionId: "fallback-run-session" },
179+{ type: "session.state", state: "processing", sessionId: "fallback-run-session" },
180+{ type: "session.state", state: "idle", sessionId: "persisted-run-session" },
181+{ type: "message.processed", sessionId: "persisted-run-session" },
182+]);
183+});
129184});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。