Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ws.test.ts

50 lines1.9 KB

1import { assert, it } from "@effect/vitest";
2import { ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts";
3import * as Deferred from "effect/Deferred";
4import * as Duration from "effect/Duration";
5import * as Effect from "effect/Effect";
6import * as Fiber from "effect/Fiber";
7import * as TestClock from "effect/testing/TestClock";
8​
9import {
10 hasCompatibleOrchestrationProtocol,
11 resolveAvailableEditorsForConfig,
12 shouldUseBoundedThreadSnapshot,
13} from "./ws.ts";
14​
15it("accepts only the current orchestration protocol before websocket RPC setup", () => {
16 assert.isTrue(
17 hasCompatibleOrchestrationProtocol(
18 new URL(`https://host.test/ws?orchestrationProtocol=${ORCHESTRATION_PROTOCOL_VERSION}`),
19 ),
20 );
21 assert.isFalse(hasCompatibleOrchestrationProtocol(new URL("https://host.test/ws")));
22 assert.isFalse(
23 hasCompatibleOrchestrationProtocol(
24 new URL(`https://host.test/ws?orchestrationProtocol=${ORCHESTRATION_PROTOCOL_VERSION - 1}`),
25 ),
26 );
27});
28​
29it("keeps full thread snapshot fallback unless the client opts into bounded history", () => {
30 assert.isFalse(shouldUseBoundedThreadSnapshot({}));
31 assert.isFalse(shouldUseBoundedThreadSnapshot({ acceptBoundedSnapshot: false }));
32 assert.isTrue(shouldUseBoundedThreadSnapshot({ acceptBoundedSnapshot: true }));
33});
34​
35it.effect("does not block server config when editor discovery never resolves", () =>
36 Effect.gen(function* () {
37 const discoveryInterrupted = yield* Deferred.make<void>();
38 const responseFiber = yield* resolveAvailableEditorsForConfig(
39 Effect.never.pipe(
40 Effect.onInterrupt(() => Deferred.succeed(discoveryInterrupted, undefined)),
41 ),
42 ).pipe(Effect.forkChild);
43​
44 yield* TestClock.adjust(Duration.seconds(5));
45​
46 const availableEditors = yield* Fiber.join(responseFiber);
47 yield* Deferred.await(discoveryInterrupted);
48 assert.deepEqual(availableEditors, []);
49 }),
50);