mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:00:43 +00:00
test: share export command session mocks
This commit is contained in:
@@ -1,33 +1,26 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HandleCommandsParams } from "./commands-types.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
resolveDefaultSessionStorePathMock: vi.fn(() => "/tmp/target-store/sessions.json"),
|
||||
resolveSessionFilePathMock: vi.fn(() => "/tmp/target-store/session.jsonl"),
|
||||
resolveSessionFilePathOptionsMock: vi.fn(
|
||||
(params: { agentId: string; storePath: string }) => params,
|
||||
),
|
||||
loadSessionStoreMock: vi.fn(() => ({
|
||||
"agent:target:session": {
|
||||
sessionId: "session-1",
|
||||
updatedAt: 1,
|
||||
},
|
||||
})),
|
||||
resolveCommandsSystemPromptBundleMock: vi.fn(async () => ({
|
||||
systemPrompt: "system prompt",
|
||||
tools: [],
|
||||
skillsPrompt: "",
|
||||
bootstrapFiles: [],
|
||||
injectedFiles: [],
|
||||
sandboxRuntime: { sandboxed: false, mode: "off" },
|
||||
})),
|
||||
getEntriesMock: vi.fn(() => []),
|
||||
getHeaderMock: vi.fn(() => null),
|
||||
getLeafIdMock: vi.fn(() => null),
|
||||
writeFileSyncMock: vi.fn(),
|
||||
mkdirSyncMock: vi.fn(),
|
||||
existsSyncMock: vi.fn(() => true),
|
||||
}));
|
||||
const hoisted = await vi.hoisted(async () => {
|
||||
const { createExportCommandSessionMocks } = await import("./commands-export-test-mocks.js");
|
||||
return {
|
||||
...createExportCommandSessionMocks(vi),
|
||||
resolveCommandsSystemPromptBundleMock: vi.fn(async () => ({
|
||||
systemPrompt: "system prompt",
|
||||
tools: [],
|
||||
skillsPrompt: "",
|
||||
bootstrapFiles: [],
|
||||
injectedFiles: [],
|
||||
sandboxRuntime: { sandboxed: false, mode: "off" },
|
||||
})),
|
||||
getEntriesMock: vi.fn(() => []),
|
||||
getHeaderMock: vi.fn(() => null),
|
||||
getLeafIdMock: vi.fn(() => null),
|
||||
writeFileSyncMock: vi.fn(),
|
||||
mkdirSyncMock: vi.fn(),
|
||||
existsSyncMock: vi.fn(() => true),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@mariozechner/pi-coding-agent", () => ({
|
||||
SessionManager: {
|
||||
|
||||
19
src/auto-reply/reply/commands-export-test-mocks.ts
Normal file
19
src/auto-reply/reply/commands-export-test-mocks.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { vi } from "vitest";
|
||||
|
||||
type ViLike = Pick<typeof vi, "fn">;
|
||||
|
||||
export function createExportCommandSessionMocks(viInstance: ViLike) {
|
||||
return {
|
||||
resolveDefaultSessionStorePathMock: viInstance.fn(() => "/tmp/target-store/sessions.json"),
|
||||
resolveSessionFilePathMock: viInstance.fn(() => "/tmp/target-store/session.jsonl"),
|
||||
resolveSessionFilePathOptionsMock: viInstance.fn(
|
||||
(params: { agentId: string; storePath: string }) => params,
|
||||
),
|
||||
loadSessionStoreMock: viInstance.fn(() => ({
|
||||
"agent:target:session": {
|
||||
sessionId: "session-1",
|
||||
updatedAt: 1,
|
||||
},
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -4,36 +4,29 @@ import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { HandleCommandsParams } from "./commands-types.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
resolveDefaultSessionStorePathMock: vi.fn(() => "/tmp/target-store/sessions.json"),
|
||||
resolveSessionFilePathMock: vi.fn(() => "/tmp/target-store/session.jsonl"),
|
||||
resolveSessionFilePathOptionsMock: vi.fn(
|
||||
(params: { agentId: string; storePath: string }) => params,
|
||||
),
|
||||
loadSessionStoreMock: vi.fn(() => ({
|
||||
"agent:target:session": {
|
||||
sessionId: "session-1",
|
||||
updatedAt: 1,
|
||||
},
|
||||
})),
|
||||
exportTrajectoryBundleMock: vi.fn(() => ({
|
||||
outputDir: "/tmp/workspace/.openclaw/trajectory-exports/openclaw-trajectory-session",
|
||||
manifest: {
|
||||
eventCount: 7,
|
||||
runtimeEventCount: 3,
|
||||
transcriptEventCount: 4,
|
||||
},
|
||||
events: [{ type: "context.compiled" }],
|
||||
runtimeFile: "/tmp/target-store/session.trajectory.jsonl",
|
||||
supplementalFiles: ["metadata.json", "artifacts.json", "prompts.json"],
|
||||
})),
|
||||
resolveDefaultTrajectoryExportDirMock: vi.fn(
|
||||
() => "/tmp/workspace/.openclaw/trajectory-exports/openclaw-trajectory-session",
|
||||
),
|
||||
existsSyncMock: vi.fn((file: fs.PathLike, actualExistsSync: (path: fs.PathLike) => boolean) =>
|
||||
actualExistsSync(file),
|
||||
),
|
||||
}));
|
||||
const hoisted = await vi.hoisted(async () => {
|
||||
const { createExportCommandSessionMocks } = await import("./commands-export-test-mocks.js");
|
||||
return {
|
||||
...createExportCommandSessionMocks(vi),
|
||||
exportTrajectoryBundleMock: vi.fn(() => ({
|
||||
outputDir: "/tmp/workspace/.openclaw/trajectory-exports/openclaw-trajectory-session",
|
||||
manifest: {
|
||||
eventCount: 7,
|
||||
runtimeEventCount: 3,
|
||||
transcriptEventCount: 4,
|
||||
},
|
||||
events: [{ type: "context.compiled" }],
|
||||
runtimeFile: "/tmp/target-store/session.trajectory.jsonl",
|
||||
supplementalFiles: ["metadata.json", "artifacts.json", "prompts.json"],
|
||||
})),
|
||||
resolveDefaultTrajectoryExportDirMock: vi.fn(
|
||||
() => "/tmp/workspace/.openclaw/trajectory-exports/openclaw-trajectory-session",
|
||||
),
|
||||
existsSyncMock: vi.fn((file: fs.PathLike, actualExistsSync: (path: fs.PathLike) => boolean) =>
|
||||
actualExistsSync(file),
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../config/sessions/paths.js", () => ({
|
||||
resolveDefaultSessionStorePath: hoisted.resolveDefaultSessionStorePathMock,
|
||||
|
||||
Reference in New Issue
Block a user