























@@ -1,8 +1,20 @@
11import { afterEach, describe, expect, it, vi } from "vitest";
2-import { configHandlers, resolveConfigOpenCommand } from "./config.js";
2+import {
3+clearConfigSchemaResponseCacheForTests,
4+configHandlers,
5+loadConfigSchemaResponseForTests,
6+resolveConfigOpenCommand,
7+} from "./config.js";
38import { createConfigHandlerHarness } from "./config.test-helpers.js";
495-const execFileMock = vi.hoisted(() => vi.fn());
10+const { execFileMock, loadGatewayRuntimeConfigSchemaMock } = vi.hoisted(() => ({
11+execFileMock: vi.fn(),
12+loadGatewayRuntimeConfigSchemaMock: vi.fn(() => ({
13+schema: { type: "object" },
14+uiHints: undefined,
15+version: "test-schema",
16+})),
17+}));
618719vi.mock("node:child_process", async () => {
820const { mockNodeBuiltinModule } = await import("openclaw/plugin-sdk/test-node-mocks");
@@ -16,6 +28,10 @@ vi.mock("node:child_process", async () => {
1628);
1729});
183031+vi.mock("../../config/runtime-schema.js", () => ({
32+loadGatewayRuntimeConfigSchema: loadGatewayRuntimeConfigSchemaMock,
33+}));
34+1935function invokeExecFileCallback(args: unknown[], error: Error | null) {
2036const callback = args.at(-1);
2137if (typeof callback !== "function") {
@@ -24,6 +40,11 @@ function invokeExecFileCallback(args: unknown[], error: Error | null) {
2440callback(error);
2541}
264243+afterEach(() => {
44+clearConfigSchemaResponseCacheForTests();
45+vi.clearAllMocks();
46+});
47+2748describe("resolveConfigOpenCommand", () => {
2849it("uses open on macOS", () => {
2950expect(resolveConfigOpenCommand("/tmp/openclaw.json", "darwin")).toEqual({
@@ -55,7 +76,6 @@ describe("resolveConfigOpenCommand", () => {
5576describe("config.openFile", () => {
5677afterEach(() => {
5778delete process.env.OPENCLAW_CONFIG_PATH;
58-vi.clearAllMocks();
5979});
60806181it("opens the configured file without shell interpolation", async () => {
@@ -109,3 +129,20 @@ describe("config.openFile", () => {
109129);
110130});
111131});
132+133+describe("config schema response cache", () => {
134+it("reuses a recent schema build across burst config requests", () => {
135+loadConfigSchemaResponseForTests();
136+loadConfigSchemaResponseForTests();
137+138+expect(loadGatewayRuntimeConfigSchemaMock).toHaveBeenCalledTimes(1);
139+});
140+141+it("can be cleared when config writes change schema inputs", () => {
142+loadConfigSchemaResponseForTests();
143+clearConfigSchemaResponseCacheForTests();
144+loadConfigSchemaResponseForTests();
145+146+expect(loadGatewayRuntimeConfigSchemaMock).toHaveBeenCalledTimes(2);
147+});
148+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。