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

main
ts 434 lines 14.3 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import {
3 AnnotationStore,
4 ReferenceStore,
5 RunGroup,
6 SequenceStore,
7 VariantStore,
8 Workflow,
9 } from "@alchemy.run/aws/Omics";
10 import { expect } from "@alchemy.run/test";
11 import * as Test from "@alchemy.run/test/Alchemy";
12 import * as omics from "@distilled.cloud/aws/omics";
13 import * as Effect from "effect/Effect";
14 import * as Schedule from "effect/Schedule";
15
16 const { test } = Test.make({ providers: AWS.providers() });
17
18 // Ungated typed-error probe: prove the distilled error union carries the
19 // not-found tag every Omics read/delete path depends on. Runs in every CI
20 // pass at near-zero cost, unlike the gated lifecycles below.
21 test.provider(
22 "getReferenceStore on a nonexistent id fails with ResourceNotFoundException",
23 () =>
24 Effect.gen(function* () {
25 const error = yield* Effect.flip(omics.getReferenceStore({ id: "1234567890" }));
26 expect(error._tag).toBe("ResourceNotFoundException");
27 }),
28 { tags: ["provider:aws", "provider:aws:omics", "live"] },
29 );
30
31 // Ungated probes for the `analytics-` HealthOmics endpoint (annotation/variant
32 // stores). A missing-store read is safe (creates nothing) and proves both the
33 // operation-level `analytics-` hostPrefix routing and the typed not-found tag
34 // the AnnotationStore/VariantStore providers depend on. The create path for
35 // these two stores is entitlement-gated (see the gated lifecycles below).
36 test.provider(
37 "getAnnotationStore on a nonexistent name fails with ResourceNotFoundException",
38 () =>
39 Effect.gen(function* () {
40 const error = yield* Effect.flip(
41 omics.getAnnotationStore({ name: "alchemy_probe_nonexistent_store" }),
42 );
43 expect(error._tag).toBe("ResourceNotFoundException");
44 }),
45 { tags: ["provider:aws", "provider:aws:omics", "live"] },
46 );
47
48 test.provider(
49 "getVariantStore on a nonexistent name fails with ResourceNotFoundException",
50 () =>
51 Effect.gen(function* () {
52 const error = yield* Effect.flip(
53 omics.getVariantStore({ name: "alchemy_probe_nonexistent_store" }),
54 );
55 expect(error._tag).toBe("ResourceNotFoundException");
56 }),
57 { tags: ["provider:aws", "provider:aws:omics", "live"] },
58 );
59
60 const assertReferenceStoreGone = (id: string) =>
61 Effect.gen(function* () {
62 const gone = yield* omics.getReferenceStore({ id }).pipe(
63 Effect.map(() => false),
64 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
65 );
66 if (!gone) {
67 return yield* Effect.fail(new Error(`reference store '${id}' still exists`));
68 }
69 }).pipe(
70 Effect.retry({ schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]) }),
71 );
72
73 test.provider(
74 "ReferenceStore: create, verify out-of-band, destroy",
75 (stack) =>
76 Effect.gen(function* () {
77 yield* stack.destroy();
78
79 const { store } = yield* stack.deploy(
80 Effect.gen(function* () {
81 const store = yield* ReferenceStore("Refs", {
82 description: "alchemy omics test reference store",
83 tags: { fixture: "omics-reference-store" },
84 });
85 return { store };
86 }),
87 );
88
89 expect(store.referenceStoreId).toBeDefined();
90 expect(store.referenceStoreArn).toContain(":referenceStore/");
91
92 const live = yield* omics.getReferenceStore({ id: store.referenceStoreId });
93 expect(live.id).toBe(store.referenceStoreId);
94 expect(live.description).toBe("alchemy omics test reference store");
95
96 const tags = yield* omics.listTagsForResource({ resourceArn: store.referenceStoreArn });
97 expect(tags.tags["fixture"]).toBe("omics-reference-store");
98 expect(tags.tags["alchemy::id"]).toBe("Refs");
99
100 yield* stack.destroy();
101 yield* assertReferenceStoreGone(store.referenceStoreId);
102 }),
103 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 180_000 },
104 );
105
106 const assertSequenceStoreGone = (id: string) =>
107 Effect.gen(function* () {
108 const gone = yield* omics.getSequenceStore({ id }).pipe(
109 Effect.map(() => false),
110 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
111 );
112 if (!gone) {
113 return yield* Effect.fail(new Error(`sequence store '${id}' still exists`));
114 }
115 }).pipe(
116 Effect.retry({ schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]) }),
117 );
118
119 test.provider(
120 "SequenceStore: create, verify out-of-band, destroy",
121 (stack) =>
122 Effect.gen(function* () {
123 yield* stack.destroy();
124
125 const { store } = yield* stack.deploy(
126 Effect.gen(function* () {
127 const store = yield* SequenceStore("Reads", {
128 description: "alchemy omics test sequence store",
129 eTagAlgorithmFamily: "SHA256up",
130 tags: { fixture: "omics-sequence-store" },
131 });
132 return { store };
133 }),
134 );
135
136 expect(store.sequenceStoreId).toBeDefined();
137 expect(store.sequenceStoreArn).toContain(":sequenceStore/");
138
139 const live = yield* omics.getSequenceStore({ id: store.sequenceStoreId });
140 expect(live.id).toBe(store.sequenceStoreId);
141 expect(live.eTagAlgorithmFamily).toBe("SHA256up");
142
143 yield* stack.destroy();
144 yield* assertSequenceStoreGone(store.sequenceStoreId);
145 }),
146 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 180_000 },
147 );
148
149 const assertRunGroupGone = (id: string) =>
150 Effect.gen(function* () {
151 const gone = yield* omics.getRunGroup({ id }).pipe(
152 Effect.map(() => false),
153 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
154 );
155 if (!gone) {
156 return yield* Effect.fail(new Error(`run group '${id}' still exists`));
157 }
158 }).pipe(
159 Effect.retry({ schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]) }),
160 );
161
162 test.provider(
163 "RunGroup: create, update limits, destroy",
164 (stack) =>
165 Effect.gen(function* () {
166 yield* stack.destroy();
167
168 // Create with an initial CPU cap.
169 const first = yield* stack.deploy(
170 Effect.gen(function* () {
171 const group = yield* RunGroup("Batch", {
172 maxCpus: 4,
173 maxRuns: 2,
174 tags: { fixture: "omics-run-group" },
175 });
176 return { group };
177 }),
178 );
179 expect(first.group.runGroupId).toBeDefined();
180 const runGroupId = first.group.runGroupId;
181
182 const created = yield* omics.getRunGroup({ id: runGroupId });
183 expect(created.maxCpus).toBe(4);
184 expect(created.maxRuns).toBe(2);
185
186 // Update the CPU cap in place — same logical id, no replacement.
187 const second = yield* stack.deploy(
188 Effect.gen(function* () {
189 const group = yield* RunGroup("Batch", {
190 maxCpus: 8,
191 maxRuns: 2,
192 tags: { fixture: "omics-run-group" },
193 });
194 return { group };
195 }),
196 );
197 expect(second.group.runGroupId).toBe(runGroupId);
198
199 const updated = yield* omics.getRunGroup({ id: runGroupId });
200 expect(updated.maxCpus).toBe(8);
201
202 yield* stack.destroy();
203 yield* assertRunGroupGone(runGroupId);
204 }),
205 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 180_000 },
206 );
207
208 // ---------------------------------------------------------------------------
209 // Gated lifecycles — Workflow, AnnotationStore, and VariantStore each require
210 // async provisioning (and VariantStore a real reference genome ARN), so they
211 // are gated behind AWS_TEST_OMICS=1. VariantStore additionally reads a
212 // reference ARN from OMICS_REFERENCE_ARN.
213 //
214 // AnnotationStore/VariantStore CREATE additionally requires the account to be
215 // entitled for HealthOmics Analytics; without it the analytics- endpoint
216 // returns `AccessDeniedException: "Unable to determine service/operation name
217 // to be authorized"`. The ungated read probes above cover the endpoint routing
218 // and typed errors on every CI pass regardless of entitlement.
219 // ---------------------------------------------------------------------------
220
221 // A minimal WDL workflow definition, zipped in memory. A trivial workflow is
222 // accepted by HealthOmics without any genomics data.
223 const minimalWdl = `version 1.0
224 workflow HelloWorld {
225 call Hello {}
226 }
227 task Hello {
228 command { echo "hello" }
229 output { String out = read_string(stdout()) }
230 runtime { cpus: 1, memory: "1 GiB" }
231 }
232 `;
233
234 // Build a store-only (uncompressed) ZIP archive containing main.wdl. Kept
235 // dependency-free so the fixture needs no zip library.
236 const buildZip = (fileName: string, content: string): Uint8Array => {
237 const enc = new TextEncoder();
238 const nameBytes = enc.encode(fileName);
239 const dataBytes = enc.encode(content);
240 const crcTable = Array.from({ length: 256 }, (_, n) => {
241 let c = n;
242 for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
243 return c >>> 0;
244 });
245 let crc = 0xffffffff;
246 for (const b of dataBytes) crc = crcTable[(crc ^ b) & 0xff] ^ (crc >>> 8);
247 crc = (crc ^ 0xffffffff) >>> 0;
248
249 const chunks: number[] = [];
250 const push32 = (v: number) => {
251 chunks.push(v & 0xff, (v >>> 8) & 0xff, (v >>> 16) & 0xff, (v >>> 24) & 0xff);
252 };
253 const push16 = (v: number) => chunks.push(v & 0xff, (v >>> 8) & 0xff);
254
255 // Local file header.
256 push32(0x04034b50);
257 push16(20);
258 push16(0);
259 push16(0);
260 push16(0);
261 push16(0);
262 push32(crc);
263 push32(dataBytes.length);
264 push32(dataBytes.length);
265 push16(nameBytes.length);
266 push16(0);
267 for (const b of nameBytes) chunks.push(b);
268 for (const b of dataBytes) chunks.push(b);
269 const centralOffset = chunks.length;
270
271 // Central directory header.
272 push32(0x02014b50);
273 push16(20);
274 push16(20);
275 push16(0);
276 push16(0);
277 push16(0);
278 push16(0);
279 push32(crc);
280 push32(dataBytes.length);
281 push32(dataBytes.length);
282 push16(nameBytes.length);
283 push16(0);
284 push16(0);
285 push16(0);
286 push16(0);
287 push32(0);
288 push32(0);
289 for (const b of nameBytes) chunks.push(b);
290 const centralSize = chunks.length - centralOffset;
291
292 // End of central directory.
293 push32(0x06054b50);
294 push16(0);
295 push16(0);
296 push16(1);
297 push16(1);
298 push32(centralSize);
299 push32(centralOffset);
300 push16(0);
301
302 return Uint8Array.from(chunks);
303 };
304
305 const assertWorkflowGone = (id: string) =>
306 Effect.gen(function* () {
307 const status = yield* omics.getWorkflow({ id }).pipe(
308 Effect.map((w) => w.status ?? "gone"),
309 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("gone" as const)),
310 );
311 if (status !== "gone" && status !== "DELETED") {
312 return yield* Effect.fail(new Error(`workflow '${id}' still exists (status: ${status})`));
313 }
314 }).pipe(
315 Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(12)]) }),
316 );
317
318 test.provider.skipIf(!process.env.AWS_TEST_OMICS)(
319 "Workflow: create from inline WDL zip, verify ACTIVE, destroy",
320 (stack) =>
321 Effect.gen(function* () {
322 yield* stack.destroy();
323
324 const definitionZip = buildZip("main.wdl", minimalWdl);
325
326 const { workflow } = yield* stack.deploy(
327 Effect.gen(function* () {
328 const workflow = yield* Workflow("Hello", {
329 engine: "WDL",
330 main: "main.wdl",
331 definitionZip,
332 tags: { fixture: "omics-workflow" },
333 });
334 return { workflow };
335 }),
336 );
337
338 expect(workflow.workflowId).toBeDefined();
339 expect(workflow.status).toBe("ACTIVE");
340
341 const live = yield* omics.getWorkflow({ id: workflow.workflowId });
342 expect(live.status).toBe("ACTIVE");
343
344 yield* stack.destroy();
345 yield* assertWorkflowGone(workflow.workflowId);
346 }),
347 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 240_000 },
348 );
349
350 const assertAnnotationStoreGone = (name: string) =>
351 Effect.gen(function* () {
352 const gone = yield* omics.getAnnotationStore({ name }).pipe(
353 Effect.map(() => false),
354 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
355 );
356 if (!gone) {
357 return yield* Effect.fail(new Error(`annotation store '${name}' still exists`));
358 }
359 }).pipe(
360 Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(24)]) }),
361 );
362
363 test.provider.skipIf(!process.env.AWS_TEST_OMICS)(
364 "AnnotationStore: create TSV store, verify ACTIVE, destroy",
365 (stack) =>
366 Effect.gen(function* () {
367 yield* stack.destroy();
368
369 const { store } = yield* stack.deploy(
370 Effect.gen(function* () {
371 const store = yield* AnnotationStore("Annotations", {
372 storeFormat: "TSV",
373 storeOptions: { tsvStoreOptions: { annotationType: "GENERIC" } },
374 tags: { fixture: "omics-annotation-store" },
375 });
376 return { store };
377 }),
378 );
379
380 expect(store.annotationStoreId).toBeDefined();
381 expect(store.status).toBe("ACTIVE");
382
383 const live = yield* omics.getAnnotationStore({ name: store.name });
384 expect(live.status).toBe("ACTIVE");
385 expect(live.storeFormat).toBe("TSV");
386
387 yield* stack.destroy();
388 yield* assertAnnotationStoreGone(store.name);
389 }),
390 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 240_000 },
391 );
392
393 const assertVariantStoreGone = (name: string) =>
394 Effect.gen(function* () {
395 const gone = yield* omics.getVariantStore({ name }).pipe(
396 Effect.map(() => false),
397 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
398 );
399 if (!gone) {
400 return yield* Effect.fail(new Error(`variant store '${name}' still exists`));
401 }
402 }).pipe(
403 Effect.retry({ schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(24)]) }),
404 );
405
406 test.provider.skipIf(!process.env.AWS_TEST_OMICS || !process.env.OMICS_REFERENCE_ARN)(
407 "VariantStore: create with reference, verify ACTIVE, destroy",
408 (stack) =>
409 Effect.gen(function* () {
410 yield* stack.destroy();
411
412 const referenceArn = process.env.OMICS_REFERENCE_ARN!;
413
414 const { store } = yield* stack.deploy(
415 Effect.gen(function* () {
416 const store = yield* VariantStore("Variants", {
417 reference: { referenceArn },
418 tags: { fixture: "omics-variant-store" },
419 });
420 return { store };
421 }),
422 );
423
424 expect(store.variantStoreId).toBeDefined();
425 expect(store.status).toBe("ACTIVE");
426
427 const live = yield* omics.getVariantStore({ name: store.name });
428 expect(live.status).toBe("ACTIVE");
429
430 yield* stack.destroy();
431 yield* assertVariantStoreGone(store.name);
432 }),
433 { tags: ["provider:aws", "provider:aws:omics", "live"], timeout: 240_000 },
434 );