| 1 | import * as Axiom from "@/Axiom"; |
| 2 | import * as Provider from "@/Provider"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: Axiom.providers() }); |
| 9 | |
| 10 | const logLevel = Effect.provideService( |
| 11 | MinimumLogLevel, |
| 12 | process.env.DEBUG ? "Debug" : "Info", |
| 13 | ); |
| 14 | |
| 15 | // Axiom credentials are resolved via the AuthProvider (env method reads |
| 16 | // AXIOM_TOKEN / AXIOM_API_KEY). When neither is present the suite can't talk |
| 17 | // to the real API, so skipIf-gate the live list test. On an entitled run the |
| 18 | // failure mode without creds is an `AuthError`: |
| 19 | // "Axiom env credentials not found. Set AXIOM_TOKEN (or AXIOM_API_KEY)." |
| 20 | const hasAxiomCreds = !!(process.env.AXIOM_TOKEN || process.env.AXIOM_API_KEY); |
| 21 | |
| 22 | // Deterministic token name (no Date.now) so reruns target the same token and |
| 23 | // the start/end destroy bookends keep the org clean. |
| 24 | const TOKEN_NAME = "alchemy-list-test-token"; |
| 25 | |
| 26 | test.provider.skipIf(!hasAxiomCreds)( |
| 27 | "list enumerates the deployed api token", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const deployed = yield* stack.deploy( |
| 33 | Effect.gen(function* () { |
| 34 | return yield* Axiom.ApiToken("ListApiToken", { |
| 35 | name: TOKEN_NAME, |
| 36 | description: "alchemy list() lifecycle op test", |
| 37 | // Axiom rejects a token with no capabilities ("at least one |
| 38 | // capability must be set"). An org-level read scope is the |
| 39 | // simplest valid grant that needs no pre-existing dataset. |
| 40 | orgCapabilities: { datasets: ["read"] }, |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | const provider = yield* Provider.findProvider(Axiom.ApiToken); |
| 46 | const all = yield* provider.list(); |
| 47 | |
| 48 | // `getAPITokens` returns the full account-wide list in one shot; the |
| 49 | // freshly created token must be present, hydrated into the exact `read` |
| 50 | // Attributes shape (so `.id` / `.name` are directly usable by `delete`). |
| 51 | expect(all.some((t) => t.id === deployed.id)).toBe(true); |
| 52 | |
| 53 | const row = all.find((t) => t.id === deployed.id)!; |
| 54 | expect(row.name).toEqual(TOKEN_NAME); |
| 55 | // The bearer secret is only returned at creation and is never echoed back |
| 56 | // on enumeration, so `list()` surfaces an empty Redacted token (matching |
| 57 | // the fact that `read` would only source it from cached state). |
| 58 | expect(row.token).toBeDefined(); |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | }).pipe(logLevel), |
| 62 | { |
| 63 | tags: ["provider:axiom", "provider:axiom:apitoken", "live"], |
| 64 | timeout: 120_000, |
| 65 | }, |
| 66 | ); |