Config: migrate legacy top-level memorySearch

This commit is contained in:
Vignesh Natarajan
2026-02-07 19:45:22 -08:00
committed by Vignesh
parent efc79f69a2
commit 8688730161
6 changed files with 104 additions and 54 deletions

View File

@@ -200,6 +200,24 @@ describe("legacy config detection", () => {
expect(parsed.channels).toBeUndefined();
});
});
it("flags top-level memorySearch as legacy in snapshot", async () => {
await withTempHome(async (home) => {
const configPath = path.join(home, ".openclaw", "openclaw.json");
await fs.mkdir(path.dirname(configPath), { recursive: true });
await fs.writeFile(
configPath,
JSON.stringify({ memorySearch: { provider: "local", fallback: "none" } }),
"utf-8",
);
vi.resetModules();
const { readConfigFileSnapshot } = await import("./config.js");
const snap = await readConfigFileSnapshot();
expect(snap.valid).toBe(false);
expect(snap.legacyIssues.some((issue) => issue.path === "memorySearch")).toBe(true);
});
});
it("does not auto-migrate claude-cli auth profile mode on load", async () => {
await withTempHome(async (home) => {
const configPath = path.join(home, ".openclaw", "openclaw.json");

View File

@@ -173,6 +173,52 @@ describe("legacy config detection", () => {
});
expect((res.config as { agent?: unknown }).agent).toBeUndefined();
});
it("migrates top-level memorySearch to agents.defaults.memorySearch", async () => {
vi.resetModules();
const { migrateLegacyConfig } = await import("./config.js");
const res = migrateLegacyConfig({
memorySearch: {
provider: "local",
fallback: "none",
query: { maxResults: 7 },
},
});
expect(res.changes).toContain("Moved memorySearch → agents.defaults.memorySearch.");
expect(res.config?.agents?.defaults?.memorySearch).toMatchObject({
provider: "local",
fallback: "none",
query: { maxResults: 7 },
});
expect((res.config as { memorySearch?: unknown }).memorySearch).toBeUndefined();
});
it("merges top-level memorySearch into agents.defaults.memorySearch", async () => {
vi.resetModules();
const { migrateLegacyConfig } = await import("./config.js");
const res = migrateLegacyConfig({
memorySearch: {
provider: "local",
fallback: "none",
query: { maxResults: 7 },
},
agents: {
defaults: {
memorySearch: {
provider: "openai",
model: "text-embedding-3-small",
},
},
},
});
expect(res.changes).toContain(
"Merged memorySearch → agents.defaults.memorySearch (preserved explicit agents.defaults overrides).",
);
expect(res.config?.agents?.defaults?.memorySearch).toMatchObject({
provider: "openai",
model: "text-embedding-3-small",
fallback: "none",
query: { maxResults: 7 },
});
});
it("migrates tools.bash to tools.exec", async () => {
vi.resetModules();
const { migrateLegacyConfig } = await import("./config.js");

View File

@@ -14,6 +14,34 @@ import {
// tools.alsoAllow legacy migration intentionally omitted (field not shipped in prod).
export const LEGACY_CONFIG_MIGRATIONS_PART_3: LegacyConfigMigration[] = [
{
id: "memorySearch->agents.defaults.memorySearch",
describe: "Move top-level memorySearch to agents.defaults.memorySearch",
apply: (raw, changes) => {
const legacyMemorySearch = getRecord(raw.memorySearch);
if (!legacyMemorySearch) {
return;
}
const agents = ensureRecord(raw, "agents");
const defaults = ensureRecord(agents, "defaults");
const existing = getRecord(defaults.memorySearch);
if (!existing) {
defaults.memorySearch = legacyMemorySearch;
changes.push("Moved memorySearch → agents.defaults.memorySearch.");
} else {
mergeMissing(existing, legacyMemorySearch);
defaults.memorySearch = existing;
changes.push(
"Merged memorySearch → agents.defaults.memorySearch (preserved explicit agents.defaults overrides).",
);
}
agents.defaults = defaults;
raw.agents = agents;
delete raw.memorySearch;
},
},
{
id: "auth.anthropic-claude-cli-mode-oauth",
describe: "Switch anthropic:claude-cli auth profile mode to oauth",

View File

@@ -85,6 +85,11 @@ export const LEGACY_CONFIG_RULES: LegacyConfigRule[] = [
message:
"agent.* was moved; use agents.defaults (and tools.* for tool/elevated/exec settings) instead (auto-migrated on load).",
},
{
path: ["memorySearch"],
message:
"top-level memorySearch was moved; use agents.defaults.memorySearch instead (auto-migrated on load).",
},
{
path: ["tools", "bash"],
message: "tools.bash was removed; use tools.exec instead (auto-migrated on load).",