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 { InstrumentationConfiguration } from "@alchemy.run/aws/ApplicationSignals"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as appsignals from "@distilled.cloud/aws/application-signals"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | // The instrumented service does not need to exist — configurations are |
| 11 | // stored server-side and picked up by SDK agents on their next sync. |
| 12 | const SERVICE = "alchemy-test-appsignals-ic"; |
| 13 | const ENVIRONMENT = "alchemy-test-env"; |
| 14 | |
| 15 | const location = (lineNumber: number): appsignals.CodeLocation => ({ |
| 16 | Language: "Python", |
| 17 | CodeUnit: "app.main", |
| 18 | MethodName: "handler", |
| 19 | FilePath: "app/main.py", |
| 20 | LineNumber: lineNumber, |
| 21 | }); |
| 22 | |
| 23 | const getConfiguration = (locationHash: string) => |
| 24 | appsignals |
| 25 | .getInstrumentationConfiguration({ |
| 26 | InstrumentationType: "PROBE", |
| 27 | Service: SERVICE, |
| 28 | Environment: ENVIRONMENT, |
| 29 | SignalType: "SNAPSHOT", |
| 30 | LocationIdentifier: { LocationHash: locationHash }, |
| 31 | }) |
| 32 | .pipe(Effect.map((r) => r.Configuration)); |
| 33 | |
| 34 | const assertGone = (locationHash: string) => |
| 35 | getConfiguration(locationHash).pipe( |
| 36 | Effect.flatMap((c) => Effect.fail(new Error(`configuration '${c.LocationHash}' still exists`))), |
| 37 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 38 | ); |
| 39 | |
| 40 | test.provider( |
| 41 | "create, update tags in place, replace on location change, destroy", |
| 42 | (stack) => |
| 43 | Effect.gen(function* () { |
| 44 | yield* stack.destroy(); |
| 45 | |
| 46 | const props = { |
| 47 | instrumentationType: "PROBE", |
| 48 | service: SERVICE, |
| 49 | environment: ENVIRONMENT, |
| 50 | signalType: "SNAPSHOT", |
| 51 | captureConfiguration: { |
| 52 | CaptureLocals: ["x"], |
| 53 | CaptureLimits: { MaxHits: 5 }, |
| 54 | } satisfies appsignals.CodeCaptureConfiguration, |
| 55 | }; |
| 56 | |
| 57 | // CREATE |
| 58 | const { probe } = yield* stack.deploy( |
| 59 | Effect.gen(function* () { |
| 60 | const probe = yield* InstrumentationConfiguration("Probe", { |
| 61 | ...props, |
| 62 | location: location(10), |
| 63 | description: "alchemy instrumentation configuration test", |
| 64 | tags: { fixture: "application-signals-ic" }, |
| 65 | }); |
| 66 | return { probe }; |
| 67 | }), |
| 68 | ); |
| 69 | |
| 70 | expect(probe.arn).toContain(":instrumentationConfig/"); |
| 71 | expect(probe.locationHash).toBeTruthy(); |
| 72 | expect(probe.service).toBe(SERVICE); |
| 73 | |
| 74 | const observed = yield* getConfiguration(probe.locationHash); |
| 75 | expect(observed.ARN).toBe(probe.arn); |
| 76 | expect(observed.Description).toBe("alchemy instrumentation configuration test"); |
| 77 | |
| 78 | // Tags: user tag + internal Alchemy branding. |
| 79 | const tags = yield* appsignals |
| 80 | .listTagsForResource({ ResourceArn: probe.arn }) |
| 81 | .pipe(Effect.map((r) => Object.fromEntries((r.Tags ?? []).map((t) => [t.Key, t.Value])))); |
| 82 | expect(tags.fixture).toBe("application-signals-ic"); |
| 83 | expect(tags["alchemy::id"]).toBe("Probe"); |
| 84 | |
| 85 | // UPDATE IN PLACE — configurations are immutable, but tags are not. |
| 86 | const { probe: retagged } = yield* stack.deploy( |
| 87 | Effect.gen(function* () { |
| 88 | const probe = yield* InstrumentationConfiguration("Probe", { |
| 89 | ...props, |
| 90 | location: location(10), |
| 91 | description: "alchemy instrumentation configuration test", |
| 92 | tags: { fixture: "application-signals-ic", updated: "true" }, |
| 93 | }); |
| 94 | return { probe }; |
| 95 | }), |
| 96 | ); |
| 97 | expect(retagged.arn).toBe(probe.arn); |
| 98 | const updatedTags = yield* appsignals |
| 99 | .listTagsForResource({ ResourceArn: probe.arn }) |
| 100 | .pipe(Effect.map((r) => Object.fromEntries((r.Tags ?? []).map((t) => [t.Key, t.Value])))); |
| 101 | expect(updatedTags.updated).toBe("true"); |
| 102 | |
| 103 | // REPLACE — changing the code location replaces the configuration. |
| 104 | const { probe: replaced } = yield* stack.deploy( |
| 105 | Effect.gen(function* () { |
| 106 | const probe = yield* InstrumentationConfiguration("Probe", { |
| 107 | ...props, |
| 108 | location: location(20), |
| 109 | description: "alchemy instrumentation configuration test", |
| 110 | tags: { fixture: "application-signals-ic" }, |
| 111 | }); |
| 112 | return { probe }; |
| 113 | }), |
| 114 | ); |
| 115 | expect(replaced.locationHash).not.toBe(probe.locationHash); |
| 116 | yield* assertGone(probe.locationHash); |
| 117 | |
| 118 | // DESTROY |
| 119 | yield* stack.destroy(); |
| 120 | yield* assertGone(replaced.locationHash); |
| 121 | }), |
| 122 | { |
| 123 | tags: ["provider:aws", "provider:aws:applicationsignals", "live"], |
| 124 | timeout: 120_000, |
| 125 | }, |
| 126 | ); |