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