Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import * as Exit from "effect/Exit";
3import * as Schema from "effect/Schema";
4
5import { ORCHESTRATION_V2_WS_METHODS } from "./orchestrationV2.ts";
6import { WS_METHODS, WsRpcGroup, WsSubscribeServerConfigRpc } from "./rpc.ts";
7
8describe("subscribeServerConfig payload compatibility", () => {
9 it("is accepted by a server whose schema predates the field", () => {
10 const oldServerPayload = Schema.Struct({});
11 const decoded = Schema.decodeExit(oldServerPayload)({ environmentThemes: true });
12 expect(Exit.isSuccess(decoded)).toBe(true);
13 });
14
15 it("is carried by a server that declares it", () => {
16 const decoded = Schema.decodeSync(WsSubscribeServerConfigRpc.payloadSchema)({
17 environmentThemes: true,
18 });
19 expect(decoded).toEqual({ environmentThemes: true });
20 });
21
22 it("stays optional, so a client that never sends it still subscribes", () => {
23 const decoded = Schema.decodeSync(WsSubscribeServerConfigRpc.payloadSchema)({});
24 expect(decoded).toEqual({});
25 });
26});
27
28describe("WebSocket RPC contracts", () => {
29 it("exposes only the V2 orchestration transport surface", () => {
30 const methods = [...WsRpcGroup.requests.keys()];
31
32 expect(methods).toEqual(expect.arrayContaining(Object.values(ORCHESTRATION_V2_WS_METHODS)));
33 expect(methods.filter((method) => method.startsWith("orchestrationV1."))).toEqual([]);
34 });
35
36 it("rejects server-internal commands sent to dispatchCommand", () => {
37 const dispatchCommand = WsRpcGroup.requests.get(ORCHESTRATION_V2_WS_METHODS.dispatchCommand);
38 if (dispatchCommand === undefined) throw new Error("dispatchCommand is not registered");
39 const decode = Schema.decodeUnknownExit(dispatchCommand.payloadSchema);
40
41 expect(
42 Exit.isFailure(
43 decode({
44 type: "checkpoint.rollback.fail",
45 commandId: "forged-rollback-failure",
46 threadId: "thread-1",
47 requestId: "rollback-1",
48 message: "Forged failure.",
49 }),
50 ),
51 ).toBe(true);
52 expect(
53 Exit.isSuccess(
54 decode({
55 type: "checkpoint.rollback",
56 commandId: "rollback-1",
57 threadId: "thread-1",
58 scopeId: "scope-1",
59 checkpointId: "checkpoint-1",
60 }),
61 ),
62 ).toBe(true);
63 });
64
65 it("lets the server pick a new worktree's folder", () => {
66 const createWorktree = WsRpcGroup.requests.get(WS_METHODS.vcsCreateWorktree);
67 if (createWorktree === undefined) throw new Error("vcs.createWorktree is not registered");
68 const decode = Schema.decodeUnknownExit(createWorktree.payloadSchema);
69 const request = { cwd: "/repo", refName: "main", newRefName: "feature/x" };
70
71 expect(Exit.isSuccess(decode({ ...request, path: null }))).toBe(true);
72 expect(Exit.isFailure(decode({ ...request, path: "/repo/.git/hooks" }))).toBe(true);
73 });
74});