mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:40:42 +00:00
test(perf): fold duplicate compaction fallback coverage
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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`, () => {
|
||||
|
||||
Reference in New Issue
Block a user