Files
openclaw/src/config/logging.test.ts
T
Peter Steinberger e390781534 refactor: burn cross-directory export name collisions (#121893)
* refactor: name subsystem logger exports

* refactor(test): distinguish exported test doubles

* refactor: consolidate canonical owner helpers

* refactor: give cross-domain helpers distinct names

* chore(lint): ratchet collision debt baselines

* fix(test): complete collision rename consumers

* fix(test): update remaining collision mock consumers

* fix(test): update transcript reader mock export

* refactor: keep embedded logger name at its owner

* fix(test): align embedded logger mock with owner

* refactor: name shared assistant phase extraction

* fix(ui): update assistant phase extractor import

* chore(generated): refresh collision and SDK baselines

* style(test): format merged plugin mocks

* chore(sdk): refresh API content hashes
2026-08-11 06:50:22 -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 formatConfigFilePath: typeof import("./logging.js").formatConfigFilePath;
let formatConfigUpdatedMessage: typeof import("./logging.js").formatConfigUpdatedMessage;
let logConfigUpdated: typeof import("./logging.js").logConfigUpdated;
beforeAll(async () => {
({ formatConfigFilePath, 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(formatConfigFilePath()).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}`);
});
});
});