-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Expand file tree
/
Copy pathsetupPromptLogging.vitest.ts
More file actions
62 lines (50 loc) · 1.43 KB
/
setupPromptLogging.vitest.ts
File metadata and controls
62 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { afterEach, describe, expect, it, vi } from "vitest";
const {
mockCreateWriteStream,
mockEnd,
mockGetPromptLogsPath,
mockLLMLogFormatter,
} = vi.hoisted(() => ({
mockEnd: vi.fn(),
mockCreateWriteStream: vi.fn(() => ({
end: vi.fn(),
})),
mockGetPromptLogsPath: vi.fn(() => "/tmp/prompt.log"),
mockLLMLogFormatter: vi.fn(),
}));
mockCreateWriteStream.mockImplementation(() => ({
end: mockEnd,
}));
vi.mock("node:fs", () => ({
__esModule: true,
default: {
createWriteStream: mockCreateWriteStream,
},
}));
vi.mock("core/util/paths", () => ({
getPromptLogsPath: mockGetPromptLogsPath,
}));
vi.mock("core/llm/logFormatter", () => ({
LLMLogFormatter: mockLLMLogFormatter,
}));
import { setupPromptLogging } from "./setupPromptLogging";
describe("setupPromptLogging", () => {
afterEach(() => {
vi.clearAllMocks();
mockCreateWriteStream.mockImplementation(() => ({
end: mockEnd,
}));
});
it("creates a prompt log stream and closes it on dispose", () => {
const llmLogger = {} as any;
const disposable = setupPromptLogging(llmLogger);
expect(mockGetPromptLogsPath).toHaveBeenCalledTimes(1);
expect(mockCreateWriteStream).toHaveBeenCalledWith("/tmp/prompt.log");
expect(mockLLMLogFormatter).toHaveBeenCalledWith(
llmLogger,
expect.objectContaining({ end: mockEnd }),
);
disposable.dispose();
expect(mockEnd).toHaveBeenCalledTimes(1);
});
});