The best way to control Claude Code, Codex and more from any computer or phone
| 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 androiddeviceprovisioning from "@distilled.cloud/gcp/androiddeviceprovisioning_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | customerName, |
| 8 | logLevel, |
| 9 | probeName, |
| 10 | probeParent, |
| 11 | resolveDpc, |
| 12 | runLifecycle, |
| 13 | waitUntilGone, |
| 14 | } from "./common.ts"; |
| 15 | |
| 16 | const { test } = Test.make({ providers: GCP.providers() }); |
| 17 | |
| 18 | test.provider.skipIf(!runLifecycle)( |
| 19 | "getCustomersConfigurations on a missing configuration fails with a typed tag", |
| 20 | (stack) => |
| 21 | Effect.gen(function* () { |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | androiddeviceprovisioning.getCustomersConfigurations({ |
| 26 | name: probeName, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 35 | timeout: 90_000, |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | test.provider.skipIf(runLifecycle)( |
| 40 | "createCustomersConfigurations without zero-touch access fails with a typed entitlement error", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const error = yield* Effect.flip( |
| 46 | androiddeviceprovisioning.createCustomersConfigurations({ |
| 47 | parent: probeParent, |
| 48 | body: { |
| 49 | configurationName: "Alchemy Probe", |
| 50 | dpcResourcePath: `${probeParent}/dpcs/0`, |
| 51 | companyName: "Alchemy", |
| 52 | contactEmail: "alchemy-test@example.com", |
| 53 | contactPhone: "+1 555 0100", |
| 54 | isDefault: false, |
| 55 | }, |
| 56 | }), |
| 57 | ); |
| 58 | expect(error._tag).toEqual("InsufficientAuthenticationScopes"); |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | }).pipe(logLevel), |
| 62 | { |
| 63 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 64 | timeout: 90_000, |
| 65 | }, |
| 66 | ); |
| 67 | |
| 68 | test.provider.skipIf(!runLifecycle)( |
| 69 | "create, update, and delete a configuration", |
| 70 | (stack) => |
| 71 | Effect.gen(function* () { |
| 72 | yield* stack.destroy(); |
| 73 | |
| 74 | const parent = customerName!; |
| 75 | const dpcResourcePath = yield* resolveDpc(parent); |
| 76 | |
| 77 | const created = yield* stack.deploy( |
| 78 | Effect.gen(function* () { |
| 79 | return yield* GCP.AndroidDeviceProvisioning.CustomersConfiguration("Sales", { |
| 80 | parent, |
| 81 | dpcResourcePath, |
| 82 | companyName: "Alchemy", |
| 83 | contactEmail: "alchemy-test@example.com", |
| 84 | contactPhone: "+1 555 0100", |
| 85 | configurationName: "Sales team", |
| 86 | isDefault: false, |
| 87 | }); |
| 88 | }), |
| 89 | ); |
| 90 | |
| 91 | expect(created.name).toContain("/configurations/"); |
| 92 | expect(created.parent).toEqual(parent); |
| 93 | expect(created.configurationId.length).toBeGreaterThan(0); |
| 94 | expect(created.configurationName).toEqual("Sales team"); |
| 95 | expect(created.companyName).toEqual("Alchemy"); |
| 96 | expect(created.contactEmail).toEqual("alchemy-test@example.com"); |
| 97 | expect(created.isDefault).toEqual(false); |
| 98 | |
| 99 | const fetched = yield* androiddeviceprovisioning.getCustomersConfigurations({ |
| 100 | name: created.name, |
| 101 | }); |
| 102 | expect(fetched.name).toEqual(created.name); |
| 103 | expect(fetched.configurationName).toContain("[alchemy "); |
| 104 | |
| 105 | const updated = yield* stack.deploy( |
| 106 | Effect.gen(function* () { |
| 107 | return yield* GCP.AndroidDeviceProvisioning.CustomersConfiguration("Sales", { |
| 108 | parent: created.parent, |
| 109 | configurationId: created.configurationId, |
| 110 | dpcResourcePath: created.dpcResourcePath ?? dpcResourcePath, |
| 111 | companyName: created.companyName ?? "Alchemy", |
| 112 | contactEmail: "help@example.com", |
| 113 | contactPhone: created.contactPhone ?? "+1 555 0100", |
| 114 | configurationName: "Field sales", |
| 115 | customMessage: "Contact IT for setup help.", |
| 116 | isDefault: false, |
| 117 | }); |
| 118 | }), |
| 119 | ); |
| 120 | |
| 121 | expect(updated.name).toEqual(created.name); |
| 122 | expect(updated.configurationName).toEqual("Field sales"); |
| 123 | expect(updated.contactEmail).toEqual("help@example.com"); |
| 124 | expect(updated.customMessage).toEqual("Contact IT for setup help."); |
| 125 | |
| 126 | const fetchedUpdate = yield* androiddeviceprovisioning.getCustomersConfigurations({ |
| 127 | name: updated.name, |
| 128 | }); |
| 129 | expect(fetchedUpdate.configurationName).toContain("Field sales"); |
| 130 | expect(fetchedUpdate.contactEmail).toEqual("help@example.com"); |
| 131 | |
| 132 | yield* stack.destroy(); |
| 133 | |
| 134 | const gone = yield* waitUntilGone(created.name); |
| 135 | expect(gone).toEqual("gone"); |
| 136 | }).pipe(logLevel), |
| 137 | { |
| 138 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 139 | timeout: 90_000, |
| 140 | }, |
| 141 | ); |