| 1 | import * as Axiom from "@/Axiom"; |
| 2 | import * as Output from "@/Output"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: Axiom.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService( |
| 12 | MinimumLogLevel, |
| 13 | process.env.DEBUG ? "Debug" : "Info", |
| 14 | ); |
| 15 | |
| 16 | // Axiom credentials are resolved via the AuthProvider (env method reads |
| 17 | // AXIOM_TOKEN / AXIOM_API_KEY). When neither is present the suite can't talk |
| 18 | // to the real API, so skipIf-gate the live list test. On an entitled run the |
| 19 | // failure mode without creds is an `AuthError`: |
| 20 | // "Axiom env credentials not found. Set AXIOM_TOKEN (or AXIOM_API_KEY)." |
| 21 | const hasAxiomCreds = !!(process.env.AXIOM_TOKEN || process.env.AXIOM_API_KEY); |
| 22 | |
| 23 | // Deterministic names so re-runs reconcile the same resources rather than |
| 24 | // piling up duplicates. The monitor's APL query needs a real dataset target. |
| 25 | const DATASET_NAME = "alchemy-test-monitor-list"; |
| 26 | const MONITOR_NAME = "alchemy-test-monitor-list"; |
| 27 | |
| 28 | test.provider.skipIf(!hasAxiomCreds)( |
| 29 | "list enumerates the deployed monitor", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const deployed = yield* stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const dataset = yield* Axiom.Dataset("ListDataset", { |
| 37 | name: DATASET_NAME, |
| 38 | }); |
| 39 | return yield* Axiom.Monitor("ListMonitor", { |
| 40 | name: MONITOR_NAME, |
| 41 | description: "alchemy list() lifecycle op test", |
| 42 | type: "Threshold", |
| 43 | // Reference the dataset's OUTPUT so the monitor create waits for |
| 44 | // the dataset create (a bare name string carries no graph edge — |
| 45 | // Axiom rejects a monitor whose APL targets a missing dataset). |
| 46 | aplQuery: Output.interpolate`['${dataset.name}'] | summarize count()`, |
| 47 | intervalMinutes: 5, |
| 48 | rangeMinutes: 5, |
| 49 | operator: "Above", |
| 50 | threshold: 1, |
| 51 | notifierIds: [], |
| 52 | alertOnNoData: false, |
| 53 | resolvable: true, |
| 54 | }); |
| 55 | }), |
| 56 | ); |
| 57 | |
| 58 | const provider = yield* Provider.findProvider(Axiom.Monitor); |
| 59 | const all = yield* provider.list(); |
| 60 | |
| 61 | // `getMonitors` returns the full account-wide list in one shot; the |
| 62 | // freshly created monitor must be present, hydrated into the exact `read` |
| 63 | // Attributes shape (so `.id` / `.type` are directly usable by `delete`). |
| 64 | const found = all.find((m) => m.id === deployed.id); |
| 65 | expect(found).toBeDefined(); |
| 66 | expect(found?.name).toEqual(MONITOR_NAME); |
| 67 | expect(found?.type).toEqual("Threshold"); |
| 68 | |
| 69 | yield* stack.destroy(); |
| 70 | }).pipe(logLevel), |
| 71 | { |
| 72 | tags: [ |
| 73 | "provider:axiom", |
| 74 | "provider:axiom:dataset", |
| 75 | "provider:axiom:monitor", |
| 76 | "live", |
| 77 | ], |
| 78 | timeout: 120_000, |
| 79 | }, |
| 80 | ); |