@@ -79,17 +79,23 @@ describe('Maker Lua LSP runtime', () => {
7979 test ( 'setup installs maker-lua-lsp with the selected Python and configures all IDEs' , ( ) => {
8080 const calls : SpawnCall [ ] = [ ] ;
8181 const python = path . join ( tempDir , 'python' , 'bin' , 'python3' ) ;
82- const scriptsDir = path . join ( tempDir , 'python' , 'bin' ) ;
82+ const venvDir = path . join ( tempDir , 'maker-home' , 'lua-lsp-venv' ) ;
83+ const venvPython = path . join ( venvDir , 'bin' , 'python' ) ;
84+ const scriptsDir = path . join ( venvDir , 'bin' ) ;
8385 const lspCommand = path . join ( scriptsDir , 'maker-lua-lsp' ) ;
84- fs . mkdirSync ( scriptsDir , { recursive : true } ) ;
85- fs . writeFileSync ( lspCommand , '' ) ;
8686
8787 const spawn = ( command : string , args : string [ ] , options ?: { timeout ?: number } ) => {
8888 calls . push ( { command, args, timeout : options ?. timeout } ) ;
89- if ( command === python && args . join ( ' ' ) === '-m pip install --upgrade maker-lua-lsp' ) {
89+ if ( command === python && args . join ( ' ' ) === `-m venv ${ venvDir } ` ) {
90+ fs . mkdirSync ( scriptsDir , { recursive : true } ) ;
91+ fs . writeFileSync ( venvPython , '' ) ;
92+ fs . writeFileSync ( lspCommand , '' ) ;
93+ return spawnResult ( 0 , 'created venv\n' ) ;
94+ }
95+ if ( command === venvPython && args . join ( ' ' ) === '-m pip install --upgrade maker-lua-lsp' ) {
9096 return spawnResult ( 0 , 'installed maker-lua-lsp\n' ) ;
9197 }
92- if ( command === python && args . includes ( '-c' ) ) {
98+ if ( command === venvPython && args . includes ( '-c' ) ) {
9399 return spawnResult ( 0 , `${ scriptsDir } \n` ) ;
94100 }
95101 if ( command === lspCommand && args . join ( ' ' ) === 'install --ide codex,cursor,claude' ) {
@@ -112,6 +118,10 @@ describe('Maker Lua LSP runtime', () => {
112118 expect . arrayContaining ( [
113119 expect . objectContaining ( {
114120 command : python ,
121+ args : [ '-m' , 'venv' , venvDir ] ,
122+ } ) ,
123+ expect . objectContaining ( {
124+ command : venvPython ,
115125 args : [ '-m' , 'pip' , 'install' , '--upgrade' , 'maker-lua-lsp' ] ,
116126 } ) ,
117127 expect . objectContaining ( {
@@ -120,18 +130,28 @@ describe('Maker Lua LSP runtime', () => {
120130 } ) ,
121131 ] )
122132 ) ;
123- expect ( calls . find ( ( call ) => call . command === python && call . args [ 0 ] === '-m ' ) ?. timeout ) . toBe (
133+ expect ( calls . find ( ( call ) => call . command === python && call . args [ 1 ] === 'venv ' ) ?. timeout ) . toBe (
124134 120_000
125135 ) ;
136+ expect (
137+ calls . find ( ( call ) => call . command === venvPython && call . args [ 1 ] === 'pip' ) ?. timeout
138+ ) . toBe ( 120_000 ) ;
126139 expect (
127140 calls . find ( ( call ) => call . command === lspCommand && call . args [ 0 ] === 'install' ) ?. timeout
128141 ) . toBe ( 120_000 ) ;
129142 } ) ;
130143
131144 test ( 'setup reports LSP install failure without throwing' , ( ) => {
132145 const python = path . join ( tempDir , 'python' , 'bin' , 'python3' ) ;
146+ const venvDir = path . join ( tempDir , 'maker-home' , 'lua-lsp-venv' ) ;
147+ const venvPython = path . join ( venvDir , 'bin' , 'python' ) ;
133148 const spawn = ( command : string , args : string [ ] ) => {
134- if ( command === python && args . join ( ' ' ) === '-m pip install --upgrade maker-lua-lsp' ) {
149+ if ( command === python && args . join ( ' ' ) === `-m venv ${ venvDir } ` ) {
150+ fs . mkdirSync ( path . dirname ( venvPython ) , { recursive : true } ) ;
151+ fs . writeFileSync ( venvPython , '' ) ;
152+ return spawnResult ( 0 , 'created venv\n' ) ;
153+ }
154+ if ( command === venvPython && args . join ( ' ' ) === '-m pip install --upgrade maker-lua-lsp' ) {
135155 return spawnResult ( 1 , '' , 'network timeout' ) ;
136156 }
137157 return spawnResult ( 1 , '' , `unexpected command: ${ command } ${ args . join ( ' ' ) } ` ) ;
@@ -169,4 +189,32 @@ describe('Maker Lua LSP runtime', () => {
169189 expect ( environment . ready ) . toBe ( false ) ;
170190 expect ( environment . nextAction ) . toContain ( 'taptap-maker lua-lsp setup' ) ;
171191 } ) ;
192+
193+ test ( 'doctor accepts LSP command that supports help but not version' , ( ) => {
194+ const python = path . join ( tempDir , 'python' , 'bin' , 'python3' ) ;
195+ const scriptsDir = path . join ( tempDir , 'maker-home' , 'lua-lsp-venv' , 'bin' ) ;
196+ const lspCommand = path . join ( scriptsDir , 'maker-lua-lsp' ) ;
197+ fs . mkdirSync ( scriptsDir , { recursive : true } ) ;
198+ fs . writeFileSync ( lspCommand , '' ) ;
199+
200+ const spawn = ( command : string , args : string [ ] ) => {
201+ if ( command === lspCommand && args [ 0 ] === '--version' ) {
202+ return spawnResult ( 2 , '' , 'maker-lua-lsp: error: unrecognized arguments: --version' ) ;
203+ }
204+ if ( command === lspCommand && args [ 0 ] === '--help' ) {
205+ return spawnResult ( 0 , 'usage: maker-lua-lsp\n' ) ;
206+ }
207+ return spawnResult ( 1 , '' , `unexpected command: ${ command } ${ args . join ( ' ' ) } ` ) ;
208+ } ;
209+
210+ const environment = checkMakerLuaLspEnvironment ( {
211+ pythonEnvironment : readyPython ( python ) ,
212+ spawn,
213+ } ) ;
214+
215+ expect ( environment . ready ) . toBe ( true ) ;
216+ expect ( environment . status ) . toBe ( 'ready' ) ;
217+ expect ( environment . command ) . toBe ( lspCommand ) ;
218+ expect ( environment . version ) . toBe ( 'installed' ) ;
219+ } ) ;
172220} ) ;
0 commit comments