@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 96 lines 3.14 KB
Raw
1 import { ResourceDeletionPending, waitUntilDeleted } from "@alchemy.run/railway/GraphQL";
2 import { describe, expect, it } from "@alchemy.run/test";
3 import { GraphQLFailure, type GraphQLIssue } from "@distilled.cloud/railway";
4 import * as Effect from "effect/Effect";
5 import * as Fiber from "effect/Fiber";
6 import * as TestClock from "effect/testing/TestClock";
7
8 describe("Railway deletion confirmation", { tags: ["unit", "provider:railway", "local"] }, () => {
9 it.effect("fails with resource identity when bounded polls never confirm absence", () =>
10 Effect.gen(function* () {
11 let reads = 0;
12 const absent = Effect.sync(() => {
13 reads++;
14 return false;
15 });
16 const fiber = yield* waitUntilDeleted("Railway.Project", "project-1", absent).pipe(
17 Effect.flip,
18 Effect.forkChild({ startImmediately: true }),
19 );
20
21 yield* TestClock.adjust("8 seconds");
22 const error = yield* Fiber.join(fiber);
23 expect(error).toBeInstanceOf(ResourceDeletionPending);
24 expect(error._tag).toBe("Railway.ResourceDeletionPending");
25 expect(error.resourceType).toBe("Railway.Project");
26 expect(error.resourceId).toBe("project-1");
27 expect(reads).toBe(9);
28 }),
29 );
30
31 it.effect("succeeds immediately when the first read confirms absence", () =>
32 Effect.gen(function* () {
33 let reads = 0;
34 const result = yield* waitUntilDeleted(
35 "Railway.Service",
36 "service-1",
37 Effect.sync(() => {
38 reads++;
39 return true;
40 }),
41 );
42 expect(result).toBeUndefined();
43 expect(reads).toBe(1);
44 }),
45 );
46
47 it.effect("stops polling once a later read confirms absence", () =>
48 Effect.gen(function* () {
49 let reads = 0;
50 const fiber = yield* waitUntilDeleted(
51 "Railway.Group",
52 "group-1",
53 Effect.sync(() => ++reads === 3),
54 4,
55 ).pipe(Effect.forkChild({ startImmediately: true }));
56
57 yield* TestClock.adjust("2 seconds");
58 expect(yield* Fiber.join(fiber)).toBeUndefined();
59 yield* TestClock.adjust("10 seconds");
60 expect(reads).toBe(3);
61 }),
62 );
63
64 it.effect("preserves the query's typed aggregate failure during polling", () =>
65 Effect.gen(function* () {
66 const denied: GraphQLIssue = {
67 _tag: "RailwayForbidden",
68 message: "Not Authorized",
69 path: ["project"],
70 };
71 const failure = new GraphQLFailure({
72 errors: [denied],
73 data: { project: null },
74 status: 200,
75 });
76 let reads = 0;
77 const absent = Effect.suspend(() =>
78 ++reads === 1 ? Effect.succeed(false) : Effect.fail(failure),
79 );
80 const fiber = yield* waitUntilDeleted("Railway.Project", "project-1", absent).pipe(
81 Effect.flip,
82 Effect.forkChild({ startImmediately: true }),
83 );
84
85 yield* TestClock.adjust("1 second");
86 const error = yield* Fiber.join(fiber);
87 expect(error).toBe(failure);
88 expect(
89 error._tag === "GraphQLFailure" &&
90 error.errors.every((issue) => issue._tag === "RailwayForbidden"),
91 ).toBe(true);
92 yield* TestClock.adjust("10 seconds");
93 expect(reads).toBe(2);
94 }),
95 );
96 });