@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 106 lines 3.55 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as datastore from "@distilled.cloud/gcp/datastore_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !process.env.FAST;
15
16 // Project setup (one-time): the Datastore index admin API only targets the
17 // project's `(default)` database, which must exist in Datastore mode:
18 // gcloud firestore databases create --database='(default)' \
19 // --location=us-central1 --type=datastore-mode --project=PROJECT_ID
20 // Without it every call fails with `NotFound: Project '…' does not exist.`
21
22 const waitUntilGone = (indexId: string) =>
23 Effect.gen(function* () {
24 const { project } = yield* GcpEnvironment.current;
25
26 return yield* datastore.getProjectsIndexes({ projectId: project, indexId }).pipe(
27 Effect.as("found" as const),
28 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("5 seconds"),
31 until: (status) => status === "gone",
32 times: 24,
33 }),
34 );
35 });
36
37 test.provider(
38 "getProjectsIndexes on a missing index fails with a typed tag",
39 (stack) =>
40 Effect.gen(function* () {
41 const { project } = yield* GcpEnvironment.current;
42
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 datastore.getProjectsIndexes({
47 projectId: project,
48 indexId: "CICAgOjXh4AA",
49 }),
50 );
51 expect(error._tag).toBe("NotFound");
52
53 const page = yield* datastore.listProjectsIndexes({
54 projectId: project,
55 });
56 expect((page.indexes ?? []).map((index) => index.indexId)).not.toContain("CICAgOjXh4AA");
57
58 yield* stack.destroy();
59 }).pipe(logLevel),
60 { tags: ["provider:gcp", "provider:gcp:datastore", "live"], timeout: 90_000 },
61 );
62
63 test.provider.skipIf(!runLifecycle)(
64 "create and delete a datastore composite index",
65 (stack) =>
66 Effect.gen(function* () {
67 const { project } = yield* GcpEnvironment.current;
68
69 yield* stack.destroy();
70
71 const created = yield* stack.deploy(
72 Effect.gen(function* () {
73 return yield* GCP.Datastore.Index("TasksByDone", {
74 ancestor: "NONE",
75 properties: [
76 { name: "done", direction: "ASCENDING" },
77 { name: "priority", direction: "DESCENDING" },
78 ],
79 });
80 }),
81 );
82
83 expect(created.indexId).toEqual(expect.any(String));
84 expect(created.indexId.length).toBeGreaterThan(0);
85 expect(created.kind.length).toBeGreaterThan(0);
86 expect(created.ancestor).toEqual("NONE");
87 expect(created.name).toContain("/indexes/");
88
89 const fetched = yield* datastore.getProjectsIndexes({
90 projectId: project,
91 indexId: created.indexId,
92 });
93 expect(fetched.indexId).toEqual(created.indexId);
94 expect(fetched.kind).toEqual(created.kind);
95 expect((fetched.properties ?? []).some((property) => property.name === "done")).toEqual(true);
96
97 yield* stack.destroy();
98
99 const gone = yield* waitUntilGone(created.indexId);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 {
103 tags: ["provider:gcp", "provider:gcp:datastore", "live"],
104 timeout: 180_000,
105 },
106 );