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 { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as migrationcenter from "@distilled.cloud/gcp/migrationcenter_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const waitUntilGone = (name: string) => |
| 15 | migrationcenter.getProjectsLocationsImportJobsImportDataFiles({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getProjectsLocationsImportJobsImportDataFiles on a missing file fails with a typed tag", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const error = yield* Effect.flip( |
| 33 | migrationcenter.getProjectsLocationsImportJobsImportDataFiles({ |
| 34 | name: `projects/${project}/locations/us-central1/importJobs/alchemy-missing-job/importDataFiles/alchemy-missing-file`, |
| 35 | }), |
| 36 | ); |
| 37 | expect(error._tag).toEqual("NotFound"); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | { |
| 42 | tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"], |
| 43 | timeout: 90_000, |
| 44 | }, |
| 45 | ); |
| 46 | |
| 47 | test.provider( |
| 48 | "create and delete a migration center import data file", |
| 49 | (stack) => |
| 50 | Effect.gen(function* () { |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const created = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | const source = yield* GCP.MigrationCenter.Source("Upload", { |
| 56 | location: "us-central1", |
| 57 | type: "SOURCE_TYPE_UPLOAD", |
| 58 | displayName: "file-source", |
| 59 | }); |
| 60 | const job = yield* GCP.MigrationCenter.ImportJob("Rvtools", { |
| 61 | location: "us-central1", |
| 62 | assetSource: source.name, |
| 63 | displayName: "file-import", |
| 64 | }); |
| 65 | const file = yield* GCP.MigrationCenter.ImportJobsImportDataFile("Payload", { |
| 66 | importJob: job.name, |
| 67 | location: "us-central1", |
| 68 | format: "IMPORT_JOB_FORMAT_RVTOOLS_CSV", |
| 69 | displayName: "inventory", |
| 70 | }); |
| 71 | return { source, job, file }; |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | expect(created.file.importDataFileId).toEqual(expect.any(String)); |
| 76 | expect(created.file.importJob).toEqual(created.job.name); |
| 77 | expect(created.file.format).toEqual("IMPORT_JOB_FORMAT_RVTOOLS_CSV"); |
| 78 | |
| 79 | const fetched = yield* migrationcenter.getProjectsLocationsImportJobsImportDataFiles({ |
| 80 | name: created.file.name, |
| 81 | }); |
| 82 | expect(fetched.name).toEqual(created.file.name); |
| 83 | expect(fetched.format).toEqual("IMPORT_JOB_FORMAT_RVTOOLS_CSV"); |
| 84 | expect(fetched.displayName).toContain("alchemy-id="); |
| 85 | |
| 86 | yield* stack.destroy(); |
| 87 | const gone = yield* waitUntilGone(created.file.name); |
| 88 | expect(gone).toEqual("gone"); |
| 89 | }).pipe(logLevel), |
| 90 | { |
| 91 | tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"], |
| 92 | timeout: 180_000, |
| 93 | }, |
| 94 | ); |