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