test: trim duplicate memory hotspot coverage

This commit is contained in:
Peter Steinberger
2026-04-16 23:15:38 +01:00
parent a98754d504
commit b2cae7f12a
5 changed files with 74 additions and 762 deletions

View File

@@ -532,19 +532,6 @@ describe("Registry tests", () => {
existingOwner: "core",
});
});
it("shares registered engines across duplicate module copies", async () => {
const registryUrl = new URL("./registry.ts", import.meta.url).href;
const suffix = Date.now().toString(36);
const first = await import(/* @vite-ignore */ `${registryUrl}?copy=${suffix}-a`);
const second = await import(/* @vite-ignore */ `${registryUrl}?copy=${suffix}-b`);
const engineId = `dup-copy-${suffix}`;
const factory = () => new MockContextEngine();
first.registerContextEngine(engineId, factory);
expect(second.getContextEngineFactory(engineId)).toBe(factory);
});
});
// ═══════════════════════════════════════════════════════════════════════════
@@ -1019,34 +1006,15 @@ describe("Initialization guard", () => {
// ═══════════════════════════════════════════════════════════════════════════
describe("Bundle chunk isolation (#40096)", () => {
it("Symbol.for key is stable across independently loaded modules", async () => {
// Simulate two distinct bundle chunks by loading the registry module
// twice with different query strings (forces separate module instances
// in Vite/esbuild but shares globalThis).
it("shares registrations and resolves engines across independently loaded chunks", async () => {
const ts = Date.now().toString(36);
const registryUrl = new URL("./registry.ts", import.meta.url).href;
const chunkA = await import(/* @vite-ignore */ `${registryUrl}?chunk=a-${ts}`);
const chunkB = await import(/* @vite-ignore */ `${registryUrl}?chunk=b-${ts}`);
// Chunk A registers an engine
const engineId = `cross-chunk-${ts}`;
chunkA.registerContextEngine(engineId, () => new MockContextEngine());
// Chunk B must see it
expect(chunkB.getContextEngineFactory(engineId)).toBeDefined();
expect(chunkB.listContextEngineIds()).toContain(engineId);
});
it("resolveContextEngine from chunk B finds engine registered in chunk A", async () => {
const ts = Date.now().toString(36);
const registryUrl = new URL("./registry.ts", import.meta.url).href;
const chunkA = await import(/* @vite-ignore */ `${registryUrl}?chunk=resolve-a-${ts}`);
const chunkB = await import(/* @vite-ignore */ `${registryUrl}?chunk=resolve-b-${ts}`);
const engineId = `resolve-cross-${ts}`;
chunkA.registerContextEngine(engineId, () => ({
const factory = () => ({
info: { id: engineId, name: "Cross-chunk Engine", version: "0.0.1" },
async ingest() {
return { ingested: true };
@@ -1057,9 +1025,11 @@ describe("Bundle chunk isolation (#40096)", () => {
async compact() {
return { ok: true, compacted: false };
},
}));
});
chunkA.registerContextEngine(engineId, factory);
// Resolve from chunk B using a config that points to this engine
expect(chunkB.getContextEngineFactory(engineId)).toBe(factory);
expect(chunkB.listContextEngineIds()).toContain(engineId);
const engine = await chunkB.resolveContextEngine(configWithSlot(engineId));
expect(engine.info.id).toBe(engineId);
});

View File

@@ -27,6 +27,11 @@ const {
resolveCredentialsMock: vi.fn(),
}));
vi.mock("../../agents/model-auth.js", async () => {
const { createModelAuthMockModule } = await import("../../test-utils/model-auth-mock.js");
return createModelAuthMockModule();
});
vi.mock("./embeddings-ollama.js", () => ({
createOllamaEmbeddingProvider: createOllamaEmbeddingProviderMock,
}));

View File

@@ -108,7 +108,6 @@ describe("plugin activation boundary", () => {
let configHelpersPromise:
| Promise<{
isStaticallyChannelConfigured: typeof import("./config/channel-configured-shared.js").isStaticallyChannelConfigured;
resolveEnvApiKey: typeof import("./agents/model-auth-env.js").resolveEnvApiKey;
}>
| undefined;
let modelSelectionPromise:
@@ -134,13 +133,11 @@ describe("plugin activation boundary", () => {
}>
| undefined;
function importConfigHelpers() {
configHelpersPromise ??= Promise.all([
import("./config/channel-configured-shared.js"),
import("./agents/model-auth-env.js"),
]).then(([channelConfigured, modelAuthEnv]) => ({
isStaticallyChannelConfigured: channelConfigured.isStaticallyChannelConfigured,
resolveEnvApiKey: modelAuthEnv.resolveEnvApiKey,
}));
configHelpersPromise ??= import("./config/channel-configured-shared.js").then(
(channelConfigured) => ({
isStaticallyChannelConfigured: channelConfigured.isStaticallyChannelConfigured,
}),
);
return configHelpersPromise;
}
@@ -175,8 +172,10 @@ describe("plugin activation boundary", () => {
}
it("keeps config and model boundary helpers cold", async () => {
const [{ isStaticallyChannelConfigured, resolveEnvApiKey }, { normalizeModelRef }] =
await Promise.all([importConfigHelpers(), importModelSelection()]);
const [{ isStaticallyChannelConfigured }, { normalizeModelRef }] = await Promise.all([
importConfigHelpers(),
importModelSelection(),
]);
expect(isStaticallyChannelConfigured({}, "telegram", { TELEGRAM_BOT_TOKEN: "token" })).toBe(
true,
@@ -190,14 +189,6 @@ describe("plugin activation boundary", () => {
}),
).toBe(true);
expect(isStaticallyChannelConfigured({}, "whatsapp", {})).toBe(false);
expect(
resolveEnvApiKey("anthropic-vertex", {
ANTHROPIC_VERTEX_USE_GCP_METADATA: "true",
}),
).toEqual({
apiKey: "gcp-vertex-credentials",
source: "gcloud adc",
});
expect(normalizeModelRef("google", "gemini-3.1-pro")).toEqual({
provider: "google",
model: "gemini-3.1-pro-preview",