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

main
ts 247 lines 6.96 KB
Raw
1 import * as Prisma from "@alchemy.run/prisma";
2 import type { PrismaManagementClient } from "@alchemy.run/prisma/Client";
3 import { describe, expect, it } from "@alchemy.run/test";
4 import {
5 managementApiContract,
6 productionManagementApiRoutes,
7 } from "./fixtures/ManagementApiContract.ts";
8
9 const canonicalComputeOperations = [
10 "listApps",
11 "getApp",
12 "createApp",
13 "updateApp",
14 "deleteApp",
15 "promoteApp",
16 "rollbackApp",
17 "listAppDomains",
18 "createAppDomain",
19 "listAppDeployments",
20 "createAppDeployment",
21 "getDeployment",
22 "deleteDeployment",
23 "startDeployment",
24 "stopDeployment",
25 "getDeploymentLogsRequest",
26 "getBuildLogsRequest",
27 ] as const satisfies ReadonlyArray<keyof PrismaManagementClient>;
28
29 const lifecycleResources = [
30 {
31 name: "Project",
32 resource: Prisma.Project,
33 routes: [
34 "GET /v1/projects",
35 "POST /v1/projects",
36 "GET /v1/projects/{id}",
37 "PATCH /v1/projects/{id}",
38 "DELETE /v1/projects/{id}",
39 ],
40 },
41 {
42 name: "Database",
43 resource: Prisma.Database,
44 routes: [
45 "GET /v1/databases",
46 "POST /v1/databases",
47 "GET /v1/projects/{projectId}/databases",
48 "POST /v1/projects/{projectId}/databases",
49 "GET /v1/databases/{databaseId}",
50 "PATCH /v1/databases/{databaseId}",
51 "DELETE /v1/databases/{databaseId}",
52 ],
53 },
54 {
55 name: "Connection",
56 resource: Prisma.Connection,
57 routes: [
58 "GET /v1/connections",
59 "POST /v1/connections",
60 "GET /v1/databases/{databaseId}/connections",
61 "POST /v1/databases/{databaseId}/connections",
62 "GET /v1/connections/{id}",
63 "DELETE /v1/connections/{id}",
64 ],
65 },
66 {
67 name: "Branch",
68 resource: Prisma.Branch,
69 routes: [
70 "GET /v1/projects/{projectId}/branches",
71 "POST /v1/projects/{projectId}/branches",
72 "GET /v1/branches/{branchId}",
73 "PATCH /v1/branches/{branchId}",
74 "DELETE /v1/branches/{branchId}",
75 ],
76 },
77 {
78 name: "Bucket",
79 resource: Prisma.Bucket,
80 routes: [
81 "GET /v1/buckets",
82 "POST /v1/buckets",
83 "GET /v1/buckets/{bucketId}",
84 "DELETE /v1/buckets/{bucketId}",
85 ],
86 },
87 {
88 name: "BucketAccessKey",
89 resource: Prisma.BucketAccessKey,
90 routes: [
91 "GET /v1/buckets/{bucketId}/keys",
92 "POST /v1/buckets/{bucketId}/keys",
93 "DELETE /v1/buckets/{bucketId}/keys/{keyId}",
94 ],
95 },
96 {
97 name: "App",
98 resource: Prisma.App,
99 routes: [
100 "GET /v1/apps",
101 "POST /v1/apps",
102 "GET /v1/apps/{appId}",
103 "PATCH /v1/apps/{appId}",
104 "DELETE /v1/apps/{appId}",
105 ],
106 },
107 {
108 name: "Deployment",
109 resource: Prisma.Deployment,
110 routes: [
111 "GET /v1/apps/{appId}/deployments",
112 "POST /v1/apps/{appId}/deployments",
113 "GET /v1/deployments/{deploymentId}",
114 "DELETE /v1/deployments/{deploymentId}",
115 "POST /v1/deployments/{deploymentId}/start",
116 "POST /v1/deployments/{deploymentId}/stop",
117 "GET /v1/deployments/{deploymentId}/logs",
118 ],
119 },
120 {
121 name: "CustomDomain",
122 resource: Prisma.CustomDomain,
123 routes: [
124 "GET /v1/apps/{appId}/domains",
125 "POST /v1/apps/{appId}/domains",
126 "GET /v1/domains/{domainId}",
127 "DELETE /v1/domains/{domainId}",
128 ],
129 },
130 {
131 name: "EnvironmentVariable",
132 resource: Prisma.EnvironmentVariable,
133 routes: [
134 "GET /v1/environment-variables",
135 "POST /v1/environment-variables",
136 "GET /v1/environment-variables/{envVarId}",
137 "PATCH /v1/environment-variables/{envVarId}",
138 "DELETE /v1/environment-variables/{envVarId}",
139 ],
140 },
141 {
142 name: "SourceRepository",
143 resource: Prisma.SourceRepository,
144 routes: [
145 "GET /v1/source-repositories",
146 "POST /v1/source-repositories",
147 "GET /v1/source-repositories/{id}",
148 "DELETE /v1/source-repositories/{id}",
149 ],
150 },
151 ] as const;
152
153 const operationOnlyRoutes = [
154 "POST /v1/apps/{appId}/promote",
155 "POST /v1/apps/{appId}/rollback",
156 "GET /v1/builds/{buildId}/logs",
157 "POST /v1/projects/{id}/transfer",
158 "GET /v1/databases/{databaseId}/backups",
159 "POST /v1/databases/{targetDatabaseId}/restore",
160 "GET /v1/databases/{databaseId}/usage",
161 "POST /v1/connections/{id}/rotate",
162 "POST /v1/domains/{domainId}/retry",
163 "GET /v1/me",
164 "GET /v1/workspaces",
165 "GET /v1/workspaces/{id}",
166 "GET /v1/regions",
167 "GET /v1/regions/postgres",
168 "GET /v1/regions/accelerate",
169 "GET /v1/scm-installations",
170 "POST /v1/scm-installations/install-intents",
171 "GET /v1/scm-installations/{installationId}/repositories",
172 "GET /v1/integrations",
173 "GET /v1/integrations/{id}",
174 "DELETE /v1/integrations/{id}",
175 "GET /v1/workspaces/{workspaceId}/integrations",
176 "DELETE /v1/workspaces/{workspaceId}/integrations/{clientId}",
177 ] as const;
178
179 const expectedManagementApiRoutes = [
180 ...lifecycleResources.flatMap((resource) => resource.routes),
181 ...operationOnlyRoutes,
182 ].sort();
183
184 describe("Prisma Management API coverage", { tags: ["unit", "provider:prisma", "local"] }, () => {
185 it(
186 "maps lifecycle route groups to Alchemy resources",
187 () => {
188 for (const { name, resource } of lifecycleResources) {
189 expect(resource.Type).toBe(`Prisma.${name}`);
190 }
191 },
192 {
193 tags: [
194 "provider:prisma:app",
195 "provider:prisma:branch",
196 "provider:prisma:bucket",
197 "provider:prisma:bucketaccesskey",
198 "provider:prisma:connection",
199 "provider:prisma:customdomain",
200 "provider:prisma:database",
201 "provider:prisma:deployment",
202 "provider:prisma:environmentvariable",
203 "provider:prisma:project",
204 "provider:prisma:sourcerepository",
205 ],
206 },
207 );
208
209 it(
210 "accounts for every route in the pinned Management API contract",
211 () => {
212 expect(managementApiContract.repository).toBe("prisma/pdp-control-plane");
213 expect(managementApiContract.commit).toMatch(/^[0-9a-f]{40}$/);
214 expect(managementApiContract.routes).toHaveLength(78);
215 expect(managementApiContract.deferredRoutes).toHaveLength(0);
216 expect(
217 managementApiContract.deferredRoutes.every((route) =>
218 managementApiContract.routes.includes(route),
219 ),
220 ).toBe(true);
221 expect(expectedManagementApiRoutes).toHaveLength(78);
222 expect(expectedManagementApiRoutes).toEqual([...productionManagementApiRoutes].sort());
223 expect(expectedManagementApiRoutes.some((route) => route.includes("/__admin"))).toBe(false);
224 },
225 {
226 tags: [
227 "provider:prisma:app",
228 "provider:prisma:branch",
229 "provider:prisma:bucket",
230 "provider:prisma:bucketaccesskey",
231 "provider:prisma:connection",
232 "provider:prisma:customdomain",
233 "provider:prisma:database",
234 "provider:prisma:deployment",
235 "provider:prisma:environmentvariable",
236 "provider:prisma:project",
237 "provider:prisma:sourcerepository",
238 ],
239 },
240 );
241
242 it("exports the canonical app and deployment operations", () => {
243 for (const operation of canonicalComputeOperations) {
244 expect(operation in Prisma).toBe(true);
245 }
246 });
247 });