@@ -210,6 +210,145 @@ fn config_show_uses_defaults_when_no_higher_precedence_inputs_exist() -> TestRes
210210 Ok ( ( ) )
211211}
212212
213+ #[ test]
214+ fn config_show_auth_env_overrides_config_and_baked_default ( ) -> TestResult < ( ) > {
215+ let harness = ConfigIntegrationHarness :: new ( "sce-config-precedence" ) ?;
216+ let config_path = write_config_file (
217+ & harness,
218+ "explicit-config.json" ,
219+ r#"{"workos_client_id":"from-config"}"# ,
220+ ) ?;
221+
222+ let output = harness
223+ . base_command ( support:: sce_binary_path ( ) )
224+ . args ( [
225+ OsStr :: new ( "config" ) ,
226+ OsStr :: new ( "show" ) ,
227+ OsStr :: new ( "--format" ) ,
228+ OsStr :: new ( "json" ) ,
229+ OsStr :: new ( "--config" ) ,
230+ config_path. as_os_str ( ) ,
231+ ] )
232+ . env ( "WORKOS_CLIENT_ID" , "from-env" )
233+ . output ( ) ?;
234+
235+ let result = render_command_result ( output) ;
236+ assert ! (
237+ result. success( ) ,
238+ "config show with auth env override should succeed\n stdout:\n {}\n stderr:\n {}" ,
239+ result. stdout,
240+ result. stderr
241+ ) ;
242+
243+ let parsed = parse_json_stdout ( & result. stdout ) ?;
244+ assert_eq ! (
245+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "value" ] ,
246+ "from-env"
247+ ) ;
248+ assert_eq ! (
249+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "source" ] ,
250+ "env"
251+ ) ;
252+ assert_eq ! (
253+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "config_source" ] ,
254+ Value :: Null
255+ ) ;
256+ assert_eq ! (
257+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "precedence" ] ,
258+ "env (WORKOS_CLIENT_ID) > config file (workos_client_id) > baked default (client_sce_default)"
259+ ) ;
260+
261+ Ok ( ( ) )
262+ }
263+
264+ #[ test]
265+ fn config_show_auth_uses_config_when_env_is_absent ( ) -> TestResult < ( ) > {
266+ let harness = ConfigIntegrationHarness :: new ( "sce-config-precedence" ) ?;
267+ let config_path = write_config_file (
268+ & harness,
269+ "explicit-config.json" ,
270+ r#"{"workos_client_id":"from-config"}"# ,
271+ ) ?;
272+
273+ let output = harness
274+ . base_command ( support:: sce_binary_path ( ) )
275+ . args ( [
276+ OsStr :: new ( "config" ) ,
277+ OsStr :: new ( "show" ) ,
278+ OsStr :: new ( "--format" ) ,
279+ OsStr :: new ( "json" ) ,
280+ OsStr :: new ( "--config" ) ,
281+ config_path. as_os_str ( ) ,
282+ ] )
283+ . env_remove ( "WORKOS_CLIENT_ID" )
284+ . output ( ) ?;
285+
286+ let result = render_command_result ( output) ;
287+ assert ! (
288+ result. success( ) ,
289+ "config show with auth config fallback should succeed\n stdout:\n {}\n stderr:\n {}" ,
290+ result. stdout,
291+ result. stderr
292+ ) ;
293+
294+ let parsed = parse_json_stdout ( & result. stdout ) ?;
295+ assert_eq ! (
296+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "value" ] ,
297+ "from-config"
298+ ) ;
299+ assert_eq ! (
300+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "source" ] ,
301+ "config_file"
302+ ) ;
303+ assert_eq ! (
304+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "config_source" ] ,
305+ "flag"
306+ ) ;
307+
308+ Ok ( ( ) )
309+ }
310+
311+ #[ test]
312+ fn config_show_auth_uses_baked_default_when_env_and_config_are_absent ( ) -> TestResult < ( ) > {
313+ let harness = ConfigIntegrationHarness :: new ( "sce-config-precedence" ) ?;
314+
315+ let output = harness
316+ . base_command ( support:: sce_binary_path ( ) )
317+ . args ( [
318+ OsStr :: new ( "config" ) ,
319+ OsStr :: new ( "show" ) ,
320+ OsStr :: new ( "--format" ) ,
321+ OsStr :: new ( "json" ) ,
322+ ] )
323+ . env_remove ( "WORKOS_CLIENT_ID" )
324+ . env_remove ( "SCE_CONFIG_FILE" )
325+ . output ( ) ?;
326+
327+ let result = render_command_result ( output) ;
328+ assert ! (
329+ result. success( ) ,
330+ "config show with auth baked default should succeed\n stdout:\n {}\n stderr:\n {}" ,
331+ result. stdout,
332+ result. stderr
333+ ) ;
334+
335+ let parsed = parse_json_stdout ( & result. stdout ) ?;
336+ assert_eq ! (
337+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "value" ] ,
338+ "client_sce_default"
339+ ) ;
340+ assert_eq ! (
341+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "source" ] ,
342+ "default"
343+ ) ;
344+ assert_eq ! (
345+ parsed[ "result" ] [ "resolved" ] [ "workos_client_id" ] [ "config_source" ] ,
346+ Value :: Null
347+ ) ;
348+
349+ Ok ( ( ) )
350+ }
351+
213352fn write_config_file (
214353 harness : & ConfigIntegrationHarness ,
215354 relative_path : & str ,
0 commit comments