@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 126 lines 4.89 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 spanner from "@distilled.cloud/gcp/spanner_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 waitUntilGone = (name: string) =>
15 spanner.getProjectsInstancesDatabasesBackupSchedules({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsInstancesDatabasesBackupSchedules on a missing schedule fails with NotFound",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 spanner.getProjectsInstancesDatabasesBackupSchedules({
34 name: `projects/${project}/instances/alchemy-spanner-missing/databases/alchemy-missing/backupSchedules/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toBe("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 { tags: ["provider:gcp", "provider:gcp:spanner", "live"], timeout: 90_000 },
42 );
43
44 test.provider(
45 "create, update, and delete a spanner backup schedule",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const created = yield* stack.deploy(
51 Effect.gen(function* () {
52 const instance = yield* GCP.Spanner.Instance("App", {
53 config: "regional-us-central1",
54 processingUnits: 100,
55 displayName: "alchemy-sch-spnr",
56 defaultBackupScheduleType: "NONE",
57 });
58 const database = yield* GCP.Spanner.Database("AppDb", {
59 instance: instance.instanceId,
60 });
61 const schedule = yield* GCP.Spanner.InstancesDatabasesBackupSchedule("Nightly", {
62 instance: instance.instanceId,
63 database: database.databaseId,
64 spec: { cron: "0 2 * * *" },
65 retentionDuration: "604800s",
66 });
67 return { instance, database, schedule };
68 }),
69 );
70
71 expect(created.schedule.name).toContain("/backupSchedules/");
72 expect(created.schedule.backupScheduleId).toEqual(expect.any(String));
73 expect(created.schedule.instanceId).toEqual(created.instance.instanceId);
74 expect(created.schedule.databaseId).toEqual(created.database.databaseId);
75 expect(created.schedule.cron).toEqual("0 2 * * *");
76 expect(created.schedule.retentionDuration).toEqual("604800s");
77 expect(created.schedule.incremental).toEqual(false);
78
79 const fetched = yield* spanner.getProjectsInstancesDatabasesBackupSchedules({
80 name: created.schedule.name,
81 });
82 expect(fetched.name).toEqual(created.schedule.name);
83 expect(fetched.spec?.cronSpec?.text).toEqual("0 2 * * *");
84 expect(fetched.retentionDuration).toEqual("604800s");
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 const instance = yield* GCP.Spanner.Instance("App", {
89 instanceId: created.instance.instanceId,
90 config: "regional-us-central1",
91 processingUnits: 100,
92 displayName: "alchemy-sch-spnr",
93 defaultBackupScheduleType: "NONE",
94 });
95 const database = yield* GCP.Spanner.Database("AppDb", {
96 instance: instance.instanceId,
97 databaseId: created.database.databaseId,
98 });
99 const schedule = yield* GCP.Spanner.InstancesDatabasesBackupSchedule("Nightly", {
100 instance: instance.instanceId,
101 database: database.databaseId,
102 backupScheduleId: created.schedule.backupScheduleId,
103 spec: { cron: "0 14 * * *" },
104 retentionDuration: "1209600s",
105 });
106 return { instance, database, schedule };
107 }),
108 );
109
110 expect(updated.schedule.name).toEqual(created.schedule.name);
111 expect(updated.schedule.cron).toEqual("0 14 * * *");
112 expect(updated.schedule.retentionDuration).toEqual("1209600s");
113
114 const refetched = yield* spanner.getProjectsInstancesDatabasesBackupSchedules({
115 name: created.schedule.name,
116 });
117 expect(refetched.spec?.cronSpec?.text).toEqual("0 14 * * *");
118 expect(refetched.retentionDuration).toEqual("1209600s");
119
120 yield* stack.destroy();
121
122 const gone = yield* waitUntilGone(created.schedule.name);
123 expect(gone).toEqual("gone");
124 }).pipe(logLevel),
125 { tags: ["provider:gcp", "provider:gcp:spanner", "live"], timeout: 180_000 },
126 );