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 names (no Date.now) so reruns reconcile the same dataset and
23// virtual field rather than piling up duplicates.
24const DATASET_NAME = "alchemy-test-virtualfield-list";
25const FIELD_NAME = "alchemy_list_status_class";
26
27test.provider.skipIf(!hasAxiomCreds)(
28 "list enumerates the deployed virtual field",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const deployed = yield* stack.deploy(
34 Effect.gen(function* () {
35 const dataset = yield* Axiom.Dataset("ListDataset", {
36 name: DATASET_NAME,
37 });
38 return yield* Axiom.VirtualField("ListVirtualField", {
39 dataset: dataset.name,
40 name: FIELD_NAME,
41 description: "list() coverage marker",
42 expression: 'strcat(tostring(toint(status / 100)), "xx")',
43 type: "string",
44 });
45 }),
46 );
47
48 const provider = yield* Provider.findProvider(Axiom.VirtualField);
49 const all = yield* provider.list();
50
51 // `getVirtualFields` is per-dataset, so `list()` enumerates every dataset
52 // and fans out the per-dataset vfields list; the freshly created field
53 // must be present, hydrated into the exact `read` shape (so `.id` /
54 // `.dataset` are directly usable by `delete`).
55 const found = all.find((vf) => vf.id === deployed.id);
56 expect(found).toBeDefined();
57 expect(found?.name).toEqual(FIELD_NAME);
58 expect(found?.dataset).toEqual(DATASET_NAME);
59
60 yield* stack.destroy();
61 }).pipe(logLevel),
62 {
63 tags: [
64 "provider:axiom",
65 "provider:axiom:dataset",
66 "provider:axiom:virtualfield",
67 "live",
68 ],
69 timeout: 120_000,
70 },
71);