fix(mongodb): install legacy driver during connection test

This commit is contained in:
zipg authored and GitHub committed 2026-08-14 14:45:35 +08:00
1 parent b6c4a0be0f
commit 325127419f
8 files changed
+64 -12

No files matched your search

@@ -8249,7 +8249,7 @@ function openExternalUrl(url: string) {
<div v-if="agentInstallError" class="space-y-2">
<div class="text-sm font-medium text-destructive">{{ t("connection.driverInstall.fullError") }}</div>
<pre class="max-h-56 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/30 p-3 text-xs leading-5 text-destructive">{{ agentInstallError }}</pre>
<pre class="max-h-56 min-w-0 max-w-full overflow-x-hidden overflow-y-auto whitespace-pre-wrap break-all [overflow-wrap:anywhere] rounded-md border bg-muted/30 p-3 text-xs leading-5 text-destructive">{{ agentInstallError }}</pre>
</div>
</div>
@@ -8266,14 +8266,14 @@ function openExternalUrl(url: string) {
</Dialog>
<Dialog v-model:open="showConnectionErrorDialog">
<DialogContent class="sm:max-w-[560px]">
<DialogContent class="min-w-0 sm:max-w-[680px]">
<DialogHeader>
<DialogTitle>{{ t("connection.connectFailedTitle") }}</DialogTitle>
</DialogHeader>
<div class="space-y-2">
<div class="min-w-0 space-y-2">
<div class="text-sm text-muted-foreground">{{ t("connection.fullErrorMessage") }}</div>
<pre class="max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/30 p-3 text-xs leading-5 text-destructive">{{ connectionErrorDetail }}</pre>
<pre class="max-h-72 min-w-0 max-w-full overflow-x-hidden overflow-y-auto whitespace-pre-wrap break-all [overflow-wrap:anywhere] rounded-md border bg-muted/30 p-3 text-xs leading-5 text-destructive">{{ connectionErrorDetail }}</pre>
</div>
<DialogFooter class="gap-2">
@@ -0,0 +1,21 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
describe("connection dialog error layout", () => {
it("installs a required agent before running a connection test", () => {
const installIndex = dialogSource.indexOf("await ensureRequiredAgentDriverInstalled(config);");
const testIndex = dialogSource.indexOf("const result = await testConnectionWithTimeout(config, runId);");
expect(installIndex).toBeGreaterThan(-1);
expect(testIndex).toBeGreaterThan(installIndex);
});
it("wraps long connection and driver installation errors inside the dialog", () => {
const wrappingClasses = "min-w-0 max-w-full overflow-x-hidden overflow-y-auto whitespace-pre-wrap break-all [overflow-wrap:anywhere]";
expect(dialogSource.split(wrappingClasses)).toHaveLength(3);
expect(dialogSource).toContain('<DialogContent class="min-w-0 sm:max-w-[680px]">');
});
});
@@ -37,15 +37,22 @@ export function agentDriverInstallKey(dbType: DatabaseType | undefined, driverPr
return driverProfile && driverProfile !== dbType ? driverProfile : dbType;
}
function usesManagedAgentDriver(dbType: DatabaseType | undefined, driverProfile?: string): boolean {
if (supportsDriverManagement(dbType)) return true;
if (dbType !== "mongodb") return false;
const profile = driverProfile?.trim().toLowerCase();
return profile === "mongodb-legacy" || profile === "mongodb_legacy" || profile === "legacy";
}
export function showAgentDriverInstallHint(dbType: DatabaseType | undefined, drivers: readonly AgentDriverInstallState[], driverProfile?: string): boolean {
if (!supportsDriverManagement(dbType)) return false;
if (!usesManagedAgentDriver(dbType, driverProfile)) return false;
const driverKey = agentDriverInstallKey(dbType, driverProfile);
if (!driverKey) return false;
return drivers.find((driver) => driver.db_type === driverKey)?.installed !== true;
}
export function hasAgentDriverUpdate(dbType: DatabaseType | undefined, drivers: readonly AgentDriverInstallState[], driverProfile?: string): boolean {
if (!supportsDriverManagement(dbType)) return false;
if (!usesManagedAgentDriver(dbType, driverProfile)) return false;
const driverKey = agentDriverInstallKey(dbType, driverProfile);
return drivers.find((driver) => driver.db_type === driverKey)?.update_available === true;
}
@@ -75,7 +75,10 @@ export function mongodbAuthFailureHint(message: string): string {
const source = message.match(/source='([^']+)'/)?.[1];
if (!source || !message.includes("Exception authenticating MongoCredential")) return message;
return `${message}\n\nCurrent authentication database: ${source}. If this user was created in admin, set Authentication database to admin or add authSource=admin to URL params.`;
const verificationHint = `Current authentication database: ${source}. The server rejected these credentials. Verify the username and password, and confirm that the user was created in ${source}.`;
if (source.toLowerCase() === "admin") return `${message}\n\n${verificationHint}`;
return `${message}\n\n${verificationHint} If the user was created in admin, set Authentication database to admin or add authSource=admin to URL params.`;
}
function parseMongoUrlParams(urlParams: string | undefined): URLSearchParams {