The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Monitor } from "@alchemy.run/aws/InternetMonitor"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as logs from "@distilled.cloud/aws/cloudwatch-logs"; |
| 6 | import * as im from "@distilled.cloud/aws/internetmonitor"; |
| 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 (getMonitor's |
| 14 | // Smithy model omits ResourceNotFoundException — patched in distilled). |
| 15 | test.provider( |
| 16 | "getMonitor on a nonexistent monitor fails with ResourceNotFoundException", |
| 17 | () => |
| 18 | Effect.gen(function* () { |
| 19 | const error = yield* Effect.flip( |
| 20 | im.getMonitor({ MonitorName: "alchemy-nonexistent-internetmonitor-probe" }), |
| 21 | ); |
| 22 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 23 | }), |
| 24 | { tags: ["provider:aws", "provider:aws:internetmonitor", "live"] }, |
| 25 | ); |
| 26 | |
| 27 | // Typed wait-until-gone after destroy. |
| 28 | const assertMonitorGone = (monitorName: string) => |
| 29 | im.getMonitor({ MonitorName: monitorName }).pipe( |
| 30 | Effect.flatMap(() => Effect.fail(new Error(`monitor ${monitorName} still exists`))), |
| 31 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 32 | Effect.retry({ |
| 33 | while: (e) => e instanceof Error, |
| 34 | schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]), |
| 35 | }), |
| 36 | ); |
| 37 | |
| 38 | describe( |
| 39 | "AWS.InternetMonitor.Monitor", |
| 40 | { tags: ["provider:aws", "provider:aws:internetmonitor", "live"] }, |
| 41 | () => { |
| 42 | test.provider( |
| 43 | "monitor lifecycle: create, update city-networks cap + tags, destroy", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | yield* stack.destroy(); |
| 47 | |
| 48 | const deployMonitor = (props: { |
| 49 | maxCityNetworksToMonitor: number; |
| 50 | tags: Record<string, string>; |
| 51 | }) => |
| 52 | stack.deploy( |
| 53 | Effect.gen(function* () { |
| 54 | const monitor = yield* Monitor("AppMonitor", { |
| 55 | // No resources — an empty monitor is cheap and still |
| 56 | // exercises the full PENDING -> ACTIVE lifecycle. |
| 57 | resources: [], |
| 58 | ...props, |
| 59 | }); |
| 60 | return { |
| 61 | monitorName: monitor.monitorName, |
| 62 | monitorArn: monitor.monitorArn, |
| 63 | status: monitor.status, |
| 64 | maxCityNetworksToMonitor: monitor.maxCityNetworksToMonitor, |
| 65 | tags: monitor.tags, |
| 66 | }; |
| 67 | }), |
| 68 | ); |
| 69 | |
| 70 | const created = yield* deployMonitor({ |
| 71 | maxCityNetworksToMonitor: 1, |
| 72 | tags: { purpose: "alchemy-test" }, |
| 73 | }); |
| 74 | expect(created.monitorArn).toContain(":monitor/"); |
| 75 | expect(created.status).toBe("ACTIVE"); |
| 76 | expect(created.maxCityNetworksToMonitor).toBe(1); |
| 77 | expect(created.tags.purpose).toBe("alchemy-test"); |
| 78 | expect(created.tags["alchemy::id"]).toBe("AppMonitor"); |
| 79 | |
| 80 | // Out-of-band verification via distilled. |
| 81 | const observed = yield* im.getMonitor({ MonitorName: created.monitorName }); |
| 82 | expect(observed.MonitorArn).toBe(created.monitorArn); |
| 83 | expect(observed.Status).toBe("ACTIVE"); |
| 84 | expect(observed.Resources).toEqual([]); |
| 85 | expect(observed.MaxCityNetworksToMonitor).toBe(1); |
| 86 | |
| 87 | // Update in place: raise the city-networks cap and add a tag. The |
| 88 | // monitor identity (name/arn) is stable. |
| 89 | const updated = yield* deployMonitor({ |
| 90 | maxCityNetworksToMonitor: 2, |
| 91 | tags: { purpose: "alchemy-test", updated: "true" }, |
| 92 | }); |
| 93 | expect(updated.monitorName).toBe(created.monitorName); |
| 94 | expect(updated.monitorArn).toBe(created.monitorArn); |
| 95 | expect(updated.maxCityNetworksToMonitor).toBe(2); |
| 96 | expect(updated.tags.updated).toBe("true"); |
| 97 | |
| 98 | const observedUpdated = yield* im.getMonitor({ MonitorName: created.monitorName }); |
| 99 | expect(observedUpdated.MaxCityNetworksToMonitor).toBe(2); |
| 100 | expect(observedUpdated.Tags?.updated).toBe("true"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | yield* assertMonitorGone(created.monitorName); |
| 104 | |
| 105 | // Internet Monitor auto-creates per-monitor CloudWatch log groups |
| 106 | // (/aws/internet-monitor/{name}/{byCity,byCountry,byMetro, |
| 107 | // bySubdivision}) that survive DeleteMonitor. The provider delete |
| 108 | // reaps them — prove none remain after destroy. |
| 109 | const remainingLogGroups = yield* logs |
| 110 | .describeLogGroups({ |
| 111 | logGroupNamePrefix: `/aws/internet-monitor/${created.monitorName}`, |
| 112 | }) |
| 113 | .pipe(Effect.map((r) => (r.logGroups ?? []).map((g) => g.logGroupName))); |
| 114 | expect(remainingLogGroups).toEqual([]); |
| 115 | }), |
| 116 | { timeout: 300_000 }, |
| 117 | ); |
| 118 | }, |
| 119 | ); |