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
| 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 androidmanagement from "@distilled.cloud/gcp/androidmanagement_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { enterpriseName, logLevel, runLifecycle } from "./common.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const waitUntilGone = (name: string) => |
| 12 | androidmanagement.getEnterprisesEnrollmentTokens({ name }).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 | "getEnterprisesEnrollmentTokens without the Android Management scope fails with InsufficientScopes", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | |
| 28 | const error = yield* Effect.flip( |
| 29 | androidmanagement.getEnterprisesEnrollmentTokens({ |
| 30 | name: "enterprises/alchemy-missing-enterprise/enrollmentTokens/alchemy-missing", |
| 31 | }), |
| 32 | ); |
| 33 | expect(error._tag).toEqual("InsufficientScopes"); |
| 34 | |
| 35 | yield* stack.destroy(); |
| 36 | }).pipe(logLevel), |
| 37 | { |
| 38 | tags: ["provider:gcp", "provider:gcp:androidmanagement", "live"], |
| 39 | timeout: 90_000, |
| 40 | }, |
| 41 | ); |
| 42 | |
| 43 | test.provider.skipIf(runLifecycle)( |
| 44 | "createEnterprisesEnrollmentTokens without Android Management access fails with a typed entitlement error", |
| 45 | (stack) => |
| 46 | Effect.gen(function* () { |
| 47 | yield* stack.destroy(); |
| 48 | |
| 49 | const error = yield* Effect.flip( |
| 50 | androidmanagement.createEnterprisesEnrollmentTokens({ |
| 51 | parent: "enterprises/alchemy-missing-enterprise", |
| 52 | body: { |
| 53 | duration: "3600s", |
| 54 | additionalData: "alchemy-probe", |
| 55 | }, |
| 56 | }), |
| 57 | ); |
| 58 | expect(error._tag).toEqual("InsufficientScopes"); |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | }).pipe(logLevel), |
| 62 | { |
| 63 | tags: ["provider:gcp", "provider:gcp:androidmanagement", "live"], |
| 64 | timeout: 90_000, |
| 65 | }, |
| 66 | ); |
| 67 | |
| 68 | test.provider.skipIf(!runLifecycle)( |
| 69 | "create, update, and delete an enrollment token", |
| 70 | (stack) => |
| 71 | Effect.gen(function* () { |
| 72 | yield* stack.destroy(); |
| 73 | |
| 74 | const created = yield* stack.deploy( |
| 75 | Effect.gen(function* () { |
| 76 | const enterprise = enterpriseName |
| 77 | ? { name: enterpriseName } |
| 78 | : yield* GCP.AndroidManagement.Enterprise("TokenHost", { |
| 79 | enterpriseDisplayName: "Token Host", |
| 80 | }); |
| 81 | const token = yield* GCP.AndroidManagement.EnterprisesEnrollmentToken("Enroll", { |
| 82 | parent: enterprise.name, |
| 83 | duration: "86400s", |
| 84 | additionalData: "org-unit-a", |
| 85 | }); |
| 86 | return { enterprise, token }; |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | expect(created.token.name).toContain("/enrollmentTokens/"); |
| 91 | expect(created.token.parent).toEqual(created.enterprise.name); |
| 92 | expect(created.token.enrollmentTokenId.length).toBeGreaterThan(0); |
| 93 | expect(created.token.value).toEqual(expect.any(String)); |
| 94 | |
| 95 | const fetched = yield* androidmanagement.getEnterprisesEnrollmentTokens({ |
| 96 | name: created.token.name, |
| 97 | }); |
| 98 | expect(fetched.name).toEqual(created.token.name); |
| 99 | |
| 100 | const updated = yield* stack.deploy( |
| 101 | Effect.gen(function* () { |
| 102 | const enterprise = enterpriseName |
| 103 | ? { name: enterpriseName } |
| 104 | : yield* GCP.AndroidManagement.Enterprise("TokenHost", { |
| 105 | enterpriseDisplayName: "Token Host", |
| 106 | }); |
| 107 | return yield* GCP.AndroidManagement.EnterprisesEnrollmentToken("Enroll", { |
| 108 | parent: enterprise.name, |
| 109 | duration: "172800s", |
| 110 | additionalData: "org-unit-b", |
| 111 | }); |
| 112 | }), |
| 113 | ); |
| 114 | |
| 115 | expect(updated.name).not.toEqual(created.token.name); |
| 116 | expect(updated.parent).toEqual(created.enterprise.name); |
| 117 | |
| 118 | yield* stack.destroy(); |
| 119 | |
| 120 | const gone = yield* waitUntilGone(updated.name); |
| 121 | expect(gone).toEqual("gone"); |
| 122 | }).pipe(logLevel), |
| 123 | { |
| 124 | tags: ["provider:gcp", "provider:gcp:androidmanagement", "live"], |
| 125 | timeout: 90_000, |
| 126 | }, |
| 127 | ); |