@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 3.18 KB
Raw
1 import { assert, describe, it } from "@effect/vitest";
2 import * as Tracer from "effect/Tracer";
3 import * as Effect from "effect/Effect";
4 import * as Predicate from "effect/Predicate";
5
6 import type { ProviderReplayTranscript } from "@t3tools/contracts";
7 import { materializeReplayTranscriptWorkspace } from "@t3tools/provider-testing/replayTranscript";
8 import { CodexOrchestratorReplayHarness } from "../Adapters/CodexAdapterV2.testkit.ts";
9 import {
10 findReplayFixture,
11 itRunsReplayFixtures,
12 runReplayFixture,
13 } from "./ProviderReplayFixtures.ts";
14
15 /** A transcript borrowed from another scenario names the thread after that scenario's title. */
16 const renameRecordedThread =
17 (recordedScenario: string, scenario: string) =>
18 (transcript: ProviderReplayTranscript): ProviderReplayTranscript => ({
19 ...transcript,
20 entries: transcript.entries.map((entry) =>
21 entry.type === "expect_outbound" &&
22 Predicate.isObject(entry.frame) &&
23 entry.frame.method === "thread/name/set" &&
24 Predicate.isObject(entry.frame.params) &&
25 entry.frame.params.name === `Replay fixture: ${recordedScenario}`
26 ? {
27 ...entry,
28 frame: {
29 ...entry.frame,
30 params: { ...entry.frame.params, name: `Replay fixture: ${scenario}` },
31 },
32 }
33 : entry,
34 ),
35 });
36
37 describe("Codex replay fixtures", () => {
38 itRunsReplayFixtures("codex", (input) =>
39 runReplayFixture({
40 ...input,
41 harness: CodexOrchestratorReplayHarness,
42 materializeWorkspace: (transcript, workspace) =>
43 Effect.succeed(materializeReplayTranscriptWorkspace(transcript, workspace)),
44 ...(input.driver.recordedScenario === undefined
45 ? {}
46 : {
47 transformTranscript: renameRecordedThread(
48 input.driver.recordedScenario,
49 input.fixtureName,
50 ),
51 }),
52 }),
53 );
54 });
55
56 it.effect(
57 "persists recorded Codex snapshots through provider transactions in the real run consumer",
58 () =>
59 Effect.gen(function* () {
60 const fixture = findReplayFixture("multi_turn")!;
61 const driver = fixture.providers.find((provider) => provider.driver === "codex")!;
62 const writes: number[] = [];
63 const tracer = Tracer.make({
64 span(options) {
65 const span = new Tracer.NativeSpan(options);
66 const end = span.end.bind(span);
67 span.end = (time, exit) => {
68 end(time, exit);
69 if (span.name === "orchestrationV2.EventSink.providerBatch") {
70 writes.push(Number(span.attributes.get("orchestration_v2.batch_writes")));
71 }
72 };
73 return span;
74 },
75 });
76 yield* runReplayFixture({
77 fixtureName: fixture.name,
78 buildInput: fixture.buildInput,
79 driver,
80 harness: CodexOrchestratorReplayHarness,
81 materializeWorkspace: (transcript, workspace) =>
82 Effect.succeed(materializeReplayTranscriptWorkspace(transcript, workspace)),
83 }).pipe(Effect.withTracer(tracer), Effect.withTracerEnabled(true));
84 assert.equal(
85 writes.reduce((total, count) => total + count, 0),
86 6,
87 );
88 assert.isTrue(writes.every((count) => count <= 3));
89 }),
90 );