@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 108 lines 3.96 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as storage from "@distilled.cloud/gcp/storage_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (bucketName: string, notificationId: string) =>
14 storage
15 .getNotifications({
16 bucket: bucketName,
17 notification: notificationId,
18 })
19 .pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("1 second"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "create, replace, and delete a notification",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const created = yield* stack.deploy(
36 Effect.gen(function* () {
37 const bucket = yield* GCP.Storage.Bucket("Assets", {
38 location: "US-CENTRAL1",
39 forceDestroy: true,
40 });
41 const topic = yield* GCP.PubSub.Topic("Events", {});
42 return yield* GCP.Storage.Notification("ObjectEvents", {
43 bucketName: bucket.bucketName,
44 topic: topic.name,
45 customAttributes: { env: "test" },
46 });
47 }),
48 );
49
50 expect(created.notificationId).toEqual(expect.any(String));
51 expect(created.bucketName).toEqual(expect.any(String));
52 expect(created.payloadFormat).toEqual("JSON_API_V1");
53 expect(created.customAttributes).toMatchObject({ env: "test" });
54 expect(created.topic).toContain(created.topicId);
55
56 const fetched = yield* storage.getNotifications({
57 bucket: created.bucketName,
58 notification: created.notificationId,
59 });
60 expect(fetched.id).toEqual(created.notificationId);
61 expect(fetched.payload_format).toEqual("JSON_API_V1");
62 expect(fetched.custom_attributes?.env).toEqual("test");
63 expect(fetched.custom_attributes).toEqual({ env: "test" });
64
65 const updated = yield* stack.deploy(
66 Effect.gen(function* () {
67 const bucket = yield* GCP.Storage.Bucket("Assets", {
68 bucketName: created.bucketName,
69 location: "US-CENTRAL1",
70 forceDestroy: true,
71 });
72 const topic = yield* GCP.PubSub.Topic("Events", {
73 topicId: created.topicId,
74 });
75 return yield* GCP.Storage.Notification("ObjectEvents", {
76 bucketName: bucket.bucketName,
77 topic: topic.name,
78 eventTypes: ["OBJECT_FINALIZE"],
79 objectNamePrefix: "uploads/",
80 customAttributes: { env: "prod" },
81 });
82 }),
83 );
84
85 expect(updated.bucketName).toEqual(created.bucketName);
86 expect(updated.eventTypes).toEqual(["OBJECT_FINALIZE"]);
87 expect(updated.objectNamePrefix).toEqual("uploads/");
88 expect(updated.customAttributes).toMatchObject({ env: "prod" });
89 expect(updated.notificationId).not.toEqual(created.notificationId);
90
91 const refetched = yield* storage.getNotifications({
92 bucket: updated.bucketName,
93 notification: updated.notificationId,
94 });
95 expect(refetched.event_types).toEqual(["OBJECT_FINALIZE"]);
96 expect(refetched.object_name_prefix).toEqual("uploads/");
97 expect(refetched.custom_attributes?.env).toEqual("prod");
98
99 const previousGone = yield* waitUntilGone(created.bucketName, created.notificationId);
100 expect(previousGone).toEqual("gone");
101
102 yield* stack.destroy();
103
104 const gone = yield* waitUntilGone(updated.bucketName, updated.notificationId);
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 { tags: ["provider:gcp", "provider:gcp:storage", "live"], timeout: 90_000 },
108 );