mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 17:01:11 +00:00
fix: add memory search health check to openclaw doctor (openclaw#16294) thanks @superlowburn
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test (noted unrelated local flakes) Co-authored-by: superlowburn <24779772+superlowburn@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
87
src/commands/doctor-memory-search.test.ts
Normal file
87
src/commands/doctor-memory-search.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
|
||||
const note = vi.hoisted(() => vi.fn());
|
||||
const resolveDefaultAgentId = vi.hoisted(() => vi.fn(() => "agent-default"));
|
||||
const resolveAgentDir = vi.hoisted(() => vi.fn(() => "/tmp/agent-default"));
|
||||
const resolveMemorySearchConfig = vi.hoisted(() => vi.fn());
|
||||
const resolveApiKeyForProvider = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("../terminal/note.js", () => ({
|
||||
note,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/agent-scope.js", () => ({
|
||||
resolveDefaultAgentId,
|
||||
resolveAgentDir,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/memory-search.js", () => ({
|
||||
resolveMemorySearchConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../agents/model-auth.js", () => ({
|
||||
resolveApiKeyForProvider,
|
||||
}));
|
||||
|
||||
import { noteMemorySearchHealth } from "./doctor-memory-search.js";
|
||||
|
||||
describe("noteMemorySearchHealth", () => {
|
||||
const cfg = {} as OpenClawConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
note.mockReset();
|
||||
resolveDefaultAgentId.mockClear();
|
||||
resolveAgentDir.mockClear();
|
||||
resolveMemorySearchConfig.mockReset();
|
||||
resolveApiKeyForProvider.mockReset();
|
||||
});
|
||||
|
||||
it("does not warn when remote apiKey is configured for explicit provider", async () => {
|
||||
resolveMemorySearchConfig.mockReturnValue({
|
||||
provider: "openai",
|
||||
local: {},
|
||||
remote: { apiKey: "from-config" },
|
||||
});
|
||||
|
||||
await noteMemorySearchHealth(cfg);
|
||||
|
||||
expect(note).not.toHaveBeenCalled();
|
||||
expect(resolveApiKeyForProvider).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not warn in auto mode when remote apiKey is configured", async () => {
|
||||
resolveMemorySearchConfig.mockReturnValue({
|
||||
provider: "auto",
|
||||
local: {},
|
||||
remote: { apiKey: "from-config" },
|
||||
});
|
||||
|
||||
await noteMemorySearchHealth(cfg);
|
||||
|
||||
expect(note).not.toHaveBeenCalled();
|
||||
expect(resolveApiKeyForProvider).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolves provider auth from the default agent directory", async () => {
|
||||
resolveMemorySearchConfig.mockReturnValue({
|
||||
provider: "gemini",
|
||||
local: {},
|
||||
remote: {},
|
||||
});
|
||||
resolveApiKeyForProvider.mockResolvedValue({
|
||||
apiKey: "k",
|
||||
source: "env: GEMINI_API_KEY",
|
||||
mode: "api-key",
|
||||
});
|
||||
|
||||
await noteMemorySearchHealth(cfg);
|
||||
|
||||
expect(resolveApiKeyForProvider).toHaveBeenCalledWith({
|
||||
provider: "google",
|
||||
cfg,
|
||||
agentDir: "/tmp/agent-default",
|
||||
});
|
||||
expect(note).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user