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

main
ts 70 lines 2.23 KB
Raw
1 import { fileURLToPath } from "node:url";
2 import { describe, expect, it } from "@alchemy.run/test";
3 import { PlatformServices } from "alchemy/Util/PlatformServices";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as ChildProcess from "effect/process/ChildProcess";
7
8 const CLI = fileURLToPath(new URL("../../../alchemy/bin/cli.js", import.meta.url));
9
10 /**
11 * The CLI discovers providers from the `package.json` dependencies of its
12 * cwd, so these run from this package, which depends on `@alchemy.run/aws`.
13 */
14 const PROJECT = fileURLToPath(new URL("../..", import.meta.url));
15
16 const checkEnv = (args: ReadonlyArray<string>, env: Record<string, string>) =>
17 Effect.gen(function* () {
18 const fs = yield* FileSystem.FileSystem;
19 const home = yield* fs.makeTempDirectoryScoped({
20 prefix: "alchemy-check-env-",
21 });
22 const handle = yield* ChildProcess.make("bun", [CLI, "provider", "check-env", ...args], {
23 cwd: PROJECT,
24 env: { ALCHEMY_HOME: home, ...env },
25 extendEnv: true,
26 stdin: "ignore",
27 stdout: "ignore",
28 stderr: "ignore",
29 killSignal: "SIGTERM",
30 forceKillAfter: "1 second",
31 });
32 return yield* handle.exitCode;
33 }).pipe(Effect.scoped, Effect.provide(PlatformServices));
34
35 describe("provider check-env", { tags: ["unit", "local"] }, () => {
36 it.live("exits 1 when a required var is missing", () =>
37 Effect.gen(function* () {
38 expect(
39 yield* checkEnv(["--provider", "aws"], {
40 AWS_ACCESS_KEY_ID: "",
41 AWS_SECRET_ACCESS_KEY: "",
42 }),
43 ).toBe(1);
44 }),
45 );
46
47 it.live("exits 0 when the contract is satisfied", () =>
48 Effect.gen(function* () {
49 expect(
50 yield* checkEnv(["--provider", "aws"], {
51 AWS_ACCESS_KEY_ID: "AKIATESTKEY",
52 AWS_SECRET_ACCESS_KEY: "test-secret",
53 AWS_REGION: "us-east-1",
54 }),
55 ).toBe(0);
56 }),
57 );
58
59 it.live("accepts an explicit profile", () =>
60 Effect.gen(function* () {
61 expect(
62 yield* checkEnv(["--profile", "default", "--provider", "aws"], {
63 AWS_ACCESS_KEY_ID: "AKIATESTKEY",
64 AWS_SECRET_ACCESS_KEY: "test-secret",
65 AWS_REGION: "us-east-1",
66 }),
67 ).toBe(0);
68 }),
69 );
70 });