-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathdebug-logger.test.ts
More file actions
46 lines (43 loc) · 1.62 KB
/
debug-logger.test.ts
File metadata and controls
46 lines (43 loc) · 1.62 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
import { test } from "node:test";
import assert from "node:assert/strict";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { getDebugLogPath, logOpenAIChatCompletionDebug } from "../common/debug-logger";
test("debug logger appends full entries without rotation", () => {
const originalHome = process.env.HOME;
const home = fs.mkdtempSync(path.join(os.tmpdir(), "deepcode-debug-log-home-"));
process.env.HOME = home;
try {
for (let index = 0; index < 25; index += 1) {
logOpenAIChatCompletionDebug({
timestamp: "2026-01-01T00:00:00.000Z",
location: "test.location",
requestId: `request-${index}`,
model: "test-model",
request: {
model: "test-model",
messages: [{ role: "user", content: `full request content ${index}` }],
},
response: {
choices: [{ message: { content: `full response content ${index}` } }],
},
});
}
const raw = fs.readFileSync(getDebugLogPath(), "utf8");
const lines = raw.trim().split("\n");
assert.equal(lines.length, 25);
const first = JSON.parse(lines[0]) as Record<string, any>;
const last = JSON.parse(lines[24]) as Record<string, any>;
assert.equal(first.requestId, "request-0");
assert.equal(first.request.messages[0].content, "full request content 0");
assert.equal(last.requestId, "request-24");
assert.equal(last.response.choices[0].message.content, "full response content 24");
} finally {
if (originalHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = originalHome;
}
}
});