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

main
ts 48 lines 1.88 KB
Raw
1 import { spawnSync } from "node:child_process";
2 import { mkdtempSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { fileURLToPath } from "node:url";
6 import { expect, it } from "@alchemy.run/test";
7
8 const cli = fileURLToPath(new URL("../../bin/cli.js", import.meta.url));
9
10 it(
11 "state unsafe nuke requires approval and clears every stack with --yes",
12 () => {
13 const cwd = mkdtempSync(join(tmpdir(), "alchemy-state-nuke-"));
14 const state = join(cwd, ".alchemy", "state");
15 try {
16 for (const stack of ["First", "Second"]) {
17 for (const stage of ["dev", "prod"]) {
18 const directory = join(state, stack, stage);
19 mkdirSync(directory, { recursive: true });
20 writeFileSync(join(directory, "output.json"), "{}");
21 }
22 }
23 const run = (args: string[]) =>
24 spawnSync("bun", [cli, ...args], {
25 cwd,
26 env: { ...process.env, ALCHEMY_HOME: join(cwd, "home") },
27 encoding: "utf8",
28 timeout: 10000,
29 });
30 const args = ["state", "unsafe", "nuke", "--backend", "local"];
31 expect(run(args).status).toBe(1);
32 expect(readdirSync(state).sort()).toEqual(["First", "Second"]);
33 const cleared = run([...args, "--yes"]);
34 expect(cleared.status).toBe(0);
35 expect(cleared.stdout).toContain("• First\n• Second");
36 expect(cleared.stdout).toContain("Cleared First");
37 expect(cleared.stdout).toContain("Cleared Second");
38 expect(readdirSync(state)).toEqual([]);
39 const empty = run(args);
40 expect(empty.status).toBe(0);
41 expect(empty.stdout).toContain("Nothing to clear");
42 expect(run(["state", "delete", "/", "--recursive", "--backend", "local"]).status).toBe(1);
43 } finally {
44 rmSync(cwd, { recursive: true, force: true });
45 }
46 },
47 { tags: ["unit", "local"] },
48 );