mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:10:44 +00:00
test: share cache trace memory fixture
This commit is contained in:
@@ -5,6 +5,25 @@ import { resolveUserPath } from "../utils.js";
|
||||
import { createCacheTrace } from "./cache-trace.js";
|
||||
|
||||
describe("createCacheTrace", () => {
|
||||
function createMemoryTraceForTest() {
|
||||
const lines: string[] = [];
|
||||
const trace = createCacheTrace({
|
||||
cfg: {
|
||||
diagnostics: {
|
||||
cacheTrace: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
env: {},
|
||||
writer: {
|
||||
filePath: "memory",
|
||||
write: (line) => lines.push(line),
|
||||
},
|
||||
});
|
||||
return { lines, trace };
|
||||
}
|
||||
|
||||
it("returns null when diagnostics cache tracing is disabled", () => {
|
||||
const trace = createCacheTrace({
|
||||
cfg: {} as OpenClawConfig,
|
||||
@@ -135,21 +154,7 @@ describe("createCacheTrace", () => {
|
||||
});
|
||||
|
||||
it("sanitizes cache-trace payloads before writing", () => {
|
||||
const lines: string[] = [];
|
||||
const trace = createCacheTrace({
|
||||
cfg: {
|
||||
diagnostics: {
|
||||
cacheTrace: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
env: {},
|
||||
writer: {
|
||||
filePath: "memory",
|
||||
write: (line) => lines.push(line),
|
||||
},
|
||||
});
|
||||
const { lines, trace } = createMemoryTraceForTest();
|
||||
|
||||
trace?.recordStage("stream:context", {
|
||||
system: {
|
||||
@@ -241,21 +246,7 @@ describe("createCacheTrace", () => {
|
||||
});
|
||||
|
||||
it("handles circular references in messages without stack overflow", () => {
|
||||
const lines: string[] = [];
|
||||
const trace = createCacheTrace({
|
||||
cfg: {
|
||||
diagnostics: {
|
||||
cacheTrace: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
env: {},
|
||||
writer: {
|
||||
filePath: "memory",
|
||||
write: (line) => lines.push(line),
|
||||
},
|
||||
});
|
||||
const { lines, trace } = createMemoryTraceForTest();
|
||||
|
||||
const parent: Record<string, unknown> = { role: "user", content: "hello" };
|
||||
const child: Record<string, unknown> = { ref: parent };
|
||||
|
||||
Reference in New Issue
Block a user