fix(build): validate Linux node-pty prebuilds in Windows artifacts (#13867)

This commit is contained in:
Yash Singh authored and GitHub committed 2026-09-26 15:38:24 -05:00
1 parent d110f98670
commit ea7d46ac10
3 files changed
+74 -21

No files matched your search

+61 -2
View File
@@ -175,6 +175,8 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
readonly copyUnpackedNatives: boolean;
readonly serverEntrySource?: string;
readonly wslRuntime?: "valid" | "loose-server-tree" | "missing-pty" | "bad-digest";
readonly targetArch?: "x64" | "arm64";
readonly ptyPrebuildArch?: "x64" | "arm64";
}) {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -212,7 +214,7 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
yield* fs.writeFileString(path.join(packagedAppDir, "chrome_crashpad_handler.exe"), "crashpad");
if (input.wslRuntime !== undefined) {
const stem = wslRuntimeArchiveStem(WINDOWS_PAYLOAD_FIXTURE_VERSION, "x64");
const stem = wslRuntimeArchiveStem(WINDOWS_PAYLOAD_FIXTURE_VERSION, input.targetArch ?? "x64");
const sourceArchivePath =
input.wslRuntime === "loose-server-tree"
? // The old hand-rolled runtime: apps/server/dist + node_modules at the
@@ -226,9 +228,16 @@ const makeWindowsPayloadFixture = Effect.fn("test.makeWindowsPayloadFixture")(fu
: yield* makeLinuxCliArchiveFixture({
root: path.join(tempDir, "wsl-runtime"),
stem,
...(input.wslRuntime === "missing-pty"
...(input.wslRuntime === "missing-pty" || input.ptyPrebuildArch !== undefined
? { omitMembers: [`${stem}/node_modules/node-pty/build/Release/pty.node`] }
: {}),
...(input.ptyPrebuildArch !== undefined
? {
extraMembers: [
`${stem}/node_modules/node-pty/prebuilds/linux-${input.ptyPrebuildArch}/pty.node`,
],
}
: {}),
});
const archivePath = path.join(resourcesDir, WSL_RUNTIME_ARCHIVE_NAME);
const hashPath = path.join(resourcesDir, WSL_RUNTIME_ARCHIVE_HASH_NAME);
@@ -1206,6 +1215,55 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
).pipe(Effect.provideService(HostProcessPlatform, "linux")),
);
for (const targetArch of ["x64", "arm64"] as const) {
it.effect(`accepts an embedded archive with the Linux ${targetArch} node-pty prebuild`, () =>
Effect.scoped(
Effect.gen(function* () {
const fixture = yield* makeWindowsPayloadFixture({
copyUnpackedNatives: true,
wslRuntime: "valid",
targetArch,
ptyPrebuildArch: targetArch,
});
const result = yield* validateWindowsPackagedPayload({
stageDistDir: fixture.stageDistDir,
appExecutableName: fixture.appExecutableName,
targetArch,
appVersion: WINDOWS_PAYLOAD_FIXTURE_VERSION,
expectWslRuntime: true,
});
assert.equal(result.packagedAppDir, fixture.packagedAppDir);
}),
).pipe(Effect.provideService(HostProcessPlatform, "linux")),
);
it.effect(
`rejects a node-pty prebuild for the wrong architecture in a Linux ${targetArch} archive`,
() =>
Effect.scoped(
Effect.gen(function* () {
const fixture = yield* makeWindowsPayloadFixture({
copyUnpackedNatives: true,
wslRuntime: "valid",
targetArch,
ptyPrebuildArch: targetArch === "x64" ? "arm64" : "x64",
});
const error = yield* validateWindowsPackagedPayload({
stageDistDir: fixture.stageDistDir,
appExecutableName: fixture.appExecutableName,
targetArch,
appVersion: WINDOWS_PAYLOAD_FIXTURE_VERSION,
expectWslRuntime: true,
}).pipe(Effect.flip);
assert.instanceOf(error, WindowsPackagedPayloadValidationError);
assert.equal(error.reason, "wsl-runtime-invalid");
}),
),
);
}
it.effect("rejects an embedded archive built for a different release version", () =>
Effect.scoped(
Effect.gen(function* () {
@@ -1285,6 +1343,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
assert.equal(error.reason, "wsl-runtime-invalid");
assert.deepStrictEqual(error.missingFiles, [
`${wslRuntimeArchiveStem(WINDOWS_PAYLOAD_FIXTURE_VERSION, "x64")}/node_modules/node-pty/build/Release/pty.node`,
`${wslRuntimeArchiveStem(WINDOWS_PAYLOAD_FIXTURE_VERSION, "x64")}/node_modules/node-pty/prebuilds/linux-x64/pty.node`,
]);
}),
),
+9 -6
View File
@@ -3291,13 +3291,16 @@ export const validateWindowsPackagedPayload = Effect.fn(
),
);
}
const requiredMembers = [
`${stem}/t3`,
`${stem}/client`,
`${stem}/node_modules`,
`${stem}/node_modules/node-pty/build/Release/pty.node`,
];
const requiredMembers = [`${stem}/t3`, `${stem}/client`, `${stem}/node_modules`];
const missingMembers = requiredMembers.filter((member) => !members.includes(member));
// node-pty can load a source build or the prebuild for the WSL target.
const ptyCandidates = [
`${stem}/node_modules/node-pty/build/Release/pty.node`,
`${stem}/node_modules/node-pty/prebuilds/linux-${input.targetArch}/pty.node`,
];
if (!ptyCandidates.some((member) => members.includes(member))) {
missingMembers.push(...ptyCandidates);
}
if (missingMembers.length > 0) {
return yield* new WindowsPackagedPayloadValidationError({
reason: "wsl-runtime-invalid",