mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
Resynced onto the release tip after #12051/#12052/#12053 landed. Same LKGP-clear conflict as #12053 (kept the current clearStaleLKGP() helper at both call sites). One additional issue this final phase's combined-worktree validation surfaced: clearStaleLKGP() itself (added by #12013, which none of the 4 phase PRs could have seen since it landed after they were authored) still had a dynamic `await import("@/lib/localDb")` — a real break once this PR deletes the barrel. Fixed to `await import("@/lib/db/settings")`, matching the direct-import pattern used at every other call site. typecheck:core, check-db-rules, check:cycles, and the eslint-import-boundaries regression test (3/3, including "G14 rejects localDb barrel imports") all green after resync — zero barrel-importing production files remain. Nice clean 5-phase migration, and thanks for taking on the full #11795 cleanup.
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
/**
|
|
* Cursor-specific sweep-glue for the proactive token health check. Cursor has
|
|
* no refresh_token by design — its ~24h import-token is renewed via a
|
|
* cursor-agent nudge + IDE/agent credential re-scrape (see
|
|
* src/lib/cursor/renewal.ts), not a standard OAuth refresh_token exchange.
|
|
*
|
|
* Sibling to tokenHealthCheckCopilot.ts (same injection-to-avoid-circular-
|
|
* import technique — tokenHealthCheck.ts-private helpers passed as params
|
|
* rather than imported) but greenfield: type-checked normally, no
|
|
* @ts-nocheck, and imports updateProviderConnection directly from its
|
|
* owning db/ module (Hard Rule #2).
|
|
*/
|
|
|
|
import { updateProviderConnection } from "@/lib/db/providers";
|
|
import {
|
|
renewCursorConnection,
|
|
buildCursorRenewedUpdate,
|
|
runCursorRenewalExclusive,
|
|
} from "@/lib/cursor/renewal";
|
|
import type { buildRefreshFailureUpdate } from "@/lib/tokenHealthCheck";
|
|
|
|
export async function checkCursorConnectionIfNeeded(params: {
|
|
conn: any;
|
|
now: string;
|
|
buildRefreshFailureUpdate: typeof buildRefreshFailureUpdate;
|
|
log: (message: string, ...args: any[]) => void;
|
|
logWarn: (message: string, ...args: any[]) => void;
|
|
logError: (message: string, ...args: any[]) => void;
|
|
getConnectionLogLabel: (conn: { name?: string; email?: string; id?: string }) => string;
|
|
logPrefix: string;
|
|
/** Testability seam forwarded verbatim to renewCursorConnection() — mirrors
|
|
* the deps param Task 2 added there, so tests can force a {status:"error"}
|
|
* result without a mock.module() shim. */
|
|
deps?: Parameters<typeof renewCursorConnection>[1];
|
|
}): Promise<void> {
|
|
const {
|
|
conn,
|
|
now,
|
|
buildRefreshFailureUpdate,
|
|
log,
|
|
logWarn,
|
|
logError,
|
|
getConnectionLogLabel,
|
|
logPrefix,
|
|
deps,
|
|
} = params;
|
|
|
|
await runCursorRenewalExclusive(conn.id, async () => {
|
|
const result = await renewCursorConnection(
|
|
{
|
|
accessToken: conn.accessToken,
|
|
machineId: conn.providerSpecificData?.machineId ?? null,
|
|
},
|
|
deps
|
|
);
|
|
|
|
switch (result.status) {
|
|
case "renewed": {
|
|
await updateProviderConnection(conn.id, buildCursorRenewedUpdate(conn, result, now));
|
|
log(
|
|
`${logPrefix} ✓ Cursor session renewed for ${getConnectionLogLabel(conn)} (source: ${result.source})`
|
|
);
|
|
return;
|
|
}
|
|
case "unchanged":
|
|
case "error": {
|
|
const message =
|
|
result.status === "error"
|
|
? `Cursor session renewal failed: ${result.error}`
|
|
: "Cursor session unchanged — no newer token found on this host.";
|
|
await updateProviderConnection(
|
|
conn.id,
|
|
buildRefreshFailureUpdate(conn, now, {
|
|
errorCode: "cursor_session_stale",
|
|
lastErrorType: "cursor_session_stale",
|
|
lastError: message,
|
|
testStatus: "active",
|
|
})
|
|
);
|
|
const logFn = result.status === "error" ? logError : logWarn;
|
|
logFn(`${logPrefix} ✗ Cursor session stale for ${getConnectionLogLabel(conn)}: ${message}`);
|
|
return;
|
|
}
|
|
default: {
|
|
const _exhaustive: never = result;
|
|
throw new Error(`Unhandled CursorRenewalResult status: ${JSON.stringify(_exhaustive)}`);
|
|
}
|
|
}
|
|
});
|
|
}
|