The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GitHub from "@alchemy.run/github"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Provider from "alchemy/Provider"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import { scopedToOwner } from "./scope.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GitHub.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | // Creating a real repository + variable requires an owner the token can |
| 14 | // write to — the dedicated test org (never a real one). Set |
| 15 | // GITHUB_TEST_OWNER="" to skip. |
| 16 | const owner = process.env.GITHUB_TEST_OWNER ?? "alchemy-run-test"; |
| 17 | const repo = process.env.GITHUB_TEST_REPOSITORY ?? "test-repo"; |
| 18 | |
| 19 | test.provider.skipIf(!owner)( |
| 20 | "list enumerates the deployed variable", |
| 21 | (stack) => |
| 22 | Effect.gen(function* () { |
| 23 | // Clean up any leftovers from a previous run before deploying. |
| 24 | yield* stack.destroy(); |
| 25 | |
| 26 | yield* stack.deploy( |
| 27 | Effect.gen(function* () { |
| 28 | // `Repository` defaults to `retain`, so we intentionally do NOT pipe |
| 29 | // `destroy()` here: the test only needs a repo to host the variable, |
| 30 | // and deleting it would require `delete_repo`/admin rights. The repo |
| 31 | // is created once and reused (reconcile is idempotent). |
| 32 | const repository = yield* GitHub.Repository("Repo", { |
| 33 | owner, |
| 34 | name: repo, |
| 35 | description: "alchemy-effect variable list test", |
| 36 | visibility: "private", |
| 37 | autoInit: true, |
| 38 | }); |
| 39 | |
| 40 | return yield* GitHub.Variable("Variable", { |
| 41 | owner, |
| 42 | // Use the known repo name; reference a repository output in `value` |
| 43 | // so the engine orders this resource after the repository exists. |
| 44 | repository: repo, |
| 45 | name: "ALCHEMY_LIST_TEST", |
| 46 | value: repository.fullName, |
| 47 | }); |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | // Resolve the provider with the typed helper so `list()`'s element type |
| 52 | // is the resource's `Attributes` (no `any`). |
| 53 | const provider = yield* Provider.findProvider(GitHub.Variable); |
| 54 | const all = yield* provider.list().pipe(scopedToOwner(owner)); |
| 55 | |
| 56 | // `list()` enumerates variables across repositories in the test org. |
| 57 | // The variable we just deployed guarantees at least one row. The |
| 58 | // resource's `Attributes` only exposes `updatedAt`, so we assert presence |
| 59 | // by the enumeration being non-empty (it cannot key on a specific name). |
| 60 | expect(all.length).toBeGreaterThan(0); |
| 61 | expect(all.every((v) => typeof v.updatedAt === "string")).toBe(true); |
| 62 | |
| 63 | yield* stack.destroy(); |
| 64 | }).pipe(logLevel), |
| 65 | { |
| 66 | tags: ["provider:github", "provider:github:repository", "provider:github:variable", "live"], |
| 67 | timeout: 180_000, |
| 68 | }, |
| 69 | ); |