@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 140 lines 4.75 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import { CloudflareEnvironment } from "@alchemy.run/cloudflare/CloudflareEnvironment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as zeroTrust from "@distilled.cloud/cloudflare/zero-trust";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import { testName } from "../../names.ts";
9
10 const { test } = Test.make({ providers: Cloudflare.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // DLP is a paid Zero Trust add-on. On the standard testing account
15 // `POST /accounts/{id}/dlp/profiles/custom` fails with HTTP 403 code
16 // 3314 "Forbidden" — surfaced as the typed `Forbidden` error. The
17 // lifecycle tests are gated behind an entitled account supplied via env;
18 // the probe test always runs and pins the typed tag.
19 const entitled = !!process.env.CLOUDFLARE_TEST_DLP;
20
21 test.provider.skipIf(entitled)(
22 "unentitled accounts surface the typed Forbidden error",
23 (stack) =>
24 Effect.gen(function* () {
25 const { accountId } = yield* yield* CloudflareEnvironment;
26
27 yield* stack.destroy();
28
29 const profileError = yield* zeroTrust
30 .createDlpProfileCustom({
31 accountId,
32 name: "alchemy-dlp-entitlement-probe",
33 entries: [
34 {
35 enabled: true,
36 name: "probe-entry",
37 pattern: { regex: "x{9}" },
38 },
39 ],
40 })
41 .pipe(Effect.flip);
42 expect(profileError._tag).toEqual("Forbidden");
43
44 const entryError = yield* zeroTrust
45 .createDlpEntryCustom({
46 accountId,
47 enabled: true,
48 name: "alchemy-dlp-entry-probe",
49 pattern: { regex: "y{9}" },
50 })
51 .pipe(Effect.flip);
52 expect(entryError._tag).toEqual("Forbidden");
53
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 {
57 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
58 timeout: 90_000,
59 },
60 );
61
62 test.provider.skipIf(!entitled)(
63 "create, update, and destroy a DLP profile with a standalone entry",
64 (stack) =>
65 Effect.gen(function* () {
66 const { accountId } = yield* yield* CloudflareEnvironment;
67
68 yield* stack.destroy();
69
70 const created = yield* stack.deploy(
71 Effect.gen(function* () {
72 const profile = yield* Cloudflare.Dlp.Profile("EmployeeIds", {
73 name: testName("alchemy-test-dlp-profile"),
74 description: "v1",
75 allowedMatchCount: 0,
76 entries: [
77 {
78 name: "employee-id",
79 enabled: true,
80 pattern: { regex: "EMP-[0-9]{6}" },
81 },
82 ],
83 });
84 const entry = yield* Cloudflare.Dlp.Entry("CardNumber", {
85 name: testName("alchemy-test-dlp-entry"),
86 pattern: { regex: "[0-9]{13,16}", validation: "luhn" },
87 profileId: profile.profileId,
88 });
89 return { profile, entry };
90 }),
91 );
92
93 expect(created.profile.profileId).toBeDefined();
94 expect(created.profile.entryIds["employee-id"]).toBeDefined();
95 expect(created.entry.entryId).toBeDefined();
96 expect(created.entry.profileId).toEqual(created.profile.profileId);
97
98 // Description update converges in place — same profile id.
99 const updated = yield* stack.deploy(
100 Effect.gen(function* () {
101 const profile = yield* Cloudflare.Dlp.Profile("EmployeeIds", {
102 name: testName("alchemy-test-dlp-profile"),
103 description: "v2",
104 allowedMatchCount: 3,
105 entries: [
106 {
107 name: "employee-id",
108 enabled: true,
109 pattern: { regex: "EMP-[0-9]{8}" },
110 },
111 ],
112 });
113 const entry = yield* Cloudflare.Dlp.Entry("CardNumber", {
114 name: testName("alchemy-test-dlp-entry"),
115 pattern: { regex: "[0-9]{13,16}", validation: "luhn" },
116 profileId: profile.profileId,
117 });
118 return { profile, entry };
119 }),
120 );
121 expect(updated.profile.profileId).toEqual(created.profile.profileId);
122 expect(updated.profile.description).toEqual("v2");
123 expect(updated.profile.allowedMatchCount).toEqual(3);
124 expect(updated.entry.entryId).toEqual(created.entry.entryId);
125
126 yield* stack.destroy();
127
128 const gone = yield* zeroTrust
129 .getDlpProfileCustom({
130 accountId,
131 profileId: created.profile.profileId,
132 })
133 .pipe(Effect.flip);
134 expect(gone._tag).toEqual("DlpProfileNotFound");
135 }).pipe(logLevel),
136 {
137 tags: ["provider:cloudflare", "provider:cloudflare:dlp", "live"],
138 timeout: 90_000,
139 },
140 );