Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

test(modelSync,antigravity): align with post-merge route behavior

diegosouzapw22f2c033dac1
diff --git a/tests/unit/model-sync-route.test.ts b/tests/unit/model-sync-route.test.ts
index c173ab68e4..ab60e1a734 100644
--- a/tests/unit/model-sync-route.test.ts
+++ b/tests/unit/model-sync-route.test.ts
@@ -24,6 +24,14 @@ const originalFetch = globalThis.fetch;
async function resetStorage() {
delete process.env.INITIAL_PASSWORD;
globalThis.fetch = originalFetch;
+ // Reset the shared loopback readiness gate between tests so the cached
+ // promise from a previous test doesn't poison this one (PR #2221 adds
+ // an __loopbackReadyPromise module-level cache that, once resolved, is
+ // reused for the rest of the process). Without this reset, the very
+ // first test's mock-fetch resolution (or rejection) leaks into every
+ // subsequent test, causing the route to use in-process fallback instead
+ // of the test's mocked self-fetch.
+ modelSyncRoute.__resetLoopbackReadinessForTests();
core.resetDbInstance();
apiKeysDb.resetApiKeyState();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
@@ -63,9 +71,10 @@ test("model sync route skips success log when fetched models do not change store
const originalFetch = globalThis.fetch;
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [{ id: "custom-model-1", name: "Custom Model 1" }],
@@ -107,9 +116,10 @@ test("model sync route stores the real provider while keeping the account label"
const originalFetch = globalThis.fetch;
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [{ id: "custom-model-2", name: "Custom Model 2" }],
@@ -191,9 +201,10 @@ test("model sync route propagates upstream failures and records an error log ent
});
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({ error: "Provider upstream unavailable" }, { status: 502 });
};
@@ -227,9 +238,10 @@ test("model sync route falls back to the upstream HTTP status when the models pa
});
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({}, { status: 429 });
};
@@ -262,9 +274,10 @@ test("model sync route reports invalid JSON /models responses without losing ups
});
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return new Response("<html>bad gateway</html>", {
status: 200,
@@ -309,9 +322,10 @@ test("model sync route preserves previously synced models when the upstream omit
]);
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({});
};
@@ -352,9 +366,10 @@ test("model sync route writes synced available models for Gemini connections", a
});
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [
@@ -415,9 +430,10 @@ test("model sync route writes synced available models for non-Gemini providers t
});
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [
@@ -470,9 +486,10 @@ test("model sync route import mode merges discovered models without deleting man
await localDb.setModelAlias("manual-only", "openrouter/manual-only");
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [{ id: "router-v4", name: "Router V4" }],
@@ -535,9 +552,10 @@ test("model sync route import mode ignores supported endpoint ordering changes",
]);
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [
@@ -598,9 +616,10 @@ test("model sync route import mode reports updates without counting them as new
]);
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [
@@ -671,9 +690,10 @@ test("model sync route records added, removed, and updated model diffs with fall
]);
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [
@@ -749,9 +769,10 @@ test("model sync route forwards cookies, filters built-ins, and syncs aliases fo
await localDb.setModelAlias("router-v2", "other-provider/router-v2");
globalThis.fetch = async (url, init = {}) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
assert.equal(init.headers.cookie, "session=test-cookie");
assert.equal(
@@ -813,9 +834,10 @@ test("model sync route reports synced managed models separately from preserved m
await modelsDb.addCustomModel("openrouter", "router-v4", "Manual Router V4", "manual");
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [{ id: "router-v4", name: "Router V4" }],
@@ -877,9 +899,10 @@ test("model sync route uses provider-node prefixes when syncing compatible-provi
await localDb.setModelAlias("sonnet-4-6", "some-other-provider/sonnet-4-6");
globalThis.fetch = async (url) => {
+ if (String(url).includes("__readiness_probe__")) return new Response(null, { status: 404 });
assert.equal(
String(url),
- `http://localhost/api/providers/${connection.id}/models?refresh=true`
+ `http://127.0.0.1:20128/api/providers/${connection.id}/models?refresh=true`
);
return Response.json({
models: [{ id: "sonnet-4-6", name: "Sonnet 4.6" }],
diff --git a/tests/unit/provider-models-route.test.ts b/tests/unit/provider-models-route.test.ts
index 46566c1c6a..b15540876e 100644
--- a/tests/unit/provider-models-route.test.ts
+++ b/tests/unit/provider-models-route.test.ts
@@ -645,11 +645,18 @@ test("provider models route retries Antigravity discovery endpoints before retur
accessToken: "ag-access",
apiKey: null,
});
- const seenUrls = [];
+ const seenUrls: string[] = [];
antigravityVersion.seedAntigravityVersionCache("1.22.2");
globalThis.fetch = async (url, init = {}) => {
- seenUrls.push(String(url));
+ const urlString = String(url);
+ // After PR #2219, the discovery flow calls loadCodeAssist first as a project
+ // bootstrap; treat all bootstrap calls as non-fatal failures so the test
+ // exercises the discovery retry path.
+ if (urlString.includes("/v1internal:loadCodeAssist")) {
+ return new Response("nope", { status: 503 });
+ }
+ seenUrls.push(urlString);
if (seenUrls.length === 1) {
return new Response("unavailable", { status: 503 });
}
@@ -664,13 +671,20 @@ test("provider models route retries Antigravity discovery endpoints before retur
const response = await callRoute(connection.id);
const body = (await response.json()) as any;
- const discoveryUrls = seenUrls.filter((url) => url.includes("/v1internal:models"));
+ // After PR #2219, the route tries `:fetchAvailableModels` URLs before
+ // `:models` URLs. The test mock returns 503 on the first call and success
+ // on the second, so only the first two `:fetchAvailableModels` URLs are
+ // hit — `:models` URLs are never reached. Assert on the actual discovery
+ // sequence the route follows.
+ const discoveryUrls = seenUrls.filter(
+ (url) => url.includes("/v1internal:fetchAvailableModels") || url.includes("/v1internal:models")
+ );
assert.equal(response.status, 200);
assert.equal(body.source, "api");
assert.deepEqual(discoveryUrls, [
- "https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:models",
- "https://daily-cloudcode-pa.googleapis.com/v1internal:models",
+ "https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:fetchAvailableModels",
+ "https://daily-cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels",
]);
assert.deepEqual(body.models, [{ id: "gemini-3-flash-preview", name: "Gemini 3 Flash" }]);
});