| 1 | import { AlchemyContext } from "@/AlchemyContext.ts"; |
| 2 | import { ArtifactStore, createArtifactStore } from "@/Artifacts.ts"; |
| 3 | import { AuthProviders } from "@/Auth/AuthProvider.ts"; |
| 4 | import { ProfileStoreLive } from "@/Auth/Profile.ts"; |
| 5 | import * as AWS from "@/AWS"; |
| 6 | import { AWSEnvironment } from "@/AWS/Environment.ts"; |
| 7 | import { Stack } from "@/Stack.ts"; |
| 8 | import { Stage } from "@/Stage.ts"; |
| 9 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 10 | import { expect, it } from "alchemy-test"; |
| 11 | import * as ConfigProvider from "effect/ConfigProvider"; |
| 12 | import * as Effect from "effect/Effect"; |
| 13 | import * as Layer from "effect/Layer"; |
| 14 | import * as Result from "effect/Result"; |
| 15 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 16 | import { v4 as uuidv4 } from "uuid"; |
| 17 | |
| 18 | it.live( |
| 19 | "building the AWS provider layers rejects an unknown explicit profile", |
| 20 | () => |
| 21 | Effect.gen(function* () { |
| 22 | // AWSEnvironment is constructed lazily so `alchemy dev` can build |
| 23 | // provider layers without credentials. The unknown-profile rejection |
| 24 | // surfaces on first use, not at `Layer.build`. |
| 25 | const result = yield* Effect.result( |
| 26 | Effect.sandbox( |
| 27 | AWSEnvironment.current.pipe(Effect.provide(AWS.providers())), |
| 28 | ), |
| 29 | ); |
| 30 | expect(Result.isFailure(result)).toBe(true); |
| 31 | if (Result.isFailure(result)) { |
| 32 | expect(String(result.failure)).toContain("does not exist"); |
| 33 | expect(String(result.failure)).toContain("alchemy profile create"); |
| 34 | } |
| 35 | }).pipe( |
| 36 | Effect.provide( |
| 37 | Layer.mergeAll( |
| 38 | Layer.succeed(AuthProviders, {}), |
| 39 | Layer.sync(ArtifactStore, createArtifactStore), |
| 40 | Layer.succeed(Stage, "test"), |
| 41 | Layer.succeed(Stack, { |
| 42 | name: "test", |
| 43 | stage: "test", |
| 44 | resources: {}, |
| 45 | bindings: {}, |
| 46 | actions: {}, |
| 47 | }), |
| 48 | Layer.succeed(AlchemyContext, { |
| 49 | dev: false, |
| 50 | adopt: false, |
| 51 | dotAlchemy: ".alchemy", |
| 52 | }), |
| 53 | ConfigProvider.layer( |
| 54 | ConfigProvider.fromUnknown({ |
| 55 | ALCHEMY_PROFILE: `non-existent-${uuidv4()}`, |
| 56 | }), |
| 57 | ), |
| 58 | ProfileStoreLive, |
| 59 | ).pipe( |
| 60 | Layer.provideMerge( |
| 61 | Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer), |
| 62 | ), |
| 63 | ), |
| 64 | ), |
| 65 | ), |
| 66 | { tags: ["unit", "provider:aws", "local"] }, |
| 67 | ); |