-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathconfiguration.spec.ts
More file actions
213 lines (177 loc) · 6.17 KB
/
configuration.spec.ts
File metadata and controls
213 lines (177 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { test, expect } from './fixtures'
import {
createVirtualEnvironment,
openServerPage,
pipInstall,
REPO_ROOT,
SUSHI_SOURCE_PATH,
waitForLoadedSQLMesh,
} from './utils'
import path from 'path'
import fs from 'fs-extra'
async function setupPythonEnvironment(tempDir: string): Promise<void> {
// Create a temporary directory for the virtual environment
const venvDir = path.join(tempDir, '.venv')
fs.mkdirSync(venvDir, { recursive: true })
// Create virtual environment
const pythonDetails = await createVirtualEnvironment(venvDir)
// Install sqlmesh from the local repository with LSP support
const customMaterializations = path.join(
REPO_ROOT,
'examples',
'custom_materializations',
)
const sqlmeshWithExtras = `${REPO_ROOT}[lsp,bigquery]`
await pipInstall(pythonDetails, [sqlmeshWithExtras, customMaterializations])
}
/**
* Creates an entrypoint file used to test the LSP configuration.
*
* The entrypoint file is a bash script that simply calls out to the
*/
const createEntrypointFile = (
tempDir: string,
entrypointFileName: string,
bitToStripFromArgs = '',
): {
entrypointFile: string
fileWhereStoredInputs: string
} => {
const entrypointFile = path.join(tempDir, entrypointFileName)
const fileWhereStoredInputs = path.join(tempDir, 'inputs.txt')
const sqlmeshLSPFile = path.join(tempDir, '.venv/bin/sqlmesh_lsp')
// Create the entrypoint file
fs.writeFileSync(
entrypointFile,
`#!/bin/bash
echo "$@" > ${fileWhereStoredInputs}
# Strip bitToStripFromArgs from the beginning of the args if it matches
if [[ "$1" == "${bitToStripFromArgs}" ]]; then
shift
fi
# Call the sqlmesh_lsp with the remaining arguments
${sqlmeshLSPFile} "$@"`,
{ mode: 0o755 }, // Make it executable
)
return {
entrypointFile,
fileWhereStoredInputs,
}
}
test.describe('Test LSP Entrypoint configuration', () => {
test('specify single entrypoint relalative path', async ({
page,
sharedCodeServer,
tempDir,
}) => {
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await setupPythonEnvironment(tempDir)
const { fileWhereStoredInputs } = createEntrypointFile(
tempDir,
'entrypoint.sh',
)
const settings = {
'sqlmesh.lspEntrypoint': './entrypoint.sh',
}
// Write the settings to the settings.json file
const settingsPath = path.join(tempDir, '.vscode', 'settings.json')
fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2))
await openServerPage(page, tempDir, sharedCodeServer)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
// Click on the models folder, excluding external_models
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
// Open the customer_revenue_lifetime model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()
await waitForLoadedSQLMesh(page)
// Check that the output file exists and contains the entrypoint script arguments
expect(fs.existsSync(fileWhereStoredInputs)).toBe(true)
expect(fs.readFileSync(fileWhereStoredInputs, 'utf8')).toBe(`--stdio
`)
})
test('specify one entrypoint absolute path', async ({
page,
sharedCodeServer,
tempDir,
}) => {
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await setupPythonEnvironment(tempDir)
const { entrypointFile, fileWhereStoredInputs } = createEntrypointFile(
tempDir,
'entrypoint.sh',
)
// Assert that the entrypoint file is an absolute path
expect(path.isAbsolute(entrypointFile)).toBe(true)
const settings = {
'sqlmesh.lspEntrypoint': `${entrypointFile}`,
}
// Write the settings to the settings.json file
const settingsPath = path.join(tempDir, '.vscode', 'settings.json')
fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2))
await openServerPage(page, tempDir, sharedCodeServer)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
// Click on the models folder, excluding external_models
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
// Open the customer_revenue_lifetime model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()
await waitForLoadedSQLMesh(page)
// Check that the output file exists and contains the entrypoint script arguments
expect(fs.existsSync(fileWhereStoredInputs)).toBe(true)
expect(fs.readFileSync(fileWhereStoredInputs, 'utf8')).toBe(`--stdio
`)
})
test('specify entrypoint with arguments', async ({
page,
sharedCodeServer,
tempDir,
}) => {
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await setupPythonEnvironment(tempDir)
const { fileWhereStoredInputs } = createEntrypointFile(
tempDir,
'entrypoint.sh',
'--argToIgnore',
)
const settings = {
'sqlmesh.lspEntrypoint': './entrypoint.sh --argToIgnore',
}
// Write the settings to the settings.json file
const settingsPath = path.join(tempDir, '.vscode', 'settings.json')
fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2))
await openServerPage(page, tempDir, sharedCodeServer)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
// Click on the models folder, excluding external_models
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
// Open the customer_revenue_lifetime model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()
await waitForLoadedSQLMesh(page)
// Check that the output file exists and contains the entrypoint script arguments
expect(fs.existsSync(fileWhereStoredInputs)).toBe(true)
expect(fs.readFileSync(fileWhereStoredInputs, 'utf8'))
.toBe(`--argToIgnore --stdio
`)
})
})