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 { Pipeline } from "@alchemy.run/aws/CodePipeline/Pipeline"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as codepipeline from "@distilled.cloud/aws/codepipeline"; |
| 6 | import * as Output from "alchemy/Output"; |
| 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 | const pipelineName = "alchemy-test-codepipeline"; |
| 13 | |
| 14 | const getPipeline = codepipeline |
| 15 | .getPipeline({ name: pipelineName }) |
| 16 | .pipe(Effect.catchTag("PipelineNotFoundException", () => Effect.succeed(undefined))); |
| 17 | |
| 18 | // Build the stack: an S3 source bucket (must be versioned for an S3 source |
| 19 | // action), an artifact bucket, a pipeline role, and the pipeline itself. |
| 20 | const makeStack = (objectKey: string) => |
| 21 | Effect.gen(function* () { |
| 22 | const source = yield* AWS.S3.Bucket("PipelineSource", { |
| 23 | versioning: "Enabled", |
| 24 | forceDestroy: true, |
| 25 | }); |
| 26 | const artifacts = yield* AWS.S3.Bucket("PipelineArtifacts", { |
| 27 | forceDestroy: true, |
| 28 | }); |
| 29 | const role = yield* AWS.IAM.Role("PipelineRole", { |
| 30 | assumeRolePolicyDocument: { |
| 31 | Version: "2012-10-17", |
| 32 | Statement: [ |
| 33 | { |
| 34 | Effect: "Allow", |
| 35 | Principal: { Service: "codepipeline.amazonaws.com" }, |
| 36 | Action: ["sts:AssumeRole"], |
| 37 | }, |
| 38 | ], |
| 39 | }, |
| 40 | inlinePolicies: { |
| 41 | Artifacts: { |
| 42 | Version: "2012-10-17", |
| 43 | Statement: [ |
| 44 | { |
| 45 | Effect: "Allow", |
| 46 | Action: [ |
| 47 | "s3:GetObject", |
| 48 | "s3:GetObjectVersion", |
| 49 | "s3:PutObject", |
| 50 | "s3:GetBucketVersioning", |
| 51 | "s3:ListBucket", |
| 52 | ], |
| 53 | Resource: [ |
| 54 | source.bucketArn, |
| 55 | Output.interpolate`${source.bucketArn}/*` as any, |
| 56 | artifacts.bucketArn, |
| 57 | Output.interpolate`${artifacts.bucketArn}/*` as any, |
| 58 | ], |
| 59 | }, |
| 60 | ], |
| 61 | }, |
| 62 | }, |
| 63 | }); |
| 64 | return yield* Pipeline("LifecyclePipeline", { |
| 65 | pipelineName, |
| 66 | roleArn: role.roleArn, |
| 67 | artifactStore: { type: "S3", location: artifacts.bucketName }, |
| 68 | stages: [ |
| 69 | { |
| 70 | name: "Source", |
| 71 | actions: [ |
| 72 | { |
| 73 | name: "S3Source", |
| 74 | category: "Source", |
| 75 | owner: "AWS", |
| 76 | provider: "S3", |
| 77 | outputArtifacts: ["SourceOutput"], |
| 78 | configuration: { |
| 79 | S3Bucket: source.bucketName, |
| 80 | S3ObjectKey: objectKey, |
| 81 | PollForSourceChanges: "false", |
| 82 | }, |
| 83 | }, |
| 84 | ], |
| 85 | }, |
| 86 | { |
| 87 | name: "Approve", |
| 88 | actions: [ |
| 89 | { |
| 90 | name: "ManualApproval", |
| 91 | category: "Approval", |
| 92 | owner: "AWS", |
| 93 | provider: "Manual", |
| 94 | }, |
| 95 | ], |
| 96 | }, |
| 97 | ], |
| 98 | }); |
| 99 | }); |
| 100 | |
| 101 | test.provider( |
| 102 | "lifecycle: create S3-source pipeline, update, destroy", |
| 103 | (stack) => |
| 104 | Effect.gen(function* () { |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | // Create. |
| 108 | const deployed = yield* stack.deploy(makeStack("source.zip")); |
| 109 | expect(deployed.pipelineName).toBe(pipelineName); |
| 110 | expect(deployed.pipelineArn).toContain(`:${pipelineName}`); |
| 111 | |
| 112 | // Out-of-band verification via distilled. |
| 113 | const created = yield* getPipeline; |
| 114 | expect(created?.pipeline?.name).toBe(pipelineName); |
| 115 | expect(created?.pipeline?.stages?.length).toBe(2); |
| 116 | expect(created?.pipeline?.stages?.[0]?.name).toBe("Source"); |
| 117 | expect(created?.pipeline?.stages?.[0]?.actions?.[0]?.configuration?.S3ObjectKey).toBe( |
| 118 | "source.zip", |
| 119 | ); |
| 120 | |
| 121 | // Canonical list() coverage. |
| 122 | const provider = yield* Provider.findProvider(Pipeline); |
| 123 | const all = yield* provider.list(); |
| 124 | expect(all.some((p) => p.pipelineName === pipelineName)).toBe(true); |
| 125 | |
| 126 | // Update — change the source object key in place (no replacement). |
| 127 | yield* stack.deploy(makeStack("release.zip")); |
| 128 | const updated = yield* getPipeline; |
| 129 | expect(updated?.pipeline?.stages?.[0]?.actions?.[0]?.configuration?.S3ObjectKey).toBe( |
| 130 | "release.zip", |
| 131 | ); |
| 132 | |
| 133 | // Destroy — pipeline is deleted; verify it is gone out-of-band. |
| 134 | yield* stack.destroy(); |
| 135 | const after = yield* getPipeline; |
| 136 | expect(after).toBeUndefined(); |
| 137 | }), |
| 138 | { |
| 139 | tags: [ |
| 140 | "provider:aws", |
| 141 | "provider:aws:codepipeline", |
| 142 | "provider:aws:iam", |
| 143 | "provider:aws:s3", |
| 144 | "live", |
| 145 | ], |
| 146 | timeout: 300_000, |
| 147 | }, |
| 148 | ); |