fix(export): preserve explicit trajectory session keys (#83308)

This commit is contained in:
Gio Della-Libera 2026-05-18 16:48:23 -07:00 committed by GitHub
parent 567fe2957d
commit 87aa319568
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 7 deletions

View file

@ -57,6 +57,32 @@ describe("exportTrajectoryCommand", () => {
expect(runtime.exit).toHaveBeenCalledWith(1);
});
it("preserves direct options when an encoded request omits them", async () => {
const runtime = createRuntime();
const requestJsonBase64 = Buffer.from(
JSON.stringify({ output: "/tmp/export.json" }),
"utf8",
).toString("base64url");
await exportTrajectoryCommand(
{
requestJsonBase64,
sessionKey: "agent:main:telegram:direct:123",
store: "/tmp/direct-store.json",
},
runtime,
);
expect(mocks.resolveDefaultSessionStorePath).not.toHaveBeenCalled();
expect(mocks.loadSessionStore).toHaveBeenCalledWith("/tmp/direct-store.json", {
skipCache: true,
});
expect(runtime.error).toHaveBeenCalledWith(
"Session not found: agent:main:telegram:direct:123. Run openclaw sessions to see available sessions.",
);
expect(runtime.exit).toHaveBeenCalledWith(1);
});
it("points missing session users at the sessions command", async () => {
const runtime = createRuntime();

View file

@ -56,13 +56,28 @@ function decodeExportTrajectoryRequest(encoded: string): Partial<ExportTrajector
throw new Error("Encoded trajectory export request must be a JSON object");
}
const request = decoded as EncodedExportTrajectoryRequest;
return {
sessionKey: readOptionalString(request.sessionKey) ?? "",
output: readOptionalString(request.output),
store: readOptionalString(request.store),
agent: readOptionalString(request.agent),
workspace: readOptionalString(request.workspace),
};
const opts: Partial<ExportTrajectoryCommandOptions> = {};
const sessionKey = readOptionalString(request.sessionKey);
if (sessionKey !== undefined) {
opts.sessionKey = sessionKey;
}
const output = readOptionalString(request.output);
if (output !== undefined) {
opts.output = output;
}
const store = readOptionalString(request.store);
if (store !== undefined) {
opts.store = store;
}
const agent = readOptionalString(request.agent);
if (agent !== undefined) {
opts.agent = agent;
}
const workspace = readOptionalString(request.workspace);
if (workspace !== undefined) {
opts.workspace = workspace;
}
return opts;
}
function resolveExportTrajectoryOptions(