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
| 1 | import { describe, it } from "@effect/vitest"; |
| 2 | import type { ProviderReplayEntry } from "@t3tools/contracts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | |
| 5 | import { OpenCodeOrchestratorReplayHarness } from "../Adapters/OpenCodeAdapterV2.testkit.ts"; |
| 6 | import { |
| 7 | OPENCODE2_HTTP_PROTOCOL, |
| 8 | OpenCode2OrchestratorReplayHarness, |
| 9 | } from "../Adapters/OpenCode2AdapterV2.testkit.ts"; |
| 10 | import { |
| 11 | findReplayFixture, |
| 12 | itRunsReplayFixtures, |
| 13 | readReplayFixtureTranscript, |
| 14 | runReplayFixture, |
| 15 | type ReplayFixtureCase, |
| 16 | } from "./ProviderReplayFixtures.ts"; |
| 17 | |
| 18 | // OpenCode fixtures are recorded against either the v1 or the v2 HTTP protocol. |
| 19 | function runOpenCodeReplayFixture(input: ReplayFixtureCase) { |
| 20 | return readReplayFixtureTranscript(input.driver.transcriptFile).pipe( |
| 21 | Effect.flatMap((transcript) => |
| 22 | transcript.protocol === OPENCODE2_HTTP_PROTOCOL |
| 23 | ? runReplayFixture({ ...input, harness: OpenCode2OrchestratorReplayHarness }) |
| 24 | : runReplayFixture({ ...input, harness: OpenCodeOrchestratorReplayHarness }), |
| 25 | ), |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | describe("OpenCode replay fixtures", () => { |
| 30 | itRunsReplayFixtures("opencode", runOpenCodeReplayFixture); |
| 31 | |
| 32 | it.effect.each( |
| 33 | ( |
| 34 | [ |
| 35 | ["opencode2_subagent", "session.execution.started.2"], |
| 36 | ["opencode2_background", "session.execution.started.3"], |
| 37 | ] as const |
| 38 | ).flatMap(([fixtureName, label]) => { |
| 39 | const fixture = findReplayFixture(fixtureName); |
| 40 | const provider = fixture?.providers[0]; |
| 41 | return fixture === undefined || provider === undefined |
| 42 | ? [] |
| 43 | : [[fixtureName, label, fixture, provider] as const]; |
| 44 | }), |
| 45 | )( |
| 46 | "runs %s when %s is an execution start this build cannot decode", |
| 47 | ([fixtureName, label, fixture, provider]) => |
| 48 | runOpenCodeReplayFixture({ |
| 49 | fixtureName, |
| 50 | buildInput: fixture.buildInput, |
| 51 | driver: provider, |
| 52 | transformTranscript: (transcript) => ({ |
| 53 | ...transcript, |
| 54 | entries: transcript.entries.map((entry) => |
| 55 | entry.type === "emit_inbound" && entry.label === label |
| 56 | ? undecodableEvent(entry) |
| 57 | : entry, |
| 58 | ), |
| 59 | }), |
| 60 | }), |
| 61 | ); |
| 62 | }); |
| 63 | |
| 64 | function undecodableEvent(entry: ProviderReplayEntry): ProviderReplayEntry { |
| 65 | if (entry.type !== "emit_inbound") return entry; |
| 66 | const frame = entry.frame as { readonly event: Record<string, unknown> }; |
| 67 | return { ...entry, frame: { ...frame, event: { ...frame.event, durable: "not-an-envelope" } } }; |
| 68 | } |