Skip to content

Commit 363ebe4

Browse files
committed
Make tests platform specific.
1 parent 67c4fbb commit 363ebe4

File tree

2 files changed

+38
-56
lines changed

2 files changed

+38
-56
lines changed

src/handlers/pathHandlers.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function registerPathHandlers() {
3838
return {
3939
appData: app.getPath('appData'),
4040
appPath: app.getAppPath(),
41-
defaultInstallPath: path.win32.join(documentsPath, 'ComfyUI'),
41+
defaultInstallPath: path.join(documentsPath, 'ComfyUI'),
4242
};
4343
}
4444

@@ -74,9 +74,13 @@ export function registerPathHandlers() {
7474
if (process.platform === 'win32') {
7575
// Check if path is in OneDrive
7676
const { oneDrive } = process.env;
77-
const normalizedPath = path.resolve(inputPath);
78-
if (oneDrive && path.resolve(oneDrive).toLowerCase().startsWith(normalizedPath.toLowerCase())) {
79-
result.isOneDrive = true;
77+
if (oneDrive) {
78+
const normalizedInput = path.resolve(inputPath).toLowerCase();
79+
const normalizedOneDrive = path.resolve(oneDrive).toLowerCase();
80+
// Check if the normalized OneDrive path is a parent of the input path
81+
if (normalizedInput.startsWith(normalizedOneDrive)) {
82+
result.isOneDrive = true;
83+
}
8084
}
8185

8286
// Check if path is on non-default drive
@@ -113,17 +117,15 @@ export function registerPathHandlers() {
113117
result.error = `${error}`;
114118
}
115119

116-
result.isValid = true; // Start with true and set to false if any validation fails
117-
if (
120+
result.isValid =
118121
result.cannotWrite ||
119122
result.parentMissing ||
120123
result.freeSpace < requiredSpace ||
121124
result.error ||
122125
result.isOneDrive ||
123126
result.isNonDefaultDrive
124-
) {
125-
result.isValid = false;
126-
}
127+
? false
128+
: true;
127129
return result;
128130
}
129131
);

tests/unit/handlers/pathHandler.test.ts

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,6 @@ const mockFileSystem = ({ exists = true, writable = true } = {}) => {
8383
}
8484
};
8585

86-
const mockProcessPlatform = (platform: string, systemDrive?: string) => {
87-
const originalPlatform = process.platform;
88-
const originalSystemDrive = process.env.SystemDrive;
89-
Object.defineProperty(process, 'platform', { value: platform });
90-
if (systemDrive) {
91-
process.env = { ...process.env, SystemDrive: systemDrive };
92-
}
93-
return () => {
94-
Object.defineProperty(process, 'platform', { value: originalPlatform });
95-
if (systemDrive) {
96-
process.env = { ...process.env, SystemDrive: originalSystemDrive };
97-
}
98-
};
99-
};
100-
10186
type HandlerType<T extends (...args: never[]) => unknown> = T;
10287
type IpcHandler = (event: IpcMainEvent, ...args: unknown[]) => unknown;
10388

@@ -156,23 +141,27 @@ describe('PathHandlers', () => {
156141
});
157142

158143
it('Windows: accepts valid install path with sufficient space', async () => {
144+
if (process.platform !== 'win32') {
145+
return;
146+
}
159147
mockFileSystem({ exists: true, writable: true });
160-
const restorePlatform = mockProcessPlatform('win32', '/');
148+
161149
const result = await validateHandler({}, '/valid/path');
162150
expect(result).toMatchObject({
163151
isValid: true,
164152
exists: true,
165153
freeSpace: DEFAULT_FREE_SPACE,
166154
requiredSpace: WIN_REQUIRED_SPACE,
155+
isOneDrive: false,
167156
});
168-
169-
restorePlatform();
170157
});
171158

172159
it('Windows: rejects path with insufficient disk space', async () => {
160+
if (process.platform !== 'win32') {
161+
return;
162+
}
173163
mockFileSystem({ exists: true, writable: true });
174164
mockDiskSpace(LOW_FREE_SPACE);
175-
const restorePlatform = mockProcessPlatform('win32');
176165

177166
const result = await validateHandler({}, '/low/space/path');
178167
expect(result).toMatchObject({
@@ -181,28 +170,29 @@ describe('PathHandlers', () => {
181170
freeSpace: LOW_FREE_SPACE,
182171
requiredSpace: WIN_REQUIRED_SPACE,
183172
});
184-
185-
restorePlatform();
186173
});
187174

188175
it('Mac: accepts valid install path with sufficient space', async () => {
176+
if (process.platform !== 'darwin') {
177+
return;
178+
}
189179
mockFileSystem({ exists: true, writable: true });
190-
const restorePlatform = mockProcessPlatform('darwin');
180+
191181
const result = await validateHandler({}, '/valid/path');
192182
expect(result).toMatchObject({
193183
isValid: true,
194184
exists: true,
195185
freeSpace: DEFAULT_FREE_SPACE,
196186
requiredSpace: MAC_REQUIRED_SPACE,
197187
});
198-
199-
restorePlatform();
200188
});
201189

202190
it('Mac: rejects path with insufficient disk space', async () => {
191+
if (process.platform !== 'darwin') {
192+
return;
193+
}
203194
mockFileSystem({ exists: true, writable: true });
204195
mockDiskSpace(LOW_FREE_SPACE_MAC);
205-
const restorePlatform = mockProcessPlatform('darwin');
206196

207197
const result = await validateHandler({}, '/low/space/path');
208198
expect(result).toMatchObject({
@@ -211,8 +201,6 @@ describe('PathHandlers', () => {
211201
freeSpace: LOW_FREE_SPACE_MAC,
212202
requiredSpace: MAC_REQUIRED_SPACE,
213203
});
214-
215-
restorePlatform();
216204
});
217205

218206
it('rejects path with missing parent directory', async () => {
@@ -239,15 +227,15 @@ describe('PathHandlers', () => {
239227
});
240228

241229
it('Windows: should handle and log errors during validation', async () => {
230+
if (process.platform !== 'win32') {
231+
return;
232+
}
242233
const mockError = new Error('Test error');
243234
vi.mocked(fs.existsSync).mockImplementation(() => {
244235
throw mockError;
245236
});
246237
vi.spyOn(log, 'error').mockImplementation(() => {});
247238

248-
// Mock process.platform is win32
249-
const restorePlatform = mockProcessPlatform('win32');
250-
251239
const result = await validateHandler({}, '/error/path');
252240

253241
expect(result).toMatchObject({
@@ -257,14 +245,13 @@ describe('PathHandlers', () => {
257245
requiredSpace: WIN_REQUIRED_SPACE,
258246
});
259247
expect(log.error).toHaveBeenCalledWith('Error validating install path:', mockError);
260-
261-
// Restore original platform
262-
restorePlatform();
263248
});
264249

265250
it('Windows: OneDrive paths not allowed', async () => {
266251
mockFileSystem({ exists: true, writable: true });
267-
const restorePlatform = mockProcessPlatform('win32');
252+
if (process.platform !== 'win32') {
253+
return;
254+
}
268255

269256
const result = await validateHandler({}, String.raw`C:\Users\Test\OneDrive\ComfyUI`);
270257

@@ -273,15 +260,13 @@ describe('PathHandlers', () => {
273260
isOneDrive: true,
274261
requiredSpace: WIN_REQUIRED_SPACE,
275262
});
276-
277-
// Restore original platform
278-
restorePlatform();
279263
});
280264

281265
it('Windows: non-system drive paths not allowed', async () => {
266+
if (process.platform !== 'win32') {
267+
return;
268+
}
282269
mockFileSystem({ exists: true, writable: true });
283-
const restorePlatform = mockProcessPlatform('win32', 'C:');
284-
285270
const result = await validateHandler({}, String.raw`D:\ComfyUI`);
286271

287272
expect(result).toMatchObject({
@@ -291,9 +276,6 @@ describe('PathHandlers', () => {
291276
isNonDefaultDrive: true,
292277
requiredSpace: WIN_REQUIRED_SPACE,
293278
});
294-
295-
// Restore original values
296-
restorePlatform();
297279
});
298280
});
299281

@@ -356,16 +338,14 @@ describe('PathHandlers', () => {
356338
});
357339

358340
it('Windows: should remove OneDrive from documents path', async () => {
359-
// Mock Windows platform
360-
const restorePlatform = mockProcessPlatform('win32');
341+
if (process.platform !== 'win32') {
342+
return;
343+
}
361344
mockPaths({ documents: String.raw`C:\Users\Test\OneDrive\Documents` });
362345

363346
const result = await getSystemPathsHandler({});
364347
const expected = String.raw`C:\Users\Test\Documents\ComfyUI`;
365348
expect(result.defaultInstallPath).toBe(expected);
366-
367-
// Restore original platform
368-
restorePlatform();
369349
});
370350
});
371351

0 commit comments

Comments
 (0)