mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 06:47:39 +00:00
Gateway: deep-compare array config paths for reload diff
This commit is contained in:
@@ -23,6 +23,48 @@ describe("diffConfigPaths", () => {
|
||||
const paths = diffConfigPaths(prev, next);
|
||||
expect(paths).toContain("messages.groupChat.mentionPatterns");
|
||||
});
|
||||
|
||||
it("does not report unchanged arrays of objects as changed", () => {
|
||||
const prev = {
|
||||
memory: {
|
||||
qmd: {
|
||||
paths: [{ path: "~/docs", pattern: "**/*.md", name: "docs" }],
|
||||
scope: {
|
||||
rules: [{ when: { channel: "slack" }, include: ["docs"] }],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const next = {
|
||||
memory: {
|
||||
qmd: {
|
||||
paths: [{ path: "~/docs", pattern: "**/*.md", name: "docs" }],
|
||||
scope: {
|
||||
rules: [{ when: { channel: "slack" }, include: ["docs"] }],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(diffConfigPaths(prev, next)).toEqual([]);
|
||||
});
|
||||
|
||||
it("reports changed arrays of objects", () => {
|
||||
const prev = {
|
||||
memory: {
|
||||
qmd: {
|
||||
paths: [{ path: "~/docs", pattern: "**/*.md", name: "docs" }],
|
||||
},
|
||||
},
|
||||
};
|
||||
const next = {
|
||||
memory: {
|
||||
qmd: {
|
||||
paths: [{ path: "~/docs", pattern: "**/*.txt", name: "docs" }],
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(diffConfigPaths(prev, next)).toContain("memory.qmd.paths");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildGatewayReloadPlan", () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import chokidar from "chokidar";
|
||||
import { type ChannelId, listChannelPlugins } from "../channels/plugins/index.js";
|
||||
import type { OpenClawConfig, ConfigFileSnapshot, GatewayReloadMode } from "../config/config.js";
|
||||
@@ -150,7 +151,9 @@ export function diffConfigPaths(prev: unknown, next: unknown, prefix = ""): stri
|
||||
return paths;
|
||||
}
|
||||
if (Array.isArray(prev) && Array.isArray(next)) {
|
||||
if (prev.length === next.length && prev.every((val, idx) => val === next[idx])) {
|
||||
// Arrays can contain object entries (for example memory.qmd.paths/scope.rules);
|
||||
// compare structurally so identical values are not reported as changed.
|
||||
if (isDeepStrictEqual(prev, next)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user