mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:07:38 +00:00
fix(config): harden object-array merge-by-id fallback
This commit is contained in:
@@ -72,7 +72,7 @@ describe("applyMergePatch", () => {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "primary", model: "new-model" },
|
||||
{ workspace: "/tmp/orphan" }, // no id
|
||||
{ workspace: "/tmp/orphan" },
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -84,7 +84,6 @@ describe("applyMergePatch", () => {
|
||||
list?: Array<{ id?: string; workspace?: string; model?: string }>;
|
||||
};
|
||||
};
|
||||
// Both original entries preserved, patch without id appended
|
||||
expect(merged.agents?.list).toHaveLength(3);
|
||||
const primary = merged.agents?.list?.find((entry) => entry.id === "primary");
|
||||
expect(primary?.workspace).toBe("/tmp/one");
|
||||
@@ -117,16 +116,55 @@ describe("applyMergePatch", () => {
|
||||
list?: Array<{ id?: string; workspace?: string; model?: string; default?: boolean }>;
|
||||
};
|
||||
};
|
||||
// All 4 agents must survive
|
||||
expect(merged.agents?.list).toHaveLength(4);
|
||||
const main = merged.agents?.list?.find((e) => e.id === "main");
|
||||
const main = merged.agents?.list?.find((entry) => entry.id === "main");
|
||||
expect(main?.model).toBe("claude-opus-4-20250918");
|
||||
expect(main?.default).toBe(true);
|
||||
expect(main?.workspace).toBe("/home/main");
|
||||
// Others untouched
|
||||
expect(merged.agents?.list?.find((e) => e.id === "ota")?.workspace).toBe("/home/ota");
|
||||
expect(merged.agents?.list?.find((e) => e.id === "trading")?.workspace).toBe("/home/trading");
|
||||
expect(merged.agents?.list?.find((e) => e.id === "codex")?.workspace).toBe("/home/codex");
|
||||
expect(merged.agents?.list?.find((entry) => entry.id === "ota")?.workspace).toBe("/home/ota");
|
||||
expect(merged.agents?.list?.find((entry) => entry.id === "trading")?.workspace).toBe(
|
||||
"/home/trading",
|
||||
);
|
||||
expect(merged.agents?.list?.find((entry) => entry.id === "codex")?.workspace).toBe(
|
||||
"/home/codex",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps existing id entries when patch mixes id and primitive entries", () => {
|
||||
const base = {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "primary", workspace: "/tmp/one" },
|
||||
{ id: "secondary", workspace: "/tmp/two" },
|
||||
],
|
||||
},
|
||||
};
|
||||
const patch = {
|
||||
agents: {
|
||||
list: [{ id: "primary", workspace: "/tmp/one-updated" }, "non-object entry"],
|
||||
},
|
||||
};
|
||||
|
||||
const merged = applyMergePatch(base, patch, {
|
||||
mergeObjectArraysById: true,
|
||||
}) as {
|
||||
agents?: {
|
||||
list?: Array<{ id?: string; workspace?: string } | string>;
|
||||
};
|
||||
};
|
||||
|
||||
expect(merged.agents?.list).toHaveLength(3);
|
||||
const primary = merged.agents?.list?.find(
|
||||
(entry): entry is { id?: string; workspace?: string } =>
|
||||
typeof entry === "object" && entry !== null && "id" in entry && entry.id === "primary",
|
||||
);
|
||||
const secondary = merged.agents?.list?.find(
|
||||
(entry): entry is { id?: string; workspace?: string } =>
|
||||
typeof entry === "object" && entry !== null && "id" in entry && entry.id === "secondary",
|
||||
);
|
||||
expect(primary?.workspace).toBe("/tmp/one-updated");
|
||||
expect(secondary?.workspace).toBe("/tmp/two");
|
||||
expect(merged.agents?.list?.[2]).toBe("non-object entry");
|
||||
});
|
||||
|
||||
it("falls back to replacement for non-id arrays even when enabled", () => {
|
||||
|
||||
Reference in New Issue
Block a user