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

main
ts 79 lines 3.11 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 { Action } from "alchemy/Action";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
11
12 test.provider(
13 "ReadBucket, WriteBucket, and ReadWriteBucket clients",
14 (stack) =>
15 Effect.gen(function* () {
16 yield* stack.destroy();
17
18 const out = yield* stack.deploy(
19 Effect.gen(function* () {
20 const bucket = yield* GCP.Storage.Bucket("Files", {
21 location: "US-CENTRAL1",
22 forceDestroy: true,
23 });
24 const Probe = Action(
25 "Probe",
26 Effect.gen(function* () {
27 yield* bucket.bucketName;
28 const reader = yield* GCP.Storage.ReadBucket(bucket);
29 const writer = yield* GCP.Storage.WriteBucket(bucket);
30 const both = yield* GCP.Storage.ReadWriteBucket(bucket);
31 return Effect.fn(function* () {
32 const missing = yield* reader.get("docs/a.txt");
33 const missingHead = yield* reader.head("docs/a.txt");
34 yield* writer.put("docs/a.txt", "alpha", {
35 contentType: "text/plain",
36 });
37 yield* both.put("docs/b.txt", new TextEncoder().encode("beta"));
38 yield* both.put("other/c.txt", "gamma");
39 const a = yield* reader.get("docs/a.txt");
40 const head = yield* reader.head("docs/a.txt");
41 const listed = yield* both.list({ prefix: "docs/" });
42 const grouped = yield* reader.list({ delimiter: "/" });
43 yield* writer.delete("docs/a.txt");
44 yield* writer.delete("never-existed.txt");
45 const afterDelete = yield* both.get("docs/a.txt");
46 return {
47 missing: missing === undefined,
48 missingHead: missingHead === undefined,
49 a: a && new TextDecoder().decode(a.body),
50 contentType: head?.contentType,
51 listed: listed.objects.map((object) => object.name).sort(),
52 prefixes: grouped.prefixes.sort(),
53 afterDelete: afterDelete === undefined,
54 };
55 });
56 }).pipe(
57 Effect.provide(GCP.Storage.ReadBucketHttp),
58 Effect.provide(GCP.Storage.WriteBucketHttp),
59 Effect.provide(GCP.Storage.ReadWriteBucketHttp),
60 ),
61 );
62 return { probe: yield* Probe({}) };
63 }),
64 );
65
66 expect(out.probe).toEqual({
67 missing: true,
68 missingHead: true,
69 a: "alpha",
70 contentType: "text/plain",
71 listed: ["docs/a.txt", "docs/b.txt"],
72 prefixes: ["docs/", "other/"],
73 afterDelete: true,
74 });
75
76 yield* stack.destroy();
77 }).pipe(logLevel),
78 { tags: ["provider:gcp", "provider:gcp:storage", "live"], timeout: 180_000 },
79 );