Files
paperclip/server/src/__tests__/codex-local-adapter.test.ts
Forgotten 6e335b3fd0 Improve codex-local adapter: skill injection, stdin piping, and error parsing
Codex adapter now auto-injects Paperclip skills into ~/.codex/skills,
pipes prompts via stdin instead of passing as CLI args, filters out noisy
rollout stderr warnings, and extracts error/turn.failed messages from
JSONL output. Also broadens stale session detection for rollout path
errors. Claude-local adapter gets the same template vars (agentId,
companyId, runId) that codex-local already had.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 14:39:37 -06:00

33 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { isCodexUnknownSessionError, parseCodexJsonl } from "@paperclip/adapter-codex-local/server";
describe("codex_local parser", () => {
it("extracts session, summary, usage, and terminal error message", () => {
const stdout = [
JSON.stringify({ type: "thread.started", thread_id: "thread-123" }),
JSON.stringify({ type: "item.completed", item: { type: "agent_message", text: "hello" } }),
JSON.stringify({ type: "turn.completed", usage: { input_tokens: 10, cached_input_tokens: 2, output_tokens: 4 } }),
JSON.stringify({ type: "turn.failed", error: { message: "model access denied" } }),
].join("\n");
const parsed = parseCodexJsonl(stdout);
expect(parsed.sessionId).toBe("thread-123");
expect(parsed.summary).toBe("hello");
expect(parsed.usage).toEqual({
inputTokens: 10,
cachedInputTokens: 2,
outputTokens: 4,
});
expect(parsed.errorMessage).toBe("model access denied");
});
});
describe("codex_local stale session detection", () => {
it("treats missing rollout path as an unknown session error", () => {
const stderr =
"2026-02-19T19:58:53.281939Z ERROR codex_core::rollout::list: state db missing rollout path for thread 019c775d-967c-7ef1-acc7-e396dc2c87cc";
expect(isCodexUnknownSessionError("", stderr)).toBe(true);
});
});