mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
e390781534
* 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
55 lines
1.8 KiB
TypeScript
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}`);
|
|
});
|
|
});
|
|
});
|