From e83e59e19b68022844212d4b6412436f4d682fd7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 22:00:03 +0100 Subject: [PATCH] test: tighten trajectory assertions --- src/trajectory/export.test.ts | 24 +++++++++++++----------- src/trajectory/metadata.test.ts | 23 ++++++++++------------- src/trajectory/runtime.test.ts | 12 ++++-------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/trajectory/export.test.ts b/src/trajectory/export.test.ts index 35e2c777ef5..712f0c92396 100644 --- a/src/trajectory/export.test.ts +++ b/src/trajectory/export.test.ts @@ -213,14 +213,17 @@ describe("exportTrajectoryBundle", () => { writeSimpleSessionFile(sessionFile); fs.mkdirSync(outputDir); - await expect( - exportTrajectoryBundle({ + try { + await exportTrajectoryBundle({ outputDir, sessionFile, sessionId: "session-1", workspaceDir: tmpDir, - }), - ).rejects.toMatchObject({ code: "EEXIST" }); + }); + throw new Error("expected trajectory export to reject an existing output directory"); + } catch (error) { + expect((error as NodeJS.ErrnoException).code).toBe("EEXIST"); + } }); it("does not synthesize prompt files from export-time fallbacks", async () => { @@ -748,9 +751,10 @@ describe("exportTrajectoryBundle", () => { .trim() .split(/\r?\n/u) .map((line) => JSON.parse(line) as TrajectoryEvent); - expect(eventTypes(exportedEvents)).toEqual( - expect.arrayContaining(["tool.call", "tool.result", "context.compiled"]), - ); + const types = eventTypes(exportedEvents); + expect(types).toContain("tool.call"); + expect(types).toContain("tool.result"); + expect(types).toContain("context.compiled"); expect(JSON.stringify(exportedEvents)).toContain("$WORKSPACE_DIR/inside.txt"); expect(JSON.stringify(exportedEvents)).not.toContain("$WORKSPACE_DIR2"); @@ -777,10 +781,8 @@ describe("exportTrajectoryBundle", () => { const metadata = JSON.parse(fs.readFileSync(path.join(outputDir, "metadata.json"), "utf8")) as { skills?: { entries?: Array<{ id?: string; invoked?: boolean }> }; }; - expect(metadata.skills?.entries?.[0]).toMatchObject({ - id: "weather", - invoked: true, - }); + expect(metadata.skills?.entries?.[0]?.id).toBe("weather"); + expect(metadata.skills?.entries?.[0]?.invoked).toBe(true); const prompts = fs.readFileSync(path.join(outputDir, "prompts.json"), "utf8"); const artifacts = fs.readFileSync(path.join(outputDir, "artifacts.json"), "utf8"); const systemPrompt = fs.readFileSync(path.join(outputDir, "system-prompt.txt"), "utf8"); diff --git a/src/trajectory/metadata.test.ts b/src/trajectory/metadata.test.ts index ef3aa3cde45..f3911cc8453 100644 --- a/src/trajectory/metadata.test.ts +++ b/src/trajectory/metadata.test.ts @@ -171,10 +171,8 @@ describe("trajectory metadata", () => { expect(config.redacted?.providers?.openai?.apiKey).toBe(REDACTED_SENTINEL); expect(plugins.source).toBe("active-registry"); expect(plugins.entries?.map((entry) => entry.id)).toEqual(["demo-plugin"]); - expect(skills.entries?.[0]).toMatchObject({ - id: "weather", - filePath: "/tmp/workspace/skills/weather/SKILL.md", - }); + expect(skills.entries?.[0]?.id).toBe("weather"); + expect(skills.entries?.[0]?.filePath).toBe("/tmp/workspace/skills/weather/SKILL.md"); }); it("captures final artifact summaries for export sidecars", () => { @@ -202,14 +200,13 @@ describe("trajectory metadata", () => { messagingToolSentTargets: [], }); - expect(artifacts).toMatchObject({ - finalStatus: "success", - assistantTexts: ["done"], - itemLifecycle: { - startedCount: 2, - completedCount: 2, - activeCount: 0, - }, - }); + expect(artifacts.finalStatus).toBe("success"); + expect(artifacts.assistantTexts).toEqual(["done"]); + const lifecycle = artifacts.itemLifecycle as + | { startedCount?: number; completedCount?: number; activeCount?: number } + | undefined; + expect(lifecycle?.startedCount).toBe(2); + expect(lifecycle?.completedCount).toBe(2); + expect(lifecycle?.activeCount).toBe(0); }); }); diff --git a/src/trajectory/runtime.test.ts b/src/trajectory/runtime.test.ts index beec1a4c0b4..b7f82861da2 100644 --- a/src/trajectory/runtime.test.ts +++ b/src/trajectory/runtime.test.ts @@ -121,10 +121,8 @@ describe("trajectory runtime", () => { expect(writes).toHaveLength(1); const parsed = JSON.parse(writes[0]); - expect(parsed.data.prompt).toMatchObject({ - truncated: true, - reason: "trajectory-field-size-limit", - }); + expect(parsed.data.prompt.truncated).toBe(true); + expect(parsed.data.prompt.reason).toBe("trajectory-field-size-limit"); expect(Buffer.byteLength(writes[0], "utf8")).toBeLessThanOrEqual( TRAJECTORY_RUNTIME_EVENT_MAX_BYTES + 1, ); @@ -162,10 +160,8 @@ describe("trajectory runtime", () => { const parsed = writes.map((line) => JSON.parse(line)); expect(parsed.map((event) => event.type)).toContain("trace.truncated"); const truncated = parsed.find((event) => event.type === "trace.truncated"); - expect(truncated?.data).toMatchObject({ - reason: "trajectory-runtime-file-size-limit", - limitBytes: 900, - }); + expect(truncated?.data.reason).toBe("trajectory-runtime-file-size-limit"); + expect(truncated?.data.limitBytes).toBe(900); expect(truncated?.data.droppedEvents).toBeGreaterThan(0); });