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
| 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 HL7 = [ |
| 15 | "MSH|^~\\&|ALCHEMY|TESTFAC|RECEIVER|RECVFAC|20240101120000||ADT^A01|MSG00001|P|2.5", |
| 16 | "PID|1||PAT001^^^MR||DOE^JOHN", |
| 17 | ].join("\r"); |
| 18 | |
| 19 | const waitUntilGone = (name: string) => |
| 20 | healthcare.getProjectsLocationsDatasetsHl7V2StoresMessages({ name }).pipe( |
| 21 | Effect.as("found" as const), |
| 22 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 23 | Effect.repeat({ |
| 24 | schedule: Schedule.spaced("1 second"), |
| 25 | until: (status) => status === "gone", |
| 26 | times: 10, |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | test.provider( |
| 31 | "getProjectsLocationsDatasetsHl7V2StoresMessages on a missing message fails with a typed tag", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | const { project } = yield* GcpEnvironment.current; |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const error = yield* Effect.flip( |
| 38 | healthcare.getProjectsLocationsDatasetsHl7V2StoresMessages({ |
| 39 | name: `projects/${project}/locations/us-central1/datasets/alchemy-missing/hl7V2Stores/alchemy-missing/messages/alchemy-missing-hl7`, |
| 40 | }), |
| 41 | ); |
| 42 | expect(error._tag).toEqual("NotFound"); |
| 43 | |
| 44 | yield* stack.destroy(); |
| 45 | }).pipe(logLevel), |
| 46 | { |
| 47 | tags: ["provider:gcp", "provider:gcp:healthcare", "live"], |
| 48 | timeout: 90_000, |
| 49 | }, |
| 50 | ); |
| 51 | |
| 52 | test.provider( |
| 53 | "create, update, and delete an HL7v2 message", |
| 54 | (stack) => |
| 55 | Effect.gen(function* () { |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | const created = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | const dataset = yield* GCP.Healthcare.Dataset("Clinic", {}); |
| 61 | const store = yield* GCP.Healthcare.DatasetsHl7V2Store("AdtStore", { |
| 62 | dataset: dataset.name, |
| 63 | }); |
| 64 | const message = yield* GCP.Healthcare.DatasetsHl7V2StoresMessage("Adt", { |
| 65 | parent: store.name, |
| 66 | data: HL7, |
| 67 | labels: { env: "test" }, |
| 68 | }); |
| 69 | return { dataset, store, message }; |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.message.messageId.length).toBeGreaterThan(0); |
| 74 | expect(created.message.parent).toEqual(created.store.name); |
| 75 | expect(created.message.name).toContain("/messages/"); |
| 76 | expect(created.message.data).toContain("ADT^A01"); |
| 77 | expect(created.message.labels).toMatchObject({ env: "test" }); |
| 78 | |
| 79 | const fetched = yield* healthcare.getProjectsLocationsDatasetsHl7V2StoresMessages({ |
| 80 | name: created.message.name, |
| 81 | view: "FULL", |
| 82 | }); |
| 83 | expect(fetched.name).toEqual(created.message.name); |
| 84 | expect(fetched.labels?.env).toEqual("test"); |
| 85 | expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String)); |
| 86 | |
| 87 | const updated = yield* stack.deploy( |
| 88 | Effect.gen(function* () { |
| 89 | const dataset = yield* GCP.Healthcare.Dataset("Clinic", { |
| 90 | datasetId: created.dataset.datasetId, |
| 91 | location: created.dataset.location, |
| 92 | }); |
| 93 | const store = yield* GCP.Healthcare.DatasetsHl7V2Store("AdtStore", { |
| 94 | dataset: dataset.name, |
| 95 | hl7V2StoreId: created.store.hl7V2StoreId, |
| 96 | }); |
| 97 | const message = yield* GCP.Healthcare.DatasetsHl7V2StoresMessage("Adt", { |
| 98 | parent: store.name, |
| 99 | messageId: created.message.messageId, |
| 100 | data: HL7, |
| 101 | labels: { env: "prod", role: "adt" }, |
| 102 | }); |
| 103 | return { dataset, store, message }; |
| 104 | }), |
| 105 | ); |
| 106 | |
| 107 | expect(updated.message.messageId).toEqual(created.message.messageId); |
| 108 | expect(updated.message.labels).toMatchObject({ |
| 109 | env: "prod", |
| 110 | role: "adt", |
| 111 | }); |
| 112 | |
| 113 | yield* stack.destroy(); |
| 114 | |
| 115 | const gone = yield* waitUntilGone(created.message.name); |
| 116 | expect(gone).toEqual("gone"); |
| 117 | }).pipe(logLevel), |
| 118 | { |
| 119 | tags: ["provider:gcp", "provider:gcp:healthcare", "live"], |
| 120 | timeout: 120_000, |
| 121 | }, |
| 122 | ); |