



















@@ -11,6 +11,8 @@ import {
1111toTrajectoryToolDefinitions,
1212} from "./runtime.js";
131314+type TrajectoryRuntimeRecorder = NonNullable<ReturnType<typeof createTrajectoryRuntimeRecorder>>;
15+1416const tempDirs: string[] = [];
15171618function makeTempDir(): string {
@@ -25,6 +27,16 @@ afterEach(() => {
2527}
2628});
272930+function expectTrajectoryRuntimeRecorder(
31+recorder: ReturnType<typeof createTrajectoryRuntimeRecorder>,
32+): TrajectoryRuntimeRecorder {
33+expect(recorder).toEqual(expect.objectContaining({ recordEvent: expect.any(Function) }));
34+if (recorder === null) {
35+throw new Error("Expected trajectory runtime recorder");
36+}
37+return recorder;
38+}
39+2840describe("trajectory runtime", () => {
2941it("resolves a session-adjacent trajectory file by default", () => {
3042expect(
@@ -63,8 +75,8 @@ describe("trajectory runtime", () => {
6375},
6476});
657766-expect(recorder).not.toBeNull();
67-recorder?.recordEvent("context.compiled", {
78+const runtimeRecorder = expectTrajectoryRuntimeRecorder(recorder);
79+runtimeRecorder.recordEvent("context.compiled", {
6880systemPrompt: "system prompt",
6981headers: [{ name: "Authorization", value: "Bearer sk-test-secret-token" }],
7082command: "curl -H 'Authorization: Bearer sk-other-secret-token'",
@@ -102,7 +114,8 @@ describe("trajectory runtime", () => {
102114},
103115});
104116105-recorder?.recordEvent("context.compiled", {
117+const runtimeRecorder = expectTrajectoryRuntimeRecorder(recorder);
118+runtimeRecorder.recordEvent("context.compiled", {
106119prompt: "x".repeat(TRAJECTORY_RUNTIME_EVENT_MAX_BYTES + 1),
107120});
108121@@ -132,18 +145,19 @@ describe("trajectory runtime", () => {
132145},
133146});
134147135-recorder?.recordEvent("context.compiled", {
148+const runtimeRecorder = expectTrajectoryRuntimeRecorder(recorder);
149+runtimeRecorder.recordEvent("context.compiled", {
136150prompt: "x".repeat(180),
137151});
138-recorder?.recordEvent("prompt.submitted", {
152+runtimeRecorder.recordEvent("prompt.submitted", {
139153prompt: "y".repeat(180),
140154});
141-recorder?.recordEvent("model.completed", {
155+runtimeRecorder.recordEvent("model.completed", {
142156get prompt() {
143157throw new Error("stopped recorder should not read dropped payloads");
144158},
145159});
146-await recorder?.flush();
160+await runtimeRecorder.flush();
147161148162const parsed = writes.map((line) => JSON.parse(line));
149163expect(parsed.map((event) => event.type)).toContain("trace.truncated");
@@ -170,7 +184,7 @@ describe("trajectory runtime", () => {
170184},
171185});
172186173-expect(recorder).not.toBeNull();
187+expectTrajectoryRuntimeRecorder(recorder);
174188const pointer = JSON.parse(
175189fs.readFileSync(resolveTrajectoryPointerFilePath(sessionFile), "utf8"),
176190) as { runtimeFile?: string };
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。