Skip to content

Commit eab2b94

Browse files
committed
fix(server): apply Effect overrides at pinned-runtime install root
npm only honors overrides on the root project, so installing t3 into an empty staging directory ignored published Effect pins and hung on ERESOLVE. Write the target's Effect overrides into the staging manifest before install, and surface a truncated npm output tail when install fails.
1 parent 211618f commit eab2b94

3 files changed

Lines changed: 314 additions & 60 deletions

File tree

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,18 @@ export class BootServiceCommandError extends Schema.TaggedError<BootServiceComma
389389
exitCode: Schema.optional(Schema.Number),
390390
stdoutLength: Schema.optional(Schema.Number),
391391
stderrLength: Schema.optional(Schema.Number),
392+
outputTail: Schema.optional(Schema.String),
392393
cause: Schema.optional(Schema.Defect()),
393394
},
394395
) {
395396
override get message(): string {
396-
return this.exitCode === undefined
397-
? `Background setup failed while ${this.step}.`
398-
: `Background setup failed while ${this.step} (exit code ${this.exitCode}).`;
397+
const base =
398+
this.exitCode === undefined
399+
? `Background setup failed while ${this.step}.`
400+
: `Background setup failed while ${this.step} (exit code ${this.exitCode}).`;
401+
return this.outputTail === undefined || this.outputTail.length === 0
402+
? base
403+
: `${base}\n${this.outputTail}`;
399404
}
400405
}
401406

@@ -745,6 +750,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
745750
exitCode: error.exitCode,
746751
stdoutLength: error.stdoutLength,
747752
stderrLength: error.stderrLength,
753+
outputTail: error.outputTail,
748754
cause: error,
749755
})
750756
: new BootServiceInstallError({ cause: error }),

‎apps/server/src/cloud/pinnedRuntime.test.ts‎

Lines changed: 157 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,174 @@ import {
1313
ensurePinnedRuntimeInstalled,
1414
pinnedRuntimePaths,
1515
PinnedRuntimeInstallError,
16+
selectEffectOverrides,
17+
truncateProcessOutputTail,
1618
} from "./pinnedRuntime.ts";
1719

20+
const effectOverridesJson = JSON.stringify({
21+
effect: "4.0.0-rc.112",
22+
"@effect/platform-node": "4.0.0-rc.112",
23+
"@effect/platform-node-shared": "4.0.0-rc.112",
24+
vite: "npm:@voidzero-dev/[email protected]",
25+
});
26+
27+
const okResult = (stdout = "", stderr = "") => ({
28+
stdout,
29+
stderr,
30+
code: ChildProcessSpawner.ExitCode(0),
31+
timedOut: false,
32+
stdoutTruncated: false,
33+
stderrTruncated: false,
34+
stdoutInvalidUtf8: false,
35+
stderrInvalidUtf8: false,
36+
});
37+
38+
const failedResult = (stderr: string, stdout = "") => ({
39+
...okResult(stdout, stderr),
40+
code: ChildProcessSpawner.ExitCode(1),
41+
});
42+
43+
const isNpmView = (input: ProcessRunner.ProcessRunInput) =>
44+
input.args[0] === "view" || (input.command === "pnpm" && input.args.includes("view"));
45+
46+
const isNpmInstall = (input: ProcessRunner.ProcessRunInput) =>
47+
input.args[0] === "install" || (input.command === "pnpm" && input.args.includes("install"));
48+
49+
const stagingPrefix = (input: ProcessRunner.ProcessRunInput) => {
50+
const prefixIndex = input.args.indexOf("--prefix");
51+
return input.args[prefixIndex + 1];
52+
};
53+
1854
const successfulRunner = (fs: FileSystem.FileSystem, path: Path.Path) =>
1955
ProcessRunner.ProcessRunner.of({
2056
run: (input) =>
2157
Effect.gen(function* () {
22-
const prefixIndex = input.args.indexOf("--prefix");
23-
const stagingDir = input.args[prefixIndex + 1];
58+
if (isNpmView(input)) {
59+
return okResult(effectOverridesJson);
60+
}
61+
if (!isNpmInstall(input)) {
62+
return yield* Effect.die(`unexpected command: ${input.command} ${input.args.join(" ")}`);
63+
}
64+
const stagingDir = stagingPrefix(input);
2465
if (stagingDir === undefined) return yield* Effect.die("missing npm --prefix");
66+
assert.isUndefined(
67+
input.args.find((arg) => arg.startsWith("t3@")),
68+
"install must use the staging manifest, not a positional t3@version",
69+
);
2570
const entry = path.join(stagingDir, "node_modules", "t3", "dist", "bin.mjs");
2671
yield* fs.makeDirectory(path.dirname(entry), { recursive: true }).pipe(Effect.orDie);
2772
yield* fs.writeFileString(entry, "export {};\n").pipe(Effect.orDie);
28-
return {
29-
stdout: "",
30-
stderr: "",
31-
code: ChildProcessSpawner.ExitCode(0),
32-
timedOut: false,
33-
stdoutTruncated: false,
34-
stderrTruncated: false,
35-
stdoutInvalidUtf8: false,
36-
stderrInvalidUtf8: false,
37-
};
73+
return okResult();
3874
}),
3975
});
4076

77+
it("selectEffectOverrides keeps only effect and @effect/* string pins", () => {
78+
assert.deepEqual(
79+
selectEffectOverrides({
80+
effect: "4.0.0-rc.112",
81+
"@effect/platform-node": "4.0.0-rc.112",
82+
vite: "1.0.0",
83+
"@clerk/react": "6.0.0",
84+
"@effect/broken": 12,
85+
}),
86+
{
87+
effect: "4.0.0-rc.112",
88+
"@effect/platform-node": "4.0.0-rc.112",
89+
},
90+
);
91+
});
92+
93+
it("truncateProcessOutputTail keeps a bounded suffix", () => {
94+
assert.equal(truncateProcessOutputTail(""), undefined);
95+
assert.equal(truncateProcessOutputTail("short"), "short");
96+
const long = "x".repeat(3000);
97+
const tail = truncateProcessOutputTail(long);
98+
assert.equal(tail?.length, 2048);
99+
assert.equal(tail, long.slice(long.length - 2048));
100+
});
101+
41102
it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
103+
it.effect("writes Effect overrides into the staging manifest before install", () =>
104+
Effect.gen(function* () {
105+
const fs = yield* FileSystem.FileSystem;
106+
const path = yield* Path.Path;
107+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-manifest-" });
108+
const commands: Array<ProcessRunner.ProcessRunInput> = [];
109+
let manifestBeforeInstall: unknown;
110+
111+
yield* ensurePinnedRuntimeInstalled({
112+
baseDir,
113+
version: "1.2.3",
114+
fs,
115+
path,
116+
runner: ProcessRunner.ProcessRunner.of({
117+
run: (input) =>
118+
Effect.gen(function* () {
119+
commands.push(input);
120+
if (isNpmView(input)) {
121+
assert.deepEqual(input.args, ["view", "[email protected]", "overrides", "--json"]);
122+
return okResult(effectOverridesJson);
123+
}
124+
const stagingDir = stagingPrefix(input);
125+
if (stagingDir === undefined) return yield* Effect.die("missing npm --prefix");
126+
manifestBeforeInstall = JSON.parse(
127+
yield* fs.readFileString(path.join(stagingDir, "package.json")).pipe(Effect.orDie),
128+
);
129+
return yield* successfulRunner(fs, path).run(input);
130+
}),
131+
}),
132+
validate: () => Effect.void,
133+
});
134+
135+
assert.equal(commands[0]?.args[0], "view");
136+
assert.equal(commands[1]?.args[0], "install");
137+
assert.deepEqual(commands[1]?.args, [
138+
"install",
139+
"--prefix",
140+
stagingPrefix(commands[1]!),
141+
"--no-fund",
142+
"--no-audit",
143+
]);
144+
assert.deepEqual(manifestBeforeInstall, {
145+
dependencies: { t3: "1.2.3" },
146+
overrides: {
147+
effect: "4.0.0-rc.112",
148+
"@effect/platform-node": "4.0.0-rc.112",
149+
"@effect/platform-node-shared": "4.0.0-rc.112",
150+
},
151+
});
152+
}),
153+
);
154+
155+
it.effect("surfaces a truncated npm stderr tail when install fails", () =>
156+
Effect.gen(function* () {
157+
const fs = yield* FileSystem.FileSystem;
158+
const path = yield* Path.Path;
159+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-stderr-" });
160+
const stderr = `npm warn ERESOLVE overriding peer dependency\n${"x".repeat(2500)}`;
161+
162+
const error = yield* ensurePinnedRuntimeInstalled({
163+
baseDir,
164+
version: "1.2.3",
165+
fs,
166+
path,
167+
runner: ProcessRunner.ProcessRunner.of({
168+
run: (input) =>
169+
isNpmView(input)
170+
? Effect.succeed(okResult(effectOverridesJson))
171+
: Effect.succeed(failedResult(stderr)),
172+
}),
173+
validate: () => Effect.die("must not validate a failed install"),
174+
}).pipe(Effect.flip);
175+
176+
assert.equal(error._tag, "PinnedRuntimeInstallError");
177+
assert.equal(error.exitCode, 1);
178+
assert.isTrue(error.message.includes("exit code 1"));
179+
assert.equal(error.outputTail, truncateProcessOutputTail(stderr));
180+
assert.isTrue(error.message.endsWith(error.outputTail!));
181+
}),
182+
);
183+
42184
it.effect("installs through pnpm when its Node runtime has no npm executable", () =>
43185
Effect.gen(function* () {
44186
const fs = yield* FileSystem.FileSystem;
@@ -77,9 +219,10 @@ it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
77219
});
78220
assert.deepEqual(
79221
commands.map((command) => command.command),
80-
["npm", "pnpm"],
222+
["npm", "pnpm", "npm", "pnpm"],
81223
);
82224
assert.deepEqual(commands[1]!.args, ["--package=npm@11", "dlx", "npm", ...commands[0]!.args]);
225+
assert.deepEqual(commands[3]!.args, ["--package=npm@11", "dlx", "npm", ...commands[2]!.args]);
83226
assert.equal(yield* fs.readFileString(paths.sentinelPath), "1.2.3\n");
84227
}),
85228
);
@@ -113,6 +256,7 @@ it.layer(NodeServices.layer)("ensurePinnedRuntimeInstalled", (it) => {
113256
}),
114257
validate: () => Effect.die("must not validate a failed install"),
115258
}).pipe(Effect.flip);
259+
// Fails on the first npm (view) without falling back to pnpm.
116260
assert.deepEqual(commands, ["npm"]);
117261
}),
118262
);

0 commit comments

Comments
 (0)