fix: add freshness to Perplexity cache key + use unique test query to avoid cache collision

This commit is contained in:
echoVic
2026-02-13 21:03:47 +08:00
committed by Sebastian
parent 4e1ba306fe
commit 140e4f4d01
3 changed files with 7 additions and 5 deletions

1
.gitignore vendored
View File

@@ -83,3 +83,4 @@ USER.md
.agent/*.json
!.agent/workflows/
local/
package-lock.json

View File

@@ -569,7 +569,7 @@ async function runWebSearch(params: {
params.provider === "brave"
? `${params.provider}:${params.query}:${params.count}:${params.country || "default"}:${params.search_lang || "default"}:${params.ui_lang || "default"}:${params.freshness || "default"}`
: params.provider === "perplexity"
? `${params.provider}:${params.query}:${params.perplexityBaseUrl ?? DEFAULT_PERPLEXITY_BASE_URL}:${params.perplexityModel ?? DEFAULT_PERPLEXITY_MODEL}`
? `${params.provider}:${params.query}:${params.perplexityBaseUrl ?? DEFAULT_PERPLEXITY_BASE_URL}:${params.perplexityModel ?? DEFAULT_PERPLEXITY_MODEL}:${params.freshness || "default"}`
: `${params.provider}:${params.query}:${params.grokModel ?? DEFAULT_GROK_MODEL}:${String(params.grokInlineCitations ?? false)}`,
);
const cached = readCache(SEARCH_CACHE, cacheKey);

View File

@@ -159,7 +159,7 @@ describe("web_search perplexity baseUrl defaults", () => {
expect(body.model).toBe("sonar-pro");
});
it("rejects freshness for Perplexity provider", async () => {
it("passes freshness to Perplexity provider as search_recency_filter", async () => {
vi.stubEnv("PERPLEXITY_API_KEY", "pplx-test");
const mockFetch = vi.fn(() =>
Promise.resolve({
@@ -174,10 +174,11 @@ describe("web_search perplexity baseUrl defaults", () => {
config: { tools: { web: { search: { provider: "perplexity" } } } },
sandboxed: true,
});
const result = await tool?.execute?.(1, { query: "test", freshness: "pw" });
await tool?.execute?.(1, { query: "perplexity-freshness-test", freshness: "pw" });
expect(mockFetch).not.toHaveBeenCalled();
expect(result?.details).toMatchObject({ error: "unsupported_freshness" });
expect(mockFetch).toHaveBeenCalledOnce();
const body = JSON.parse(mockFetch.mock.calls[0][1].body as string);
expect(body.search_recency_filter).toBe("week");
});
it("defaults to OpenRouter when OPENROUTER_API_KEY is set", async () => {