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 { ExperimentTemplate, TargetAccountConfiguration } from "@alchemy.run/aws/FIS"; |
| 3 | import { Role } from "@alchemy.run/aws/IAM/Role"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as fis from "@distilled.cloud/aws/fis"; |
| 7 | import * as sts from "@distilled.cloud/aws/sts"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const findConfiguration = (experimentTemplateId: string, accountId: string) => |
| 13 | fis.getTargetAccountConfiguration({ experimentTemplateId, accountId }).pipe( |
| 14 | Effect.map((r) => r.targetAccountConfiguration), |
| 15 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 16 | ); |
| 17 | |
| 18 | test.provider( |
| 19 | "create, update, delete target account configuration", |
| 20 | (stack) => |
| 21 | Effect.gen(function* () { |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | // Multi-account experiments accept the orchestrator account itself as a |
| 25 | // target account, so the whole lifecycle runs single-account. |
| 26 | const { Account } = yield* sts.getCallerIdentity({}); |
| 27 | const accountId = Account!; |
| 28 | |
| 29 | const program = (description: string) => |
| 30 | Effect.gen(function* () { |
| 31 | const role = yield* Role("FisTargetAccountRole", { |
| 32 | assumeRolePolicyDocument: { |
| 33 | Version: "2012-10-17", |
| 34 | Statement: [ |
| 35 | { |
| 36 | Effect: "Allow", |
| 37 | Principal: { Service: "fis.amazonaws.com" }, |
| 38 | Action: ["sts:AssumeRole"], |
| 39 | }, |
| 40 | ], |
| 41 | }, |
| 42 | }); |
| 43 | const template = yield* ExperimentTemplate("MultiAccountTemplate", { |
| 44 | roleArn: role.roleArn, |
| 45 | experimentOptions: { accountTargeting: "multi-account" }, |
| 46 | actions: { |
| 47 | Wait: { |
| 48 | actionId: "aws:fis:wait", |
| 49 | parameters: { duration: "PT1M" }, |
| 50 | }, |
| 51 | }, |
| 52 | }); |
| 53 | const config = yield* TargetAccountConfiguration("TargetAccount", { |
| 54 | experimentTemplateId: template.id, |
| 55 | accountId, |
| 56 | roleArn: role.roleArn, |
| 57 | description, |
| 58 | }); |
| 59 | return { template, config }; |
| 60 | }); |
| 61 | |
| 62 | const { template, config } = yield* stack.deploy(program("alchemy fis tac test")); |
| 63 | expect(config.experimentTemplateId).toBe(template.id); |
| 64 | expect(config.accountId).toBe(accountId); |
| 65 | expect(config.roleArn).toContain(":role/"); |
| 66 | |
| 67 | // out-of-band verification via distilled |
| 68 | const created = yield* findConfiguration(template.id, accountId); |
| 69 | expect(created).toBeDefined(); |
| 70 | expect(created?.accountId).toBe(accountId); |
| 71 | expect(created?.roleArn).toBe(config.roleArn); |
| 72 | expect(created?.description).toBe("alchemy fis tac test"); |
| 73 | |
| 74 | // update in place — same identity, new description |
| 75 | const updated = yield* stack.deploy(program("alchemy fis tac test updated")); |
| 76 | expect(updated.config.experimentTemplateId).toBe(template.id); |
| 77 | expect(updated.config.accountId).toBe(accountId); |
| 78 | |
| 79 | const afterUpdate = yield* findConfiguration(template.id, accountId); |
| 80 | expect(afterUpdate?.description).toBe("alchemy fis tac test updated"); |
| 81 | |
| 82 | yield* stack.destroy(); |
| 83 | const afterDestroy = yield* findConfiguration(template.id, accountId); |
| 84 | expect(afterDestroy).toBeUndefined(); |
| 85 | }), |
| 86 | { |
| 87 | tags: ["provider:aws", "provider:aws:fis", "provider:aws:iam", "live"], |
| 88 | timeout: 120_000, |
| 89 | }, |
| 90 | ); |