The best way to control Claude Code, Codex and more from any computer or phone

main
ts 66 lines 2.43 KB
Raw
1 import { AccountId } from "@bank/domain/Account/Account.id";
2 import { CustomerApi } from "@bank/domain/CustomerApi.api";
3 import { expect, it } from "@effect/vitest";
4 import * as Effect from "effect/Effect";
5 import * as Option from "effect/Option";
6 import * as RpcClientError from "effect/rpc/RpcClientError";
7 import { Deliver } from "../src/Bank.ts";
8 import { Client } from "./Domain.ts";
9
10 const accountId = AccountId.make("c-1-main");
11 it.live("retries only the unknown intent with its original id and queues the rest", () =>
12 Effect.gen(function* () {
13 const client = yield* CustomerApi.Client;
14 const ids: Array<string | undefined> = [];
15 const result = yield* Deliver({
16 accountId,
17 intents: [
18 { commandId: "page:0", kind: "deposit", amount: 100 },
19 { commandId: "page:1", kind: "deposit", amount: 200 },
20 ],
21 }).effect.pipe(
22 Effect.provideService(CustomerApi.Client, {
23 ...client,
24 // The server applies each send; every reply is lost on the way back.
25 DepositMoney: (target, input, options) =>
26 Effect.suspend(() => {
27 ids.push(options?.commandId);
28 return client.DepositMoney(target, input, options);
29 }).pipe(
30 Effect.exit,
31 Effect.andThen(
32 Effect.fail(
33 RpcClientError.RpcClientError.make({
34 reason: RpcClientError.RpcClientDefect.make({
35 cause: "lost reply",
36 message: "lost reply",
37 }),
38 }),
39 ),
40 ),
41 ),
42 }),
43 );
44 expect(ids).toEqual(["page:0", "page:0", "page:0", "page:0"]);
45 expect(result.outcomes).toEqual([
46 { commandId: "page:0", result: "Queued", reason: Option.none() },
47 { commandId: "page:1", result: "Queued", reason: Option.none() },
48 ]);
49 }).pipe(Effect.provide(Client)),
50 );
51
52 it.live("does not retry middleware denial and sends later intents", () =>
53 Effect.gen(function* () {
54 const result = yield* Deliver({
55 accountId,
56 intents: [
57 { commandId: "page:0", kind: "withdrawal", amount: 100 },
58 { commandId: "page:1", kind: "deposit", amount: 200 },
59 ],
60 }).effect;
61 expect(result.outcomes).toEqual([
62 { commandId: "page:0", result: "Denied", reason: Option.some("MfaRequired") },
63 { commandId: "page:1", result: "Rejected", reason: Option.some("NotOpen") },
64 ]);
65 }).pipe(Effect.provide(Client)),
66 );