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 * as Location from "@alchemy.run/aws/Location"; |
| 3 | import { describe, expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as location from "@distilled.cloud/aws/location"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Redacted from "effect/Redacted"; |
| 8 | import * as Result from "effect/Result"; |
| 9 | import * as Schedule from "effect/Schedule"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: AWS.providers() }); |
| 12 | |
| 13 | // Bounded wait-until-gone: a Describe on a deleted Location resource returns a |
| 14 | // typed ResourceNotFoundException. Poll a few times so the assertion tolerates |
| 15 | // the brief eventual-consistency window after Delete. |
| 16 | const assertGone = <R>(probe: Effect.Effect<unknown, { _tag: string }, R>) => |
| 17 | probe.pipe( |
| 18 | Effect.flatMap(() => Effect.fail({ _tag: "StillExists" as const })), |
| 19 | Effect.retry({ |
| 20 | while: (e: { _tag: string }) => e._tag === "StillExists", |
| 21 | schedule: Schedule.max([Schedule.spaced("2 seconds"), Schedule.recurs(10)]), |
| 22 | }), |
| 23 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 24 | ); |
| 25 | |
| 26 | describe.skipIf(!!process.env.FAST)( |
| 27 | "AWS.Location", |
| 28 | { tags: ["provider:aws", "provider:aws:location", "live"] }, |
| 29 | () => { |
| 30 | test.provider( |
| 31 | "Map: create, update description, delete", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | const map = yield* stack.deploy( |
| 36 | Effect.gen(function* () { |
| 37 | return yield* Location.Map("TestMap", { |
| 38 | configuration: { style: "VectorEsriNavigation" }, |
| 39 | tags: { Environment: "test" }, |
| 40 | }); |
| 41 | }), |
| 42 | ); |
| 43 | |
| 44 | expect(map.mapName).toBeDefined(); |
| 45 | expect(map.mapArn).toContain(":map/"); |
| 46 | expect(map.style).toEqual("VectorEsriNavigation"); |
| 47 | |
| 48 | const described = yield* location.describeMap({ MapName: map.mapName }); |
| 49 | expect(described.Configuration.Style).toEqual("VectorEsriNavigation"); |
| 50 | expect(described.Tags?.Environment).toEqual("test"); |
| 51 | expect(described.Tags?.["alchemy::id"]).toEqual("TestMap"); |
| 52 | |
| 53 | // Update the description in place (no replacement). |
| 54 | const updated = yield* stack.deploy( |
| 55 | Effect.gen(function* () { |
| 56 | return yield* Location.Map("TestMap", { |
| 57 | configuration: { style: "VectorEsriNavigation" }, |
| 58 | description: "updated map", |
| 59 | tags: { Environment: "prod" }, |
| 60 | }); |
| 61 | }), |
| 62 | ); |
| 63 | expect(updated.mapName).toEqual(map.mapName); |
| 64 | expect(updated.description).toEqual("updated map"); |
| 65 | expect(updated.tags.Environment).toEqual("prod"); |
| 66 | |
| 67 | yield* stack.destroy(); |
| 68 | yield* assertGone(location.describeMap({ MapName: map.mapName })); |
| 69 | }), |
| 70 | { timeout: 180_000 }, |
| 71 | ); |
| 72 | |
| 73 | test.provider( |
| 74 | "PlaceIndex: create, update, delete", |
| 75 | (stack) => |
| 76 | Effect.gen(function* () { |
| 77 | yield* stack.destroy(); |
| 78 | const index = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | return yield* Location.PlaceIndex("TestIndex", { dataSource: "Esri" }); |
| 81 | }), |
| 82 | ); |
| 83 | |
| 84 | expect(index.indexArn).toContain(":place-index/"); |
| 85 | expect(index.dataSource).toEqual("Esri"); |
| 86 | |
| 87 | const described = yield* location.describePlaceIndex({ IndexName: index.indexName }); |
| 88 | expect(described.DataSource).toEqual("Esri"); |
| 89 | expect(described.Tags?.["alchemy::id"]).toEqual("TestIndex"); |
| 90 | |
| 91 | const updated = yield* stack.deploy( |
| 92 | Effect.gen(function* () { |
| 93 | return yield* Location.PlaceIndex("TestIndex", { |
| 94 | dataSource: "Esri", |
| 95 | description: "updated index", |
| 96 | }); |
| 97 | }), |
| 98 | ); |
| 99 | expect(updated.indexName).toEqual(index.indexName); |
| 100 | expect(updated.description).toEqual("updated index"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | yield* assertGone(location.describePlaceIndex({ IndexName: index.indexName })); |
| 104 | }), |
| 105 | { timeout: 180_000 }, |
| 106 | ); |
| 107 | |
| 108 | test.provider( |
| 109 | "RouteCalculator: create and delete", |
| 110 | (stack) => |
| 111 | Effect.gen(function* () { |
| 112 | yield* stack.destroy(); |
| 113 | const calc = yield* stack.deploy( |
| 114 | Effect.gen(function* () { |
| 115 | return yield* Location.RouteCalculator("TestCalc", { dataSource: "Esri" }); |
| 116 | }), |
| 117 | ); |
| 118 | |
| 119 | expect(calc.calculatorArn).toContain(":route-calculator/"); |
| 120 | expect(calc.dataSource).toEqual("Esri"); |
| 121 | |
| 122 | const described = yield* location.describeRouteCalculator({ |
| 123 | CalculatorName: calc.calculatorName, |
| 124 | }); |
| 125 | expect(described.DataSource).toEqual("Esri"); |
| 126 | expect(described.Tags?.["alchemy::id"]).toEqual("TestCalc"); |
| 127 | |
| 128 | yield* stack.destroy(); |
| 129 | yield* assertGone( |
| 130 | location.describeRouteCalculator({ CalculatorName: calc.calculatorName }), |
| 131 | ); |
| 132 | }), |
| 133 | { timeout: 180_000 }, |
| 134 | ); |
| 135 | |
| 136 | test.provider( |
| 137 | "GeofenceCollection: create, update, delete", |
| 138 | (stack) => |
| 139 | Effect.gen(function* () { |
| 140 | yield* stack.destroy(); |
| 141 | const collection = yield* stack.deploy( |
| 142 | Effect.gen(function* () { |
| 143 | return yield* Location.GeofenceCollection("TestFences", {}); |
| 144 | }), |
| 145 | ); |
| 146 | |
| 147 | expect(collection.collectionArn).toContain(":geofence-collection/"); |
| 148 | |
| 149 | const described = yield* location.describeGeofenceCollection({ |
| 150 | CollectionName: collection.collectionName, |
| 151 | }); |
| 152 | expect(described.Tags?.["alchemy::id"]).toEqual("TestFences"); |
| 153 | |
| 154 | const updated = yield* stack.deploy( |
| 155 | Effect.gen(function* () { |
| 156 | return yield* Location.GeofenceCollection("TestFences", { |
| 157 | description: "updated fences", |
| 158 | }); |
| 159 | }), |
| 160 | ); |
| 161 | expect(updated.collectionName).toEqual(collection.collectionName); |
| 162 | expect(updated.description).toEqual("updated fences"); |
| 163 | |
| 164 | yield* stack.destroy(); |
| 165 | yield* assertGone( |
| 166 | location.describeGeofenceCollection({ CollectionName: collection.collectionName }), |
| 167 | ); |
| 168 | }), |
| 169 | { timeout: 180_000 }, |
| 170 | ); |
| 171 | |
| 172 | // Ungated probe: this account cannot create Location V1 API keys — even |
| 173 | // AdministratorAccess gets an AccessDeniedException with an EMPTY action |
| 174 | // name ("is not authorized to perform: because no resource-based policy |
| 175 | // allows the action") from `geo:CreateKey` in every region. That is a |
| 176 | // service-side gate (Location classic is closed to newer accounts), not an |
| 177 | // IAM misconfiguration. The probe pins the typed tag forever at near-zero |
| 178 | // cost; an entitled account instead exercises cleanup of the probe key. |
| 179 | test.provider( |
| 180 | "ApiKey: CreateKey is service-gated (typed AccessDeniedException) or succeeds", |
| 181 | (_stack) => |
| 182 | Effect.gen(function* () { |
| 183 | const created = yield* Effect.result( |
| 184 | location.createKey({ |
| 185 | KeyName: "alchemy-apikey-probe", |
| 186 | NoExpiry: true, |
| 187 | Restrictions: { |
| 188 | AllowActions: ["geo:GetMap*"], |
| 189 | AllowResources: ["arn:aws:geo:*:*:map/*"], |
| 190 | }, |
| 191 | }), |
| 192 | ); |
| 193 | if (Result.isSuccess(created)) { |
| 194 | // Entitled account: clean up the probe key immediately. |
| 195 | yield* location.deleteKey({ KeyName: "alchemy-apikey-probe", ForceDelete: true }); |
| 196 | } else { |
| 197 | expect(created.failure._tag).toBe("AccessDeniedException"); |
| 198 | } |
| 199 | }), |
| 200 | { timeout: 60_000 }, |
| 201 | ); |
| 202 | |
| 203 | test.provider.skipIf(!process.env.AWS_TEST_LOCATION_API_KEYS)( |
| 204 | "ApiKey: create, update description, delete", |
| 205 | (stack) => |
| 206 | Effect.gen(function* () { |
| 207 | yield* stack.destroy(); |
| 208 | const key = yield* stack.deploy( |
| 209 | Effect.gen(function* () { |
| 210 | return yield* Location.ApiKey("TestKey", { |
| 211 | restrictions: { |
| 212 | allowActions: ["geo:GetMap*"], |
| 213 | allowResources: ["arn:aws:geo:*:*:map/*"], |
| 214 | }, |
| 215 | }); |
| 216 | }), |
| 217 | ); |
| 218 | |
| 219 | expect(key.keyArn).toContain(":api-key/"); |
| 220 | expect(Redacted.value(key.key)).toMatch(/^v1\.public\./); |
| 221 | expect(key.restrictions.allowActions).toEqual(["geo:GetMap*"]); |
| 222 | |
| 223 | const described = yield* location.describeKey({ KeyName: key.keyName }); |
| 224 | expect(described.Tags?.["alchemy::id"]).toEqual("TestKey"); |
| 225 | |
| 226 | const updated = yield* stack.deploy( |
| 227 | Effect.gen(function* () { |
| 228 | return yield* Location.ApiKey("TestKey", { |
| 229 | restrictions: { |
| 230 | allowActions: ["geo:GetMap*"], |
| 231 | allowResources: ["arn:aws:geo:*:*:map/*"], |
| 232 | allowReferers: ["https://example.com/*"], |
| 233 | }, |
| 234 | description: "updated key", |
| 235 | }); |
| 236 | }), |
| 237 | ); |
| 238 | expect(updated.keyName).toEqual(key.keyName); |
| 239 | expect(updated.description).toEqual("updated key"); |
| 240 | expect(updated.restrictions.allowReferers).toEqual(["https://example.com/*"]); |
| 241 | expect(Redacted.value(updated.key)).toEqual(Redacted.value(key.key)); |
| 242 | |
| 243 | yield* stack.destroy(); |
| 244 | yield* assertGone(location.describeKey({ KeyName: key.keyName })); |
| 245 | }), |
| 246 | { timeout: 180_000 }, |
| 247 | ); |
| 248 | |
| 249 | test.provider( |
| 250 | "TrackerConsumer: link tracker to geofence collection, delete", |
| 251 | (stack) => |
| 252 | Effect.gen(function* () { |
| 253 | yield* stack.destroy(); |
| 254 | const out = yield* stack.deploy( |
| 255 | Effect.gen(function* () { |
| 256 | const tracker = yield* Location.Tracker("ConsumerTracker", {}); |
| 257 | const collection = yield* Location.GeofenceCollection("ConsumerFences", {}); |
| 258 | const link = yield* Location.TrackerConsumer("Link", { |
| 259 | trackerName: tracker.trackerName, |
| 260 | consumerArn: collection.collectionArn, |
| 261 | }); |
| 262 | return { |
| 263 | trackerName: tracker.trackerName, |
| 264 | collectionArn: collection.collectionArn, |
| 265 | linkTracker: link.trackerName, |
| 266 | linkConsumer: link.consumerArn, |
| 267 | }; |
| 268 | }), |
| 269 | ); |
| 270 | |
| 271 | expect(out.linkTracker).toEqual(out.trackerName); |
| 272 | expect(out.linkConsumer).toEqual(out.collectionArn); |
| 273 | |
| 274 | const consumers = yield* location.listTrackerConsumers({ TrackerName: out.trackerName }); |
| 275 | expect(consumers.ConsumerArns).toContain(out.collectionArn); |
| 276 | |
| 277 | yield* stack.destroy(); |
| 278 | yield* assertGone(location.describeTracker({ TrackerName: out.trackerName })); |
| 279 | }), |
| 280 | { timeout: 180_000 }, |
| 281 | ); |
| 282 | |
| 283 | test.provider( |
| 284 | "Tracker: create, update filtering, delete", |
| 285 | (stack) => |
| 286 | Effect.gen(function* () { |
| 287 | yield* stack.destroy(); |
| 288 | const tracker = yield* stack.deploy( |
| 289 | Effect.gen(function* () { |
| 290 | return yield* Location.Tracker("TestTracker", {}); |
| 291 | }), |
| 292 | ); |
| 293 | |
| 294 | expect(tracker.trackerArn).toContain(":tracker/"); |
| 295 | expect(tracker.positionFiltering).toEqual("TimeBased"); |
| 296 | |
| 297 | const described = yield* location.describeTracker({ TrackerName: tracker.trackerName }); |
| 298 | expect(described.Tags?.["alchemy::id"]).toEqual("TestTracker"); |
| 299 | |
| 300 | const updated = yield* stack.deploy( |
| 301 | Effect.gen(function* () { |
| 302 | return yield* Location.Tracker("TestTracker", { |
| 303 | positionFiltering: "DistanceBased", |
| 304 | description: "fleet tracker", |
| 305 | }); |
| 306 | }), |
| 307 | ); |
| 308 | expect(updated.trackerName).toEqual(tracker.trackerName); |
| 309 | expect(updated.positionFiltering).toEqual("DistanceBased"); |
| 310 | expect(updated.description).toEqual("fleet tracker"); |
| 311 | |
| 312 | yield* stack.destroy(); |
| 313 | yield* assertGone(location.describeTracker({ TrackerName: tracker.trackerName })); |
| 314 | }), |
| 315 | { timeout: 180_000 }, |
| 316 | ); |
| 317 | }, |
| 318 | ); |