|
| 1 | +// Config Reload Mutate Metadata tests cover config reload metadata mutation script behavior. |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { readFileSync, writeFileSync } from "node:fs"; |
| 4 | +import path from "node:path"; |
| 5 | +import { afterEach, describe, expect, it } from "vitest"; |
| 6 | +import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js"; |
| 7 | + |
| 8 | +const SCRIPT_PATH = "scripts/e2e/lib/config-reload/mutate-metadata.mjs"; |
| 9 | +const tempDirs: string[] = []; |
| 10 | + |
| 11 | +afterEach(() => { |
| 12 | +cleanupTempDirs(tempDirs); |
| 13 | +}); |
| 14 | + |
| 15 | +function runMutateMetadata(configPath: string) { |
| 16 | +return spawnSync(process.execPath, [SCRIPT_PATH], { |
| 17 | +encoding: "utf8", |
| 18 | +env: { |
| 19 | + ...process.env, |
| 20 | +OPENCLAW_CONFIG_PATH: configPath, |
| 21 | +}, |
| 22 | +}); |
| 23 | +} |
| 24 | + |
| 25 | +describe("config reload metadata mutator", () => { |
| 26 | +it("updates the config reload gateway metadata knob without dropping existing config", () => { |
| 27 | +const root = makeTempDir(tempDirs, "openclaw-config-reload-metadata-"); |
| 28 | +const configPath = path.join(root, "openclaw.json"); |
| 29 | +writeFileSync( |
| 30 | +configPath, |
| 31 | +`${JSON.stringify( |
| 32 | + { |
| 33 | + gateway: { |
| 34 | + channelHealthCheckMinutes: 1, |
| 35 | + port: 18789, |
| 36 | + }, |
| 37 | + plugins: { |
| 38 | + entries: { |
| 39 | + demo: { enabled: true }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + null, |
| 44 | + 2, |
| 45 | + )}\n`, |
| 46 | +"utf8", |
| 47 | +); |
| 48 | + |
| 49 | +const result = runMutateMetadata(configPath); |
| 50 | + |
| 51 | +expect(result.status).toBe(0); |
| 52 | +expect(result.stderr).toBe(""); |
| 53 | +expect(JSON.parse(readFileSync(configPath, "utf8"))).toEqual({ |
| 54 | +gateway: { |
| 55 | +channelHealthCheckMinutes: 2, |
| 56 | +port: 18789, |
| 57 | +}, |
| 58 | +plugins: { |
| 59 | +entries: { |
| 60 | +demo: { enabled: true }, |
| 61 | +}, |
| 62 | +}, |
| 63 | +}); |
| 64 | +expect(readFileSync(configPath, "utf8")).toMatch(/\n$/u); |
| 65 | +}); |
| 66 | +}); |