mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-28 18:33:37 +00:00
test: share auto-reply typing helpers
This commit is contained in:
@@ -36,45 +36,14 @@ vi.mock("ajv", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../api.js", () => ({
|
||||
formatXHighModelHint: () => "provider models that advertise xhigh reasoning",
|
||||
normalizeThinkLevel: (raw?: string | null) => {
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const key = raw.trim().toLowerCase();
|
||||
const collapsed = key.replace(/[\s_-]+/g, "");
|
||||
if (collapsed === "adaptive" || collapsed === "auto") {
|
||||
return "adaptive";
|
||||
}
|
||||
if (collapsed === "xhigh" || collapsed === "extrahigh") {
|
||||
return "xhigh";
|
||||
}
|
||||
if (["off"].includes(key)) {
|
||||
return "off";
|
||||
}
|
||||
if (["on", "enable", "enabled"].includes(key)) {
|
||||
return "low";
|
||||
}
|
||||
if (["min", "minimal", "think"].includes(key)) {
|
||||
return "minimal";
|
||||
}
|
||||
if (["low", "thinkhard", "think-hard", "think_hard"].includes(key)) {
|
||||
return "low";
|
||||
}
|
||||
if (["mid", "med", "medium", "thinkharder", "think-harder", "harder"].includes(key)) {
|
||||
return "medium";
|
||||
}
|
||||
if (
|
||||
["high", "ultra", "ultrathink", "think-hard", "thinkhardest", "highest", "max"].includes(key)
|
||||
) {
|
||||
return "high";
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
resolvePreferredOpenClawTmpDir: () => "/tmp",
|
||||
supportsXHighThinking: () => false,
|
||||
}));
|
||||
vi.mock("../api.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../api.js")>();
|
||||
return {
|
||||
...actual,
|
||||
resolvePreferredOpenClawTmpDir: () => "/tmp",
|
||||
supportsXHighThinking: () => false,
|
||||
};
|
||||
});
|
||||
|
||||
import { createLlmTaskTool } from "./llm-task-tool.js";
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createMockTypingController } from "./reply/reply.test-helpers.js";
|
||||
import type { MsgContext } from "./templating.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -62,16 +63,7 @@ vi.mock("./reply/stage-sandbox-media.js", () => ({
|
||||
stageSandboxMedia: vi.fn(async () => undefined),
|
||||
}));
|
||||
vi.mock("./reply/typing.js", () => ({
|
||||
createTypingController: vi.fn(() => ({
|
||||
onReplyStart: async () => undefined,
|
||||
startTypingLoop: async () => undefined,
|
||||
startTypingOnText: async () => undefined,
|
||||
refreshTypingTtl: () => undefined,
|
||||
isActive: () => false,
|
||||
markRunComplete: () => undefined,
|
||||
markDispatchIdle: () => undefined,
|
||||
cleanup: () => undefined,
|
||||
})),
|
||||
createTypingController: vi.fn(() => createMockTypingController()),
|
||||
}));
|
||||
|
||||
vi.mock("./reply/get-reply-directives.js", () => ({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { vi } from "vitest";
|
||||
import { createMockTypingController } from "./reply.test-helpers.js";
|
||||
|
||||
export function registerGetReplyCommonMocks(): void {
|
||||
vi.mock("../../agents/agent-scope.js", async (importOriginal) => {
|
||||
@@ -57,15 +58,6 @@ export function registerGetReplyCommonMocks(): void {
|
||||
stageSandboxMedia: vi.fn(async () => undefined),
|
||||
}));
|
||||
vi.mock("./typing.js", () => ({
|
||||
createTypingController: vi.fn(() => ({
|
||||
onReplyStart: async () => undefined,
|
||||
startTypingLoop: async () => undefined,
|
||||
startTypingOnText: async () => undefined,
|
||||
refreshTypingTtl: () => undefined,
|
||||
isActive: () => false,
|
||||
markRunComplete: () => undefined,
|
||||
markDispatchIdle: () => undefined,
|
||||
cleanup: () => undefined,
|
||||
})),
|
||||
createTypingController: vi.fn(() => createMockTypingController()),
|
||||
}));
|
||||
}
|
||||
|
||||
12
src/auto-reply/reply/reply.test-helpers.ts
Normal file
12
src/auto-reply/reply/reply.test-helpers.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function createMockTypingController() {
|
||||
return {
|
||||
onReplyStart: async () => undefined,
|
||||
startTypingLoop: async () => undefined,
|
||||
startTypingOnText: async () => undefined,
|
||||
refreshTypingTtl: () => undefined,
|
||||
isActive: () => false,
|
||||
markRunComplete: () => undefined,
|
||||
markDispatchIdle: () => undefined,
|
||||
cleanup: () => undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user