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 { fileURLToPath } from "node:url"; |
| 2 | import { expect, it } from "@alchemy.run/test"; |
| 3 | import { PlatformServices } from "alchemy/Util/PlatformServices"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as ChildProcess from "effect/process/ChildProcess"; |
| 6 | import * as Stream from "effect/Stream"; |
| 7 | import { nodePath, nodeSupportsDevMode } from "../nodeProbe.ts"; |
| 8 | |
| 9 | // Pins buildless node dev end to end: the register-dev-mode hooks must |
| 10 | // (1) resolve the monorepo's own packages through their `bun` export |
| 11 | // condition onto src/ — otherwise the CLI runs from src while a user's |
| 12 | // stack (which imports `alchemy`) resolves built lib/, splitting the |
| 13 | // process across two copies of the package — while leaving packages |
| 14 | // without a `bun` condition (published sigil) on their built output, and |
| 15 | // (2) transpile `.tsx` with ALCHEMY'S tsconfig (react-jsx) regardless of |
| 16 | // the invoking project: the child's cwd is an example on purpose. Oxc resolves |
| 17 | // the nearest tsconfig per source file, so the CLI's React files cannot inherit |
| 18 | // the example's JSX settings (which previously produced classic-runtime output |
| 19 | // and "ReferenceError: React is not defined"). |
| 20 | it.live.skipIf(!nodeSupportsDevMode)( |
| 21 | "dev-mode hooks resolve monorepo packages to src and transpile tsx", |
| 22 | () => |
| 23 | Effect.gen(function* () { |
| 24 | const packageDir = fileURLToPath(new URL("../../../alchemy", import.meta.url)); |
| 25 | const exampleDir = fileURLToPath(new URL("../../../../examples/aws-dev", import.meta.url)); |
| 26 | const runtimeTsx = fileURLToPath( |
| 27 | new URL("../../../alchemy/src/Cli/components/view/Runtime.tsx", import.meta.url), |
| 28 | ); |
| 29 | const resolutionProbe = fileURLToPath( |
| 30 | new URL("./fixtures/register-dev-mode-probe.ts", import.meta.url), |
| 31 | ); |
| 32 | // No explicit sigil probe: two-arg import.meta.resolve is flagged in |
| 33 | // node, and Runtime.tsx importing sigil transitively already proves |
| 34 | // the published package (no `bun` condition) loads from its dist. |
| 35 | const script = ` |
| 36 | const probe = await import(${JSON.stringify(resolutionProbe)}); |
| 37 | console.log("alchemy=" + probe.alchemyUrl); |
| 38 | console.log("sub=" + probe.subpathUrl); |
| 39 | await import(${JSON.stringify(runtimeTsx)}); |
| 40 | console.log("tsx=ok"); |
| 41 | `; |
| 42 | const handle = yield* ChildProcess.make( |
| 43 | nodePath!, |
| 44 | ["--import", `${packageDir}/bin/register-dev-mode.js`, "--input-type=module", "-e", script], |
| 45 | { |
| 46 | cwd: exampleDir, |
| 47 | env: { |
| 48 | NO_COLOR: "1", |
| 49 | // The Bun test runner's markers must not select Bun for this |
| 50 | // explicitly Node/pnpm invocation. |
| 51 | npm_execpath: "", |
| 52 | npm_config_user_agent: "", |
| 53 | }, |
| 54 | extendEnv: true, |
| 55 | stdin: "ignore", |
| 56 | stdout: "pipe", |
| 57 | stderr: "pipe", |
| 58 | killSignal: "SIGKILL", |
| 59 | }, |
| 60 | ); |
| 61 | const [stdout, stderr, exitCode] = yield* Effect.all( |
| 62 | [ |
| 63 | handle.stdout.pipe( |
| 64 | Stream.decodeText, |
| 65 | Stream.runCollect, |
| 66 | Effect.map((chunks) => chunks.join("")), |
| 67 | ), |
| 68 | handle.stderr.pipe( |
| 69 | Stream.decodeText, |
| 70 | Stream.runCollect, |
| 71 | Effect.map((chunks) => chunks.join("")), |
| 72 | ), |
| 73 | handle.exitCode, |
| 74 | ], |
| 75 | { concurrency: 3 }, |
| 76 | ); |
| 77 | expect(stderr).toBe(""); |
| 78 | expect(exitCode).toBe(0); |
| 79 | expect(stdout).toMatch(/alchemy=file:.*\/src\/index\.ts/); |
| 80 | expect(stdout).toMatch(/sub=file:.*\/packages\/aws\/src\/S3\/index\.ts/); |
| 81 | expect(stdout).toContain("tsx=ok"); |
| 82 | |
| 83 | const repoDir = fileURLToPath(new URL("../../../..", import.meta.url)); |
| 84 | const pnpm = Bun.which("pnpm"); |
| 85 | expect(pnpm).not.toBeNull(); |
| 86 | const cli = yield* ChildProcess.make(pnpm!, ["alchemy", "--version"], { |
| 87 | cwd: repoDir, |
| 88 | env: { |
| 89 | NO_COLOR: "1", |
| 90 | // The Bun test runner's markers must not select Bun for this |
| 91 | // explicitly Node/pnpm invocation. |
| 92 | npm_execpath: "", |
| 93 | npm_config_user_agent: "", |
| 94 | }, |
| 95 | extendEnv: true, |
| 96 | stdin: "ignore", |
| 97 | stdout: "pipe", |
| 98 | stderr: "pipe", |
| 99 | killSignal: "SIGKILL", |
| 100 | }); |
| 101 | const [cliStdout, cliStderr, cliExitCode] = yield* Effect.all( |
| 102 | [ |
| 103 | cli.stdout.pipe( |
| 104 | Stream.decodeText, |
| 105 | Stream.runCollect, |
| 106 | Effect.map((chunks) => chunks.join("")), |
| 107 | ), |
| 108 | cli.stderr.pipe( |
| 109 | Stream.decodeText, |
| 110 | Stream.runCollect, |
| 111 | Effect.map((chunks) => chunks.join("")), |
| 112 | ), |
| 113 | cli.exitCode, |
| 114 | ], |
| 115 | { concurrency: 3 }, |
| 116 | ); |
| 117 | expect(cliStderr).toBe(""); |
| 118 | expect(cliExitCode).toBe(0); |
| 119 | expect(cliStdout).toMatch(/alchemy v.*\(node [^,]+, src\)/); |
| 120 | }).pipe(Effect.scoped, Effect.provide(PlatformServices)), |
| 121 | { tags: ["local"], timeout: 60_000 }, |
| 122 | ); |