@@ -18,10 +18,16 @@ import crypto from "node:crypto";
1818import { Context } from "@databricks/databricks-sdk/dist/context" ;
1919import { logging } from "@databricks/databricks-sdk" ;
2020import { LoggerManager } from "../logger" ;
21+ import { ProfileAuthProvider } from "../configuration/auth/AuthProvider" ;
22+ import { isMatch } from "lodash" ;
23+ import { removeUndefinedKeys } from "../utils/envVarGenerators" ;
2124
2225const execFile = promisify ( execFileCb ) ;
2326const cliPath = path . join ( __dirname , "../../bin/databricks" ) ;
2427
28+ // eslint-disable-next-line @typescript-eslint/no-var-requires
29+ const extensionVersion = require ( "../../package.json" ) . version ;
30+
2531function getTempLogFilePath ( ) {
2632 return path . join (
2733 os . tmpdir ( ) ,
@@ -204,4 +210,50 @@ nothing = true
204210 assert . equal ( profiles . length , 0 ) ;
205211 } ) ;
206212 } ) ;
213+
214+ it ( "should set required env vars to the bundle run CLI calls" , async ( ) => {
215+ const logFilePath = getTempLogFilePath ( ) ;
216+ const cli = createCliWrapper ( logFilePath ) ;
217+ const authProvider = new ProfileAuthProvider (
218+ new URL ( "https://test.com" ) ,
219+ "PROFILE" ,
220+ true
221+ ) ;
222+ const workspaceFolder = Uri . file ( "/test/123" ) ;
223+ const runCmd = cli . getBundleRunCommand (
224+ "dev" ,
225+ authProvider ,
226+ "resource-key" ,
227+ workspaceFolder
228+ ) ;
229+ const expected = {
230+ args : [ "bundle" , "run" , "--target" , "dev" , "resource-key" ] ,
231+ cmd : cli . cliPath ,
232+ options : {
233+ cwd : workspaceFolder . fsPath ,
234+ env : removeUndefinedKeys ( {
235+ /* eslint-disable @typescript-eslint/naming-convention */
236+ DATABRICKS_CLI_UPSTREAM : "databricks-vscode" ,
237+ DATABRICKS_CLI_UPSTREAM_VERSION : extensionVersion ,
238+ DATABRICKS_CONFIG_PROFILE : "PROFILE" ,
239+ DATABRICKS_HOST : "https://test.com/" ,
240+ DATABRICKS_LOG_FILE : logFilePath ,
241+ DATABRICKS_LOG_FORMAT : "json" ,
242+ DATABRICKS_LOG_LEVEL : "debug" ,
243+ DATABRICKS_OUTPUT_FORMAT : "json" ,
244+ HOME : process . env . HOME ,
245+ PATH : process . env . PATH ,
246+ /* eslint-enable @typescript-eslint/naming-convention */
247+ } ) ,
248+ shell : true ,
249+ } ,
250+ } ;
251+ try {
252+ assert . ok ( isMatch ( runCmd , expected ) ) ;
253+ } catch ( e ) {
254+ // Run this in the "catch" case to show better error messages
255+ assert . deepStrictEqual ( runCmd , expected ) ;
256+ throw e ;
257+ }
258+ } ) ;
207259} ) ;
0 commit comments