Replace all console.* calls in src/ with pino child-loggers. Add rootLogger + childLogger(component) in src/runtime/logger.ts. pino-pretty used as dev transport only. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
2.4 KiB
TypeScript
62 lines
2.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import * as os from "os";
|
|
import * as path from "path";
|
|
import { expandWorkspacesRoot } from "../../src/config/loader";
|
|
import { rootLogger } from "../../src/runtime/logger";
|
|
|
|
const HOME = os.homedir();
|
|
// Use an absolute path that is portable across Linux, macOS, and Windows.
|
|
// os.tmpdir() always returns an absolute path on all platforms.
|
|
const REPO_ROOT = path.join(os.tmpdir(), "fake-disclaw-repo");
|
|
|
|
describe("expandWorkspacesRoot", () => {
|
|
beforeEach(() => {
|
|
vi.spyOn(rootLogger, "warn").mockImplementation(() => undefined);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("(a) expands leading ~ to os.homedir() and resolves to absolute path", () => {
|
|
const result = expandWorkspacesRoot("~/.disclaw/workspaces", REPO_ROOT);
|
|
expect(result).toBe(path.resolve(HOME, ".disclaw", "workspaces"));
|
|
expect(path.isAbsolute(result)).toBe(true);
|
|
});
|
|
|
|
it("(a) expands ~ with no trailing path to os.homedir()", () => {
|
|
const result = expandWorkspacesRoot("~", REPO_ROOT);
|
|
expect(result).toBe(path.resolve(HOME));
|
|
});
|
|
|
|
it("(b) leaves an already-absolute path unchanged (no double expansion)", () => {
|
|
const absolute = path.join(HOME, ".disclaw", "workspaces");
|
|
const result = expandWorkspacesRoot(absolute, REPO_ROOT);
|
|
expect(result).toBe(absolute);
|
|
});
|
|
|
|
it("(c) resolves a relative path (without ~) against repoRoot to an absolute path", () => {
|
|
const result = expandWorkspacesRoot("myworkspaces", REPO_ROOT);
|
|
expect(result).toBe(path.join(REPO_ROOT, "myworkspaces"));
|
|
expect(path.isAbsolute(result)).toBe(true);
|
|
});
|
|
|
|
it("(d) triggers logger.warn when workspaces_root is inside the repo", () => {
|
|
expandWorkspacesRoot("workspaces", REPO_ROOT);
|
|
expect(rootLogger.warn).toHaveBeenCalledOnce();
|
|
expect(rootLogger.warn).toHaveBeenCalledWith(
|
|
expect.objectContaining({ workspacesRoot: expect.stringContaining(REPO_ROOT) }),
|
|
expect.stringContaining("CLAUDE.md")
|
|
);
|
|
});
|
|
|
|
it("(d) does NOT warn when workspaces_root is outside the repo", () => {
|
|
expandWorkspacesRoot("~/.disclaw/workspaces", REPO_ROOT);
|
|
expect(rootLogger.warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("(d) does NOT warn when an absolute path outside the repo is given", () => {
|
|
expandWorkspacesRoot("/tmp/disclaw-workspaces", REPO_ROOT);
|
|
expect(rootLogger.warn).not.toHaveBeenCalled();
|
|
});
|
|
});
|