The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Domain } from "@alchemy.run/aws/CodeArtifact/Domain"; |
| 3 | import { Repository } from "@alchemy.run/aws/CodeArtifact/Repository"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as codeartifact from "@distilled.cloud/aws/codeartifact"; |
| 7 | import * as Provider from "alchemy/Provider"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | // CodeArtifact domain names must be lowercase; keep them deterministic. |
| 13 | const domainName = "alchemy-test-ca"; |
| 14 | const repositoryName = "alchemy-test-repo"; |
| 15 | |
| 16 | const getRepository = codeartifact |
| 17 | .describeRepository({ domain: domainName, repository: repositoryName }) |
| 18 | .pipe( |
| 19 | Effect.map((res) => res.repository), |
| 20 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 21 | ); |
| 22 | |
| 23 | const makeStack = (description: string, upstreamDescription: string) => |
| 24 | Effect.gen(function* () { |
| 25 | const domain = yield* Domain("Domain", { domainName }); |
| 26 | const shared = yield* Repository("Shared", { |
| 27 | domain: domain.domainName, |
| 28 | repositoryName: `${repositoryName}-shared`, |
| 29 | description: upstreamDescription, |
| 30 | }); |
| 31 | const repo = yield* Repository("Repo", { |
| 32 | domain: domain.domainName, |
| 33 | repositoryName, |
| 34 | description, |
| 35 | upstreams: [shared.repositoryName], |
| 36 | tags: { env: "test" }, |
| 37 | }); |
| 38 | return { domain, repo }; |
| 39 | }); |
| 40 | |
| 41 | test.provider( |
| 42 | "lifecycle: create domain + repository with upstream, update, destroy", |
| 43 | (stack) => |
| 44 | Effect.gen(function* () { |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | // Create. |
| 48 | const deployed = yield* stack.deploy(makeStack("first", "shared-first")); |
| 49 | expect(deployed.repo.repositoryName).toBe(repositoryName); |
| 50 | expect(deployed.repo.repositoryArn).toContain(`:repository/`); |
| 51 | expect(deployed.domain.domainName).toBe(domainName); |
| 52 | expect(deployed.domain.domainArn).toContain(`:domain/`); |
| 53 | |
| 54 | // Out-of-band verification via distilled. |
| 55 | const created = yield* getRepository; |
| 56 | expect(created?.name).toBe(repositoryName); |
| 57 | expect(created?.description).toBe("first"); |
| 58 | expect(created?.upstreams?.map((u) => u.repositoryName)).toContain( |
| 59 | `${repositoryName}-shared`, |
| 60 | ); |
| 61 | |
| 62 | const domainCheck = yield* codeartifact.describeDomain({ |
| 63 | domain: domainName, |
| 64 | }); |
| 65 | expect(domainCheck.domain?.name).toBe(domainName); |
| 66 | expect(domainCheck.domain?.repositoryCount).toBeGreaterThanOrEqual(2); |
| 67 | |
| 68 | // Canonical list() coverage for Domain. |
| 69 | const domainProvider = yield* Provider.findProvider(Domain); |
| 70 | const domains = yield* domainProvider.list(); |
| 71 | expect(domains.some((d) => d.domainName === domainName)).toBe(true); |
| 72 | |
| 73 | // Update — change the repository description in place (no replacement). |
| 74 | yield* stack.deploy(makeStack("second", "shared-first")); |
| 75 | const updated = yield* getRepository; |
| 76 | expect(updated?.description).toBe("second"); |
| 77 | |
| 78 | // Destroy — verify both resources are gone out-of-band. |
| 79 | yield* stack.destroy(); |
| 80 | const afterRepo = yield* getRepository; |
| 81 | expect(afterRepo).toBeUndefined(); |
| 82 | const afterDomain = yield* codeartifact.describeDomain({ domain: domainName }).pipe( |
| 83 | Effect.map((res) => res.domain), |
| 84 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 85 | ); |
| 86 | expect(afterDomain).toBeUndefined(); |
| 87 | }), |
| 88 | { |
| 89 | tags: ["provider:aws", "provider:aws:codeartifact", "live"], |
| 90 | timeout: 300_000, |
| 91 | }, |
| 92 | ); |