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, 04:45 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { ResourceCollection } from "@alchemy.run/aws/DevOpsGuru/ResourceCollection"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as devopsguru from "@distilled.cloud/aws/devops-guru"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | // Observe the account's tag-based coverage out-of-band. An account that has |
| 11 | // never configured a collection fails with the typed ResourceNotFoundException |
| 12 | // ("No CustomerResourceFilter present") — treated as empty. A key whose last |
| 13 | // value was removed lingers with an empty TagValues list — also empty. |
| 14 | const observedTags = devopsguru.getResourceCollection({ ResourceCollectionType: "AWS_TAGS" }).pipe( |
| 15 | Effect.map((r) => (r.ResourceCollection?.Tags ?? []).filter((t) => t.TagValues.length > 0)), |
| 16 | Effect.catchTag("ResourceNotFoundException", () => |
| 17 | Effect.succeed([] as devopsguru.TagCollectionFilter[]), |
| 18 | ), |
| 19 | ); |
| 20 | |
| 21 | // Ungated typed-error probe: getResourceCollection either returns the |
| 22 | // configured collection or fails with the typed not-found tag — never an |
| 23 | // untyped catch-all. |
| 24 | test.provider( |
| 25 | "getResourceCollection returns typed results", |
| 26 | () => |
| 27 | Effect.gen(function* () { |
| 28 | const tags = yield* observedTags; |
| 29 | expect(Array.isArray(tags)).toBe(true); |
| 30 | }), |
| 31 | { tags: ["provider:aws", "provider:aws:devopsguru", "live"] }, |
| 32 | ); |
| 33 | |
| 34 | // The resource collection is an account/region singleton. This test only |
| 35 | // runs when the account has no tag-based coverage it doesn't own — it must |
| 36 | // never clobber coverage the user already operates. |
| 37 | test.provider( |
| 38 | "lifecycle: configure tag coverage, converge values, remove", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | const preexisting = yield* observedTags; |
| 42 | const foreign = preexisting.filter( |
| 43 | (t) => t.AppBoundaryKey.toLowerCase() !== "devops-guru-alchemy", |
| 44 | ); |
| 45 | if (foreign.length > 0) { |
| 46 | yield* Effect.logInfo( |
| 47 | `DevOps Guru tag coverage already configured (${foreign |
| 48 | .map((t) => t.AppBoundaryKey) |
| 49 | .join(", ")}) — skipping destructive lifecycle test`, |
| 50 | ); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | // Create — tag-based coverage. |
| 57 | const created = yield* stack.deploy( |
| 58 | Effect.gen(function* () { |
| 59 | return yield* ResourceCollection("Coverage", { |
| 60 | tags: [ |
| 61 | { |
| 62 | appBoundaryKey: "devops-guru-alchemy", |
| 63 | tagValues: ["devopsguru-test-a", "devopsguru-test-b"], |
| 64 | }, |
| 65 | ], |
| 66 | }); |
| 67 | }), |
| 68 | ); |
| 69 | expect(created.cloudFormationStackNames).toEqual([]); |
| 70 | expect(created.tags).toHaveLength(1); |
| 71 | expect(created.tags[0]!.tagValues.sort()).toEqual(["devopsguru-test-a", "devopsguru-test-b"]); |
| 72 | |
| 73 | // Out-of-band verification via distilled. |
| 74 | const observed = yield* observedTags; |
| 75 | expect(observed).toHaveLength(1); |
| 76 | expect([...(observed[0]?.TagValues ?? [])].sort()).toEqual([ |
| 77 | "devopsguru-test-a", |
| 78 | "devopsguru-test-b", |
| 79 | ]); |
| 80 | |
| 81 | // Update — add one value, remove another; the provider applies only |
| 82 | // the delta (REMOVE b, ADD c). |
| 83 | const updated = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* ResourceCollection("Coverage", { |
| 86 | tags: [ |
| 87 | { |
| 88 | appBoundaryKey: "devops-guru-alchemy", |
| 89 | tagValues: ["devopsguru-test-a", "devopsguru-test-c"], |
| 90 | }, |
| 91 | ], |
| 92 | }); |
| 93 | }), |
| 94 | ); |
| 95 | expect(updated.tags[0]!.tagValues.sort()).toEqual(["devopsguru-test-a", "devopsguru-test-c"]); |
| 96 | const observedUpdated = yield* observedTags; |
| 97 | expect([...(observedUpdated[0]?.TagValues ?? [])].sort()).toEqual([ |
| 98 | "devopsguru-test-a", |
| 99 | "devopsguru-test-c", |
| 100 | ]); |
| 101 | |
| 102 | // Destroy — the collection is emptied and the account is clean again. |
| 103 | yield* stack.destroy(); |
| 104 | const after = yield* observedTags; |
| 105 | expect(after).toEqual([]); |
| 106 | }), |
| 107 | { |
| 108 | tags: ["provider:aws", "provider:aws:devopsguru", "live"], |
| 109 | timeout: 180_000, |
| 110 | }, |
| 111 | ); |