mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 13:47:15 +00:00
test: type overflow compaction mocks
This commit is contained in:
@@ -6,6 +6,25 @@ import type {
|
|||||||
PluginHookBeforePromptBuildResult,
|
PluginHookBeforePromptBuildResult,
|
||||||
} from "../../plugins/types.js";
|
} from "../../plugins/types.js";
|
||||||
|
|
||||||
|
type MockCompactionResult =
|
||||||
|
| {
|
||||||
|
ok: true;
|
||||||
|
compacted: true;
|
||||||
|
result: {
|
||||||
|
summary: string;
|
||||||
|
firstKeptEntryId?: string;
|
||||||
|
tokensBefore?: number;
|
||||||
|
tokensAfter?: number;
|
||||||
|
};
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
ok: false;
|
||||||
|
compacted: false;
|
||||||
|
reason: string;
|
||||||
|
result?: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export const mockedGlobalHookRunner = {
|
export const mockedGlobalHookRunner = {
|
||||||
hasHooks: vi.fn((_hookName: string) => false),
|
hasHooks: vi.fn((_hookName: string) => false),
|
||||||
runBeforeAgentStart: vi.fn(
|
runBeforeAgentStart: vi.fn(
|
||||||
@@ -31,16 +50,16 @@ export const mockedGlobalHookRunner = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const mockedContextEngine = {
|
export const mockedContextEngine = {
|
||||||
info: { ownsCompaction: false },
|
info: { ownsCompaction: false as boolean },
|
||||||
compact: vi.fn(async () => ({
|
compact: vi.fn<(params: unknown) => Promise<MockCompactionResult>>(async () => ({
|
||||||
ok: false as const,
|
ok: false as const,
|
||||||
compacted: false as const,
|
compacted: false as const,
|
||||||
reason: "nothing to compact",
|
reason: "nothing to compact",
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mockedContextEngineCompact = mockedContextEngine.compact;
|
export const mockedContextEngineCompact = vi.mocked(mockedContextEngine.compact);
|
||||||
export const mockedEnsureRuntimePluginsLoaded = vi.fn();
|
export const mockedEnsureRuntimePluginsLoaded: (...args: unknown[]) => void = vi.fn();
|
||||||
|
|
||||||
vi.mock("../../plugins/hook-runner-global.js", () => ({
|
vi.mock("../../plugins/hook-runner-global.js", () => ({
|
||||||
getGlobalHookRunner: vi.fn(() => mockedGlobalHookRunner),
|
getGlobalHookRunner: vi.fn(() => mockedGlobalHookRunner),
|
||||||
|
|||||||
Reference in New Issue
Block a user