11import { constants } from "node:os" ;
2- import { afterEach , expect , it , vi } from "vitest" ;
2+ import { afterEach , beforeEach , expect , it , vi } from "vitest" ;
33
44const os = vi . hoisted ( ( ) => ( { setPriority : vi . fn ( ) } ) ) ;
55vi . mock ( "node:os" , async ( importOriginal ) => ( {
@@ -8,15 +8,33 @@ vi.mock("node:os", async (importOriginal) => ({
88} ) ) ;
99vi . mock ( "./utils/lintProject.js" , ( ) => ( { lintProject : vi . fn ( async ( ) => ( { ok : true } ) ) } ) ) ;
1010
11+ beforeEach ( ( ) => {
12+ vi . resetModules ( ) ;
13+ os . setPriority . mockReset ( ) ;
14+ process . argv [ 2 ] = "lint" ;
15+ process . env . HYPERFRAMES_RENDER_SETUP_INPUT = JSON . stringify ( { projectDir : "/project" } ) ;
16+ } ) ;
1117afterEach ( ( ) => vi . restoreAllMocks ( ) ) ;
1218
1319it ( "lints at the lowest CPU priority so it never competes with a Studio boot" , async ( ) => {
14- process . argv [ 2 ] = "lint" ;
15- process . env . HYPERFRAMES_RENDER_SETUP_INPUT = JSON . stringify ( { projectDir : "/project" } ) ;
1620 const write = vi . spyOn ( process . stdout , "write" ) . mockImplementation ( ( ) => true ) ;
1721
1822 await import ( "./renderSetupWorker.js" ) ;
1923
2024 expect ( os . setPriority ) . toHaveBeenCalledWith ( constants . priority . PRIORITY_LOW ) ;
2125 expect ( write ) . toHaveBeenCalledWith ( expect . stringContaining ( '{"ok":true}' ) ) ;
2226} ) ;
27+
28+ it ( "still lints when a sandbox forbids lowering the priority" , async ( ) => {
29+ os . setPriority . mockImplementation ( ( ) => {
30+ throw new Error ( "uv_os_setpriority returned EPERM (operation not permitted)" ) ;
31+ } ) ;
32+ const write = vi . spyOn ( process . stdout , "write" ) . mockImplementation ( ( ) => true ) ;
33+ const warn = vi . spyOn ( process . stderr , "write" ) . mockImplementation ( ( ) => true ) ;
34+
35+ await import ( "./renderSetupWorker.js" ) ;
36+
37+ expect ( write ) . toHaveBeenCalledWith ( expect . stringContaining ( '{"ok":true}' ) ) ;
38+ expect ( warn ) . toHaveBeenCalledTimes ( 1 ) ;
39+ expect ( warn ) . toHaveBeenCalledWith ( expect . stringContaining ( "EPERM" ) ) ;
40+ } ) ;
0 commit comments