mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 22:31:36 +00:00
test: stabilize vitest mocks and harness typing
This commit is contained in:
@@ -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