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 AWS from "@alchemy.run/aws"; |
| 2 | import { Environment } from "@alchemy.run/aws/FinSpace"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as finspace from "@distilled.cloud/aws/finspace"; |
| 6 | import * as finspaceData from "@distilled.cloud/aws/finspace-data"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | // Amazon FinSpace reached end of support on 2026-10-07 |
| 13 | // (https://docs.aws.amazon.com/finspace/latest/userguide/amazon-finspace-end-of-support.html). |
| 14 | // The control-plane hostname finspace.<region>.amazonaws.com no longer has |
| 15 | // A records in any region, so every control-plane call fails before reaching |
| 16 | // AWS with: |
| 17 | // HttpClientError: Transport error (GET https://finspace.us-west-2.amazonaws.com/kx/environments) |
| 18 | // (cause: getaddrinfo ENOTFOUND finspace.us-west-2.amazonaws.com) |
| 19 | // A transport failure can't be patched into a typed tag, so all control-plane |
| 20 | // tests are gated behind AWS_TEST_FINSPACE=1 for accounts that still have access. |
| 21 | const finspaceRetired = !process.env.AWS_TEST_FINSPACE; |
| 22 | |
| 23 | // Ungated typed-error probe: prove the distilled error union carries the |
| 24 | // not-found tag the Environment provider's read/delete paths depend on. |
| 25 | // (environmentId must match ^[a-zA-Z0-9]{1,26}$ — malformed ids fail earlier |
| 26 | // with ValidationException.) |
| 27 | test.provider.skipIf(finspaceRetired)( |
| 28 | "getEnvironment on a nonexistent environment fails with ResourceNotFoundException", |
| 29 | () => |
| 30 | Effect.gen(function* () { |
| 31 | const error = yield* Effect.flip( |
| 32 | finspace.getEnvironment({ |
| 33 | environmentId: "zzzzzzzzzzzzzzzzzzzzzzzzzz", |
| 34 | }), |
| 35 | ); |
| 36 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 37 | }), |
| 38 | { tags: ["provider:aws", "provider:aws:finspace", "live"] }, |
| 39 | ); |
| 40 | |
| 41 | // Ungated typed-error probe for the finspace-data (data-plane) SDK. The data |
| 42 | // API is environment-scoped and this account has no FinSpace environment, so |
| 43 | // it rejects with a plain-text 403 body ("Failed to retrieve environment"). |
| 44 | // This proves the distilled rest-json fallback turns that into the typed |
| 45 | // AccessDeniedException instead of a ParseError. |
| 46 | test.provider( |
| 47 | "finspace-data getDataset without an environment fails with AccessDeniedException", |
| 48 | () => |
| 49 | Effect.gen(function* () { |
| 50 | const error = yield* Effect.flip( |
| 51 | finspaceData.getDataset({ datasetId: "zzzzzzzzzzzzzzzzzzzzzzzzzz" }), |
| 52 | ); |
| 53 | expect(error._tag).toBe("AccessDeniedException"); |
| 54 | }), |
| 55 | { tags: ["provider:aws", "provider:aws:finspace", "live"] }, |
| 56 | ); |
| 57 | |
| 58 | // Deletion is verified as INITIATED (irreversible) or fully gone — full |
| 59 | // disappearance takes many more minutes server-side. |
| 60 | const assertEnvironmentDeleting = (environmentId: string) => |
| 61 | Effect.gen(function* () { |
| 62 | const status = yield* finspace.getEnvironment({ environmentId }).pipe( |
| 63 | Effect.map((r) => r.environment?.status ?? "gone"), |
| 64 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("gone" as const)), |
| 65 | ); |
| 66 | if ( |
| 67 | status !== "gone" && |
| 68 | status !== "DELETED" && |
| 69 | status !== "DELETING" && |
| 70 | status !== "DELETE_REQUESTED" |
| 71 | ) { |
| 72 | return yield* Effect.fail( |
| 73 | new Error(`environment '${environmentId}' still exists (${status})`), |
| 74 | ); |
| 75 | } |
| 76 | }).pipe( |
| 77 | Effect.retry({ |
| 78 | schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(18)]), |
| 79 | }), |
| 80 | ); |
| 81 | |
| 82 | // A FinSpace environment takes ~20 minutes to provision, bills while it |
| 83 | // exists, and FinSpace is closed to non-onboarded accounts. The full |
| 84 | // lifecycle is gated behind AWS_TEST_FINSPACE=1 and always destroys what it |
| 85 | // created. |
| 86 | test.provider.skipIf(finspaceRetired)( |
| 87 | "create FinSpace environment, verify, update, destroy", |
| 88 | (stack) => |
| 89 | Effect.gen(function* () { |
| 90 | yield* stack.destroy(); |
| 91 | |
| 92 | const { env } = yield* stack.deploy( |
| 93 | Effect.gen(function* () { |
| 94 | const env = yield* Environment("Analytics", { |
| 95 | description: "alchemy finspace test environment", |
| 96 | tags: { fixture: "finspace-environment" }, |
| 97 | }); |
| 98 | return { env }; |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(env.environmentId).toBeDefined(); |
| 103 | expect(env.environmentArn).toContain(":environment/"); |
| 104 | expect(env.status).toBe("CREATED"); |
| 105 | expect(env.tags.fixture).toBe("finspace-environment"); |
| 106 | |
| 107 | // Out-of-band verification via distilled. |
| 108 | const observed = yield* finspace.getEnvironment({ |
| 109 | environmentId: env.environmentId, |
| 110 | }); |
| 111 | expect(observed.environment?.status).toBe("CREATED"); |
| 112 | expect(observed.environment?.name).toBe(env.name); |
| 113 | |
| 114 | // Update the description in place (no replacement). |
| 115 | const { env: updated } = yield* stack.deploy( |
| 116 | Effect.gen(function* () { |
| 117 | const env = yield* Environment("Analytics", { |
| 118 | description: "alchemy finspace test environment (updated)", |
| 119 | tags: { fixture: "finspace-environment" }, |
| 120 | }); |
| 121 | return { env }; |
| 122 | }), |
| 123 | ); |
| 124 | expect(updated.environmentId).toBe(env.environmentId); |
| 125 | |
| 126 | // Destroy immediately — environments bill while they exist — and |
| 127 | // verify deletion was initiated out-of-band. |
| 128 | yield* stack.destroy(); |
| 129 | yield* assertEnvironmentDeleting(env.environmentId); |
| 130 | }), |
| 131 | // environment create (~20 min) + update + delete, one test. |
| 132 | { |
| 133 | tags: ["provider:aws", "provider:aws:finspace", "live"], |
| 134 | timeout: 3_000_000, |
| 135 | }, |
| 136 | ); |