@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 90 lines 2.5 KB
Raw
1 import { assert, it } from "@effect/vitest";
2 import * as CodexClient from "effect-codex-app-server/client";
3 import * as CodexReplay from "effect-codex-app-server/replay";
4 import * as Effect from "effect/Effect";
5
6 import { revertCodexThread } from "./CodexThreadRevert.ts";
7
8 const page = (
9 id: number,
10 cursor: string | null,
11 limit: number,
12 turns: string[],
13 nextCursor: string | null,
14 ) => [
15 {
16 type: "expect_outbound" as const,
17 frame: {
18 id,
19 method: "thread/turns/list",
20 params: {
21 threadId: "thread",
22 cursor,
23 limit,
24 sortDirection: "desc",
25 itemsView: "summary",
26 },
27 },
28 },
29 {
30 type: "emit_inbound" as const,
31 frame: {
32 id,
33 result: {
34 data: turns.map((id) => ({ id, items: [], status: "completed", error: null })),
35 nextCursor,
36 },
37 },
38 },
39 ];
40
41 it.effect("finds the revert boundary across pages of newest-first turns", () =>
42 Effect.gen(function* () {
43 const client = yield* CodexClient.CodexAppServerClient;
44 const result = yield* revertCodexThread(client, "thread", 3).pipe(Effect.flip);
45 assert.equal(result.message, "boundary reached");
46 }).pipe(
47 Effect.provide(
48 CodexReplay.layerReplay({
49 provider: "codex",
50 protocol: "codex.app-server",
51 version: "test",
52 scenario: "revert-pages",
53 entries: [
54 ...page(1, null, 3, ["newest", "middle"], "older"),
55 ...page(2, "older", 1, ["boundary"], null),
56 {
57 type: "expect_outbound",
58 frame: {
59 id: 3,
60 method: "thread/revert",
61 params: { threadId: "thread", beforeTurnId: "boundary" },
62 },
63 },
64 {
65 type: "emit_inbound",
66 frame: { id: 3, error: { code: -32603, message: "boundary reached" } },
67 },
68 ],
69 }),
70 ),
71 ),
72 );
73
74 it.effect("rejects repeated cursors instead of looping or reverting incomplete history", () =>
75 Effect.gen(function* () {
76 const client = yield* CodexClient.CodexAppServerClient;
77 const result = yield* revertCodexThread(client, "thread", 3).pipe(Effect.flip);
78 assert.equal(result.message, "Thread history pagination repeated a cursor.");
79 }).pipe(
80 Effect.provide(
81 CodexReplay.layerReplay({
82 provider: "codex",
83 protocol: "codex.app-server",
84 version: "test",
85 scenario: "revert-loop",
86 entries: [...page(1, null, 3, ["newest"], "again"), ...page(2, "again", 2, [], "again")],
87 }),
88 ),
89 ),
90 );