fix(combo): restore missing preferAntigravityConnectionsWithStoredProject

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.
This commit is contained in:
Matias Baglieri
2026-08-07 11:26:01 -03:00
committed by diegosouzapw
parent 0c0ff26450
commit bb07a8e5ff
2 changed files with 51 additions and 0 deletions

View File

@@ -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<Record<string, unknown>>
): Array<Record<string, unknown>> {
return connections.filter((connection) => {
const direct = connection.projectId;
const psd = connection.providerSpecificData as Record<string, unknown> | 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

View File

@@ -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([]), []);
});