Open History to see the last commit
1import {
2 EnvironmentId,
3 ORCHESTRATION_PROTOCOL_VERSION,
4 type ExecutionEnvironmentDescriptor,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "vite-plus/test";
7
8import {
9 appendOrchestrationProtocol,
10 orchestrationProtocolCompatibilityError,
11} from "./compatibility.ts";
12
13const descriptor = (orchestrationProtocolVersion?: number): ExecutionEnvironmentDescriptor => ({
14 environmentId: EnvironmentId.make("environment-remote"),
15 label: "Build Mac",
16 platform: { os: "darwin", arch: "arm64" },
17 serverVersion: "9.0.0",
18 ...(orchestrationProtocolVersion === undefined ? {} : { orchestrationProtocolVersion }),
19 capabilities: { repositoryIdentity: true },
20});
21
22describe("orchestration protocol compatibility", () => {
23 it("accepts the current protocol and announces it without disturbing socket credentials", () => {
24 expect(
25 orchestrationProtocolCompatibilityError(descriptor(ORCHESTRATION_PROTOCOL_VERSION)),
26 ).toBeNull();
27
28 const socketUrl = new URL(
29 appendOrchestrationProtocol("wss://host.test/ws?wsTicket=secret&connectionMethod=relay"),
30 );
31 expect(socketUrl.searchParams.get("orchestrationProtocol")).toBe(
32 String(ORCHESTRATION_PROTOCOL_VERSION),
33 );
34 expect(socketUrl.searchParams.get("wsTicket")).toBe("secret");
35 expect(socketUrl.searchParams.get("connectionMethod")).toBe("relay");
36 });
37
38 it("blocks a host that predates negotiation with host-specific upgrade guidance", () => {
39 const error = orchestrationProtocolCompatibilityError(descriptor());
40
41 expect(error).toMatchObject({ reason: "unsupported" });
42 expect(error?.message).toContain("Update T3 Code on Build Mac");
43 expect(error?.message).toContain(`protocol ${ORCHESTRATION_PROTOCOL_VERSION}`);
44 });
45
46 it("blocks a different explicit protocol instead of attempting to decode it", () => {
47 const error = orchestrationProtocolCompatibilityError(
48 descriptor(ORCHESTRATION_PROTOCOL_VERSION + 1),
49 );
50
51 expect(error).toMatchObject({ reason: "unsupported" });
52 expect(error?.message).toContain(
53 `host uses orchestration protocol ${ORCHESTRATION_PROTOCOL_VERSION + 1}`,
54 );
55 expect(error?.message).toContain(`client requires ${ORCHESTRATION_PROTOCOL_VERSION}`);
56 });
57});