mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Test: before_compaction & after_compaction hook wiring
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const hookMocks = vi.hoisted(() => ({
|
||||
runner: {
|
||||
@@ -20,6 +20,14 @@ vi.mock("../infra/agent-events.js", () => ({
|
||||
}));
|
||||
|
||||
describe("compaction hook wiring", () => {
|
||||
let handleAutoCompactionStart: typeof import("../agents/pi-embedded-subscribe.handlers.compaction.js").handleAutoCompactionStart;
|
||||
let handleAutoCompactionEnd: typeof import("../agents/pi-embedded-subscribe.handlers.compaction.js").handleAutoCompactionEnd;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ handleAutoCompactionStart, handleAutoCompactionEnd } =
|
||||
await import("../agents/pi-embedded-subscribe.handlers.compaction.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
hookMocks.runner.hasHooks.mockReset();
|
||||
hookMocks.runner.hasHooks.mockReturnValue(false);
|
||||
@@ -29,12 +37,9 @@ describe("compaction hook wiring", () => {
|
||||
hookMocks.runner.runAfterCompaction.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
it("calls runBeforeCompaction in handleAutoCompactionStart", async () => {
|
||||
it("calls runBeforeCompaction in handleAutoCompactionStart", () => {
|
||||
hookMocks.runner.hasHooks.mockReturnValue(true);
|
||||
|
||||
const { handleAutoCompactionStart } =
|
||||
await import("../agents/pi-embedded-subscribe.handlers.compaction.js");
|
||||
|
||||
const ctx = {
|
||||
params: { runId: "r1", session: { messages: [1, 2, 3] } },
|
||||
state: { compactionInFlight: false },
|
||||
@@ -54,12 +59,9 @@ describe("compaction hook wiring", () => {
|
||||
expect(event?.messageCount).toBe(3);
|
||||
});
|
||||
|
||||
it("calls runAfterCompaction when willRetry is false", async () => {
|
||||
it("calls runAfterCompaction when willRetry is false", () => {
|
||||
hookMocks.runner.hasHooks.mockReturnValue(true);
|
||||
|
||||
const { handleAutoCompactionEnd } =
|
||||
await import("../agents/pi-embedded-subscribe.handlers.compaction.js");
|
||||
|
||||
const ctx = {
|
||||
params: { runId: "r2", session: { messages: [1, 2] } },
|
||||
state: { compactionInFlight: true },
|
||||
@@ -88,12 +90,9 @@ describe("compaction hook wiring", () => {
|
||||
expect(event?.compactedCount).toBe(1);
|
||||
});
|
||||
|
||||
it("does not call runAfterCompaction when willRetry is true", async () => {
|
||||
it("does not call runAfterCompaction when willRetry is true", () => {
|
||||
hookMocks.runner.hasHooks.mockReturnValue(true);
|
||||
|
||||
const { handleAutoCompactionEnd } =
|
||||
await import("../agents/pi-embedded-subscribe.handlers.compaction.js");
|
||||
|
||||
const ctx = {
|
||||
params: { runId: "r3", session: { messages: [] } },
|
||||
state: { compactionInFlight: true },
|
||||
|
||||
Reference in New Issue
Block a user