test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -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 },