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 { AWSEnvironment } from "@alchemy.run/aws/Environment"; |
| 3 | import { Flow } from "@alchemy.run/aws/MediaConnect"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as mediaconnect from "@distilled.cloud/aws/mediaconnect"; |
| 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. Runs in every |
| 14 | // CI pass at near-zero cost, unlike the gated lifecycle below. |
| 15 | test.provider( |
| 16 | "describeFlow on a nonexistent flow ARN fails with NotFoundException", |
| 17 | () => |
| 18 | Effect.gen(function* () { |
| 19 | const { accountId, region } = yield* AWSEnvironment.current; |
| 20 | const error = yield* Effect.flip( |
| 21 | mediaconnect.describeFlow({ |
| 22 | FlowArn: `arn:aws:mediaconnect:${region}:${accountId}:flow:1-00000000000000000000000000000000:alchemy-nonexistent-flow-probe`, |
| 23 | }), |
| 24 | ); |
| 25 | expect(error._tag).toBe("NotFoundException"); |
| 26 | }), |
| 27 | { tags: ["provider:aws", "provider:aws:mediaconnect", "live"] }, |
| 28 | ); |
| 29 | |
| 30 | // Deletion is initiated by the provider and verified as fully gone here; |
| 31 | // bounded out-of-band re-check in case the final read raced DELETING. |
| 32 | const assertFlowGone = (flowArn: string) => |
| 33 | Effect.gen(function* () { |
| 34 | const status = yield* mediaconnect.describeFlow({ FlowArn: flowArn }).pipe( |
| 35 | Effect.map((r) => r.Flow?.Status ?? "gone"), |
| 36 | Effect.catchTag("NotFoundException", () => Effect.succeed("gone" as const)), |
| 37 | ); |
| 38 | if (status !== "gone") { |
| 39 | return yield* Effect.fail(new Error(`flow '${flowArn}' still exists (status: ${status})`)); |
| 40 | } |
| 41 | }).pipe( |
| 42 | Effect.retry({ schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(18)]) }), |
| 43 | ); |
| 44 | |
| 45 | // MediaConnect flows bill hourly while ACTIVE and provisioning is async, so |
| 46 | // the full lifecycle is gated behind AWS_TEST_MEDIACONNECT=1. Create leaves |
| 47 | // the flow in STANDBY (the provider never calls StartFlow) and the test |
| 48 | // always destroys what it created. |
| 49 | test.provider.skipIf(!process.env.AWS_TEST_MEDIACONNECT)( |
| 50 | "create flow (STANDBY), add output, sync source, destroy", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | yield* stack.destroy(); |
| 54 | |
| 55 | // Step 1: create with a single RTP source and no outputs. |
| 56 | const { flow } = yield* stack.deploy( |
| 57 | Effect.gen(function* () { |
| 58 | const flow = yield* Flow("Broadcast", { |
| 59 | source: { |
| 60 | Name: "primary", |
| 61 | Protocol: "rtp", |
| 62 | WhitelistCidr: "10.24.34.0/23", |
| 63 | IngestPort: 5000, |
| 64 | }, |
| 65 | tags: { fixture: "mediaconnect-flow" }, |
| 66 | }); |
| 67 | return { flow }; |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | expect(flow.flowArn).toContain(":flow:"); |
| 72 | expect(flow.status).toBe("STANDBY"); |
| 73 | expect(flow.availabilityZone).toBeDefined(); |
| 74 | expect(flow.sourceArn).toContain(":source:"); |
| 75 | expect(flow.sourceIngestPort).toBe(5000); |
| 76 | expect(flow.outputs).toEqual([]); |
| 77 | expect(flow.tags.fixture).toBe("mediaconnect-flow"); |
| 78 | |
| 79 | // Out-of-band verification via distilled: created but NOT started. |
| 80 | const described = yield* mediaconnect.describeFlow({ FlowArn: flow.flowArn }); |
| 81 | expect(described.Flow?.Status).toBe("STANDBY"); |
| 82 | expect(described.Flow?.Source?.WhitelistCidr).toBe("10.24.34.0/23"); |
| 83 | |
| 84 | // Step 2: update in place — widen the source whitelist and add an |
| 85 | // output. Same logical id, same name → no replacement. |
| 86 | const { flow: updated } = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | const flow = yield* Flow("Broadcast", { |
| 89 | source: { |
| 90 | Name: "primary", |
| 91 | Protocol: "rtp", |
| 92 | WhitelistCidr: "10.24.32.0/20", |
| 93 | IngestPort: 5000, |
| 94 | }, |
| 95 | outputs: [ |
| 96 | { Name: "affiliate-east", Protocol: "rtp", Destination: "198.51.100.11", Port: 5010 }, |
| 97 | ], |
| 98 | tags: { fixture: "mediaconnect-flow", stage: "updated" }, |
| 99 | }); |
| 100 | return { flow }; |
| 101 | }), |
| 102 | ); |
| 103 | |
| 104 | // Update, not replacement: the ARN is stable. |
| 105 | expect(updated.flowArn).toBe(flow.flowArn); |
| 106 | expect(updated.status).toBe("STANDBY"); |
| 107 | expect(updated.outputs).toHaveLength(1); |
| 108 | expect(updated.outputs[0]?.name).toBe("affiliate-east"); |
| 109 | expect(updated.outputs[0]?.destination).toBe("198.51.100.11"); |
| 110 | expect(updated.outputs[0]?.port).toBe(5010); |
| 111 | expect(updated.tags.stage).toBe("updated"); |
| 112 | |
| 113 | const redescribed = yield* mediaconnect.describeFlow({ FlowArn: flow.flowArn }); |
| 114 | expect(redescribed.Flow?.Source?.WhitelistCidr).toBe("10.24.32.0/20"); |
| 115 | expect(redescribed.Flow?.Outputs?.map((o) => o.Name)).toContain("affiliate-east"); |
| 116 | |
| 117 | // Step 3: drop the output again — the reconciler removes extras. |
| 118 | const { flow: pruned } = yield* stack.deploy( |
| 119 | Effect.gen(function* () { |
| 120 | const flow = yield* Flow("Broadcast", { |
| 121 | source: { |
| 122 | Name: "primary", |
| 123 | Protocol: "rtp", |
| 124 | WhitelistCidr: "10.24.32.0/20", |
| 125 | IngestPort: 5000, |
| 126 | }, |
| 127 | tags: { fixture: "mediaconnect-flow" }, |
| 128 | }); |
| 129 | return { flow }; |
| 130 | }), |
| 131 | ); |
| 132 | expect(pruned.flowArn).toBe(flow.flowArn); |
| 133 | expect(pruned.outputs).toEqual([]); |
| 134 | expect(pruned.tags.stage).toBeUndefined(); |
| 135 | |
| 136 | // Destroy and verify the flow is fully gone out-of-band. |
| 137 | yield* stack.destroy(); |
| 138 | yield* assertFlowGone(flow.flowArn); |
| 139 | }), |
| 140 | // create + 2 in-place updates + delete-until-gone. |
| 141 | { tags: ["provider:aws", "provider:aws:mediaconnect", "live"], timeout: 900_000 }, |
| 142 | ); |