mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: tighten codex event assertions
This commit is contained in:
@@ -5,7 +5,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
__testing,
|
||||
CodexAppServerClient,
|
||||
CodexAppServerRpcError,
|
||||
MIN_CODEX_APP_SERVER_VERSION,
|
||||
isCodexAppServerApprovalRequest,
|
||||
readCodexVersionFromUserAgent,
|
||||
@@ -122,11 +121,9 @@ describe("CodexAppServerClient", () => {
|
||||
const outbound = JSON.parse(harness.writes[0] ?? "{}") as { id?: number };
|
||||
harness.send({ id: outbound.id, error: { code: -32601, message: "Method not found" } });
|
||||
|
||||
await expect(request).rejects.toMatchObject({
|
||||
name: "CodexAppServerRpcError",
|
||||
code: -32601,
|
||||
message: "Method not found",
|
||||
} satisfies Partial<CodexAppServerRpcError>);
|
||||
await expect(request).rejects.toHaveProperty("name", "CodexAppServerRpcError");
|
||||
await expect(request).rejects.toHaveProperty("code", -32601);
|
||||
await expect(request).rejects.toHaveProperty("message", "Method not found");
|
||||
});
|
||||
|
||||
it("rejects timed-out requests and ignores late responses", async () => {
|
||||
|
||||
@@ -1087,26 +1087,22 @@ describe("CodexAppServerEventProjector", () => {
|
||||
mockCallArg(afterToolCall, 0, 0, "after_tool_call event"),
|
||||
"after_tool_call event",
|
||||
);
|
||||
expect(event).toMatchObject({
|
||||
toolName: "bash",
|
||||
params: { command: "pnpm test extensions/codex", cwd: "/workspace" },
|
||||
runId: "run-1",
|
||||
toolCallId: "cmd-observed",
|
||||
result: { status: "completed", exitCode: 0, durationMs: 42 },
|
||||
});
|
||||
expect(event.toolName).toBe("bash");
|
||||
expect(event.params).toEqual({ command: "pnpm test extensions/codex", cwd: "/workspace" });
|
||||
expect(event.runId).toBe("run-1");
|
||||
expect(event.toolCallId).toBe("cmd-observed");
|
||||
expect(event.result).toEqual({ status: "completed", exitCode: 0, durationMs: 42 });
|
||||
expect(event.durationMs).toBeGreaterThanOrEqual(42);
|
||||
const context = requireRecord(
|
||||
mockCallArg(afterToolCall, 0, 1, "after_tool_call context"),
|
||||
"after_tool_call context",
|
||||
);
|
||||
expect(context).toMatchObject({
|
||||
agentId: "main",
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
runId: "run-1",
|
||||
toolName: "bash",
|
||||
toolCallId: "cmd-observed",
|
||||
});
|
||||
expect(context.agentId).toBe("main");
|
||||
expect(context.sessionId).toBe("session-1");
|
||||
expect(context.sessionKey).toBe("agent:main:session-1");
|
||||
expect(context.runId).toBe("run-1");
|
||||
expect(context.toolName).toBe("bash");
|
||||
expect(context.toolCallId).toBe("cmd-observed");
|
||||
});
|
||||
|
||||
it("does not duplicate native items already covered by PostToolUse relay", async () => {
|
||||
@@ -1155,13 +1151,11 @@ describe("CodexAppServerEventProjector", () => {
|
||||
mockCallArg(afterToolCall, 0, 0, "after_tool_call event"),
|
||||
"after_tool_call event",
|
||||
);
|
||||
expect(event).toMatchObject({
|
||||
toolName: "web_search",
|
||||
params: { query: "native tool observability" },
|
||||
runId: "run-1",
|
||||
toolCallId: "search-observed",
|
||||
result: { status: "completed" },
|
||||
});
|
||||
expect(event.toolName).toBe("web_search");
|
||||
expect(event.params).toEqual({ query: "native tool observability" });
|
||||
expect(event.runId).toBe("run-1");
|
||||
expect(event.toolCallId).toBe("search-observed");
|
||||
expect(event.result).toEqual({ status: "completed" });
|
||||
});
|
||||
|
||||
it("records dynamic OpenClaw tool calls in mirrored transcript snapshots", async () => {
|
||||
|
||||
@@ -357,10 +357,12 @@ describe("Outcome/fallback runtime contract - Codex app-server adapter", () => {
|
||||
const result = await build();
|
||||
|
||||
expect(result.agentHarnessResultClassification).toBe(classification);
|
||||
expect(classifyProjectedAttemptResult(result)).toMatchObject({
|
||||
reason: "format",
|
||||
code: expectedCode,
|
||||
});
|
||||
const projected = classifyProjectedAttemptResult(result);
|
||||
if (!projected || !("reason" in projected)) {
|
||||
throw new Error("expected format fallback projection");
|
||||
}
|
||||
expect(projected.reason).toBe("format");
|
||||
expect(projected.code).toBe(expectedCode);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -162,9 +162,7 @@ describe("Codex trajectory recorder", () => {
|
||||
const parsed = JSON.parse(
|
||||
fs.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8"),
|
||||
) as { data?: { truncated?: boolean; reason?: string } };
|
||||
expect(parsed.data).toMatchObject({
|
||||
truncated: true,
|
||||
reason: "trajectory-event-size-limit",
|
||||
});
|
||||
expect(parsed.data?.truncated).toBe(true);
|
||||
expect(parsed.data?.reason).toBe("trajectory-event-size-limit");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -251,7 +251,7 @@ describe("mirrorCodexAppServerTranscript", () => {
|
||||
idempotencyScope: "scope-1",
|
||||
});
|
||||
|
||||
await expect(fs.readFile(sessionFile, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expect(fs.readFile(sessionFile, "utf8")).rejects.toHaveProperty("code", "ENOENT");
|
||||
});
|
||||
|
||||
it("migrates small linear transcripts before mirroring", async () => {
|
||||
@@ -302,8 +302,9 @@ describe("mirrorCodexAppServerTranscript", () => {
|
||||
)
|
||||
.filter((record) => record.type === "message");
|
||||
|
||||
expect(records[0]).toMatchObject({ id: "legacy-user", parentId: null });
|
||||
expect(records[1]).toMatchObject({ parentId: "legacy-user" });
|
||||
expect(records[0]?.id).toBe("legacy-user");
|
||||
expect(records[0]?.parentId).toBeNull();
|
||||
expect(records[1]?.parentId).toBe("legacy-user");
|
||||
});
|
||||
|
||||
// Helpers for the identity-based regression tests below.
|
||||
|
||||
Reference in New Issue
Block a user