Skip to content

Commit 3b7b1a3

Browse files
committed
fix(cli): lint says nothing when the OS refuses to lower its priority
1 parent f55990e commit 3b7b1a3

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎packages/cli/src/renderSetupWorker.priority.test.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,31 @@ it("lints at the lowest CPU priority so it never competes with a Studio boot", a
2525
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
2626
});
2727

28-
it("still lints when a sandbox forbids lowering the priority", async () => {
28+
const nodeSystemErrorWithOsCodeInInfo = (code: string) =>
29+
Object.assign(new Error(`A system error occurred: uv_os_setpriority returned ${code}`), {
30+
code: "ERR_SYSTEM_ERROR",
31+
info: { code, syscall: "uv_os_setpriority" },
32+
});
33+
34+
it.each(["EPERM", "EACCES"])(
35+
"still lints, saying nothing, when a sandbox refuses lowering the priority (%s)",
36+
async (code) => {
37+
os.setPriority.mockImplementation(() => {
38+
throw nodeSystemErrorWithOsCodeInInfo(code);
39+
});
40+
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
41+
const warn = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
42+
43+
await import("./renderSetupWorker.js");
44+
45+
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
46+
expect(warn).not.toHaveBeenCalled();
47+
},
48+
);
49+
50+
it("still names any other priority failure, and lints", async () => {
2951
os.setPriority.mockImplementation(() => {
30-
throw new Error("uv_os_setpriority returned EPERM (operation not permitted)");
52+
throw nodeSystemErrorWithOsCodeInInfo("ESRCH");
3153
});
3254
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
3355
const warn = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
@@ -36,5 +58,5 @@ it("still lints when a sandbox forbids lowering the priority", async () => {
3658

3759
expect(write).toHaveBeenCalledWith(expect.stringContaining('{"ok":true}'));
3860
expect(warn).toHaveBeenCalledTimes(1);
39-
expect(warn).toHaveBeenCalledWith(expect.stringContaining("EPERM"));
61+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("ESRCH"));
4062
});

‎packages/cli/src/renderSetupWorker.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ const disposeSignalHandlers = installRenderSetupSignalHandlers(
2020
process.env.HYPERFRAMES_RENDER_DETACHED !== "1",
2121
);
2222

23+
const SANDBOX_REFUSED_PRIORITY = new Set(["EPERM", "EACCES"]);
24+
2325
function lowerPriority(): void {
2426
try {
2527
setPriority(constants.priority.PRIORITY_LOW);
2628
} catch (error) {
29+
if (SANDBOX_REFUSED_PRIORITY.has((error as { info?: { code?: string } }).info?.code ?? ""))
30+
return;
2731
process.stderr.write(`Lint runs at normal priority: ${(error as Error).message}\n`);
2832
}
2933
}

0 commit comments

Comments
 (0)