Prefer active store path for session export

This commit is contained in:
Tak Hoffman
2026-04-10 19:52:14 -05:00
parent de74d843f5
commit 0c0cb1a3c0
2 changed files with 25 additions and 1 deletions

View File

@@ -140,4 +140,28 @@ describe("buildExportSessionReply", () => {
storePath: "/tmp/target-store/sessions.json",
});
});
it("prefers the active command storePath over the default target-agent store", async () => {
const { buildExportSessionReply } = await import("./commands-export-session.js");
hoisted.loadSessionStoreMock.mockReturnValue({
"agent:target:session": {
sessionId: "session-1",
updatedAt: 1,
},
});
await buildExportSessionReply({
...makeParams(),
storePath: "/tmp/custom-store/sessions.json",
});
expect(hoisted.resolveDefaultSessionStorePathMock).not.toHaveBeenCalled();
expect(hoisted.loadSessionStoreMock).toHaveBeenCalledWith("/tmp/custom-store/sessions.json", {
skipCache: true,
});
expect(hoisted.resolveSessionFilePathOptionsMock).toHaveBeenCalledWith({
agentId: "target",
storePath: "/tmp/custom-store/sessions.json",
});
});
});

View File

@@ -121,7 +121,7 @@ export async function buildExportSessionReply(params: HandleCommandsParams): Pro
}
const targetAgentId = resolveAgentIdFromSessionKey(params.sessionKey) || params.agentId;
const storePath = resolveDefaultSessionStorePath(targetAgentId);
const storePath = params.storePath ?? resolveDefaultSessionStorePath(targetAgentId);
const store = loadSessionStore(storePath, { skipCache: true });
const entry = store[params.sessionKey] as SessionEntry | undefined;
if (!entry?.sessionId) {