@@ -54,6 +54,17 @@ async function setupAuthenticatedState(tempDir: string): Promise<void> {
5454 await fs . writeJson ( authStateFile , authState )
5555}
5656
57+ /**
58+ * Helper function to set the tcloud version for testing
59+ */
60+ async function setTcloudVersion (
61+ tempDir : string ,
62+ version : string ,
63+ ) : Promise < void > {
64+ const versionStateFile = path . join ( tempDir , '.tcloud_version_state.json' )
65+ await fs . writeJson ( versionStateFile , { version } )
66+ }
67+
5768test . describe ( 'Tcloud' , ( ) => {
5869 test ( 'not signed in, shows sign in window' , async ( { } , testInfo ) => {
5970 testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
@@ -77,6 +88,9 @@ test.describe('Tcloud', () => {
7788 `url: ${ tcloudConfig . url } \norg: ${ tcloudConfig . org } \nproject: ${ tcloudConfig . project } \n` ,
7889 )
7990
91+ // Set tcloud version to 2.10.0
92+ await setTcloudVersion ( tempDir , '2.10.0' )
93+
8094 // Set up Python environment with mock tcloud and sqlmesh
8195 const pythonPath = await setupPythonEnvironment ( pythonEnvDir )
8296
@@ -126,7 +140,7 @@ test.describe('Tcloud', () => {
126140 }
127141 } )
128142
129- test ( 'signed in and not installed shows installation window and can see output ' , async ( { } , testInfo ) => {
143+ test ( 'signed in and not installed shows installation window' , async ( { } , testInfo ) => {
130144 testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
131145 const tempDir = await fs . mkdtemp (
132146 path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
@@ -151,6 +165,9 @@ test.describe('Tcloud', () => {
151165 // Write mock ".tcloud_auth_state.json" file
152166 await setupAuthenticatedState ( tempDir )
153167
168+ // Set tcloud version to 2.10.0
169+ await setTcloudVersion ( tempDir , '2.10.0' )
170+
154171 // Set up Python environment with mock tcloud and sqlmesh
155172 const pythonPath = await setupPythonEnvironment ( pythonEnvDir )
156173
@@ -199,4 +216,160 @@ test.describe('Tcloud', () => {
199216 await fs . remove ( tempDir )
200217 }
201218 } )
219+
220+ test ( 'tcloud sqlmesh_lsp command starts the sqlmesh_lsp in old version when ready' , async ( { } , testInfo ) => {
221+ testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
222+ const tempDir = await fs . mkdtemp (
223+ path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
224+ )
225+ const pythonEnvDir = path . join ( tempDir , '.venv' )
226+
227+ try {
228+ // Copy sushi project
229+ await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
230+
231+ // Create a tcloud.yaml to mark this as a tcloud project
232+ const tcloudConfig = {
233+ url : 'https://mock.tobikodata.com' ,
234+ org : 'test-org' ,
235+ project : 'test-project' ,
236+ }
237+ await fs . writeFile (
238+ path . join ( tempDir , 'tcloud.yaml' ) ,
239+ `url: ${ tcloudConfig . url } \norg: ${ tcloudConfig . org } \nproject: ${ tcloudConfig . project } \n` ,
240+ )
241+
242+ // Write mock ".tcloud_auth_state.json" file
243+ await setupAuthenticatedState ( tempDir )
244+
245+ // Set tcloud version to 2.10.0
246+ await setTcloudVersion ( tempDir , '2.10.0' )
247+
248+ // Set up Python environment with mock tcloud and sqlmesh
249+ const pythonPath = await setupPythonEnvironment ( pythonEnvDir )
250+
251+ // Mark sqlmesh as installed
252+ const binDir = path . dirname ( pythonPath )
253+ const installStateFile = path . join ( binDir , '.sqlmesh_installed' )
254+ await fs . writeFile ( installStateFile , '' )
255+
256+ // Configure VS Code settings to use our Python environment
257+ const settings = {
258+ 'python.defaultInterpreterPath' : pythonPath ,
259+ 'sqlmesh.environmentPath' : pythonEnvDir ,
260+ }
261+ await fs . ensureDir ( path . join ( tempDir , '.vscode' ) )
262+ await fs . writeJson (
263+ path . join ( tempDir , '.vscode' , 'settings.json' ) ,
264+ settings ,
265+ { spaces : 2 } ,
266+ )
267+
268+ // Start VS Code
269+ const { window, close } = await startVSCode ( tempDir )
270+
271+ // Open a SQL file to trigger SQLMesh activation
272+ // Wait for the models folder to be visible
273+ await window . waitForSelector ( 'text=models' )
274+
275+ // Click on the models folder
276+ await window
277+ . getByRole ( 'treeitem' , { name : 'models' , exact : true } )
278+ . locator ( 'a' )
279+ . click ( )
280+
281+ // Open the top_waiters model
282+ await window
283+ . getByRole ( 'treeitem' , { name : 'customers.sql' , exact : true } )
284+ . locator ( 'a' )
285+ . click ( )
286+
287+ // Verify the context loads successfully
288+ await window . waitForSelector ( 'text=Loaded SQLMesh context' )
289+
290+ // Close VS Code
291+ await close ( )
292+ } finally {
293+ // Clean up
294+ await fs . remove ( tempDir )
295+ }
296+ } )
297+
298+ test ( 'tcloud sqlmesh_lsp command starts the sqlmesh_lsp in new version when ready' , async ( { } , testInfo ) => {
299+ testInfo . setTimeout ( 120_000 ) // 2 minutes for venv creation and package installation
300+ const tempDir = await fs . mkdtemp (
301+ path . join ( os . tmpdir ( ) , 'vscode-test-tcloud-' ) ,
302+ )
303+ const pythonEnvDir = path . join ( tempDir , '.venv' )
304+
305+ try {
306+ // Copy sushi project
307+ await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
308+
309+ // Create a tcloud.yaml to mark this as a tcloud project
310+ const tcloudConfig = {
311+ url : 'https://mock.tobikodata.com' ,
312+ org : 'test-org' ,
313+ project : 'test-project' ,
314+ }
315+ await fs . writeFile (
316+ path . join ( tempDir , 'tcloud.yaml' ) ,
317+ `url: ${ tcloudConfig . url } \norg: ${ tcloudConfig . org } \nproject: ${ tcloudConfig . project } \n` ,
318+ )
319+
320+ // Write mock ".tcloud_auth_state.json" file
321+ await setupAuthenticatedState ( tempDir )
322+
323+ // Set tcloud version to 2.10.0
324+ await setTcloudVersion ( tempDir , '2.10.1' )
325+
326+ // Set up Python environment with mock tcloud and sqlmesh
327+ const pythonPath = await setupPythonEnvironment ( pythonEnvDir )
328+
329+ // Mark sqlmesh as installed
330+ const binDir = path . dirname ( pythonPath )
331+ const installStateFile = path . join ( binDir , '.sqlmesh_installed' )
332+ await fs . writeFile ( installStateFile , '' )
333+
334+ // Configure VS Code settings to use our Python environment
335+ const settings = {
336+ 'python.defaultInterpreterPath' : pythonPath ,
337+ 'sqlmesh.environmentPath' : pythonEnvDir ,
338+ }
339+ await fs . ensureDir ( path . join ( tempDir , '.vscode' ) )
340+ await fs . writeJson (
341+ path . join ( tempDir , '.vscode' , 'settings.json' ) ,
342+ settings ,
343+ { spaces : 2 } ,
344+ )
345+
346+ // Start VS Code
347+ const { window, close } = await startVSCode ( tempDir )
348+
349+ // Open a SQL file to trigger SQLMesh activation
350+ // Wait for the models folder to be visible
351+ await window . waitForSelector ( 'text=models' )
352+
353+ // Click on the models folder
354+ await window
355+ . getByRole ( 'treeitem' , { name : 'models' , exact : true } )
356+ . locator ( 'a' )
357+ . click ( )
358+
359+ // Open the top_waiters model
360+ await window
361+ . getByRole ( 'treeitem' , { name : 'customers.sql' , exact : true } )
362+ . locator ( 'a' )
363+ . click ( )
364+
365+ // Verify the context loads successfully
366+ await window . waitForSelector ( 'text=Loaded SQLMesh context' )
367+
368+ // Close VS Code
369+ await close ( )
370+ } finally {
371+ // Clean up
372+ await fs . remove ( tempDir )
373+ }
374+ } )
202375} )
0 commit comments