| ... | ... | @@ -5,6 +5,7 @@ import * as Effect from "effect/Effect"; |
| 5 | 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | 6 | import * as Fiber from "effect/Fiber"; |
| 7 | 7 | import * as Path from "effect/Path"; |
| 8 | import * as PlatformError from "effect/PlatformError"; |
| 8 | 9 | import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; |
| 9 | 10 | |
| 10 | 11 | import * as ProcessRunner from "../processRunner.ts"; |
| ... | ... | @@ -38,6 +39,84 @@ const successfulRunner = (fs: FileSystem.FileSystem, path: Path.Path) => |
| 38 | 39 | }); |
| 39 | 40 | |
| 40 | 41 | it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => { |
| 42 | it.effect("installs through pnpm when its Node runtime has no npm executable", () => |
| 43 | Effect.gen(function* () { |
| 44 | const fs = yield* FileSystem.FileSystem; |
| 45 | const path = yield* Path.Path; |
| 46 | const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-pnpm-" }); |
| 47 | const commands: Array<ProcessRunner.ProcessRunInput> = []; |
| 48 | const install = successfulRunner(fs, path); |
| 49 | const paths = yield* ensurePinnedRuntimeInstalled({ |
| 50 | baseDir, |
| 51 | version: "1.2.3", |
| 52 | fs, |
| 53 | path, |
| 54 | runner: ProcessRunner.ProcessRunner.of({ |
| 55 | run: (input) => { |
| 56 | commands.push(input); |
| 57 | return input.command === "npm" |
| 58 | ? Effect.fail( |
| 59 | new ProcessRunner.ProcessSpawnError({ |
| 60 | command: "npm", |
| 61 | argumentCount: input.args.length, |
| 62 | cause: PlatformError.systemError({ |
| 63 | _tag: "NotFound", |
| 64 | module: "ChildProcess", |
| 65 | method: "spawn", |
| 66 | }), |
| 67 | }), |
| 68 | ) |
| 69 | : install.run(input); |
| 70 | }, |
| 71 | }), |
| 72 | validate: (staging) => |
| 73 | fs.exists(staging.entryPath).pipe( |
| 74 | Effect.flatMap((exists) => (exists ? Effect.void : Effect.die("missing runtime"))), |
| 75 | Effect.orDie, |
| 76 | ), |
| 77 | }); |
| 78 | assert.deepEqual( |
| 79 | commands.map((command) => command.command), |
| 80 | ["npm", "pnpm"], |
| 81 | ); |
| 82 | assert.deepEqual(commands[1]!.args, ["--package=npm@11", "dlx", "npm", ...commands[0]!.args]); |
| 83 | assert.equal(yield* fs.readFileString(paths.sentinelPath), "1.2.3\n"); |
| 84 | }), |
| 85 | ); |
| 86 | |
| 87 | it.effect("does not try a different installer for npm permission failures", () => |
| 88 | Effect.gen(function* () { |
| 89 | const fs = yield* FileSystem.FileSystem; |
| 90 | const path = yield* Path.Path; |
| 91 | const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-permission-" }); |
| 92 | const commands: string[] = []; |
| 93 | yield* ensurePinnedRuntimeInstalled({ |
| 94 | baseDir, |
| 95 | version: "1.2.3", |
| 96 | fs, |
| 97 | path, |
| 98 | runner: ProcessRunner.ProcessRunner.of({ |
| 99 | run: (input) => { |
| 100 | commands.push(input.command); |
| 101 | return Effect.fail( |
| 102 | new ProcessRunner.ProcessSpawnError({ |
| 103 | command: input.command, |
| 104 | argumentCount: input.args.length, |
| 105 | cause: PlatformError.systemError({ |
| 106 | _tag: "PermissionDenied", |
| 107 | module: "ChildProcess", |
| 108 | method: "spawn", |
| 109 | }), |
| 110 | }), |
| 111 | ); |
| 112 | }, |
| 113 | }), |
| 114 | validate: () => Effect.die("must not validate a failed install"), |
| 115 | }).pipe(Effect.flip); |
| 116 | assert.deepEqual(commands, ["npm"]); |
| 117 | }), |
| 118 | ); |
| 119 | |
| 41 | 120 | it.effect("validates a staging tree before atomically publishing it", () => |
| 42 | 121 | Effect.gen(function* () { |
| 43 | 122 | const fs = yield* FileSystem.FileSystem; |