@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 33 lines 1.43 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Semaphore from "effect/Semaphore";
3
4 /**
5 * The testing project allows 5 VPC networks, and `default` holds one.
6 * Tests that create their own network take a slot for their whole body
7 * (deploy through destroy), so a full `pnpm test test/GCP` run never
8 * exceeds the quota. One slot stays free for stacks that outlive a run
9 * (Cloud Run keeps Direct VPC egress subnets reserved for 1–2 hours after
10 * a service is deleted).
11 *
12 * Tests that only need *a* network should use the project's `default`
13 * network instead of creating one — the GCP counterpart of AWS tests
14 * reusing the default VPC.
15 */
16 const slots = Semaphore.makeUnsafe(3);
17
18 /** Run a network-creating test body while holding one VPC quota slot. */
19 export const withNetworkSlot = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
20 slots.withPermits(1)(self);
21
22 /** Like {@link withNetworkSlot}, for a test body that creates `count` networks. */
23 export const withNetworkSlots =
24 (count: number) =>
25 <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
26 slots.withPermits(count)(self);
27
28 /** The project's pre-existing `default` network (auto-mode). */
29 export const DEFAULT_NETWORK = "default";
30
31 /** Self link of the project's `default` network. */
32 export const defaultNetworkSelfLink = (project: string) =>
33 `https://www.googleapis.com/compute/v1/projects/${project}/global/networks/${DEFAULT_NETWORK}`;