mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 09:02:15 +00:00
test: stabilize vitest mocks and harness typing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { join } from "node:path";
|
||||
import { afterEach, vi } from "vitest";
|
||||
import { afterEach, type MockInstance, vi } from "vitest";
|
||||
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
||||
|
||||
const piEmbeddedMocks = vi.hoisted(() => ({
|
||||
@@ -11,19 +11,19 @@ const piEmbeddedMocks = vi.hoisted(() => ({
|
||||
isEmbeddedPiRunStreaming: vi.fn().mockReturnValue(false),
|
||||
}));
|
||||
|
||||
export function getAbortEmbeddedPiRunMock() {
|
||||
export function getAbortEmbeddedPiRunMock(): MockInstance {
|
||||
return piEmbeddedMocks.abortEmbeddedPiRun;
|
||||
}
|
||||
|
||||
export function getCompactEmbeddedPiSessionMock() {
|
||||
export function getCompactEmbeddedPiSessionMock(): MockInstance {
|
||||
return piEmbeddedMocks.compactEmbeddedPiSession;
|
||||
}
|
||||
|
||||
export function getRunEmbeddedPiAgentMock() {
|
||||
export function getRunEmbeddedPiAgentMock(): MockInstance {
|
||||
return piEmbeddedMocks.runEmbeddedPiAgent;
|
||||
}
|
||||
|
||||
export function getQueueEmbeddedPiMessageMock() {
|
||||
export function getQueueEmbeddedPiMessageMock(): MockInstance {
|
||||
return piEmbeddedMocks.queueEmbeddedPiMessage;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ const providerUsageMocks = vi.hoisted(() => ({
|
||||
resolveUsageProviderId: vi.fn((provider: string) => provider.split("/")[0]),
|
||||
}));
|
||||
|
||||
export function getProviderUsageMocks() {
|
||||
export function getProviderUsageMocks(): Record<string, MockInstance> {
|
||||
return providerUsageMocks;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ const modelCatalogMocks = vi.hoisted(() => ({
|
||||
resetModelCatalogCacheForTest: vi.fn(),
|
||||
}));
|
||||
|
||||
export function getModelCatalogMocks() {
|
||||
export function getModelCatalogMocks(): Record<string, MockInstance> {
|
||||
return modelCatalogMocks;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ const webSessionMocks = vi.hoisted(() => ({
|
||||
readWebSelfId: vi.fn().mockReturnValue({ e164: "+1999" }),
|
||||
}));
|
||||
|
||||
export function getWebSessionMocks() {
|
||||
export function getWebSessionMocks(): Record<string, MockInstance> {
|
||||
return webSessionMocks;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { beforeEach, type MockInstance, vi } from "vitest";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import type { TypingMode } from "../../config/types.js";
|
||||
import type { TemplateContext } from "../templating.js";
|
||||
@@ -10,7 +10,7 @@ const state = vi.hoisted(() => ({
|
||||
runEmbeddedPiAgentMock: vi.fn(),
|
||||
}));
|
||||
|
||||
export function getRunEmbeddedPiAgentMock() {
|
||||
export function getRunEmbeddedPiAgentMock(): MockInstance {
|
||||
return state.runEmbeddedPiAgentMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runReplyAgent } from "./agent-runner.js";
|
||||
import {
|
||||
createBaseRun,
|
||||
getRunEmbeddedPiAgentMock,
|
||||
@@ -13,6 +12,7 @@ import { DEFAULT_MEMORY_FLUSH_PROMPT } from "./memory-flush.js";
|
||||
|
||||
describe("runReplyAgent memory flush", () => {
|
||||
it("increments compaction count when flush compaction completes", async () => {
|
||||
const { runReplyAgent } = await import("./agent-runner.js");
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
runEmbeddedPiAgentMock.mockReset();
|
||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-flush-"));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runReplyAgent } from "./agent-runner.js";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createBaseRun,
|
||||
getRunEmbeddedPiAgentMock,
|
||||
@@ -11,6 +10,12 @@ import {
|
||||
} from "./agent-runner.memory-flush.test-harness.js";
|
||||
import { DEFAULT_MEMORY_FLUSH_PROMPT } from "./memory-flush.js";
|
||||
|
||||
let runReplyAgent: typeof import("./agent-runner.js").runReplyAgent;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ runReplyAgent } = await import("./agent-runner.js"));
|
||||
});
|
||||
|
||||
describe("runReplyAgent memory flush", () => {
|
||||
it("runs a memory flush turn and updates session metadata", async () => {
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
|
||||
@@ -2,7 +2,6 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runReplyAgent } from "./agent-runner.js";
|
||||
import {
|
||||
createBaseRun,
|
||||
getRunCliAgentMock,
|
||||
@@ -13,6 +12,7 @@ import {
|
||||
|
||||
describe("runReplyAgent memory flush", () => {
|
||||
it("skips memory flush for CLI providers", async () => {
|
||||
const { runReplyAgent } = await import("./agent-runner.js");
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
const runCliAgentMock = getRunCliAgentMock();
|
||||
runEmbeddedPiAgentMock.mockReset();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runReplyAgent } from "./agent-runner.js";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createBaseRun,
|
||||
getRunEmbeddedPiAgentMock,
|
||||
@@ -10,6 +9,12 @@ import {
|
||||
type EmbeddedRunParams,
|
||||
} from "./agent-runner.memory-flush.test-harness.js";
|
||||
|
||||
let runReplyAgent: typeof import("./agent-runner.js").runReplyAgent;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ runReplyAgent } = await import("./agent-runner.js"));
|
||||
});
|
||||
|
||||
describe("runReplyAgent memory flush", () => {
|
||||
it("skips memory flush when the sandbox workspace is read-only", async () => {
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runReplyAgent } from "./agent-runner.js";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createBaseRun,
|
||||
getRunEmbeddedPiAgentMock,
|
||||
@@ -11,6 +10,12 @@ import {
|
||||
} from "./agent-runner.memory-flush.test-harness.js";
|
||||
import { DEFAULT_MEMORY_FLUSH_PROMPT } from "./memory-flush.js";
|
||||
|
||||
let runReplyAgent: typeof import("./agent-runner.js").runReplyAgent;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ runReplyAgent } = await import("./agent-runner.js"));
|
||||
});
|
||||
|
||||
describe("runReplyAgent memory flush", () => {
|
||||
it("uses configured prompts for memory flush runs", async () => {
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { vi } from "vitest";
|
||||
import { type MockInstance, vi } from "vitest";
|
||||
import type { TemplateContext } from "../templating.js";
|
||||
import type { FollowupRun, QueueSettings } from "./queue.js";
|
||||
import { createMockTypingController } from "./test-helpers.js";
|
||||
@@ -16,11 +16,11 @@ const state = vi.hoisted(() => ({
|
||||
runCliAgentMock: vi.fn(),
|
||||
}));
|
||||
|
||||
export function getRunEmbeddedPiAgentMock() {
|
||||
export function getRunEmbeddedPiAgentMock(): MockInstance {
|
||||
return state.runEmbeddedPiAgentMock;
|
||||
}
|
||||
|
||||
export function getRunCliAgentMock() {
|
||||
export function getRunCliAgentMock(): MockInstance {
|
||||
return state.runCliAgentMock;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user