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

main
ts 142 lines 4.62 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as androidenterprise from "@distilled.cloud/gcp/androidenterprise_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { enterpriseId, logLevel, probeEnterpriseId, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (accountId: string, pageId: string, clusterId: string) =>
12 androidenterprise
13 .getStorelayoutclusters({
14 enterpriseId: accountId,
15 pageId,
16 clusterId,
17 })
18 .pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28 test.provider.skipIf(!runLifecycle)(
29 "getStorelayoutclusters on a missing cluster fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 androidenterprise.getStorelayoutclusters({
36 enterpriseId: probeEnterpriseId,
37 pageId: "alchemy-missing-page",
38 clusterId: "alchemy-missing-cluster",
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 yield* stack.destroy();
44 }).pipe(logLevel),
45 {
46 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
47 timeout: 90_000,
48 },
49 );
50
51 test.provider.skipIf(runLifecycle)(
52 "insertStorelayoutclusters without the EMM OAuth scope fails with InsufficientAuthenticationScopes",
53 (stack) =>
54 Effect.gen(function* () {
55 yield* stack.destroy();
56
57 const error = yield* Effect.flip(
58 androidenterprise.insertStorelayoutclusters({
59 enterpriseId: probeEnterpriseId,
60 pageId: "alchemy-missing-page",
61 body: {
62 name: [{ locale: "en-US", text: "Alchemy Probe Cluster" }],
63 },
64 }),
65 );
66 expect(error._tag).toEqual("InsufficientAuthenticationScopes");
67
68 yield* stack.destroy();
69 }).pipe(logLevel),
70 {
71 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
72 timeout: 90_000,
73 },
74 );
75
76 test.provider.skipIf(!runLifecycle)(
77 "create, update, and delete a store layout cluster",
78 (stack) =>
79 Effect.gen(function* () {
80 yield* stack.destroy();
81
82 const created = yield* stack.deploy(
83 Effect.gen(function* () {
84 const page = yield* GCP.AndroidEnterprise.Storelayoutpage("Home", {
85 enterpriseId: enterpriseId!,
86 name: [{ locale: "en-US", text: "Home" }],
87 });
88 const cluster = yield* GCP.AndroidEnterprise.Storelayoutcluster("Apps", {
89 enterpriseId: page.enterpriseId,
90 pageId: page.pageId,
91 name: [{ locale: "en-US", text: "Work apps" }],
92 });
93 return { page, cluster };
94 }),
95 );
96
97 expect(created.cluster.clusterId.length).toBeGreaterThan(0);
98 expect(created.cluster.pageId).toEqual(created.page.pageId);
99 expect(created.cluster.name?.[0]?.text).toEqual("Work apps");
100
101 const fetched = yield* androidenterprise.getStorelayoutclusters({
102 enterpriseId: created.cluster.enterpriseId,
103 pageId: created.cluster.pageId,
104 clusterId: created.cluster.clusterId,
105 });
106 expect(fetched.id).toEqual(created.cluster.clusterId);
107 expect(fetched.name?.[0]?.text).toEqual("Work apps");
108
109 const updated = yield* stack.deploy(
110 Effect.gen(function* () {
111 const page = yield* GCP.AndroidEnterprise.Storelayoutpage("Home", {
112 enterpriseId: created.page.enterpriseId,
113 pageId: created.page.pageId,
114 name: [{ locale: "en-US", text: "Home" }],
115 });
116 const cluster = yield* GCP.AndroidEnterprise.Storelayoutcluster("Apps", {
117 enterpriseId: page.enterpriseId,
118 pageId: page.pageId,
119 clusterId: created.cluster.clusterId,
120 name: [{ locale: "en-US", text: "Featured apps" }],
121 });
122 return { page, cluster };
123 }),
124 );
125
126 expect(updated.cluster.clusterId).toEqual(created.cluster.clusterId);
127 expect(updated.cluster.name?.[0]?.text).toEqual("Featured apps");
128
129 yield* stack.destroy();
130
131 const gone = yield* waitUntilGone(
132 created.cluster.enterpriseId,
133 created.cluster.pageId,
134 created.cluster.clusterId,
135 );
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 {
139 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
140 timeout: 90_000,
141 },
142 );