Skip to content

Commit 7a9e20c

Browse files
committed
chore(vscode): add test for quickfix
- also refactored the openProblemsView
1 parent 606b740 commit 7a9e20c

File tree

4 files changed

+96
-20
lines changed

4 files changed

+96
-20
lines changed

vscode/extension/tests/broken_project.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from 'os'
44
import path from 'path'
55
import {
66
openLineageView,
7-
runCommand,
7+
openProblemsView,
88
saveFile,
99
SUSHI_SOURCE_PATH,
1010
} from './utils'
@@ -291,8 +291,7 @@ test('bad model block, then fixed', async ({ page, sharedCodeServer }) => {
291291
// Wait for the error to appear
292292
await page.waitForSelector('text=Error creating context')
293293

294-
// Open the problems view
295-
await runCommand(page, 'View: Focus Problems')
294+
await openProblemsView(page)
296295

297296
// Assert error is present in the problems view
298297
const errorElement = page

vscode/extension/tests/diagnostics.spec.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from './fixtures'
22
import path from 'path'
33
import fs from 'fs-extra'
44
import os from 'os'
5-
import { runCommand, SUSHI_SOURCE_PATH } from './utils'
5+
import { openProblemsView, SUSHI_SOURCE_PATH } from './utils'
66
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
77
import { execAsync } from '../src/utilities/exec'
88
import yaml from 'yaml'
@@ -39,8 +39,7 @@ test('Workspace diagnostics show up in the diagnostics panel', async ({
3939
.locator('a')
4040
.click()
4141

42-
// Open problems panel
43-
await runCommand(page, 'View: Focus Problems')
42+
await openProblemsView(page)
4443

4544
await page.waitForSelector('text=problems')
4645
await page.waitForSelector('text=All models should have an owner')
@@ -88,8 +87,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
8887
// Wait for the error to appear
8988
await page.waitForSelector('text=Error creating context')
9089

91-
// Open the problems view
92-
await runCommand(page, 'View: Focus Problems')
90+
await openProblemsView(page)
9391

9492
// Asser that the error is present in the problems view
9593
await page
@@ -134,8 +132,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
134132
// Wait for the error to appear
135133
await page.waitForSelector('text=Error creating context')
136134

137-
// Open the problems view
138-
await runCommand(page, 'View: Focus Problems')
135+
await openProblemsView(page)
139136

140137
// Asser that the error is present in the problems view
141138
await page
@@ -176,8 +173,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
176173
// Expect the error to appear
177174
await page.waitForSelector('text=Error creating context')
178175

179-
// Open the problems view
180-
await runCommand(page, 'View: Focus Problems')
176+
await openProblemsView(page)
181177

182178
// Assert that the error is present in the problems view
183179
const errorElement = page
@@ -215,8 +211,7 @@ test.describe('Bad config.py/config.yaml file issues', () => {
215211
// Expect the error to appear
216212
await page.waitForSelector('text=Error creating context')
217213

218-
// Open the problems view
219-
await runCommand(page, 'View: Focus Problems')
214+
await openProblemsView(page)
220215

221216
// Assert that the error is present in the problems view
222217
const errorElement = page.getByText('Failed to load config file:').first()
@@ -260,8 +255,7 @@ test.describe('Diagnostics for bad SQLMesh models', () => {
260255
// Wait for the error to appear
261256
await page.waitForSelector('text=Error creating context')
262257

263-
// Open the problems view
264-
await runCommand(page, 'View: Focus Problems')
258+
await openProblemsView(page)
265259

266260
// Asser that the error is present in the problems view
267261
await page
@@ -302,8 +296,7 @@ test.describe('Diagnostics for bad SQLMesh models', () => {
302296
// Wait for the error to appear
303297
await page.waitForSelector('text=Error creating context')
304298

305-
// Open the problems view
306-
await runCommand(page, 'View: Focus Problems')
299+
await openProblemsView(page)
307300

308301
// Assert error is present in the problems view
309302
const errorElement = page
@@ -352,8 +345,7 @@ test.describe('Diagnostics for bad audits', () => {
352345
// Wait for the error to appear
353346
await page.waitForSelector('text=Error creating context')
354347

355-
// Open the problems view
356-
await runCommand(page, 'View: Focus Problems')
348+
await openProblemsView(page)
357349

358350
// Assert that the error is present in the problems view
359351
const errorElement = page
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import fs from 'fs-extra'
2+
import path from 'path'
3+
import os from 'os'
4+
import { openProblemsView, SUSHI_SOURCE_PATH } from './utils'
5+
import { test, expect } from './fixtures'
6+
import { createPythonInterpreterSettingsSpecifier } from './utils_code_server'
7+
8+
test('noselectstar quickfix', async ({ page, sharedCodeServer }) => {
9+
// Base test setup
10+
const tempDir = await fs.mkdtemp(
11+
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
12+
)
13+
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
14+
await createPythonInterpreterSettingsSpecifier(tempDir)
15+
16+
// Override the settings for the linter
17+
const configPath = path.join(tempDir, 'config.py')
18+
const read = await fs.readFile(configPath, 'utf8')
19+
// Replace linter to be on
20+
const replaced = read.replace('enabled=False', 'enabled=True')
21+
const replacedTheOtherRules = replaced.replace(
22+
`rules=[
23+
"ambiguousorinvalidcolumn",
24+
"invalidselectstarexpansion",
25+
"noselectstar",
26+
"nomissingaudits",
27+
"nomissingowner",
28+
],`,
29+
`rules=[
30+
"noselectstar",
31+
],
32+
`,
33+
)
34+
await fs.writeFile(configPath, replacedTheOtherRules)
35+
// Replace the file to cause the error
36+
const modelPath = path.join(tempDir, 'models', 'latest_order.sql')
37+
const readModel = await fs.readFile(modelPath, 'utf8')
38+
// Replace the specific select with the select star
39+
const modelReplaced = readModel.replace(
40+
'SELECT id, customer_id, start_ts, end_ts, event_date',
41+
'SELECT *',
42+
)
43+
await fs.writeFile(modelPath, modelReplaced)
44+
45+
// Open the code server with the specified directory
46+
await page.goto(
47+
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
48+
)
49+
await page.waitForLoadState('networkidle')
50+
51+
// Open the file with the linter issue
52+
await page
53+
.getByRole('treeitem', { name: 'models', exact: true })
54+
.locator('a')
55+
.click()
56+
await page
57+
.getByRole('treeitem', { name: 'latest_order.sql', exact: true })
58+
.locator('a')
59+
.click()
60+
61+
await page.waitForSelector('text=Loaded SQLMesh context')
62+
63+
await openProblemsView(page)
64+
65+
await page.getByRole('button', { name: 'Show fixes' }).click()
66+
await page
67+
.getByRole('menuitem', { name: 'Replace SELECT * with' })
68+
.first()
69+
.click()
70+
71+
await page.waitForTimeout(1_000)
72+
73+
// Assert that the model no longer contains SELECT * but SELECT id, customer_id, waiter_id, start_ts, end_ts, event_date
74+
const readUpdatedFile = await fs.readFile(modelPath)
75+
expect(readUpdatedFile.toString()).not.toContain('SELECT *')
76+
expect(readUpdatedFile.toString()).toContain(
77+
'SELECT id, customer_id, waiter_id, start_ts, end_ts, event_date',
78+
)
79+
})

vscode/extension/tests/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ export const pipInstall = async (
8686
export const openLineageView = async (page: Page) =>
8787
await runCommand(page, 'Lineage: Focus On View')
8888

89+
/**
90+
* Open the problems/diagnostics view in the given window.
91+
*/
92+
export const openProblemsView = async (page: Page) =>
93+
await runCommand(page, 'View: Focus Problems')
94+
8995
/**
9096
* Restart the SQLMesh servers
9197
*/

0 commit comments

Comments
 (0)