1import * as Axiom from "@/Axiom";
2import * as Provider from "@/Provider";
3import * as Test from "@/Test/Alchemy";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7
8const { test } = Test.make({ providers: Axiom.providers() });
9
10const 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)."
20const hasAxiomCreds = !!(process.env.AXIOM_TOKEN || process.env.AXIOM_API_KEY);
21
22// Deterministic dataset name so re-runs reconcile the same dataset rather than
23// piling up duplicates (no Date.now in physical names).
24const DATASET_NAME = "alchemy-test-dataset-list";
25
26// Canonical `list()` test (account collection): Axiom exposes a single
27// org-wide `GET /v2/datasets` op, so `list()` enumerates every dataset and
28// hydrates each row into the exact `read` Attributes shape.
29test.provider.skipIf(!hasAxiomCreds)(
30 "list enumerates the deployed dataset",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const deployed = yield* stack.deploy(
36 Effect.gen(function* () {
37 return yield* Axiom.Dataset("ListDataset", {
38 name: DATASET_NAME,
39 description: "alchemy list() lifecycle op test",
40 });
41 }),
42 );
43
44 const provider = yield* Provider.findProvider(Axiom.Dataset);
45 const all = yield* provider.list();
46
47 // `getDatasets` returns the full account-wide list in one shot; the
48 // freshly created dataset must be present, hydrated into the exact
49 // `read` shape (so `.id` / `.name` are directly usable by `delete`).
50 const found = all.find((d) => d.id === deployed.id);
51 expect(found).toBeDefined();
52 expect(found?.name).toEqual(DATASET_NAME);
53 expect(found?.kind).toEqual(deployed.kind);
54 expect(found?.edgeDeployment).toEqual(deployed.edgeDeployment);
55 expect(found?.edgeDeploymentUrl).toEqual(deployed.edgeDeploymentUrl);
56 expect(found?.otelEndpoint).toEqual(
57 deployed.edgeDeploymentUrl.replace(/\/$/, ""),
58 );
59 expect(found?.otelTracesEndpoint).toEqual(deployed.otelTracesEndpoint);
60
61 yield* stack.destroy();
62 }).pipe(logLevel),
63 {
64 tags: ["provider:axiom", "provider:axiom:dataset", "live"],
65 timeout: 120_000,
66 },
67);