



























@@ -1,7 +1,7 @@
11import fs from "node:fs/promises";
22import path from "node:path";
33import { expect, test } from "vitest";
4-import { embeddedRunMock, writeSessionStore } from "./test-helpers.js";
4+import { embeddedRunMock, testState, writeSessionStore } from "./test-helpers.js";
55import {
66setupGatewaySessionsTestHarness,
77bootstrapCacheMocks,
@@ -410,6 +410,68 @@ test("sessions.create with emitCommandHooks=true emits reset lifecycle hooks aga
410410);
411411});
412412413+test("sessions.create with emitCommandHooks=true resets parent in place when session.dmScope is 'main' (#77434)", async () => {
414+const { dir } = await createSessionStoreDir();
415+const transcriptPath = path.join(dir, "sess-parent-dms.jsonl");
416+await fs.writeFile(
417+transcriptPath,
418+`${JSON.stringify({
419+ type: "message",
420+ id: "m1",
421+ message: { role: "user", content: "hello before /new" },
422+ })}\n`,
423+"utf-8",
424+);
425+426+testState.sessionConfig = { dmScope: "main" };
427+try {
428+await writeSessionStore({
429+entries: {
430+main: {
431+sessionId: "sess-parent-dms",
432+sessionFile: transcriptPath,
433+updatedAt: Date.now(),
434+},
435+},
436+});
437+438+const result = await directSessionReq<{
439+ok: boolean;
440+key: string;
441+sessionId: string;
442+runStarted: boolean;
443+}>("sessions.create", {
444+parentSessionKey: "main",
445+emitCommandHooks: true,
446+});
447+expect(result.ok).toBe(true);
448+// Reset-in-place: response key matches the parent main key, NOT a dashboard child.
449+expect(result.payload?.key).toBe("agent:main:main");
450+expect(result.payload?.runStarted).toBe(false);
451+expect(result.payload?.sessionId).not.toBe("sess-parent-dms");
452+453+expect(sessionLifecycleHookMocks.runSessionEnd).toHaveBeenCalledTimes(1);
454+expect(sessionLifecycleHookMocks.runSessionStart).toHaveBeenCalledTimes(1);
455+const [endEvent] = (
456+sessionLifecycleHookMocks.runSessionEnd.mock.calls as unknown as Array<[unknown, unknown]>
457+)[0] ?? [undefined, undefined];
458+const [startEvent] = (
459+sessionLifecycleHookMocks.runSessionStart.mock.calls as unknown as Array<[unknown, unknown]>
460+)[0] ?? [undefined, undefined];
461+expect(endEvent).toMatchObject({
462+sessionId: "sess-parent-dms",
463+sessionKey: "agent:main:main",
464+reason: "new",
465+});
466+expect(startEvent).toMatchObject({
467+sessionKey: "agent:main:main",
468+resumedFrom: "sess-parent-dms",
469+});
470+} finally {
471+testState.sessionConfig = undefined;
472+}
473+});
474+413475test("sessions.create without emitCommandHooks does not fire command:new hook (#76957)", async () => {
414476const { dir } = await createSessionStoreDir();
415477await writeSingleLineSession(dir, "sess-parent2", "hello from parent 2");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。