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

main
ts 109 lines 3.7 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 healthcare from "@distilled.cloud/gcp/healthcare_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 healthcare.getProjectsLocationsDatasetsFhirStores({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsDatasetsFhirStores on a missing store fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 healthcare.getProjectsLocationsDatasetsFhirStores({
34 name: `projects/${project}/locations/us-central1/datasets/missing/fhirStores/alchemy-missing`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:healthcare", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a FHIR store",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const dataset = yield* GCP.Healthcare.Dataset("Records", {
56 location: "us-central1",
57 });
58 const store = yield* GCP.Healthcare.DatasetsFhirStore("Fhir", {
59 dataset: dataset.name,
60 version: "R4",
61 labels: { env: "test" },
62 });
63 return { dataset, store };
64 }),
65 );
66
67 expect(created.store.name).toContain("/fhirStores/");
68 expect(created.store.version).toEqual("R4");
69 expect(created.store.enableUpdateCreate).toEqual(false);
70 expect(created.store.labels).toMatchObject({ env: "test" });
71
72 const fetched = yield* healthcare.getProjectsLocationsDatasetsFhirStores({
73 name: created.store.name,
74 });
75 expect(fetched.name).toEqual(created.store.name);
76 expect(fetched.version).toEqual("R4");
77 expect(fetched.labels?.env).toEqual("test");
78 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 const dataset = yield* GCP.Healthcare.Dataset("Records", {
83 datasetId: created.dataset.datasetId,
84 location: "us-central1",
85 });
86 const store = yield* GCP.Healthcare.DatasetsFhirStore("Fhir", {
87 dataset: dataset.name,
88 fhirStoreId: created.store.fhirStoreId,
89 version: "R4",
90 enableUpdateCreate: true,
91 labels: { env: "prod", role: "fhir" },
92 });
93 return { dataset, store };
94 }),
95 );
96
97 expect(updated.store.name).toEqual(created.store.name);
98 expect(updated.store.enableUpdateCreate).toEqual(true);
99 expect(updated.store.labels).toMatchObject({ env: "prod", role: "fhir" });
100
101 yield* stack.destroy();
102 const gone = yield* waitUntilGone(created.store.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 {
106 tags: ["provider:gcp", "provider:gcp:healthcare", "live"],
107 timeout: 120_000,
108 },
109 );