mirror of https://github.com/openclaw/openclaw.git
fix: widen path utils root contract
This commit is contained in:
parent
9af48d9c10
commit
69be9c4a6f
|
|
@ -76,4 +76,15 @@ describe("secrets path utils", () => {
|
|||
expect(changed).toBe(false);
|
||||
expect(getPath(config, ["talk", "apiKey"])).toBe("same");
|
||||
});
|
||||
|
||||
it("setPathCreateStrict works on nested config sub-objects", () => {
|
||||
const pluginConfig: Record<string, unknown> = {};
|
||||
const changed = setPathCreateStrict(pluginConfig, ["webSearch", "mode"], "llm-context");
|
||||
expect(changed).toBe(true);
|
||||
expect(pluginConfig).toEqual({
|
||||
webSearch: {
|
||||
mode: "llm-context",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { isDeepStrictEqual } from "node:util";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { isRecord } from "./shared.js";
|
||||
|
||||
function isArrayIndexSegment(segment: string): boolean {
|
||||
|
|
@ -89,7 +88,7 @@ export function getPath(root: unknown, segments: string[]): unknown {
|
|||
}
|
||||
|
||||
export function setPathCreateStrict(
|
||||
root: OpenClawConfig,
|
||||
root: Record<string, unknown>,
|
||||
segments: string[],
|
||||
value: unknown,
|
||||
): boolean {
|
||||
|
|
@ -153,7 +152,7 @@ export function setPathCreateStrict(
|
|||
}
|
||||
|
||||
export function setPathExistingStrict(
|
||||
root: OpenClawConfig,
|
||||
root: Record<string, unknown>,
|
||||
segments: string[],
|
||||
value: unknown,
|
||||
): boolean {
|
||||
|
|
@ -184,7 +183,7 @@ export function setPathExistingStrict(
|
|||
return false;
|
||||
}
|
||||
|
||||
export function deletePathStrict(root: OpenClawConfig, segments: string[]): boolean {
|
||||
export function deletePathStrict(root: Record<string, unknown>, segments: string[]): boolean {
|
||||
const cursor = traverseToLeafParent({ root, segments, requireExistingSegment: false });
|
||||
|
||||
const leaf = segments[segments.length - 1] ?? "";
|
||||
|
|
|
|||
Loading…
Reference in New Issue