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