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 { ServiceIntegration } from "@alchemy.run/aws/DevOpsGuru/ServiceIntegration"; |
| 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 integration out-of-band. Absent sections/statuses |
| 11 | // mean the account default (disabled / AWS-owned key). |
| 12 | const observed = devopsguru.describeServiceIntegration({}).pipe( |
| 13 | Effect.map(({ ServiceIntegration: config }) => ({ |
| 14 | opsCenter: config?.OpsCenter?.OptInStatus === "ENABLED", |
| 15 | logsAnomalyDetection: config?.LogsAnomalyDetection?.OptInStatus === "ENABLED", |
| 16 | encryptionType: config?.KMSServerSideEncryption?.Type ?? "AWS_OWNED_KMS_KEY", |
| 17 | })), |
| 18 | ); |
| 19 | |
| 20 | // Ungated typed probe: describeServiceIntegration always answers with the |
| 21 | // typed response shape — never an untyped catch-all. |
| 22 | test.provider( |
| 23 | "describeServiceIntegration returns typed results", |
| 24 | () => |
| 25 | Effect.gen(function* () { |
| 26 | const config = yield* observed; |
| 27 | expect(typeof config.opsCenter).toBe("boolean"); |
| 28 | expect(typeof config.logsAnomalyDetection).toBe("boolean"); |
| 29 | }), |
| 30 | { tags: ["provider:aws", "provider:aws:devopsguru", "live"] }, |
| 31 | ); |
| 32 | |
| 33 | // The integration is an account/region singleton. This test only runs when |
| 34 | // the account is at the defaults — it must never clobber a configuration |
| 35 | // the user already operates. |
| 36 | test.provider( |
| 37 | "lifecycle: enable log anomaly detection, add OpsCenter, restore defaults", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | const preexisting = yield* observed; |
| 41 | if ( |
| 42 | preexisting.opsCenter || |
| 43 | preexisting.logsAnomalyDetection || |
| 44 | preexisting.encryptionType !== "AWS_OWNED_KMS_KEY" |
| 45 | ) { |
| 46 | yield* Effect.logInfo( |
| 47 | "DevOps Guru service integration already configured — skipping destructive lifecycle test", |
| 48 | ); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | |
| 54 | // Create — enable log anomaly detection only. |
| 55 | const created = yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | return yield* ServiceIntegration("Integration", { |
| 58 | logsAnomalyDetection: true, |
| 59 | }); |
| 60 | }), |
| 61 | ); |
| 62 | expect(created.logsAnomalyDetection).toBe(true); |
| 63 | expect(created.opsCenter).toBe(false); |
| 64 | expect(created.encryptionType).toBe("AWS_OWNED_KMS_KEY"); |
| 65 | |
| 66 | // Out-of-band verification via distilled. |
| 67 | const afterCreate = yield* observed; |
| 68 | expect(afterCreate.logsAnomalyDetection).toBe(true); |
| 69 | expect(afterCreate.opsCenter).toBe(false); |
| 70 | |
| 71 | // Update — enable OpsCenter too; only the drifted section is updated. |
| 72 | const updated = yield* stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | return yield* ServiceIntegration("Integration", { |
| 75 | logsAnomalyDetection: true, |
| 76 | opsCenter: true, |
| 77 | }); |
| 78 | }), |
| 79 | ); |
| 80 | expect(updated.logsAnomalyDetection).toBe(true); |
| 81 | expect(updated.opsCenter).toBe(true); |
| 82 | const afterUpdate = yield* observed; |
| 83 | expect(afterUpdate.opsCenter).toBe(true); |
| 84 | |
| 85 | // Destroy — the account defaults are restored. |
| 86 | yield* stack.destroy(); |
| 87 | const after = yield* observed; |
| 88 | expect(after.opsCenter).toBe(false); |
| 89 | expect(after.logsAnomalyDetection).toBe(false); |
| 90 | expect(after.encryptionType).toBe("AWS_OWNED_KMS_KEY"); |
| 91 | }), |
| 92 | { |
| 93 | tags: ["provider:aws", "provider:aws:devopsguru", "live"], |
| 94 | timeout: 180_000, |
| 95 | }, |
| 96 | ); |