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 { assert, it } from "@effect/vitest"; |
| 2 | import { WS_METHODS } from "@t3tools/contracts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Option from "effect/Option"; |
| 5 | import type * as Tracer from "effect/Tracer"; |
| 6 | import * as Headers from "effect/http/Headers"; |
| 7 | import * as Rpc from "effect/rpc/Rpc"; |
| 8 | import { RequestId } from "effect/rpc/RpcMessage"; |
| 9 | |
| 10 | import { RpcInstrumentation, rpcInstrumentationLayer } from "./RpcInstrumentation.ts"; |
| 11 | |
| 12 | it.effect("starts each RPC in its own trace, linked to the connection span", () => |
| 13 | Effect.gen(function* () { |
| 14 | const middleware = yield* RpcInstrumentation; |
| 15 | let rpcSpan: Tracer.Span | undefined; |
| 16 | const handler = Effect.gen(function* () { |
| 17 | rpcSpan = yield* Effect.currentSpan; |
| 18 | }).pipe(Effect.orDie, Effect.asVoid); |
| 19 | |
| 20 | const connection = yield* Effect.gen(function* () { |
| 21 | const span = yield* Effect.currentSpan; |
| 22 | yield* middleware(handler as never, { |
| 23 | client: new Rpc.ServerClient(0), |
| 24 | requestId: RequestId(1), |
| 25 | rpc: Rpc.make(WS_METHODS.reviewGetDiffPreview), |
| 26 | payload: {}, |
| 27 | headers: Headers.empty, |
| 28 | }); |
| 29 | return span; |
| 30 | }).pipe(Effect.withSpan("GET /ws"), Effect.orDie); |
| 31 | |
| 32 | assert.isDefined(rpcSpan); |
| 33 | assert.equal(rpcSpan!.name, "ws.rpc.review.getDiffPreview"); |
| 34 | assert.isTrue(Option.isNone(rpcSpan!.parent)); |
| 35 | assert.notEqual(rpcSpan!.traceId, connection.traceId); |
| 36 | assert.deepEqual( |
| 37 | rpcSpan!.links.map((link) => link.span.spanId), |
| 38 | [connection.spanId], |
| 39 | ); |
| 40 | }).pipe(Effect.provide(rpcInstrumentationLayer)), |
| 41 | ); |