Files
openclaw/src/config/logging.test.ts
Peter Lee b9ae0a76fa test: prefer shared temp dir helpers in config, gateway, cron, crestodian, and state tests (#96711)
* fix: add temp dir cleanup to 14 P0 test files (Group A)

* fix: restore os import and fix fs.rmSync call in temp dir cleanup

* fix: use shared temp dir helpers in config, gateway, cron, crestodian, and state tests

* fix(test): rename underscore-prefixed temp dir vars and remove unused imports

* fix(test): remove unused path import in crestodian audit test

* fix(test): reorder expected plans to match buildVitestRunPlans output after rebase
2026-07-01 01:24:21 -07:00

55 lines
1.8 KiB
TypeScript

// Verifies logging config parsing and file path handling.
import fs from "node:fs";
import path from "node:path";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { withTempDirSync } from "../test-helpers/temp-dir.js";
const mocks = vi.hoisted(() => ({
createConfigIO: vi.fn().mockReturnValue({
configPath: "/tmp/openclaw-dev/openclaw.json",
}),
}));
vi.mock("./io.js", () => ({
createConfigIO: mocks.createConfigIO,
}));
let formatConfigPath: typeof import("./logging.js").formatConfigPath;
let formatConfigUpdatedMessage: typeof import("./logging.js").formatConfigUpdatedMessage;
let logConfigUpdated: typeof import("./logging.js").logConfigUpdated;
beforeAll(async () => {
({ formatConfigPath, formatConfigUpdatedMessage, logConfigUpdated } =
await import("./logging.js"));
});
beforeEach(() => {
mocks.createConfigIO.mockClear();
});
describe("config logging", () => {
it("formats the live config path when no explicit path is provided", () => {
expect(formatConfigPath()).toBe("/tmp/openclaw-dev/openclaw.json");
});
it("logs the live config path when no explicit path is provided", () => {
const runtime = { log: vi.fn() };
logConfigUpdated(runtime as never);
expect(runtime.log).toHaveBeenCalledWith("Updated config: /tmp/openclaw-dev/openclaw.json");
});
it("formats backup as an indented detail when present", () => {
withTempDirSync({ prefix: "openclaw-config-log-" }, (dir) => {
const configPath = path.join(dir, "openclaw.json");
const backupPath = `${configPath}.bak`;
fs.writeFileSync(backupPath, "{}", "utf8");
expect(
formatConfigUpdatedMessage(configPath, {
backupPath,
}),
).toBe(`Updated config: ${configPath}\n Backup: ${backupPath}`);
});
});
});