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
187 changes: 1 addition & 186 deletions vscode/extension/tests/broken_project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ import { test, expect } from './fixtures'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
openLineageView,
runCommand,
saveFile,
SUSHI_SOURCE_PATH,
} from './utils'
import { openLineageView, saveFile, SUSHI_SOURCE_PATH } from './utils'
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
import { execAsync } from '../src/utilities/exec'
import yaml from 'yaml'

test('bad project, double model', async ({ page, sharedCodeServer }) => {
const tempDir = await fs.mkdtemp(
Expand Down Expand Up @@ -260,181 +253,3 @@ test('bad project, double model, check lineage', async ({

await page.waitForTimeout(500)
})

const setup = async (tempDir: string) => {
// Run the sqlmesh CLI from the root of the repo using the local path
const sqlmeshCliPath = path.resolve(__dirname, '../../../.venv/bin/sqlmesh')
const result = await execAsync(sqlmeshCliPath, ['init', 'duckdb'], {
cwd: tempDir,
})
expect(result.exitCode).toBe(0)
}

test.describe('Bad config.py/config.yaml file issues', () => {
test('sqlmesh init, then corrupted config.yaml, bad yaml', async ({
page,
sharedCodeServer,
}) => {
const tempDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
)
await setup(tempDir)
await createPythonInterpreterSettingsSpecifier(tempDir)

const configYamlPath = path.join(tempDir, 'config.yaml')
// Write an invalid YAML to config.yaml
await fs.writeFile(configYamlPath, 'invalid_yaml; asdfasudfy')

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

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

// Wait for the error to appear
await page.waitForSelector('text=Error creating context')

// Open the problems view
await runCommand(page, 'View: Focus Problems')

// Asser that the error is present in the problems view
await page
.getByText('Invalid YAML configuration:')
.first()
.isVisible({ timeout: 5_000 })
})

test('sqlmesh init, then corrupted config.yaml, bad parameters', async ({
page,
sharedCodeServer,
}) => {
const tempDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
)
await setup(tempDir)
await createPythonInterpreterSettingsSpecifier(tempDir)

const configYamlPath = path.join(tempDir, 'config.yaml')
// Write an invalid YAML to config.yaml
const config = {
gateway: 'test',
}
// Write config to the yaml file
await fs.writeFile(configYamlPath, yaml.stringify(config))

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

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

// Wait for the error to appear
await page.waitForSelector('text=Error creating context')

// Open the problems view
await runCommand(page, 'View: Focus Problems')

// Asser that the error is present in the problems view
await page
.getByText('Invalid project config:', { exact: true })
.first()
.isVisible({ timeout: 5_000 })
})

test('sushi example, correct python, bad config', async ({
page,
sharedCodeServer,
}) => {
const tempDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
)
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await createPythonInterpreterSettingsSpecifier(tempDir)

const configPyPath = path.join(tempDir, 'config.py')
// Write an invalid Python to config.py
await fs.writeFile(configPyPath, 'config = {}')

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

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

// Expect the error to appear
await page.waitForSelector('text=Error creating context')

// Open the problems view
await runCommand(page, 'View: Focus Problems')

// Assert that the error is present in the problems view
const errorElement = page
.getByText('Config needs to be a valid object of type')
.first()
await expect(errorElement).toBeVisible({ timeout: 5000 })
})

test('sushi example, bad config.py', async ({ page, sharedCodeServer }) => {
const tempDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
)
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await createPythonInterpreterSettingsSpecifier(tempDir)

const configPyPath = path.join(tempDir, 'config.py')
// Write an invalid Python to config.py
await fs.writeFile(configPyPath, 'invalid_python_code = [1, 2, 3')

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

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

// Expect the error to appear
await page.waitForSelector('text=Error creating context')

// Open the problems view
await runCommand(page, 'View: Focus Problems')

// Assert that the error is present in the problems view
const errorElement = page.getByText('Failed to load config file:').first()
await expect(errorElement).toBeVisible({ timeout: 5000 })
})
})
Loading
Loading