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 reuse (and reconcile) the same dataset
23// rather than piling up duplicates.
24const DATASET_NAME = "alchemy-test-annotation-list";
25
26test.provider.skipIf(!hasAxiomCreds)(
27 "list enumerates the deployed annotation",
28 (stack) =>
29 Effect.gen(function* () {
30 yield* stack.destroy();
31
32 const deployed = yield* stack.deploy(
33 Effect.gen(function* () {
34 const dataset = yield* Axiom.Dataset("ListDataset", {
35 name: DATASET_NAME,
36 });
37 return yield* Axiom.Annotation("ListAnnotation", {
38 type: "deploy",
39 title: "list() coverage marker",
40 datasets: [dataset.name],
41 time: "2026-01-01T00:00:00Z",
42 });
43 }),
44 );
45
46 const provider = yield* Provider.findProvider(Axiom.Annotation);
47 const all = yield* provider.list();
48
49 // `getAnnotations` returns the full account-wide list in one shot; the
50 // freshly created annotation must be present, hydrated into the exact
51 // `read` shape (so `.id` / `.type` are directly usable by `delete`).
52 const found = all.find((a) => a.id === deployed.id);
53 expect(found).toBeDefined();
54 expect(found?.type).toEqual("deploy");
55
56 yield* stack.destroy();
57 }).pipe(logLevel),
58 {
59 tags: [
60 "provider:axiom",
61 "provider:axiom:annotation",
62 "provider:axiom:dataset",
63 "live",
64 ],
65 timeout: 120_000,
66 },
67);