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 a `ConfigError`:
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// Minimal, deterministic dashboard document. `owner: ""` is required when
23// authenticating with an API token (Axiom rewrites it to the org-shared
24// X-AXIOM-EVERYONE); relative windows use the `qr-now-*` form.
25const dashboardProps = {
26 dashboard: {
27 name: "Alchemy List Test",
28 owner: "",
29 description: "list() lifecycle test dashboard",
30 charts: [],
31 layout: [],
32 refreshTime: 60,
33 schemaVersion: 2,
34 timeWindowStart: "qr-now-1h",
35 timeWindowEnd: "qr-now",
36 },
37};
38
39test.provider.skipIf(!hasAxiomCreds)(
40 "list enumerates the deployed dashboard",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const deployed = yield* stack.deploy(
46 Effect.gen(function* () {
47 return yield* Axiom.Dashboard("ListDashboard", dashboardProps);
48 }),
49 );
50
51 const provider = yield* Provider.findProvider(Axiom.Dashboard);
52 const all = yield* provider.list();
53
54 expect(all.length).toBeGreaterThan(0);
55 expect(all.some((d) => d.uid === deployed.uid)).toBe(true);
56
57 const found = all.find((d) => d.uid === deployed.uid);
58 expect(found?.id).toEqual(deployed.id);
59 expect(found?.dashboard.name).toEqual("Alchemy List Test");
60
61 yield* stack.destroy();
62 }).pipe(logLevel),
63 { tags: ["provider:axiom", "provider:axiom:dashboard", "live"] },
64);