chore: consolidate test files into __tests__/ dirs and clean stray engine artifacts
- Move all co-located *.test.* files into sibling __tests__/ directories so the
layout is consistent across packages (159 renames + content-rewrite moves).
Updates relative imports, vi.mock specifiers, and __dirname/import.meta.url
path resolutions where tests read fixtures from disk.
- Drop tracked tsc-emit alongside engine .ts sources (auth-storage/logger/
skill-resolver/context-limit-detector/pi.{js,d.ts,*.map}). These were
accidentally committed in a merge and the stale pi.js was masking a real
test-mock vs source mismatch (tests imported "../pi.js" and vite preferred
the stale build over pi.ts).
- Add packages/engine/.gitignore to block future src/*.{js,d.ts,map}.
- Refactor plugin pi-module seams (openclaw/paperclip/hermes) to ESM-import
createFnAgent / promptWithFallback / describeModel from @fusion/engine
instead of require()-ing packages/engine/src/pi.js. Adds @fusion/engine to
the two plugin package.jsons that were missing it; exports describeModel
from the engine public API.
- Fix engine test mocks now that they run against current pi.ts: add
ModelRegistry.create static to mocks in pi.test.ts and pi-create-fn-agent
.test.ts; switch three boundary-result toEqual assertions to toMatchObject
so the new content/isError fields don't trip exact-match comparison.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
88
packages/engine/src/__tests__/logger.test.ts
Normal file
88
packages/engine/src/__tests__/logger.test.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import {
|
||||
createLogger,
|
||||
schedulerLog,
|
||||
executorLog,
|
||||
triageLog,
|
||||
mergerLog,
|
||||
worktreePoolLog,
|
||||
reviewerLog,
|
||||
remoteNodeLog,
|
||||
} from "../logger.js";
|
||||
|
||||
describe("createLogger", () => {
|
||||
let logSpy: ReturnType<typeof vi.spyOn>;
|
||||
let warnSpy: ReturnType<typeof vi.spyOn>;
|
||||
let errorSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
logSpy.mockRestore();
|
||||
warnSpy.mockRestore();
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("formats log output as [prefix] message on stderr", () => {
|
||||
const logger = createLogger("test");
|
||||
logger.log("hello world");
|
||||
expect(logSpy).not.toHaveBeenCalled();
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[test] hello world");
|
||||
});
|
||||
|
||||
it("formats warn output as [prefix] message", () => {
|
||||
const logger = createLogger("test");
|
||||
logger.warn("something happened");
|
||||
expect(warnSpy).toHaveBeenCalledWith("\u0000fnlvl=warn\u0000[test] something happened");
|
||||
});
|
||||
|
||||
it("formats error output as [prefix] message", () => {
|
||||
const logger = createLogger("test");
|
||||
logger.error("failure");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=error\u0000[test] failure");
|
||||
});
|
||||
|
||||
it("passes extra arguments through", () => {
|
||||
const logger = createLogger("test");
|
||||
const err = new Error("boom");
|
||||
logger.error("failed:", err);
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=error\u0000[test] failed:", err);
|
||||
});
|
||||
|
||||
it("keeps log output off stdout", () => {
|
||||
const logger = createLogger("x");
|
||||
logger.log("a");
|
||||
logger.warn("b");
|
||||
logger.error("c");
|
||||
expect(logSpy).not.toHaveBeenCalled();
|
||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("pre-built instances use correct prefixes", () => {
|
||||
schedulerLog.log("tick");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[scheduler] tick");
|
||||
|
||||
executorLog.log("run");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[executor] run");
|
||||
|
||||
triageLog.log("spec");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[triage] spec");
|
||||
|
||||
mergerLog.log("merge");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[merger] merge");
|
||||
|
||||
worktreePoolLog.log("prune");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[worktree-pool] prune");
|
||||
|
||||
reviewerLog.log("review");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[reviewer] review");
|
||||
|
||||
remoteNodeLog.log("stream");
|
||||
expect(errorSpy).toHaveBeenCalledWith("\u0000fnlvl=info\u0000[remote-node] stream");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user