Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(memory): code-review hardening — guards, asserts, useEffect
diegosouzapw516a7e5520aa
diff --git a/bin/cli/commands/memory.mjs b/bin/cli/commands/memory.mjsindex 56b4154b90..2e38acd761 100644--- a/bin/cli/commands/memory.mjs+++ b/bin/cli/commands/memory.mjs@@ -12,6 +12,29 @@ const LEGACY_TYPE_MAP = {reference: "factual",};+/**+ * Plan 21 Bug#4/D17 fix: remap legacy types in ALL CLI subcommands+ * (search/list/clear in addition to add), with a stderr warning on remap.+ * Returns the canonical type, or the original value (which the backend will+ * 400 on if invalid) — never throws.+ */+function applyLegacyTypeMap(type) {+ if (!type) return type;+ if (Object.prototype.hasOwnProperty.call(LEGACY_TYPE_MAP, type)) {+ const mapped = LEGACY_TYPE_MAP[type];+ process.stderr.write(+ `Warning: legacy type '${type}' is deprecated; using '${mapped}'. Use --type factual|episodic|procedural|semantic.\n`+ );+ return mapped;+ }+ if (!VALID_TYPES.includes(type)) {+ process.stderr.write(+ `Warning: unknown type '${type}'. Valid types: factual, episodic, procedural, semantic.\n`+ );+ }+ return type;+}+function truncate(v, len = 60) {if (v == null) return "-";const s = String(v);@@ -60,7 +83,8 @@ async function confirm(question) {export async function runMemorySearch(query, opts, cmd) {const globalOpts = cmd.optsWithGlobals();const params = new URLSearchParams({ q: query, limit: String(opts.limit ?? 20) });- if (opts.type) params.set("type", opts.type);+ const mappedSearchType = applyLegacyTypeMap(opts.type);+ if (mappedSearchType) params.set("type", mappedSearchType);if (opts.apiKey) params.set("apiKey", opts.apiKey);if (opts.tokenBudget) params.set("tokenBudget", String(opts.tokenBudget));const res = await apiFetch(`/api/memory?${params}`);@@ -79,13 +103,7 @@ export async function runMemoryAdd(opts, cmd) {process.stderr.write("--content or --file required\n");process.exit(2);}- let resolvedType = opts.type ?? "factual";- if (opts.type && Object.prototype.hasOwnProperty.call(LEGACY_TYPE_MAP, opts.type)) {- process.stderr.write(- `Warning: legacy type '${opts.type}' is deprecated; using 'factual'. Use --type factual|episodic|procedural|semantic.\n`- );- resolvedType = LEGACY_TYPE_MAP[opts.type];- }+ const resolvedType = opts.type ? applyLegacyTypeMap(opts.type) : "factual";const body = {content,type: resolvedType,@@ -108,7 +126,8 @@ export async function runMemoryClear(opts, cmd) {if (!ok) process.exit(0);}const params = new URLSearchParams();- if (opts.type) params.set("type", opts.type);+ const mappedClearType = applyLegacyTypeMap(opts.type);+ if (mappedClearType) params.set("type", mappedClearType);if (opts.olderThan) {const iso = parseDuration(opts.olderThan);if (!iso) {@@ -126,7 +145,8 @@ export async function runMemoryClear(opts, cmd) {export async function runMemoryList(opts, cmd) {const globalOpts = cmd.optsWithGlobals();const params = new URLSearchParams({ limit: String(opts.limit ?? 100) });- if (opts.type) params.set("type", opts.type);+ const mappedListType = applyLegacyTypeMap(opts.type);+ if (mappedListType) params.set("type", mappedListType);if (opts.apiKey) params.set("apiKey", opts.apiKey);const res = await apiFetch(`/api/memory?${params}`);if (!res.ok) {diff --git a/open-sse/mcp-server/tools/memoryTools.ts b/open-sse/mcp-server/tools/memoryTools.tsindex 87df5c5a66..b5ed467a95 100644--- a/open-sse/mcp-server/tools/memoryTools.ts+++ b/open-sse/mcp-server/tools/memoryTools.ts@@ -33,23 +33,17 @@ export const memoryTools = {description: "Search memories by query, type, or API key with token budget enforcement",inputSchema: MemorySearchSchema,handler: async (args: z.infer<typeof MemorySearchSchema>) => {- const memorySettings = await getMemorySettings().catch(() => null);- const baseConfig = memorySettings- ? toMemoryRetrievalConfig(memorySettings)- : {- enabled: DEFAULT_MEMORY_SETTINGS.enabled,- maxTokens: DEFAULT_MEMORY_SETTINGS.maxTokens,- retrievalStrategy: "exact" as const,- autoSummarize: false,- persistAcrossModels: false,- retentionDays: DEFAULT_MEMORY_SETTINGS.retentionDays,- scope: "apiKey" as const,- };+ // Plan 21 D16/Bug#7 fix: even on the error path the fallback must+ // respect DEFAULT_MEMORY_SETTINGS.strategy instead of hardcoding "exact".+ const memorySettings =+ (await getMemorySettings().catch(() => null)) ?? DEFAULT_MEMORY_SETTINGS;+ const baseConfig = toMemoryRetrievalConfig(memorySettings, {+ query: args.query,+ });const config = {...baseConfig,maxTokens: args.maxTokens || (baseConfig.maxTokens ?? DEFAULT_MEMORY_SETTINGS.maxTokens),- query: args.query,};const memories = await retrieveMemories(args.apiKeyId, config);diff --git a/package.json b/package.jsonindex 9f8e8ff3ac..e6a99e3f92 100644--- a/package.json+++ b/package.json@@ -125,7 +125,7 @@"coverage:summary": "node scripts/check/test-report-summary.mjs --input coverage/coverage-summary.json --output coverage/coverage-report.md","check:pr-test-policy": "node scripts/check/check-pr-test-policy.mjs","coverage:report:legacy": "c8 report --output-dir coverage --exclude=open-sse --reporter=text --reporter=text-summary",- "test:all": "npm run test:unit && npm run test:vitest && npm run test:ecosystem && npm run test:e2e",+ "test:all": "npm run test:unit && npm run test:vitest && npm run test:vitest:ui && npm run test:ecosystem && npm run test:e2e","check": "npm run lint && npm run test","prepublishOnly": "npm run build:cli-api && npm run build:cli && npm run check:pack-artifact","postinstall": "node scripts/build/postinstall.mjs",diff --git a/src/app/(dashboard)/dashboard/memory/components/MemoryEngineStatus.tsx b/src/app/(dashboard)/dashboard/memory/components/MemoryEngineStatus.tsxindex d159e73590..3a6f0d2116 100644--- a/src/app/(dashboard)/dashboard/memory/components/MemoryEngineStatus.tsx+++ b/src/app/(dashboard)/dashboard/memory/components/MemoryEngineStatus.tsx@@ -3,8 +3,11 @@import { useTranslations } from "next-intl";import type { MemoryEngineStatus } from "@/shared/schemas/memory";+type ConfigureTarget = "embedding" | "qdrant" | "rerank";+interface Props {status: MemoryEngineStatus;+ onConfigure?: (target: ConfigureTarget) => void;}type ChipColor = "green" | "gray" | "red";@@ -23,9 +26,36 @@ function StatusChip({ color }: { color: ChipColor }) {);}-export default function MemoryEngineStatus({ status }: Props) {+function ConfigureLink({+ onClick,+ label,+ testId,+}: {+ onClick: () => void;+ label: string;+ testId: string;+}) {+ return (+ <button+ type="button"+ data-testid={testId}+ onClick={onClick}+ className="text-xs text-violet-400 hover:text-violet-300 underline-offset-2 hover:underline mt-1 inline-flex items-center gap-0.5"+ >+ {label}+ <span aria-hidden="true">→</span>+ </button>+ );+}++export default function MemoryEngineStatus({ status, onConfigure }: Props) {const t = useTranslations("memory");+ const embeddingOff = !status.embedding.available;+ const qdrantOff = !status.qdrant.enabled;+ const qdrantUnhealthy = status.qdrant.enabled && status.qdrant.healthy === false;+ const rerankOff = !status.rerank.enabled || !status.rerank.available;+const rows: Array<{ label: string; chip: ChipColor; reason: string; cta?: React.ReactNode }> = [{label: t("engine.keywordLabel"),@@ -36,6 +66,14 @@ export default function MemoryEngineStatus({ status }: Props) {label: t("engine.embeddingLabel"),chip: status.embedding.available ? "green" : "gray",reason: status.embedding.reason,+ cta:+ embeddingOff && onConfigure ? (+ <ConfigureLink+ testId="engine-cta-embedding"+ onClick={() => onConfigure("embedding")}+ label={t("engine.configureCta")}+ />+ ) : undefined,},{label: t("engine.vectorStoreLabel"),@@ -62,11 +100,27 @@ export default function MemoryEngineStatus({ status }: Props) {: status.qdrant.healthy? t("engine.qdrantOk", { latencyMs: status.qdrant.latencyMs ?? 0 }): (status.qdrant.error ?? t("engine.qdrantError")),+ cta:+ (qdrantOff || qdrantUnhealthy) && onConfigure ? (+ <ConfigureLink+ testId="engine-cta-qdrant"+ onClick={() => onConfigure("qdrant")}+ label={t("engine.configureCta")}+ />+ ) : undefined,},{label: t("engine.rerankLabel"),chip: !status.rerank.enabled ? "gray" : status.rerank.available ? "green" : "red",reason: status.rerank.reason,+ cta:+ rerankOff && onConfigure ? (+ <ConfigureLink+ testId="engine-cta-rerank"+ onClick={() => onConfigure("rerank")}+ label={t("engine.configureCta")}+ />+ ) : undefined,},];diff --git a/src/app/(dashboard)/dashboard/memory/components/RerankConfigCard.tsx b/src/app/(dashboard)/dashboard/memory/components/RerankConfigCard.tsxindex a704d67f45..27ca10469f 100644--- a/src/app/(dashboard)/dashboard/memory/components/RerankConfigCard.tsx+++ b/src/app/(dashboard)/dashboard/memory/components/RerankConfigCard.tsx@@ -35,11 +35,22 @@ export default function RerankConfigCard({ settings, providers, onSave, saving }<buttontype="button"data-testid="rerank-enabled-switch"- onClick={() => onSave({ rerankEnabled: !rerankEnabled })}- disabled={saving}+ onClick={() => {+ // Plan 21 D13 fix: block enabling rerank when no provider has a key.+ // Allow disabling (turning OFF) always, even if no provider exists.+ if (!rerankEnabled && !hasProvider) return;+ onSave({ rerankEnabled: !rerankEnabled });+ }}+ disabled={saving || (!rerankEnabled && !hasProvider)}+ aria-disabled={saving || (!rerankEnabled && !hasProvider)}+ title={+ !rerankEnabled && !hasProvider+ ? t("rerank.noProviderWithKey")+ : undefined+ }role="switch"aria-checked={rerankEnabled}- className={`relative w-11 h-6 rounded-full transition-colors shrink-0 ${+ className={`relative w-11 h-6 rounded-full transition-colors shrink-0 disabled:opacity-50 disabled:cursor-not-allowed ${rerankEnabled ? "bg-violet-500" : "bg-border"}`}>diff --git a/src/app/(dashboard)/dashboard/memory/components/tabs/EngineTab.tsx b/src/app/(dashboard)/dashboard/memory/components/tabs/EngineTab.tsxindex ec028f9534..555b46a9e2 100644--- a/src/app/(dashboard)/dashboard/memory/components/tabs/EngineTab.tsx+++ b/src/app/(dashboard)/dashboard/memory/components/tabs/EngineTab.tsx@@ -1,6 +1,6 @@"use client";-import { useState } from "react";+import { useState, useEffect, useCallback } from "react";import { useTranslations } from "next-intl";import { Card, Button } from "@/shared/components";import MemoryEngineStatus from "../MemoryEngineStatus";@@ -16,21 +16,38 @@ export default function EngineTab() {const { status, isLoading: statusLoading } = useEngineStatus();const { settings, save: saveSettings, isLoading: settingsLoading } = useMemorySettings();const [providers, setProviders] = useState<EmbeddingProviderListing[]>([]);- const [providersLoaded, setProvidersLoaded] = useState(false);const [saving, setSaving] = useState(false);const [reindexing, setReindexing] = useState(false);const [reindexMsg, setReindexMsg] = useState("");- // Lazy-load providers- if (!providersLoaded && !settingsLoading) {- setProvidersLoaded(true);+ // Plan 21 fix: providers fetch moved from render body to useEffect to+ // avoid setState-during-render anti-pattern (caused double fetch in+ // React 18 Strict Mode).+ useEffect(() => {+ if (settingsLoading) return;+ let cancelled = false;fetch("/api/memory/embedding-providers").then((r) => (r.ok ? r.json() : null)).then((data) => {- if (data?.providers) setProviders(data.providers);+ if (!cancelled && data?.providers) setProviders(data.providers);}).catch(() => {});- }+ return () => {+ cancelled = true;+ };+ }, [settingsLoading]);++ // CTA handler for MemoryEngineStatus rows — scrolls to the config card+ // in the same tab so the user can fix the off/missing component.+ const handleConfigure = useCallback(+ (target: "embedding" | "qdrant" | "rerank") => {+ const id = `engine-config-${target}`;+ document+ .getElementById(id)+ ?.scrollIntoView({ behavior: "smooth", block: "start" });+ },+ []+ );const handleSaveSettings = async (updates: Parameters<typeof saveSettings>[0]) => {setSaving(true);@@ -83,7 +100,7 @@ export default function EngineTab() {{isLoading || !status ? (<div className="text-sm text-text-muted">{t("loading")}</div>) : (- <MemoryEngineStatus status={status} />+ <MemoryEngineStatus status={status} onConfigure={handleConfigure} />)}{reindexMsg && (<p className="mt-3 text-xs text-text-muted">{reindexMsg}</p>@@ -94,7 +111,7 @@ export default function EngineTab() {{/* Embedding source selector */}{settings && (<Card>- <div className="p-4">+ <div id="engine-config-embedding" className="p-4 scroll-mt-4"><h3 className="text-sm font-semibold text-text-main mb-4">{t("engine.embeddingTitle")}</h3>@@ -109,12 +126,14 @@ export default function EngineTab() {)}{/* Qdrant config */}- <QdrantConfigCard />+ <div id="engine-config-qdrant" className="scroll-mt-4">+ <QdrantConfigCard />+ </div>{/* Rerank config */}{settings && (<Card>- <div className="p-4">+ <div id="engine-config-rerank" className="p-4 scroll-mt-4"><h3 className="text-sm font-semibold text-text-main mb-4">{t("engine.rerankTitle")}</h3>diff --git a/src/app/(dashboard)/dashboard/memory/components/tabs/MemoriesTab.tsx b/src/app/(dashboard)/dashboard/memory/components/tabs/MemoriesTab.tsxindex 8ac1ba14ec..458c45c453 100644--- a/src/app/(dashboard)/dashboard/memory/components/tabs/MemoriesTab.tsx+++ b/src/app/(dashboard)/dashboard/memory/components/tabs/MemoriesTab.tsx@@ -160,20 +160,31 @@ export default function MemoriesTab() {const data = JSON.parse(text);const memoriesToImport = Array.isArray(data) ? data : [data];+ // Plan 21 fix: validate each entry against the canonical type enum+ // before POSTing. Previously only key/content presence was checked, so+ // entries with invalid `type` (e.g. legacy "user") reached the backend+ // and counted as skipped without a clear local reason.+ const VALID_TYPES = new Set(["factual", "episodic", "procedural", "semantic"]);for (const m of memoriesToImport) {- if (!m.key || !m.content) {+ if (!m || typeof m !== "object") {skipped++;continue;}+ const key = typeof m.key === "string" ? m.key.trim() : "";+ const content = typeof m.content === "string" ? m.content : "";+ if (!key || !content) {+ skipped++;+ continue;+ }+ const type = typeof m.type === "string" && VALID_TYPES.has(m.type) ? m.type : "factual";+ const metadata =+ m.metadata && typeof m.metadata === "object" && !Array.isArray(m.metadata)+ ? m.metadata+ : {};const res = await fetch("/api/memory", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify({- type: m.type || "factual",- key: m.key,- content: m.content,- metadata: m.metadata || {},- }),+ body: JSON.stringify({ type, key, content, metadata }),});if (res.ok) imported++;else skipped++;diff --git a/src/lib/db/migrationRunner.ts b/src/lib/db/migrationRunner.tsindex 67c2b34f9d..d91e2984ac 100644--- a/src/lib/db/migrationRunner.ts+++ b/src/lib/db/migrationRunner.ts@@ -438,6 +438,12 @@ function isSchemaAlreadyApplied(hasColumn(db, "version_manager", "provider_expose") &&hasColumn(db, "version_manager", "last_sync_at"));+ case "073":+ // Plan 21 D27 fix: guard memory_vec migration. Without this case, an+ // unmarked re-run of 073_memory_vec.sql would have its ALTER TABLE fail+ // mid-file and skip the CREATE INDEX that follows, leaving the index+ // missing on DBs that re-execute the script after a partial first run.+ return hasColumn(db, "memories", "needs_reindex");default:return false;}diff --git a/tests/unit/cli-memory-commands.test.ts b/tests/unit/cli-memory-commands.test.tsindex 3b6a70d8bf..8c514803a8 100644--- a/tests/unit/cli-memory-commands.test.ts+++ b/tests/unit/cli-memory-commands.test.ts@@ -82,7 +82,10 @@ test("runMemorySearch envia q e type na query", async () => {globalThis.fetch = origFetch;assert.ok(capturedUrl.includes("q=react") && capturedUrl.includes("hooks"));- assert.ok(capturedUrl.includes("type=project"));+ // Plan 21 / D17: legacy 'project' is remapped to canonical 'factual' by+ // applyLegacyTypeMap in the CLI before reaching the backend.+ assert.ok(capturedUrl.includes("type=factual"));+ assert.ok(!capturedUrl.includes("type=project"));assert.ok(capturedUrl.includes("limit=10"));});@@ -177,5 +180,8 @@ test("runMemoryClear --yes envia DELETE com filtro de type", async () => {globalThis.fetch = origFetch;assert.ok(capturedUrl.includes("/api/memory"));assert.equal(capturedInit?.method, "DELETE");- assert.ok(capturedUrl.includes("type=project"));+ // Plan 21 / D17: legacy 'project' is remapped to canonical 'factual' by+ // applyLegacyTypeMap in the CLI before reaching the backend.+ assert.ok(capturedUrl.includes("type=factual"));+ assert.ok(!capturedUrl.includes("type=project"));});diff --git a/tests/unit/memory-embedding-resolve.test.ts b/tests/unit/memory-embedding-resolve.test.tsindex 0d88747d17..90b6481185 100644--- a/tests/unit/memory-embedding-resolve.test.ts+++ b/tests/unit/memory-embedding-resolve.test.ts@@ -20,7 +20,11 @@ describe("resolveEmbeddingSource", () => {it("auto + no key + no static + no transformers => source null", () => {const res = resolveEmbeddingSource(makeSettings({ embeddingSource: "auto" }));assert.strictEqual(res.source, null);- assert.ok(res.reason.toLowerCase().includes("nenhuma") || res.reason.length > 0);+ // The reason must indicate the lack of any source — not just be non-empty.+ assert.ok(+ res.reason.toLowerCase().includes("nenhuma"),+ `expected reason to mention "nenhuma", got: ${res.reason}`+ );});it("auto + embeddingProviderModel set to openai/... => source remote", () => {@@ -58,7 +62,11 @@ describe("resolveEmbeddingSource", () => {embeddingProviderModel: null,}));assert.strictEqual(res.source, null);- assert.ok(res.reason.includes("no_key") || res.reason.includes("configurado") || res.reason.length > 0);+ // The reason must reference the missing key, not just be non-empty.+ assert.ok(+ res.reason.includes("no_key") || res.reason.includes("configurado"),+ `expected reason to mention "no_key" or "configurado", got: ${res.reason}`+ );});it("explicit 'remote' + model set => source remote (no fallback)", () => {diff --git a/tests/unit/memory-embedding-static-potion.test.ts b/tests/unit/memory-embedding-static-potion.test.tsindex 3757c06615..ee5da508d0 100644--- a/tests/unit/memory-embedding-static-potion.test.ts+++ b/tests/unit/memory-embedding-static-potion.test.ts@@ -6,6 +6,7 @@ import {_injectModel,type PotionModel,} from "../../src/lib/memory/embedding/staticPotion";+import type { EmbeddingError } from "../../src/lib/memory/embedding/types";import { invalidate as invalidateCache } from "../../src/lib/memory/embedding/cache";// ---- Mock model setup ----@@ -120,14 +121,38 @@ describe("memory-embedding-static-potion embedStatic with mock", () => {});it("model load failure returns EmbeddingError with reason model_load_failed", async () => {+ // Plan 21 fix: previously this test was tautological (`assert.ok(true)`).+ // Force a real load-failure path: point the cache dir at /dev/null/<subdir>+ // so fs.mkdir() fails with ENOTDIR (/dev/null is a file, not a dir).+ // embedStatic catches the error and must return EmbeddingError with+ // reason="model_load_failed" (staticPotion.ts:225-232)._injectModel(null);- // Clear the singleton so it tries to load (and fails)- // We need to make it fail on load; inject a model that throws- // But _injectModel(null) clears it → will try to download (which fails in test env)- // Let's not actually trigger the download; just verify the structure- // by injecting an error-inducing state- _injectModel(makeMockModel()); // restore for other tests- assert.ok(true, "Model injection pattern verified");+ const prevCacheDir = process.env.MEMORY_STATIC_CACHE_DIR;+ process.env.MEMORY_STATIC_CACHE_DIR = `/dev/null/potion-load-fail-${process.pid}-${Date.now()}`;+ try {+ const { embedStatic } = await import(+ "../../src/lib/memory/embedding/staticPotion"+ );+ const result = await embedStatic("hello world");+ assert.ok(+ !("vector" in result),+ `Expected EmbeddingError but got result with vector: ${JSON.stringify(result)}`+ );+ const err = result as EmbeddingError;+ assert.strictEqual(err.source, "static");+ assert.strictEqual(err.reason, "model_load_failed");+ assert.ok(+ typeof err.message === "string" && err.message.length > 0,+ "EmbeddingError.message must be a non-empty sanitized string"+ );+ } finally {+ if (prevCacheDir === undefined) {+ delete process.env.MEMORY_STATIC_CACHE_DIR;+ } else {+ process.env.MEMORY_STATIC_CACHE_DIR = prevCacheDir;+ }+ _injectModel(makeMockModel()); // restore for other tests+ }});it("second call reuses singleton model (no re-load)", async () => {diff --git a/tests/unit/ui/rerank-config-card.test.tsx b/tests/unit/ui/rerank-config-card.test.tsxindex 926f8052d0..8880bfd504 100644--- a/tests/unit/ui/rerank-config-card.test.tsx+++ b/tests/unit/ui/rerank-config-card.test.tsx@@ -56,6 +56,19 @@ describe("RerankConfigCard", () => {expect(container.querySelector("[data-testid='rerank-enabled-switch']")).toBeTruthy();});+ // Plan 21 D13 fix: providers with hasKey=true are now required to enable+ // rerank. The "happy path" test must pass a configured provider; a separate+ // test (below) covers the new guard that blocks enabling without a provider.+ const providersWithKey = [+ {+ provider: "cohere",+ hasKey: true,+ models: [+ { id: "cohere/rerank-english-v3.0", name: "Rerank English v3", dimensions: null },+ ],+ },+ ];+it("toggle switch calls onSave with rerankEnabled=true when disabled", async () => {const onSave = vi.fn().mockResolvedValue(true);const { default: RerankConfigCard } = await import(@@ -67,7 +80,7 @@ describe("RerankConfigCard", () => {root.render(<RerankConfigCardsettings={defaultSettings}- providers={[]}+ providers={providersWithKey}onSave={onSave}/>,);@@ -83,6 +96,36 @@ describe("RerankConfigCard", () => {expect(onSave).toHaveBeenCalledWith({ rerankEnabled: true });});+ it("toggle is blocked when no provider has a key (rerankEnabled=false)", async () => {+ // Plan 21 D13 fix: trying to enable rerank without a configured provider+ // must NOT call onSave (the guard prevents the state from becoming inconsistent).+ const onSave = vi.fn().mockResolvedValue(true);+ const { default: RerankConfigCard } = await import(+ "../../../src/app/(dashboard)/dashboard/memory/components/RerankConfigCard"+ );+ const container = makeContainer();+ const root = createRoot(container);+ await act(async () => {+ root.render(+ <RerankConfigCard+ settings={defaultSettings}+ providers={[]}+ onSave={onSave}+ />,+ );+ });++ const toggleBtn = container.querySelector(+ "[data-testid='rerank-enabled-switch']",+ ) as HTMLButtonElement | null;+ expect(toggleBtn).toBeTruthy();+ expect(toggleBtn?.hasAttribute("disabled")).toBe(true);+ await act(async () => {+ toggleBtn?.click();+ });+ expect(onSave).not.toHaveBeenCalled();+ });+it("toggle switch calls onSave with rerankEnabled=false when enabled", async () => {const onSave = vi.fn().mockResolvedValue(true);const { default: RerankConfigCard } = await import(