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

main
ts 121 lines 3.78 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, webAppId: string) =>
12 androidenterprise.getWebapps({ enterpriseId: accountId, webAppId }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider.skipIf(!runLifecycle)(
23 "getWebapps on a missing web app fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 androidenterprise.getWebapps({
30 enterpriseId: probeEnterpriseId,
31 webAppId: "app:com.google.enterprise.webapp.alchemy-missing",
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider.skipIf(runLifecycle)(
45 "insertWebapps without the EMM OAuth scope fails with InsufficientAuthenticationScopes",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const error = yield* Effect.flip(
51 androidenterprise.insertWebapps({
52 enterpriseId: probeEnterpriseId,
53 body: {
54 title: "Alchemy Probe Web App",
55 startUrl: "https://example.com/",
56 displayMode: "standalone",
57 },
58 }),
59 );
60 expect(error._tag).toEqual("InsufficientAuthenticationScopes");
61
62 yield* stack.destroy();
63 }).pipe(logLevel),
64 {
65 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
66 timeout: 90_000,
67 },
68 );
69
70 test.provider.skipIf(!runLifecycle)(
71 "create, update, and delete a web app",
72 (stack) =>
73 Effect.gen(function* () {
74 yield* stack.destroy();
75
76 const created = yield* stack.deploy(
77 Effect.gen(function* () {
78 return yield* GCP.AndroidEnterprise.Webapp("Portal", {
79 enterpriseId: enterpriseId!,
80 startUrl: "https://example.com/alchemy-portal",
81 title: "Portal",
82 });
83 }),
84 );
85
86 expect(created.webAppId.length).toBeGreaterThan(0);
87 expect(created.enterpriseId).toEqual(enterpriseId);
88 expect(created.title).toEqual("Portal");
89 expect(created.startUrl).toEqual("https://example.com/alchemy-portal");
90
91 const fetched = yield* androidenterprise.getWebapps({
92 enterpriseId: created.enterpriseId,
93 webAppId: created.webAppId,
94 });
95 expect(fetched.webAppId).toEqual(created.webAppId);
96 expect(fetched.title).toEqual("Portal");
97
98 const updated = yield* stack.deploy(
99 Effect.gen(function* () {
100 return yield* GCP.AndroidEnterprise.Webapp("Portal", {
101 enterpriseId: created.enterpriseId,
102 webAppId: created.webAppId,
103 startUrl: "https://example.com/alchemy-portal",
104 title: "Employee portal",
105 });
106 }),
107 );
108
109 expect(updated.webAppId).toEqual(created.webAppId);
110 expect(updated.title).toEqual("Employee portal");
111
112 yield* stack.destroy();
113
114 const gone = yield* waitUntilGone(created.enterpriseId, created.webAppId);
115 expect(gone).toEqual("gone");
116 }).pipe(logLevel),
117 {
118 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
119 timeout: 90_000,
120 },
121 );