


























@@ -0,0 +1,58 @@
1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import type { RuntimeEnv } from "../runtime.js";
3+import { exportTrajectoryCommand } from "./export-trajectory.js";
4+5+const mocks = vi.hoisted(() => ({
6+loadSessionStore: vi.fn(),
7+resolveDefaultSessionStorePath: vi.fn(),
8+}));
9+10+vi.mock("../config/sessions/store.js", () => ({
11+loadSessionStore: mocks.loadSessionStore,
12+}));
13+14+vi.mock("../config/sessions/paths.js", async (importOriginal) => {
15+const actual = await importOriginal<typeof import("../config/sessions/paths.js")>();
16+return {
17+ ...actual,
18+resolveDefaultSessionStorePath: mocks.resolveDefaultSessionStorePath,
19+};
20+});
21+22+function createRuntime(): RuntimeEnv {
23+return {
24+log: vi.fn(),
25+error: vi.fn(),
26+exit: vi.fn(),
27+} as unknown as RuntimeEnv;
28+}
29+30+describe("exportTrajectoryCommand", () => {
31+beforeEach(() => {
32+vi.clearAllMocks();
33+mocks.resolveDefaultSessionStorePath.mockReturnValue("/tmp/openclaw/sessions.json");
34+mocks.loadSessionStore.mockReturnValue({});
35+});
36+37+it("points missing session key users at the sessions command", async () => {
38+const runtime = createRuntime();
39+40+await exportTrajectoryCommand({}, runtime);
41+42+expect(runtime.error).toHaveBeenCalledWith(
43+"--session-key is required. Run openclaw sessions to choose a session.",
44+);
45+expect(runtime.exit).toHaveBeenCalledWith(1);
46+});
47+48+it("points missing session users at the sessions command", async () => {
49+const runtime = createRuntime();
50+51+await exportTrajectoryCommand({ sessionKey: "agent:main:telegram:direct:123" }, runtime);
52+53+expect(runtime.error).toHaveBeenCalledWith(
54+"Session not found: agent:main:telegram:direct:123. Run openclaw sessions to see available sessions.",
55+);
56+expect(runtime.exit).toHaveBeenCalledWith(1);
57+});
58+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。