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

compatibility.test.ts

79 lines3.0 KB

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("clientCapabilities")).toBe("settingsSecretReferences");
35 expect(socketUrl.searchParams.get("wsTicket")).toBe("secret");
36 expect(socketUrl.searchParams.get("connectionMethod")).toBe("relay");
37 });
38​
39 it("treats missing metadata as protocol 1", () => {
40 const error = orchestrationProtocolCompatibilityError(descriptor());
41 if (Number(ORCHESTRATION_PROTOCOL_VERSION) === 1) {
42 expect(error).toBeNull();
43 } else {
44 expect(error).toMatchObject({ reason: "unsupported" });
45 }
46 });
47​
48 it("blocks a different protocol before connecting", () => {
49 const error = orchestrationProtocolCompatibilityError(
50 descriptor(ORCHESTRATION_PROTOCOL_VERSION + 1),
51 );
52 expect(error).toMatchObject({ reason: "unsupported" });
53 expect(error?.message).toContain("This client is not supported");
54 expect(error).not.toHaveProperty("serverUpdateRequired");
55 });
56​
57 it("offers a remote update only for an older host that can update itself", () => {
58 const older = descriptor(ORCHESTRATION_PROTOCOL_VERSION - 1);
59 const withCapabilities = (capabilities: ExecutionEnvironmentDescriptor["capabilities"]) =>
60 orchestrationProtocolCompatibilityError({ ...older, capabilities });
61​
62 expect(
63 withCapabilities({ repositoryIdentity: true, serverSelfUpdate: "boot-service" }),
64 ).toMatchObject({ serverUpdateRequired: true });
65 expect(withCapabilities({ repositoryIdentity: true })).not.toHaveProperty(
66 "serverUpdateRequired",
67 );
68 expect(
69 withCapabilities({ repositoryIdentity: true, serverSelfUpdate: "desktop-managed" }),
70 ).not.toHaveProperty("serverUpdateRequired");
71 expect(
72 withCapabilities({
73 repositoryIdentity: true,
74 serverSelfUpdate: "desktop-managed",
75 desktopAppUpdate: true,
76 }),
77 ).toMatchObject({ serverUpdateRequired: true });
78 });
79});