mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 01:32:22 +03:00
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:
committed by
diegosouzapw
parent
0c0ff26450
commit
bb07a8e5ff
@@ -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
|
||||
|
||||
32
tests/unit/antigravity-project-persist-pool-filter.test.ts
Normal file
32
tests/unit/antigravity-project-persist-pool-filter.test.ts
Normal 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([]), []);
|
||||
});
|
||||
Reference in New Issue
Block a user