From b70a2451f8c9fac9b5724aab0e5d4d6f37bd6725 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 6 May 2026 14:50:45 +0100 Subject: [PATCH] test(perf): avoid compaction hook plugin metadata scans --- .../compact.hooks.harness.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/agents/pi-embedded-runner/compact.hooks.harness.ts b/src/agents/pi-embedded-runner/compact.hooks.harness.ts index d41ef51b834..ba903fa8281 100644 --- a/src/agents/pi-embedded-runner/compact.hooks.harness.ts +++ b/src/agents/pi-embedded-runner/compact.hooks.harness.ts @@ -1,4 +1,5 @@ import { vi, type Mock } from "vitest"; +import type { PluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js"; import { clearAgentHarnesses } from "../harness/registry.js"; import type { CompactionTranscriptRotation } from "./compaction-successor-transcript.js"; @@ -105,6 +106,45 @@ export const rotateTranscriptAfterCompactionMock: Mock< rotated: false, })); +const emptyPluginMetadataSnapshot: PluginMetadataSnapshot = { + policyHash: "", + index: { + version: 1, + hostContractVersion: "test", + compatRegistryVersion: "test", + migrationVersion: 1, + policyHash: "", + generatedAtMs: 1, + installRecords: {}, + plugins: [], + diagnostics: [], + }, + registryDiagnostics: [], + manifestRegistry: { plugins: [], diagnostics: [] }, + plugins: [], + diagnostics: [], + byPluginId: new Map(), + normalizePluginId: (pluginId: string) => pluginId, + owners: { + channels: new Map(), + channelConfigs: new Map(), + providers: new Map(), + modelCatalogProviders: new Map(), + cliBackends: new Map(), + setupProviders: new Map(), + commandAliases: new Map(), + contracts: new Map(), + }, + metrics: { + registrySnapshotMs: 0, + manifestRegistryMs: 0, + ownerMapsMs: 0, + totalMs: 0, + indexPluginCount: 0, + manifestPluginCount: 0, + }, +}; + export function resetCompactSessionStateMocks(): void { sanitizeSessionHistoryMock.mockReset(); sanitizeSessionHistoryMock.mockImplementation(async (params: { messages: unknown[] }) => { @@ -211,6 +251,10 @@ export async function loadCompactHooksHarness(): Promise<{ ensureRuntimePluginsLoaded, })); + vi.doMock("../../plugins/current-plugin-metadata-snapshot.js", () => ({ + getCurrentPluginMetadataSnapshot: () => emptyPluginMetadataSnapshot, + })); + vi.doMock("../harness/selection.js", () => ({ maybeCompactAgentHarnessSession: maybeCompactAgentHarnessSessionMock, }));