Skip to content

Commit 09fcd19

Browse files
committed
test: tighten codex event assertions
1 parent c20d45e commit 09fcd19

5 files changed

Lines changed: 31 additions & 39 deletions

File tree

‎extensions/codex/src/app-server/client.test.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
55
import {
66
__testing,
77
CodexAppServerClient,
8-
CodexAppServerRpcError,
98
MIN_CODEX_APP_SERVER_VERSION,
109
isCodexAppServerApprovalRequest,
1110
readCodexVersionFromUserAgent,
@@ -122,11 +121,9 @@ describe("CodexAppServerClient", () => {
122121
const outbound = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
123122
harness.send({ id: outbound.id, error: { code: -32601, message: "Method not found" } });
124123

125-
await expect(request).rejects.toMatchObject({
126-
name: "CodexAppServerRpcError",
127-
code: -32601,
128-
message: "Method not found",
129-
} satisfies Partial<CodexAppServerRpcError>);
124+
await expect(request).rejects.toHaveProperty("name", "CodexAppServerRpcError");
125+
await expect(request).rejects.toHaveProperty("code", -32601);
126+
await expect(request).rejects.toHaveProperty("message", "Method not found");
130127
});
131128

132129
it("rejects timed-out requests and ignores late responses", async () => {

‎extensions/codex/src/app-server/event-projector.test.ts‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,26 +1087,22 @@ describe("CodexAppServerEventProjector", () => {
10871087
mockCallArg(afterToolCall, 0, 0, "after_tool_call event"),
10881088
"after_tool_call event",
10891089
);
1090-
expect(event).toMatchObject({
1091-
toolName: "bash",
1092-
params: { command: "pnpm test extensions/codex", cwd: "/workspace" },
1093-
runId: "run-1",
1094-
toolCallId: "cmd-observed",
1095-
result: { status: "completed", exitCode: 0, durationMs: 42 },
1096-
});
1090+
expect(event.toolName).toBe("bash");
1091+
expect(event.params).toEqual({ command: "pnpm test extensions/codex", cwd: "/workspace" });
1092+
expect(event.runId).toBe("run-1");
1093+
expect(event.toolCallId).toBe("cmd-observed");
1094+
expect(event.result).toEqual({ status: "completed", exitCode: 0, durationMs: 42 });
10971095
expect(event.durationMs).toBeGreaterThanOrEqual(42);
10981096
const context = requireRecord(
10991097
mockCallArg(afterToolCall, 0, 1, "after_tool_call context"),
11001098
"after_tool_call context",
11011099
);
1102-
expect(context).toMatchObject({
1103-
agentId: "main",
1104-
sessionId: "session-1",
1105-
sessionKey: "agent:main:session-1",
1106-
runId: "run-1",
1107-
toolName: "bash",
1108-
toolCallId: "cmd-observed",
1109-
});
1100+
expect(context.agentId).toBe("main");
1101+
expect(context.sessionId).toBe("session-1");
1102+
expect(context.sessionKey).toBe("agent:main:session-1");
1103+
expect(context.runId).toBe("run-1");
1104+
expect(context.toolName).toBe("bash");
1105+
expect(context.toolCallId).toBe("cmd-observed");
11101106
});
11111107

11121108
it("does not duplicate native items already covered by PostToolUse relay", async () => {
@@ -1155,13 +1151,11 @@ describe("CodexAppServerEventProjector", () => {
11551151
mockCallArg(afterToolCall, 0, 0, "after_tool_call event"),
11561152
"after_tool_call event",
11571153
);
1158-
expect(event).toMatchObject({
1159-
toolName: "web_search",
1160-
params: { query: "native tool observability" },
1161-
runId: "run-1",
1162-
toolCallId: "search-observed",
1163-
result: { status: "completed" },
1164-
});
1154+
expect(event.toolName).toBe("web_search");
1155+
expect(event.params).toEqual({ query: "native tool observability" });
1156+
expect(event.runId).toBe("run-1");
1157+
expect(event.toolCallId).toBe("search-observed");
1158+
expect(event.result).toEqual({ status: "completed" });
11651159
});
11661160

11671161
it("records dynamic OpenClaw tool calls in mirrored transcript snapshots", async () => {

‎extensions/codex/src/app-server/outcome-fallback-runtime-contract.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,12 @@ describe("Outcome/fallback runtime contract - Codex app-server adapter", () => {
357357
const result = await build();
358358

359359
expect(result.agentHarnessResultClassification).toBe(classification);
360-
expect(classifyProjectedAttemptResult(result)).toMatchObject({
361-
reason: "format",
362-
code: expectedCode,
363-
});
360+
const projected = classifyProjectedAttemptResult(result);
361+
if (!projected || !("reason" in projected)) {
362+
throw new Error("expected format fallback projection");
363+
}
364+
expect(projected.reason).toBe("format");
365+
expect(projected.code).toBe(expectedCode);
364366
},
365367
);
366368

‎extensions/codex/src/app-server/trajectory.test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ describe("Codex trajectory recorder", () => {
162162
const parsed = JSON.parse(
163163
fs.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8"),
164164
) as { data?: { truncated?: boolean; reason?: string } };
165-
expect(parsed.data).toMatchObject({
166-
truncated: true,
167-
reason: "trajectory-event-size-limit",
168-
});
165+
expect(parsed.data?.truncated).toBe(true);
166+
expect(parsed.data?.reason).toBe("trajectory-event-size-limit");
169167
});
170168
});

‎extensions/codex/src/app-server/transcript-mirror.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe("mirrorCodexAppServerTranscript", () => {
251251
idempotencyScope: "scope-1",
252252
});
253253

254-
await expect(fs.readFile(sessionFile, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
254+
await expect(fs.readFile(sessionFile, "utf8")).rejects.toHaveProperty("code", "ENOENT");
255255
});
256256

257257
it("migrates small linear transcripts before mirroring", async () => {
@@ -302,8 +302,9 @@ describe("mirrorCodexAppServerTranscript", () => {
302302
)
303303
.filter((record) => record.type === "message");
304304

305-
expect(records[0]).toMatchObject({ id: "legacy-user", parentId: null });
306-
expect(records[1]).toMatchObject({ parentId: "legacy-user" });
305+
expect(records[0]?.id).toBe("legacy-user");
306+
expect(records[0]?.parentId).toBeNull();
307+
expect(records[1]?.parentId).toBe("legacy-user");
307308
});
308309

309310
// Helpers for the identity-based regression tests below.

0 commit comments

Comments
 (0)