The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@alchemy.run/test"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Option from "effect/Option"; |
| 4 | import * as Result from "effect/Result"; |
| 5 | import * as Schema from "effect/Schema"; |
| 6 | import { UserInputError } from "@/Cli/commands/errors.ts"; |
| 7 | import { resolveConfig, include, exclude, validateSelectionOptions } from "@/Cli/commands/flags.ts"; |
| 8 | import { DevOptions } from "@/Cli/DevOptions.ts"; |
| 9 | import { PlatformServices } from "@/Util/PlatformServices.ts"; |
| 10 | |
| 11 | describe("stack command config paths", { tags: ["unit", "local"] }, () => { |
| 12 | it.effect("uses the positional config path", () => |
| 13 | Effect.gen(function* () { |
| 14 | const args = yield* resolveConfig({ |
| 15 | config: undefined, |
| 16 | configPath: "infra.ts", |
| 17 | }); |
| 18 | expect(args.main).toBe("infra.ts"); |
| 19 | }), |
| 20 | ); |
| 21 | |
| 22 | it.effect("uses --config", () => |
| 23 | Effect.gen(function* () { |
| 24 | const args = yield* resolveConfig({ |
| 25 | config: "infra.ts", |
| 26 | configPath: undefined, |
| 27 | }); |
| 28 | expect(args.main).toBe("infra.ts"); |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | it.effect("defaults to alchemy.run.ts", () => |
| 33 | Effect.gen(function* () { |
| 34 | const args = yield* resolveConfig({ |
| 35 | config: undefined, |
| 36 | configPath: undefined, |
| 37 | }); |
| 38 | expect(args.main).toBe("alchemy.run.ts"); |
| 39 | }), |
| 40 | ); |
| 41 | |
| 42 | it.effect("rejects using the positional path and --config together", () => |
| 43 | Effect.gen(function* () { |
| 44 | const result = yield* resolveConfig({ |
| 45 | config: "flag.ts", |
| 46 | configPath: "positional.ts", |
| 47 | }).pipe(Effect.result); |
| 48 | |
| 49 | expect(Result.isFailure(result)).toBe(true); |
| 50 | if (Result.isFailure(result)) { |
| 51 | expect(result.failure).toBeInstanceOf(UserInputError); |
| 52 | expect(result.failure.message).toContain("not both"); |
| 53 | } |
| 54 | }), |
| 55 | ); |
| 56 | }); |
| 57 | |
| 58 | describe("stack selection options", { tags: ["unit", "local"] }, () => { |
| 59 | for (const [name, flag] of [ |
| 60 | ["include", include], |
| 61 | ["exclude", exclude], |
| 62 | ] as const) { |
| 63 | for (const [values, expected] of [ |
| 64 | [[], undefined], |
| 65 | [ |
| 66 | ["Branch,Password", "Namespace/**"], |
| 67 | ["Branch,Password", "Namespace/**"], |
| 68 | ], |
| 69 | [[""], [""]], |
| 70 | [["Branch,"], ["Branch,"]], |
| 71 | [ |
| 72 | [" App/* ", "App/*", "App/*"], |
| 73 | [" App/* ", "App/*", "App/*"], |
| 74 | ], |
| 75 | ] as const) { |
| 76 | it.effect(`parses repeated --${name} patterns ${JSON.stringify(values)}`, () => |
| 77 | Effect.gen(function* () { |
| 78 | const [, parsed] = yield* flag.parse({ |
| 79 | arguments: [], |
| 80 | flags: values.length ? { [name]: [...values] } : {}, |
| 81 | }); |
| 82 | expect(parsed).toEqual(expected); |
| 83 | }).pipe(Effect.provide(PlatformServices)), |
| 84 | ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | it.effect("retains include and exclude through dev reload JSON roundtrips", () => |
| 89 | Effect.gen(function* () { |
| 90 | for (const include of [undefined, [], ["Branch,Password", "Namespace/**"]]) { |
| 91 | for (const exclude of [undefined, [], ["Namespace/Legacy", "**/.Private"]]) { |
| 92 | const options = { |
| 93 | main: "alchemy.run.ts", |
| 94 | stage: "test", |
| 95 | envFile: Option.none(), |
| 96 | force: false, |
| 97 | include, |
| 98 | exclude, |
| 99 | }; |
| 100 | const wire = yield* Schema.encodeEffect(DevOptions)(options); |
| 101 | const decoded = yield* Schema.decodeUnknownEffect(DevOptions)( |
| 102 | JSON.parse(JSON.stringify(wire)), |
| 103 | ); |
| 104 | expect(decoded.include).toEqual(include); |
| 105 | expect(decoded.exclude).toEqual(exclude); |
| 106 | } |
| 107 | } |
| 108 | }), |
| 109 | ); |
| 110 | |
| 111 | for (const selection of [ |
| 112 | { include: ["Branch"] }, |
| 113 | { exclude: ["Branch"] }, |
| 114 | { include: [] }, |
| 115 | { exclude: [] }, |
| 116 | ]) { |
| 117 | for (const combination of [{ destroy: true }, { detectDrift: true }]) { |
| 118 | it.effect(`rejects ${JSON.stringify(selection)} with ${JSON.stringify(combination)}`, () => |
| 119 | Effect.gen(function* () { |
| 120 | const result = yield* validateSelectionOptions({ |
| 121 | ...selection, |
| 122 | ...combination, |
| 123 | }).pipe(Effect.result); |
| 124 | expect(Result.isFailure(result)).toBe(true); |
| 125 | yield* validateSelectionOptions(combination); |
| 126 | }), |
| 127 | ); |
| 128 | } |
| 129 | } |
| 130 | }); |