@@ -3,7 +3,7 @@ import log from 'electron-log/main';
33import { ChildProcess } from 'node:child_process' ;
44import { EventEmitter } from 'node:events' ;
55import path from 'node:path' ;
6- import { test as baseTest , describe , expect , vi } from 'vitest' ;
6+ import { afterEach , test as baseTest , describe , expect , vi } from 'vitest' ;
77import waitOn from 'wait-on' ;
88
99import { ServerArgs } from '@/constants' ;
@@ -64,13 +64,7 @@ const test = baseTest.extend<TestContext>({
6464 transports : { file : { transforms : [ ] } } ,
6565 } as unknown as MainLogger & { default : MainLogger } ) ;
6666
67- const server = new ComfyServer (
68- basePath ,
69- mockServerArgs ,
70- mockVirtualEnvironment as any ,
71- mockAppWindow as any ,
72- mockTelemetry as any
73- ) ;
67+ const server = new ComfyServer ( basePath , mockServerArgs , mockVirtualEnvironment , mockAppWindow , mockTelemetry ) ;
7468 await use ( server ) ;
7569 } ,
7670 runningServer : async ( { server, mockProcess } , use ) => {
@@ -80,6 +74,10 @@ const test = baseTest.extend<TestContext>({
8074 } ,
8175} ) ;
8276
77+ afterEach ( ( ) => {
78+ vi . unstubAllGlobals ( ) ;
79+ } ) ;
80+
8381describe ( 'buildLaunchArgs' , ( ) => {
8482 test ( 'should convert basic arguments correctly' , ( ) => {
8583 const args = {
@@ -145,15 +143,63 @@ describe('baseUrl', () => {
145143describe ( 'coreLaunchArgs' , ( ) => {
146144 test ( 'should return the correct core launch arguments' , ( { server } ) => {
147145 const args = server . coreLaunchArgs ;
146+ const databaseUrl = args [ 'database-url' ] ;
147+ const normalizedUserDir = server . userDirectoryPath . replaceAll ( '\\' , '/' ) ;
148148 expect ( args ) . toEqual ( {
149149 'user-directory' : server . userDirectoryPath ,
150150 'input-directory' : server . inputDirectoryPath ,
151151 'output-directory' : server . outputDirectoryPath ,
152152 'front-end-root' : server . webRootPath ,
153153 'base-directory' : basePath ,
154+ 'database-url' : databaseUrl ,
154155 'extra-model-paths-config' : expect . any ( String ) ,
155156 'log-stdout' : '' ,
156157 } ) ;
158+ expect ( databaseUrl ) . toMatch ( / ^ s q l i t e : \/ \/ / ) ;
159+ expect ( databaseUrl ) . toContain ( normalizedUserDir ) ;
160+ expect ( databaseUrl ) . toMatch ( / \/ c o m f y u i \. d b $ / ) ;
161+ } ) ;
162+
163+ test ( 'normalizes database URL path separators on win32' , ( {
164+ mockServerArgs,
165+ mockVirtualEnvironment,
166+ mockAppWindow,
167+ mockTelemetry,
168+ } ) => {
169+ vi . stubGlobal ( 'process' , { ...process , platform : 'win32' } ) ;
170+ const windowsBasePath = String . raw `C:\ComfyUI` ;
171+ const windowsServer = new ComfyServer (
172+ windowsBasePath ,
173+ mockServerArgs ,
174+ mockVirtualEnvironment ,
175+ mockAppWindow ,
176+ mockTelemetry
177+ ) ;
178+ const databaseUrl = windowsServer . coreLaunchArgs [ 'database-url' ] ;
179+ const expectedPath = path . win32 . resolve ( windowsBasePath , 'user' , 'comfyui.db' ) . replaceAll ( '\\' , '/' ) ;
180+ expect ( databaseUrl ) . toBe ( `sqlite:///${ expectedPath } ` ) ;
181+ expect ( databaseUrl ) . not . toContain ( '\\' ) ;
182+ } ) ;
183+ } ) ;
184+
185+ describe ( 'launchArgs' , ( ) => {
186+ test ( 'should allow user override of database-url' , ( { mockVirtualEnvironment, mockAppWindow, mockTelemetry } ) => {
187+ const customDatabaseUrl = 'sqlite:///override.db' ;
188+ const serverArgs : ServerArgs = {
189+ listen : 'localhost' ,
190+ port : '8188' ,
191+ 'database-url' : customDatabaseUrl ,
192+ } ;
193+ const server = new ComfyServer ( basePath , serverArgs , mockVirtualEnvironment , mockAppWindow , mockTelemetry ) ;
194+ const args = server . launchArgs ;
195+ const coreDatabaseUrl = server . coreLaunchArgs [ 'database-url' ] ;
196+ expect ( coreDatabaseUrl ) . not . toBe ( customDatabaseUrl ) ;
197+ const databaseUrlIndices = args
198+ . map ( ( value , index ) => ( value === '--database-url' ? index : - 1 ) )
199+ . filter ( ( index ) => index !== - 1 ) ;
200+ expect ( databaseUrlIndices ) . toHaveLength ( 1 ) ;
201+ expect ( args [ databaseUrlIndices [ 0 ] + 1 ] ) . toBe ( customDatabaseUrl ) ;
202+ expect ( args ) . not . toContain ( coreDatabaseUrl ) ;
157203 } ) ;
158204} ) ;
159205
0 commit comments