@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 103 lines 4.19 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { FHIRDatastore } from "@alchemy.run/aws/HealthLake";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as healthlake from "@distilled.cloud/aws/healthlake";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Ungated typed-error probe: prove the distilled error union carries the
12 // not-found tag this provider's read/delete paths depend on. Runs in every
13 // CI pass at near-zero cost, unlike the gated lifecycle below.
14 test.provider(
15 "describeFHIRDatastore on a nonexistent datastore fails with ResourceNotFoundException",
16 () =>
17 Effect.gen(function* () {
18 const error = yield* Effect.flip(
19 healthlake.describeFHIRDatastore({
20 DatastoreId: "0123456789abcdef0123456789abcdef",
21 }),
22 );
23 expect(error._tag).toBe("ResourceNotFoundException");
24 }),
25 { tags: ["provider:aws", "provider:aws:healthlake", "live"] },
26 );
27
28 // The provider's delete already waits until the data store is gone; this
29 // out-of-band check confirms it (gone, or terminal DELETED status).
30 const assertDatastoreGone = (datastoreId: string) =>
31 Effect.gen(function* () {
32 const status = yield* healthlake.describeFHIRDatastore({ DatastoreId: datastoreId }).pipe(
33 Effect.map((r) => r.DatastoreProperties.DatastoreStatus),
34 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("gone" as const)),
35 );
36 if (status !== "gone" && status !== "DELETED") {
37 return yield* Effect.fail(
38 new Error(`datastore '${datastoreId}' still exists (status: ${status})`),
39 );
40 }
41 }).pipe(
42 Effect.retry({
43 schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(8)]),
44 }),
45 );
46
47 // A HealthLake FHIR data store takes ~15-30 minutes to provision (and
48 // several more to delete) and bills while it exists. The full lifecycle is
49 // gated behind AWS_TEST_HEALTHLAKE=1 and always destroys what it created.
50 test.provider.skipIf(!process.env.AWS_TEST_HEALTHLAKE)(
51 "create FHIR R4 datastore, verify, update tags, destroy",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const { datastore } = yield* stack.deploy(
57 Effect.gen(function* () {
58 const datastore = yield* FHIRDatastore("Records", {
59 tags: { fixture: "healthlake-datastore" },
60 });
61 return { datastore };
62 }),
63 );
64
65 expect(datastore.datastoreId).toBeDefined();
66 expect(datastore.datastoreArn).toContain(":datastore/fhir/");
67 expect(datastore.datastoreStatus).toBe("ACTIVE");
68 expect(datastore.datastoreTypeVersion).toBe("R4");
69 expect(datastore.datastoreEndpoint).toContain("healthlake");
70 expect(datastore.tags.fixture).toBe("healthlake-datastore");
71
72 // Out-of-band verification via distilled.
73 const described = yield* healthlake.describeFHIRDatastore({
74 DatastoreId: datastore.datastoreId,
75 });
76 expect(described.DatastoreProperties.DatastoreStatus).toBe("ACTIVE");
77 expect(described.DatastoreProperties.DatastoreTypeVersion).toBe("R4");
78 expect(described.DatastoreProperties.DatastoreName).toBe(datastore.datastoreName);
79
80 // Idempotent re-deploy with a tag change syncs in place (no replace,
81 // no second 15-30min provisioning wait — the datastore is ACTIVE).
82 const { datastore: updated } = yield* stack.deploy(
83 Effect.gen(function* () {
84 const datastore = yield* FHIRDatastore("Records", {
85 tags: { fixture: "healthlake-datastore", updated: "true" },
86 });
87 return { datastore };
88 }),
89 );
90 expect(updated.datastoreId).toBe(datastore.datastoreId);
91 expect(updated.tags.updated).toBe("true");
92
93 // Destroy — datastores bill while they exist — and verify deletion
94 // out-of-band. The provider waits until the datastore is gone.
95 yield* stack.destroy();
96 yield* assertDatastoreGone(datastore.datastoreId);
97 }),
98 // create (~15-30 min) + tag sync + delete wait-until-gone, one test.
99 {
100 tags: ["provider:aws", "provider:aws:healthlake", "live"],
101 timeout: 5_400_000,
102 },
103 );