Skip to content

Commit ce0460d

Browse files
committed
fix(release): verify packaged Linux desktop payloads
1 parent e455200 commit ce0460d

3 files changed

Lines changed: 375 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ jobs:
730730
rust_target: aarch64-unknown-linux-gnu
731731
resource_key: linux-arm64
732732
cli_archive: true
733+
launch_check: true
733734

734735
# The Windows jobs start with the other platforms and wait for the same-arch
735736
# Linux CLI archive after their other setup. Packaging is mostly CPU and

‎scripts/build-desktop-artifact.test.ts‎

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import {
5050
MacPackagedAppMissingError,
5151
stageBrowserSecret,
5252
validateMacPackagedPayload,
53+
validateLinuxPackagedPayload,
54+
LinuxPackagedPayloadValidationError,
5355
validateWindowsPackagedPayload,
5456
verifyPackagedBundleIsSelfContained,
5557
WindowsPrimaryNativeProbeError,
@@ -235,6 +237,91 @@ const makeMacPayloadFixture = Effect.fn("test.makeMacPayloadFixture")(function*
235237
return { stageDistDir } as const;
236238
});
237239

240+
const linuxExecutables = [
241+
"t3code",
242+
"resources/resource-monitor/t3-resource-monitor",
243+
"resources/kde-capture/t3-kde-snap-shot",
244+
"resources/hyprland-capture/t3-hyprland-snap-shot",
245+
"resources/browser-secret/t3-browser-secret",
246+
];
247+
const linuxAsarEntries = [
248+
"package.json",
249+
"apps/desktop/dist-electron/boot.cjs",
250+
"apps/desktop/dist-electron/main.cjs",
251+
"apps/desktop/dist-electron/preload.cjs",
252+
"apps/server/dist/bin.mjs",
253+
"apps/server/dist/client/index.html",
254+
];
255+
const linuxNativeEntries = (arch: "arm64" | "x64") => [
256+
"node_modules/node-pty/build/Release/pty.node",
257+
`node_modules/@napi-rs/keyring/keyring.linux-${arch}-gnu.node`,
258+
`node_modules/@ff-labs/fff-bin-linux-${arch}-gnu/libfff_c.so`,
259+
];
260+
const linuxGnomeFiles = [
261+
"metadata.json",
262+
"extension.js",
263+
"captureService.js",
264+
"captureFeedback.js",
265+
"feedbackGeometry.js",
266+
];
267+
const linuxElfHeader = (arch: "arm64" | "x64") => {
268+
const header = new Uint8Array(64);
269+
header.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]);
270+
header[18] = arch === "arm64" ? 183 : 62;
271+
return header;
272+
};
273+
const makeLinuxPayloadFixture = Effect.fn("test.makeLinuxPayloadFixture")(function* (input: {
274+
readonly arch: "arm64" | "x64";
275+
readonly omitEntry?: string;
276+
readonly serverEntrySource?: string;
277+
}) {
278+
const fs = yield* FileSystem.FileSystem;
279+
const path = yield* Path.Path;
280+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-linux-payload-test-" });
281+
const packagedAppDir = path.join(
282+
root,
283+
input.arch === "x64" ? "linux-unpacked" : "linux-arm64-unpacked",
284+
);
285+
const source = path.join(root, "source");
286+
for (const entry of [
287+
...linuxAsarEntries,
288+
...linuxNativeEntries(input.arch),
289+
"node_modules/extra/addon.node",
290+
]) {
291+
if (entry === input.omitEntry) continue;
292+
const filePath = path.join(source, entry);
293+
yield* fs.makeDirectory(path.dirname(filePath), { recursive: true });
294+
yield* fs.writeFile(
295+
filePath,
296+
entry.startsWith("node_modules/")
297+
? linuxElfHeader(input.arch)
298+
: new TextEncoder().encode(
299+
entry === "apps/server/dist/bin.mjs"
300+
? (input.serverEntrySource ?? "console.log('1.2.3');")
301+
: "{}",
302+
),
303+
);
304+
}
305+
yield* fs.makeDirectory(path.join(packagedAppDir, "resources"), { recursive: true });
306+
yield* Effect.promise(() =>
307+
createPackageWithOptions(source, path.join(packagedAppDir, "resources/app.asar"), {
308+
unpack: "{**/*.node,**/*.so}",
309+
}),
310+
);
311+
for (const entry of linuxExecutables) {
312+
const filePath = path.join(packagedAppDir, entry);
313+
yield* fs.makeDirectory(path.dirname(filePath), { recursive: true });
314+
yield* fs.writeFile(filePath, linuxElfHeader(input.arch));
315+
yield* fs.chmod(filePath, 0o755);
316+
}
317+
for (const entry of linuxGnomeFiles) {
318+
const filePath = path.join(packagedAppDir, "resources/gnome-extension", entry);
319+
yield* fs.makeDirectory(path.dirname(filePath), { recursive: true });
320+
yield* fs.writeFileString(filePath, "{}");
321+
}
322+
return { stageDistDir: root, packagedAppDir };
323+
});
324+
238325
it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
239326
it.effect("rejects overlapping builds from another process until restoration finishes", () =>
240327
Effect.gen(function* () {
@@ -1334,6 +1421,138 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
13341421
),
13351422
);
13361423

1424+
it.effect("validates Linux payloads for both release architectures", () =>
1425+
Effect.scoped(
1426+
Effect.gen(function* () {
1427+
for (const arch of ["arm64", "x64"] as const) {
1428+
const fixture = yield* makeLinuxPayloadFixture({ arch });
1429+
yield* validateLinuxPackagedPayload({
1430+
stageDistDir: fixture.stageDistDir,
1431+
targetArch: arch,
1432+
});
1433+
}
1434+
}),
1435+
),
1436+
);
1437+
1438+
it.effect("rejects missing Linux payload files and archive entries", () =>
1439+
Effect.scoped(
1440+
Effect.gen(function* () {
1441+
const fs = yield* FileSystem.FileSystem;
1442+
const path = yield* Path.Path;
1443+
for (const arch of ["arm64", "x64"] as const) {
1444+
const fixture = yield* makeLinuxPayloadFixture({ arch });
1445+
const files = [
1446+
"resources/app.asar",
1447+
...linuxExecutables,
1448+
...linuxGnomeFiles.map((file) => `resources/gnome-extension/${file}`),
1449+
...linuxNativeEntries(arch).map((file) => `resources/app.asar.unpacked/${file}`),
1450+
"resources/app.asar.unpacked/node_modules/extra/addon.node",
1451+
];
1452+
for (const file of files) {
1453+
const filePath = path.join(fixture.packagedAppDir, file);
1454+
yield* fs.rename(filePath, `${filePath}.saved`);
1455+
const error = yield* validateLinuxPackagedPayload({
1456+
stageDistDir: fixture.stageDistDir,
1457+
targetArch: arch,
1458+
}).pipe(Effect.flip);
1459+
assert.instanceOf(error, LinuxPackagedPayloadValidationError);
1460+
assert.include(error.filePath, file);
1461+
yield* fs.rename(`${filePath}.saved`, filePath);
1462+
}
1463+
for (const omitEntry of [...linuxAsarEntries, ...linuxNativeEntries(arch)]) {
1464+
const missing = yield* makeLinuxPayloadFixture({ arch, omitEntry });
1465+
const error = yield* validateLinuxPackagedPayload({
1466+
stageDistDir: missing.stageDistDir,
1467+
targetArch: arch,
1468+
}).pipe(Effect.flip);
1469+
assert.instanceOf(error, LinuxPackagedPayloadValidationError);
1470+
assert.include(error.filePath, omitEntry);
1471+
}
1472+
yield* fs.writeFileString(
1473+
path.join(fixture.packagedAppDir, "resources/app.asar"),
1474+
"invalid archive",
1475+
);
1476+
const invalidArchive = yield* validateLinuxPackagedPayload({
1477+
stageDistDir: fixture.stageDistDir,
1478+
targetArch: arch,
1479+
}).pipe(Effect.flip);
1480+
assert.instanceOf(invalidArchive, LinuxPackagedPayloadValidationError);
1481+
assert.include(invalidArchive.filePath, "app.asar");
1482+
}
1483+
}),
1484+
),
1485+
);
1486+
1487+
it.effect(
1488+
"rejects Linux binaries of the wrong architecture, invalid ELF headers and non-executable helpers",
1489+
() =>
1490+
Effect.scoped(
1491+
Effect.gen(function* () {
1492+
const fs = yield* FileSystem.FileSystem;
1493+
const path = yield* Path.Path;
1494+
for (const arch of ["arm64", "x64"] as const) {
1495+
const fixture = yield* makeLinuxPayloadFixture({ arch });
1496+
for (const file of [
1497+
...linuxExecutables,
1498+
...linuxNativeEntries(arch).map((entry) => `resources/app.asar.unpacked/${entry}`),
1499+
]) {
1500+
const filePath = path.join(fixture.packagedAppDir, file);
1501+
for (const header of [
1502+
linuxElfHeader(arch === "arm64" ? "x64" : "arm64"),
1503+
new Uint8Array(),
1504+
new Uint8Array(64),
1505+
]) {
1506+
yield* fs.writeFile(filePath, header);
1507+
const error = yield* validateLinuxPackagedPayload({
1508+
stageDistDir: fixture.stageDistDir,
1509+
targetArch: arch,
1510+
}).pipe(Effect.flip);
1511+
assert.instanceOf(error, LinuxPackagedPayloadValidationError);
1512+
assert.equal(error.filePath, filePath);
1513+
}
1514+
yield* fs.writeFile(filePath, linuxElfHeader(arch));
1515+
}
1516+
for (const file of linuxExecutables) {
1517+
const filePath = path.join(fixture.packagedAppDir, file);
1518+
yield* fs.chmod(filePath, 0o644);
1519+
const error = yield* validateLinuxPackagedPayload({
1520+
stageDistDir: fixture.stageDistDir,
1521+
targetArch: arch,
1522+
}).pipe(Effect.flip);
1523+
assert.instanceOf(error, LinuxPackagedPayloadValidationError);
1524+
assert.equal(error.filePath, filePath);
1525+
yield* fs.chmod(filePath, 0o755);
1526+
}
1527+
}
1528+
}),
1529+
),
1530+
);
1531+
1532+
it.effect("rejects a Linux app whose packaged server cannot resolve", () =>
1533+
Effect.scoped(
1534+
Effect.gen(function* () {
1535+
const fixture = yield* makeLinuxPayloadFixture({
1536+
arch: "arm64",
1537+
serverEntrySource: 'import "t3code-deliberately-missing-package";',
1538+
});
1539+
const error = yield* validateLinuxPackagedPayload({
1540+
stageDistDir: fixture.stageDistDir,
1541+
targetArch: "arm64",
1542+
}).pipe(Effect.flip);
1543+
assert.instanceOf(error, BundleNotSelfContainedError);
1544+
assert.include(error.output, "t3code-deliberately-missing-package");
1545+
}),
1546+
).pipe(
1547+
Effect.provide(
1548+
Layer.mergeAll(
1549+
Layer.succeed(HostProcess.Platform, "linux"),
1550+
Layer.succeed(HostProcess.Architecture, "arm64"),
1551+
),
1552+
),
1553+
),
1554+
);
1555+
13371556
it.effect("rejects a macOS app whose packaged server bundle cannot resolve", () =>
13381557
Effect.scoped(
13391558
Effect.gen(function* () {

0 commit comments

Comments
 (0)