From bb07a8e5ffdcdfa8bdb59683fd8e4e49f84bf272 Mon Sep 17 00:00:00 2001 From: Matias Baglieri <168452313+matiasbaglieri@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:26:01 -0300 Subject: [PATCH] fix(combo): restore missing preferAntigravityConnectionsWithStoredProject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit quotaStrategies imported the reset-aware pool filter from ../antigravityProjectPersistence.ts, a module that does not exist — the helper belongs in antigravityProjectPersist.ts and was never added there, breaking typecheck. Add the helper alongside the persist path, point the import at the real module, and cover the filter with unit tests. --- .../services/antigravityProjectPersist.ts | 19 +++++++++++ ...ravity-project-persist-pool-filter.test.ts | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/unit/antigravity-project-persist-pool-filter.test.ts diff --git a/open-sse/services/antigravityProjectPersist.ts b/open-sse/services/antigravityProjectPersist.ts index 1068c4d3ec..2ebddb97c0 100644 --- a/open-sse/services/antigravityProjectPersist.ts +++ b/open-sse/services/antigravityProjectPersist.ts @@ -14,6 +14,25 @@ import { updateProviderConnection } from "@/lib/db/providers"; +/** + * Keep only Antigravity connections that already have a stored projectId when + * building the reset-aware pool (#8894). A connection without a projectId cannot + * be quota-scored, so leaving it in the pool only produces unrankable candidates. + */ +export function preferAntigravityConnectionsWithStoredProject( + connections: Array> +): Array> { + return connections.filter((connection) => { + const direct = connection.projectId; + const psd = connection.providerSpecificData as Record | undefined; + const psdProjectId = psd?.projectId; + return ( + (typeof direct === "string" && direct.trim().length > 0) || + (typeof psdProjectId === "string" && psdProjectId.trim().length > 0) + ); + }); +} + /** * Write `discoveredProjectId` onto both the `projectId` column and * `providerSpecificData.projectId` for `connectionId`, preserving any other diff --git a/tests/unit/antigravity-project-persist-pool-filter.test.ts b/tests/unit/antigravity-project-persist-pool-filter.test.ts new file mode 100644 index 0000000000..db3deeb5a9 --- /dev/null +++ b/tests/unit/antigravity-project-persist-pool-filter.test.ts @@ -0,0 +1,32 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { preferAntigravityConnectionsWithStoredProject } from "@omniroute/open-sse/services/antigravityProjectPersist.ts"; + +test("keeps connections with a projectId on the column or in providerSpecificData", () => { + const kept = preferAntigravityConnectionsWithStoredProject([ + { id: "a", projectId: "projects/a" }, + { id: "b", providerSpecificData: { projectId: "projects/b" } }, + ]); + + assert.deepEqual( + kept.map((c) => c.id), + ["a", "b"] + ); +}); + +test("drops connections whose projectId is missing, blank or not a string", () => { + const kept = preferAntigravityConnectionsWithStoredProject([ + { id: "missing" }, + { id: "blank", projectId: " " }, + { id: "null", projectId: null }, + { id: "numeric", projectId: 42 }, + { id: "blank-psd", providerSpecificData: { projectId: "" } }, + { id: "null-psd", providerSpecificData: null }, + ]); + + assert.deepEqual(kept, []); +}); + +test("returns an empty pool for an empty input instead of throwing", () => { + assert.deepEqual(preferAntigravityConnectionsWithStoredProject([]), []); +});