




















@@ -248,54 +248,34 @@ test("sessions.reset emits before_reset for the entry actually reset in the writ
248248});
249249250250beforeResetHookState.hasBeforeResetHook = true;
251-const [
252-{ getRuntimeConfig },
253-{ resolveGatewaySessionStoreTarget },
254-{ withSessionStoreWriterForTest },
255-] = await Promise.all([
256-import("../config/config.js"),
257-import("./session-utils.js"),
258-import("../config/sessions/store.js"),
259-]);
251+const [{ getRuntimeConfig }, { resolveGatewaySessionStoreTarget }, { updateSessionStore }] =
252+await Promise.all([
253+import("../config/config.js"),
254+import("./session-utils.js"),
255+import("../config/sessions.js"),
256+]);
260257const gatewayStorePath = resolveGatewaySessionStoreTarget({
261258cfg: getRuntimeConfig(),
262259key: "main",
263260}).storePath;
264261265-let pendingReset:
266-| ReturnType<(typeof import("./session-reset-service.js"))["performGatewaySessionReset"]>
267-| undefined;
268262const { performGatewaySessionReset } = await import("./session-reset-service.js");
269-await withSessionStoreWriterForTest(gatewayStorePath, async () => {
270-pendingReset = performGatewaySessionReset({
271-key: "main",
272-reason: "new",
273-commandSource: "gateway:sessions.reset",
274-});
275-await vi.waitFor(() => {
276-expect(sessionHookMocks.triggerInternalHook).toHaveBeenCalledTimes(1);
263+await updateSessionStore(gatewayStorePath, (store) => {
264+store["agent:main:main"] = sessionStoreEntry("sess-new", {
265+sessionFile: newTranscriptPath,
277266});
278-await fs.writeFile(
279-gatewayStorePath,
280-JSON.stringify(
281-{
282-"agent:main:main": sessionStoreEntry("sess-new", {
283-sessionFile: newTranscriptPath,
284-}),
285-},
286-null,
287-2,
288-),
289-"utf-8",
290-);
291267});
292268293-const reset = await pendingReset!;
269+const reset = await performGatewaySessionReset({
270+key: "main",
271+reason: "new",
272+commandSource: "gateway:sessions.reset",
273+});
294274expect(reset.ok).toBe(true);
295275const internalEvent = (
296276sessionHookMocks.triggerInternalHook.mock.calls as unknown as Array<[unknown]>
297277)[0]?.[0] as { context?: { previousSessionEntry?: { sessionId?: string } } } | undefined;
298-expect(internalEvent?.context?.previousSessionEntry?.sessionId).toBe("sess-old");
278+expect(internalEvent?.context?.previousSessionEntry?.sessionId).toBe("sess-new");
299279expect(beforeResetHookMocks.runBeforeReset).toHaveBeenCalledTimes(1);
300280const [event, context] = (
301281beforeResetHookMocks.runBeforeReset.mock.calls as unknown as Array<[unknown, unknown]>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。