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 { ComponentVersion } from "@alchemy.run/aws/GreengrassV2"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as greengrassv2 from "@distilled.cloud/aws/greengrassv2"; |
| 6 | import * as sts from "@distilled.cloud/aws/sts"; |
| 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 | // Ungated typed-error probe: prove the distilled error union carries the |
| 13 | // not-found tag this provider's read/delete paths depend on. |
| 14 | test.provider( |
| 15 | "describeComponent on a nonexistent ARN fails with ResourceNotFoundException", |
| 16 | () => |
| 17 | Effect.gen(function* () { |
| 18 | const region = yield* yield* AWS.Region; |
| 19 | const { Account } = yield* sts.getCallerIdentity({}); |
| 20 | const error = yield* Effect.flip( |
| 21 | greengrassv2.describeComponent({ |
| 22 | arn: `arn:aws:greengrass:${region}:${Account}:components:com.alchemy.test.Nonexistent:versions:0.0.1`, |
| 23 | }), |
| 24 | ); |
| 25 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 26 | }), |
| 27 | { tags: ["provider:aws", "provider:aws:greengrassv2", "live"] }, |
| 28 | ); |
| 29 | |
| 30 | const recipe = (version: string) => |
| 31 | JSON.stringify({ |
| 32 | RecipeFormatVersion: "2020-01-25", |
| 33 | ComponentName: "com.alchemy.test.GgHello", |
| 34 | ComponentVersion: version, |
| 35 | ComponentDescription: "Alchemy GreengrassV2 test component", |
| 36 | ComponentPublisher: "Alchemy", |
| 37 | Manifests: [{ Platform: { os: "linux" }, Lifecycle: { run: "echo hello from alchemy" } }], |
| 38 | }); |
| 39 | |
| 40 | const componentExists = (arn: string) => |
| 41 | greengrassv2.describeComponent({ arn }).pipe( |
| 42 | Effect.map(() => true), |
| 43 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(false)), |
| 44 | ); |
| 45 | |
| 46 | const waitUntilComponentGone = (arn: string) => |
| 47 | componentExists(arn).pipe( |
| 48 | Effect.repeat({ |
| 49 | schedule: Schedule.spaced("2 seconds"), |
| 50 | until: (exists) => exists === false, |
| 51 | times: 10, |
| 52 | }), |
| 53 | Effect.map((exists) => expect(exists).toBe(false)), |
| 54 | ); |
| 55 | |
| 56 | test.provider( |
| 57 | "create, tag-update, replace (version bump), destroy", |
| 58 | (stack) => |
| 59 | Effect.gen(function* () { |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | // 1. CREATE from an inline recipe. |
| 63 | const { component } = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | const component = yield* ComponentVersion("Hello", { |
| 66 | recipe: recipe("1.0.0"), |
| 67 | tags: { fixture: "greengrass-component" }, |
| 68 | }); |
| 69 | return { component }; |
| 70 | }), |
| 71 | ); |
| 72 | expect(component.componentName).toBe("com.alchemy.test.GgHello"); |
| 73 | expect(component.componentVersion).toBe("1.0.0"); |
| 74 | expect(component.arn).toContain(":components:com.alchemy.test.GgHello:versions:1.0.0"); |
| 75 | |
| 76 | // Out-of-band verification via distilled: DEPLOYABLE + branded tags. |
| 77 | const described = yield* greengrassv2.describeComponent({ arn: component.arn }); |
| 78 | expect(described.status?.componentState).toBe("DEPLOYABLE"); |
| 79 | expect(described.tags?.fixture).toBe("greengrass-component"); |
| 80 | expect(described.tags?.["alchemy::id"]).toBe("Hello"); |
| 81 | |
| 82 | // 2. UPDATE tags in place — same immutable component version. |
| 83 | const { component: retagged } = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | const component = yield* ComponentVersion("Hello", { |
| 86 | recipe: recipe("1.0.0"), |
| 87 | tags: { fixture: "greengrass-component", team: "edge" }, |
| 88 | }); |
| 89 | return { component }; |
| 90 | }), |
| 91 | ); |
| 92 | expect(retagged.arn).toBe(component.arn); |
| 93 | const retaggedTags = yield* greengrassv2.listTagsForResource({ resourceArn: component.arn }); |
| 94 | expect(retaggedTags.tags?.team).toBe("edge"); |
| 95 | |
| 96 | // 3. REPLACE — bumping the recipe version registers a new component |
| 97 | // version and deletes the old one. |
| 98 | const { component: bumped } = yield* stack.deploy( |
| 99 | Effect.gen(function* () { |
| 100 | const component = yield* ComponentVersion("Hello", { |
| 101 | recipe: recipe("1.0.1"), |
| 102 | tags: { fixture: "greengrass-component" }, |
| 103 | }); |
| 104 | return { component }; |
| 105 | }), |
| 106 | ); |
| 107 | expect(bumped.componentVersion).toBe("1.0.1"); |
| 108 | expect(bumped.arn).not.toBe(component.arn); |
| 109 | yield* waitUntilComponentGone(component.arn); |
| 110 | |
| 111 | // 4. DESTROY — the replacement version is deleted too. |
| 112 | yield* stack.destroy(); |
| 113 | yield* waitUntilComponentGone(bumped.arn); |
| 114 | }), |
| 115 | { tags: ["provider:aws", "provider:aws:greengrassv2", "live"], timeout: 300_000 }, |
| 116 | ); |