Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions vscode/extension/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@ export default tseslint.config(
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
{
files: ['tests/**/*.spec.ts'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@playwright/test'],
message:
'Import { test, expect, Page } from "./fixtures" instead of directly from @playwright/test',
},
],
},
],
},
},
)
159 changes: 70 additions & 89 deletions vscode/extension/tests/bad_setup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from '@playwright/test'
import { expect, test } from './fixtures'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
Expand All @@ -10,10 +10,10 @@ import {
REPO_ROOT,
SUSHI_SOURCE_PATH,
} from './utils'
import { startCodeServer, stopCodeServer } from './utils_code_server'

test('missing LSP dependencies shows install prompt', async ({
page,
sharedCodeServer,
}, testInfo) => {
testInfo.setTimeout(120_000) // 2 minutes for venv creation and package installation
const tempDir = await fs.mkdtemp(
Expand All @@ -29,54 +29,48 @@ test('missing LSP dependencies shows install prompt', async ({
const sqlmeshWithExtras = `${REPO_ROOT}[bigquery]`
await pipInstall(pythonDetails, [sqlmeshWithExtras, custom_materializations])

// Start VS Code
const context = await startCodeServer({
tempDir,
})
// Copy sushi project
await fs.copy(SUSHI_SOURCE_PATH, tempDir)

try {
// Copy sushi project
await fs.copy(SUSHI_SOURCE_PATH, tempDir)

// Configure VS Code settings to use our Python environment
const settings = {
'python.defaultInterpreterPath': pythonDetails.pythonPath,
'sqlmesh.environmentPath': pythonEnvDir,
}
await fs.ensureDir(path.join(tempDir, '.vscode'))
await fs.writeJson(
path.join(tempDir, '.vscode', 'settings.json'),
settings,
{ spaces: 2 },
)

await page.goto(`http://127.0.0.1:${context.codeServerPort}`)

// Open a SQL file to trigger SQLMesh activation
// Wait for the models folder to be visible
await page.waitForSelector('text=models')

// Click on the models folder
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()

// Open the top_waiters model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()

// Wait for the message to show that LSP extras need to be installed
await page.waitForSelector('text=LSP dependencies missing')
expect(await page.locator('text=Install').count()).toBeGreaterThanOrEqual(1)
} finally {
await stopCodeServer(context)
// Configure VS Code settings to use our Python environment
const settings = {
'python.defaultInterpreterPath': pythonDetails.pythonPath,
'sqlmesh.environmentPath': pythonEnvDir,
}
await fs.ensureDir(path.join(tempDir, '.vscode'))
await fs.writeJson(path.join(tempDir, '.vscode', 'settings.json'), settings, {
spaces: 2,
})

await page.goto(
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
)

// Open a SQL file to trigger SQLMesh activation
// Wait for the models folder to be visible
await page.waitForSelector('text=models')

// Click on the models folder
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()

// Open the top_waiters model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()

// Wait for the message to show that LSP extras need to be installed
await page.waitForSelector('text=LSP dependencies missing')
expect(await page.locator('text=Install').count()).toBeGreaterThanOrEqual(1)
})

test('lineage, no sqlmesh found', async ({ page }, testInfo) => {
test('lineage, no sqlmesh found', async ({
page,
sharedCodeServer,
}, testInfo) => {
testInfo.setTimeout(120_000) // 2 minutes for venv creation and package installation

const tempDir = await fs.mkdtemp(
Expand All @@ -85,46 +79,38 @@ test('lineage, no sqlmesh found', async ({ page }, testInfo) => {
const pythonEnvDir = path.join(tempDir, '.venv')
const pythonDetails = await createVirtualEnvironment(pythonEnvDir)

const context = await startCodeServer({
tempDir,
})
// Copy sushi project
await fs.copy(SUSHI_SOURCE_PATH, tempDir)

try {
// Copy sushi project
await fs.copy(SUSHI_SOURCE_PATH, tempDir)

// Configure VS Code settings to use our Python environment
const settings = {
'python.defaultInterpreterPath': pythonDetails.pythonPath,
'sqlmesh.environmentPath': pythonEnvDir,
}
await fs.ensureDir(path.join(tempDir, '.vscode'))
await fs.writeJson(
path.join(tempDir, '.vscode', 'settings.json'),
settings,
{ spaces: 2 },
)

// navigate to code-server instance
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
await page.waitForLoadState('networkidle')

// Open lineage view
await openLineageView(page)

// Assert shows that sqlmesh is not installed
await page.waitForSelector('text=SQLMesh LSP not found')
} finally {
// Clean up
await stopCodeServer(context)
// Configure VS Code settings to use our Python environment
const settings = {
'python.defaultInterpreterPath': pythonDetails.pythonPath,
'sqlmesh.environmentPath': pythonEnvDir,
}
await fs.ensureDir(path.join(tempDir, '.vscode'))
await fs.writeJson(path.join(tempDir, '.vscode', 'settings.json'), settings, {
spaces: 2,
})

// navigate to code-server instance
await page.goto(
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
)
await page.waitForLoadState('networkidle')

// Open lineage view
await openLineageView(page)

// Assert shows that sqlmesh is not installed
await page.waitForSelector('text=SQLMesh LSP not found')
})

// Checks that if you have another file open like somewhere else, it still checks the workspace first for a successful context
// it's very flaky but runs when debugging
// - the typing in of the file name is very flaky
test.skip('check that the LSP runs correctly by opening lineage when looking at another file before not in workspace', async ({
page,
sharedCodeServer,
}, testInfo) => {
testInfo.setTimeout(120_000) // 2 minutes for venv creation and package installation
const tempDir = await fs.mkdtemp(
Expand Down Expand Up @@ -159,18 +145,13 @@ test.skip('check that the LSP runs correctly by opening lineage when looking at
await fs.ensureDir(path.dirname(sqlFile))
await fs.writeFile(sqlFile, 'SELECT 1')

const context = await startCodeServer({
tempDir,
})
try {
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
await page.waitForLoadState('networkidle')
await page.goto(
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
)
await page.waitForLoadState('networkidle')

// Open the SQL file from the other directory
await openFile(page, sqlFile)
// Open the SQL file from the other directory
await openFile(page, sqlFile)

await page.waitForSelector('text=Loaded SQLMesh context')
} finally {
await stopCodeServer(context)
}
await page.waitForSelector('text=Loaded SQLMesh context')
})
Loading