Files
OmniRoute/tests/unit/antigravity-missing-project-chat.test.ts
backryun 888c872459 refactor(antigravity): align official clients and callable catalog (#8013)
* fix(antigravity): preserve protocol fidelity and fail closed

* chore: add PR-numbered changelog fragment

* test: split oversized Antigravity suites

* refactor(antigravity): align official IDE and CLI identities

* fix(antigravity): align catalog with callable models

* test(antigravity): update 2 test files to renamed version-cache API (#8013 fix)

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: nguyenha935 <208228297+nguyenha935@users.noreply.github.com>
Co-authored-by: backryun <backryun@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: nguyenha935 <nguyenha935@users.noreply.github.com>
Co-authored-by: Probe Test <probe@example.com>
2026-07-22 20:41:19 -03:00

87 lines
3.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { createChatPipelineHarness } from "../integration/_chatPipelineHarness.ts";
const harness = await createChatPipelineHarness("antigravity-missing-project-chat");
const { BaseExecutor, buildRequest, handleChat, resetStorage, settingsDb } = harness;
const providersDb = await import("../../src/lib/db/providers.ts");
const { clearAntigravityProjectCache } = await import(
"../../open-sse/services/antigravityProjectBootstrap.ts"
);
const { seedAntigravityIdeVersionCache, seedAntigravityCliVersionCache } = await import(
"../../open-sse/services/antigravityVersion.ts"
);
const BOOTSTRAP_URL = "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist";
test.beforeEach(async () => {
BaseExecutor.RETRY_CONFIG.delayMs = 0;
process.env.ANTIGRAVITY_CREDITS = "off";
await resetStorage();
await settingsDb.updateSettings({ requestRetry: 0, maxRetryIntervalSec: 0 });
clearAntigravityProjectCache();
seedAntigravityIdeVersionCache("2026.04.17-missing-project-test");
seedAntigravityCliVersionCache("2026.04.17-missing-project-test");
});
test.afterEach(() => {
clearAntigravityProjectCache();
delete process.env.ANTIGRAVITY_CREDITS;
});
test.after(async () => {
await harness.cleanup();
});
test("Antigravity missing-project 422 stays fail-closed without account cooldown or retry", async () => {
const connection = await providersDb.createProviderConnection({
provider: "antigravity",
authType: "oauth",
name: "antigravity-missing-project",
email: "antigravity-missing-project@example.test",
accessToken: "fake-antigravity-missing-project-token",
refreshToken: "fake-antigravity-missing-project-refresh",
expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
providerSpecificData: {},
isActive: true,
testStatus: "active",
});
assert(connection && typeof connection.id === "string");
let bootstrapCalls = 0;
globalThis.fetch = async (input, init) => {
const request = input instanceof Request ? input : new Request(input, init);
if (request.url !== BOOTSTRAP_URL) {
throw new Error(`Unexpected external fetch: ${request.url}`);
}
bootstrapCalls += 1;
return new Response("{}", {
status: 200,
headers: { "Content-Type": "application/json" },
});
};
const response = await handleChat(
buildRequest({
body: {
model: "antigravity/gemini-2.5-flash",
stream: false,
messages: [{ role: "user", content: "Missing project must fail closed" }],
},
})
);
const payload = (await response.json()) as {
error?: { code?: string; type?: string; message?: string };
};
const persisted = await providersDb.getProviderConnectionById(connection.id);
assert.equal(response.status, 422);
assert.equal(payload.error?.code, "missing_project_id");
assert.equal(payload.error?.type, "oauth_missing_project_id");
assert.equal(bootstrapCalls, 1);
assert.equal(persisted?.testStatus, "active");
assert.equal(persisted?.rateLimitedUntil, undefined);
assert.equal(persisted?.lastError, undefined);
});