test(perf): fold duplicate compaction fallback coverage

This commit is contained in:
Peter Steinberger
2026-05-06 16:57:07 +01:00
parent ec8283e3e5
commit 4c177bbe65
2 changed files with 27 additions and 60 deletions

View File

@@ -309,64 +309,6 @@ describe("compactEmbeddedPiSessionDirect hooks", () => {
);
});
it("uses the session model fallback chain when implicit compaction fails", async () => {
resolveModelMock.mockImplementation((provider = "openai", modelId = "fake") => ({
model: { provider, api: "responses", id: modelId, input: [] },
error: null,
authStorage: { setRuntimeApiKey: vi.fn() },
modelRegistry: {},
}));
sessionCompactImpl
.mockRejectedValueOnce(
Object.assign(
new Error(
"400 The response was filtered due to the prompt triggering Azure OpenAI's content management policy.",
),
{ status: 400 },
),
)
.mockResolvedValueOnce({
summary: "fallback summary",
firstKeptEntryId: "entry-fallback",
tokensBefore: 120,
details: { ok: true },
});
const result = await compactEmbeddedPiSessionDirect({
sessionId: "session-1",
sessionKey: TEST_SESSION_KEY,
sessionFile: "/tmp/session.jsonl",
workspaceDir: "/tmp/workspace",
provider: "openai",
model: "gpt-primary",
config: {
agents: {
defaults: {
model: {
primary: "openai/gpt-primary",
fallbacks: ["anthropic/claude-fallback"],
},
},
},
} as never,
});
expect(result.ok).toBe(true);
expect(result.result?.summary).toBe("fallback summary");
expect(resolveModelMock).toHaveBeenCalledWith(
"openai",
"gpt-primary",
expect.any(String),
expect.anything(),
);
expect(resolveModelMock).toHaveBeenCalledWith(
"anthropic",
"claude-fallback",
expect.any(String),
expect.anything(),
);
});
it("uses the session model fallback chain when overflow compaction fails", async () => {
resolveModelMock.mockImplementation((provider = "openai", modelId = "fake") => ({
model: { provider, api: "responses", id: modelId, input: [] },
@@ -471,6 +413,19 @@ describe("compactEmbeddedPiSessionDirect hooks", () => {
});
expect(result.ok).toBe(true);
expect(result.result?.summary).toBe("fallback summary");
expect(resolveModelMock).toHaveBeenCalledWith(
"openai",
"gpt-primary",
expect.any(String),
expect.anything(),
);
expect(resolveModelMock).toHaveBeenCalledWith(
"anthropic",
"claude-fallback",
expect.any(String),
expect.anything(),
);
expect(config).toEqual(configBefore);
});

View File

@@ -23,18 +23,30 @@ export function describeWebFetchProviderContracts(pluginId: string) {
pluginRegistrationContractRegistry.find((entry) => entry.pluginId === pluginId)
?.webFetchProviderIds ?? [];
let providerEntries:
| Array<{
pluginId: string;
provider: WebFetchProviderPlugin;
credentialValue: unknown;
}>
| undefined;
const resolveProviders = () => {
if (providerEntries) {
return providerEntries;
}
const publicArtifactProviders = resolveBundledExplicitWebFetchProvidersFromPublicArtifacts({
onlyPluginIds: [pluginId],
});
if (publicArtifactProviders) {
return publicArtifactProviders.map((provider) => ({
providerEntries = publicArtifactProviders.map((provider) => ({
pluginId: provider.pluginId,
provider,
credentialValue: resolveWebFetchCredentialValue(provider),
}));
return providerEntries;
}
return resolveWebFetchProviderContractEntriesForPluginId(pluginId);
providerEntries = resolveWebFetchProviderContractEntriesForPluginId(pluginId);
return providerEntries;
};
describe(`${pluginId} web fetch provider contract registry load`, () => {