
























@@ -8,6 +8,8 @@ import {
88resolveCodexTrajectoryPointerFlags,
99} from "./trajectory.js";
101011+type CodexTrajectoryRecorder = NonNullable<ReturnType<typeof createCodexTrajectoryRecorder>>;
12+1113const tempDirs: string[] = [];
12141315function makeTempDir(): string {
@@ -22,6 +24,16 @@ afterEach(() => {
2224}
2325});
242627+function expectTrajectoryRecorder(
28+recorder: ReturnType<typeof createCodexTrajectoryRecorder>,
29+): CodexTrajectoryRecorder {
30+expect(recorder).toEqual(expect.objectContaining({ recordEvent: expect.any(Function) }));
31+if (recorder === null) {
32+throw new Error("Expected Codex trajectory recorder");
33+}
34+return recorder;
35+}
36+2537describe("Codex trajectory recorder", () => {
2638it("keeps write flags usable when O_NOFOLLOW is unavailable", () => {
2739const constants = {
@@ -52,13 +64,13 @@ describe("Codex trajectory recorder", () => {
5264env: {},
5365});
546655-expect(recorder).not.toBeNull();
56-recorder?.recordEvent("session.started", {
67+const trajectoryRecorder = expectTrajectoryRecorder(recorder);
68+trajectoryRecorder.recordEvent("session.started", {
5769apiKey: "secret",
5870headers: [{ name: "Authorization", value: "Bearer sk-test-secret-token" }],
5971command: "curl -H 'Authorization: Bearer sk-other-secret-token'",
6072});
61-await recorder?.flush();
73+await trajectoryRecorder.flush();
62746375const filePath = path.join(tmpDir, "session.trajectory.jsonl");
6476const content = fs.readFileSync(filePath, "utf8");
@@ -82,8 +94,9 @@ describe("Codex trajectory recorder", () => {
8294env: { OPENCLAW_TRAJECTORY_DIR: tmpDir },
8395});
849685-recorder?.recordEvent("session.started");
86-await recorder?.flush();
97+const trajectoryRecorder = expectTrajectoryRecorder(recorder);
98+trajectoryRecorder.recordEvent("session.started");
99+await trajectoryRecorder.flush();
8710088101expect(fs.existsSync(path.join(tmpDir, "___evil_session.jsonl"))).toBe(true);
89102});
@@ -119,8 +132,9 @@ describe("Codex trajectory recorder", () => {
119132env: {},
120133});
121134122-recorder?.recordEvent("session.started");
123-await recorder?.flush();
135+const trajectoryRecorder = expectTrajectoryRecorder(recorder);
136+trajectoryRecorder.recordEvent("session.started");
137+await trajectoryRecorder.flush();
124138125139expect(fs.existsSync(path.join(targetDir, "session.trajectory.jsonl"))).toBe(false);
126140});
@@ -137,12 +151,13 @@ describe("Codex trajectory recorder", () => {
137151env: {},
138152});
139153140-recorder?.recordEvent("context.compiled", {
154+const trajectoryRecorder = expectTrajectoryRecorder(recorder);
155+trajectoryRecorder.recordEvent("context.compiled", {
141156fields: Object.fromEntries(
142157Array.from({ length: 100 }, (_, index) => [`field-${index}`, "x".repeat(3_000)]),
143158),
144159});
145-await recorder?.flush();
160+await trajectoryRecorder.flush();
146161147162const parsed = JSON.parse(
148163fs.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8"),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。