Harden provider reconnect and preserve native account recovery

Compare routed destinations structurally after JSONB persistence. Preserve native default selection and reconnect, respect provider access permissions, and normalize absent verification artifacts at the provider boundary.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-02 17:47:32 -05:00
1 parent 88fbc2c702
commit 4c41e57eda
13 files changed
+92 -17

No files matched your search

@@ -214,7 +214,7 @@ describe("connection usage probes", () => {
expect(unlimited).toMatchObject({ status: "ok", overage: null, limits: [{ used: 20, limit: null, usedPercent: null, limitReached: null }] });
});
it.each(["openai", "anthropic", "xai"] as const)("makes unsupported %s API probes explicit without a request", async provider => {
it.each(["openai", "anthropic", "xai", "google"] as const)("makes unsupported %s API probes explicit without a request", async provider => {
const request = fixture({});
expect(await probeAiConnectionUsage({ provider, method: "api_key" }, "key", { request })).toMatchObject({ status: "unsupported", limits: [], overage: null });
expect(request).not.toHaveBeenCalled();
+1 -1
View File
@@ -332,7 +332,7 @@ export async function probeAiConnectionUsage(
options: { request?: typeof fetch } = {},
): Promise<Omit<AiConnectionUsage, "connectionId" | "grantId">> {
const base = { ...metadata, checkedAt: new Date().toISOString(), source: null, planType: null, limits: [], overage: null };
if (!supportsAiConnectionUsage(metadata.provider, metadata.method)) {
if (metadata.provider === "google" || !supportsAiConnectionUsage(metadata.provider, metadata.method)) {
return { ...base, status: "unsupported", errorCode: "unsupported", message: messages.unsupported };
}
try {
+2 -1
View File
@@ -1,5 +1,6 @@
import { syncConnectionCredentialBindings } from "./connection-credential-bindings.js";
import { createHash, randomUUID } from "node:crypto";
import { isDeepStrictEqual } from "node:util";
import { and, eq, inArray, or } from "drizzle-orm";
import {
type Db,
@@ -488,7 +489,7 @@ export function aiConnectionService(db: Db) {
input.provider
)
throw unprocessable("Reconnect cannot change providers");
if (reconnect && JSON.stringify((reconnect.connection.config.ai as AiConnectionMetadata).routing) !== JSON.stringify(routing))
if (reconnect && !isDeepStrictEqual((reconnect.connection.config.ai as AiConnectionMetadata).routing, routing))
throw unprocessable("Reconnect must retain this connection’s routing. Create another connection to change its destination.");
if (
reconnect &&