The best way to control Claude Code, Codex and more from any computer or phone

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