1import * as Cloudflare from "@/Cloudflare";
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: Cloudflare.providers() });
9
10const logLevel = Effect.provideService(
11 MinimumLogLevel,
12 process.env.DEBUG ? "Debug" : "Info",
13);
14
15// DLP is a paid Zero Trust add-on. Custom-profile *writes* fail on the
16// standard testing account with HTTP 403 code 3314 surfaced as the typed
17// `Forbidden` error (see Dlp.test.ts). The account-scoped profiles list
18// endpoint is read-only and returns predefined/custom profiles the account
19// can see, so the read-only `list()` assertion below always runs; the
20// deploy-then-list assertion is gated behind an entitled account.
21const entitled = !!process.env.CLOUDFLARE_TEST_DLP;
22
23// Read-only: resolve the provider via the typed helper and enumerate every
24// custom DLP profile. The result is the exact `read` Attributes shape. On an
25// unentitled account there may be zero custom profiles, so we only assert the
26// result is a well-typed array whose elements have the Attributes shape.
27test.provider(
28 "list enumerates custom DLP profiles (read-only)",
29 (stack) =>
30 Effect.gen(function* () {
31 yield* stack.destroy();
32
33 const provider = yield* Provider.findProvider(Cloudflare.Dlp.Profile);
34 const all = yield* provider.list();
35
36 expect(Array.isArray(all)).toBe(true);
37 for (const profile of all) {
38 expect(typeof profile.profileId).toBe("string");
39 expect(typeof profile.accountId).toBe("string");
40 expect(typeof profile.name).toBe("string");
41 }
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 {
46 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
47 timeout: 90_000,
48 },
49);
50
51// Entitled: deploy a custom profile and confirm `list()` enumerates it.
52test.provider.skipIf(!entitled)(
53 "list includes a deployed custom DLP profile",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const deployed = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* Cloudflare.Dlp.Profile("ListResource", {
61 name: "alchemy-test-dlp-list",
62 description: "list coverage",
63 entries: [
64 {
65 name: "probe-entry",
66 enabled: true,
67 pattern: { regex: "EMP-[0-9]{6}" },
68 },
69 ],
70 });
71 }),
72 );
73
74 const provider = yield* Provider.findProvider(Cloudflare.Dlp.Profile);
75 const all = yield* provider.list();
76
77 expect(all.some((p) => p.profileId === deployed.profileId)).toBe(true);
78
79 yield* stack.destroy();
80 }).pipe(logLevel),
81 {
82 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
83 timeout: 90_000,
84 },
85);