fix: stop adding auto as Qoder model fallback

This commit is contained in:
Simon Shi
2026-07-22 19:42:46 +09:00
parent 1c44a09141
commit 55e87cbdef
4 changed files with 67 additions and 20 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "pi-provider-qoder",
"version": "0.2.5",
"version": "0.2.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "pi-provider-qoder",
"version": "0.2.5",
"version": "0.2.7",
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "2.4.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "pi-provider-qoder",
"version": "0.2.6",
"version": "0.2.7",
"description": "Pi extension for Qoder AI — with OAuth authentication, COSY signatures and WAF bypass",
"type": "module",
"license": "MIT",
+59
View File
@@ -0,0 +1,59 @@
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { getCachedModels, updateQoderModelsCache } from "../models.js";
const CACHE_PATH = join(homedir(), ".pi", "agent", "qoder-models-cache.json");
let originalCache: string | undefined;
beforeEach(() => {
originalCache = existsSync(CACHE_PATH) ? readFileSync(CACHE_PATH, "utf8") : undefined;
rmSync(CACHE_PATH, { force: true });
});
afterEach(() => {
vi.unstubAllGlobals();
if (originalCache === undefined) rmSync(CACHE_PATH, { force: true });
else writeFileSync(CACHE_PATH, originalCache, "utf8");
});
describe("Qoder model cache", () => {
it("keeps only enabled service models without adding auto as a fallback", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: () =>
Promise.resolve({
chat: [
{ key: "auto", enable: false, display_name: "Auto" },
{ key: "ultimate", enable: true, display_name: "Ultimate", is_reasoning: true },
{ key: "lite", enable: true, display_name: "Lite" },
{ key: "performance", enable: false, display_name: "Performance" },
],
}),
}),
);
await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "global");
const cache = JSON.parse(readFileSync(CACHE_PATH, "utf8"));
expect(cache.models.map((model: { id: string }) => model.id)).toEqual(["ultimate", "lite"]);
expect(cache.models.some((model: { id: string }) => model.id === "auto")).toBe(false);
});
it("filters auto from a legacy fallback cache when the service did not enable it", () => {
writeFileSync(
CACHE_PATH,
JSON.stringify({
updatedAt: Date.now(),
models: [{ id: "auto" }, { id: "ultimate" }],
configs: { ultimate: { key: "ultimate", enable: true } },
}),
"utf8",
);
expect(getCachedModels("global").map((model) => model.id)).toEqual(["ultimate"]);
});
});
+5 -17
View File
@@ -345,6 +345,11 @@ export function getCachedModels(mode?: string): QoderModelDef[] {
try {
const data = JSON.parse(readFileSync(cachePath, "utf8"));
if (data && Array.isArray(data.models)) {
// Older releases injected `auto` without a corresponding service config.
// Keep an explicitly enabled service model, but drop the legacy fallback.
if (data.configs && typeof data.configs === "object" && !data.configs.auto) {
return data.models.filter((model: QoderModelDef) => model.id !== "auto");
}
return data.models;
}
} catch {}
@@ -504,23 +509,6 @@ export async function updateQoderModelsCache(
if (newModels.length === 0) return;
// Ensure auto is present
if (!newModels.some((m) => m.id === "auto")) {
newModels.unshift({
id: "auto",
name: isQoderCNMode(mode) ? "Auto · Qoder CN" : "Qoder Auto",
api: "qoder-api",
provider: isQoderCNMode(mode) ? "qoder-cn" : "qoder",
baseUrl: getQoderBaseUrl(mode),
reasoning: true,
supportsEffort: false,
input: ["text", "image"],
cost: ZERO_COST,
contextWindow: 180000,
maxTokens: 32768,
});
}
const cacheData = {
updatedAt: Date.now(),
models: newModels,