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

rpc.test.ts

47 lines1.7 KB

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 } from "./rpc.ts";
7​
8describe("WebSocket RPC contracts", () => {
9 it("rejects server-internal commands sent to dispatchCommand", () => {
10 const dispatchCommand = WsRpcGroup.requests.get(ORCHESTRATION_V2_WS_METHODS.dispatchCommand);
11 if (dispatchCommand === undefined) throw new Error("dispatchCommand is not registered");
12 const decode = Schema.decodeUnknownExit(dispatchCommand.payloadSchema);
13​
14 expect(
15 Exit.isFailure(
16 decode({
17 type: "checkpoint.rollback.fail",
18 commandId: "forged-rollback-failure",
19 threadId: "thread-1",
20 requestId: "rollback-1",
21 message: "Forged failure.",
22 }),
23 ),
24 ).toBe(true);
25 expect(
26 Exit.isSuccess(
27 decode({
28 type: "checkpoint.rollback",
29 commandId: "rollback-1",
30 threadId: "thread-1",
31 scopeId: "scope-1",
32 checkpointId: "checkpoint-1",
33 }),
34 ),
35 ).toBe(true);
36 });
37​
38 it("lets the server pick a new worktree's folder", () => {
39 const createWorktree = WsRpcGroup.requests.get(WS_METHODS.vcsCreateWorktree);
40 if (createWorktree === undefined) throw new Error("vcs.createWorktree is not registered");
41 const decode = Schema.decodeUnknownExit(createWorktree.payloadSchema);
42 const request = { cwd: "/repo", refName: "main", newRefName: "feature/x" };
43​
44 expect(Exit.isSuccess(decode({ ...request, path: null }))).toBe(true);
45 expect(Exit.isFailure(decode({ ...request, path: "/repo/.git/hooks" }))).toBe(true);
46 });
47});