88import pytest
99
1010from fabric_cli .client .fab_api_client import (
11- _get_host_app_suffix ,
11+ _get_host_app ,
1212 _transform_workspace_url_for_private_link_if_needed ,
1313 do_request ,
1414)
@@ -311,32 +311,88 @@ def __init__(self):
311311
312312
313313@pytest .mark .parametrize (
314- "host_app_env, expected_suffix" ,
314+ "host_app_env, host_app_version_env, expected_suffix" ,
315315 [
316- ("VSCode-Extension" , "; HostApp/VSCode-Extension" ), # Valid, correct case
317- ("vscode-extension" , "; HostApp/VSCode-Extension" ), # Valid, lower case
318- ("VSCodE-ExTenSion" , "; HostApp/VSCode-Extension" ), # Valid, mixed case
319316 (
320- "Azure-DevOps-Pipeline" ,
321- "; HostApp/Azure-DevOps-Pipeline" ,
322- ), # Valid, correct case
317+ "Fabric-AzureDevops-Extension" ,
318+ None ,
319+ " host-app/fabric-azuredevops-extension" ,
320+ ),
323321 (
324- "azure-devops-pipeline" ,
325- "; HostApp/Azure-DevOps-Pipeline" ,
326- ), # Valid, lower case
327- ("Invalid-App" , "" ), # Invalid
328- ("" , "" ), # Empty
329- (None , "" ), # Not set
322+ "Fabric-AzureDevops-Extension" ,
323+ "1.2.0" ,
324+ " host-app/fabric-azuredevops-extension/1.2.0" ,
325+ ),
326+ (
327+ "fabric-azuredevops-extension" ,
328+ "1.2.0" ,
329+ " host-app/fabric-azuredevops-extension/1.2.0" ,
330+ ),
331+ ("Invalid-App" , "1.0.0" , "" ),
332+ ("" , None , "" ),
333+ (None , None , "" ),
334+ (
335+ "Fabric-AzureDevops-Extension" ,
336+ "1.2.0.4" , # Invalid format
337+ " host-app/fabric-azuredevops-extension" ,
338+ ),
339+ (
340+ "Fabric-AzureDevops-Extension" ,
341+ "1.2.a" , # Invalid format
342+ " host-app/fabric-azuredevops-extension" ,
343+ ),
344+ (
345+ "Fabric-AzureDevops-Extension" ,
346+ "a.b.c" , # Invalid format
347+ " host-app/fabric-azuredevops-extension" ,
348+ ),
349+ (
350+ "Fabric-AzureDevops-Extension" ,
351+ "1" , # valid format
352+ " host-app/fabric-azuredevops-extension/1" ,
353+ ),
354+ (
355+ "Fabric-AzureDevops-Extension" ,
356+ "1.2" , # valid format
357+ " host-app/fabric-azuredevops-extension/1.2" ,
358+ ),
359+ (
360+ "Fabric-AzureDevops-Extension" ,
361+ "1.0.0" , # valid format
362+ " host-app/fabric-azuredevops-extension/1.0.0" ,
363+ ),
364+ (
365+ "Fabric-AzureDevops-Extension" ,
366+ "1.0.0-rc.1" , # valid format
367+ " host-app/fabric-azuredevops-extension/1.0.0-rc.1" ,
368+ ),
369+ (
370+ "Fabric-AzureDevops-Extension" ,
371+ "1.0.0-alpha" , # valid format
372+ " host-app/fabric-azuredevops-extension/1.0.0-alpha" ,
373+ ),
374+ (
375+ "Fabric-AzureDevops-Extension" ,
376+ "1.0.0-beta" , # valid format
377+ " host-app/fabric-azuredevops-extension/1.0.0-beta" ,
378+ ),
330379 ],
331380)
332- def test_get_host_app_suffix (host_app_env , expected_suffix , monkeypatch ):
333- """Test the _get_host_app_suffix helper function."""
381+ def test_get_host_app (host_app_env , host_app_version_env , expected_suffix , monkeypatch ):
382+ """Test the _get_host_app helper function."""
334383 if host_app_env is not None :
335384 monkeypatch .setenv (fab_constant .FAB_HOST_APP_ENV_VAR , host_app_env )
336385 else :
337386 monkeypatch .delenv (fab_constant .FAB_HOST_APP_ENV_VAR , raising = False )
338387
339- result = _get_host_app_suffix ()
388+ if host_app_version_env is not None :
389+ monkeypatch .setenv (
390+ fab_constant .FAB_HOST_APP_VERSION_ENV_VAR , host_app_version_env
391+ )
392+ else :
393+ monkeypatch .delenv (fab_constant .FAB_HOST_APP_VERSION_ENV_VAR , raising = False )
394+
395+ result = _get_host_app ()
340396
341397 assert result == expected_suffix
342398
@@ -346,37 +402,38 @@ def setup_default_private_links(mock_fab_set_state_config):
346402 mock_fab_set_state_config (fab_constant .FAB_WS_PRIVATE_LINKS_ENABLED , "true" )
347403
348404
405+ @patch ("platform.python_version" , return_value = "3.11.5" )
349406@patch ("platform.release" , return_value = "5.4.0" )
350- @patch ("platform.machine" , return_value = "x86_64" )
351407@patch ("platform.system" , return_value = "Linux" )
352408@patch ("requests.Session.request" )
353409@patch ("fabric_cli.core.fab_auth.FabAuth" )
354410@patch ("fabric_cli.core.fab_context.Context" )
355411@pytest .mark .parametrize (
356- "host_app_env, expected_suffix" ,
412+ "host_app_env, host_app_version_env, expected_suffix" ,
357413 [
358- (None , "" ), # No env var set
359- ("VSCode-Extension" , "; HostApp/VSCode-Extension" ), # Valid and allowed
414+ (None , None , "" ),
360415 (
361- "Azure-DevOps-Pipeline" ,
362- "; HostApp/Azure-DevOps-Pipeline" ,
363- ), # Valid and allowed
416+ "Fabric-AzureDevops-Extension" ,
417+ None ,
418+ " host-app/fabric-azuredevops-extension" ,
419+ ),
364420 (
365- "vscode-extension " ,
366- "; HostApp/VSCode-Extension " ,
367- ), # Valid and allowed (case-insensitive)
368- ( "Invalid-App" , "" ), # Invalid and not in allowlist
369- ("" , "" ), # Empty value
421+ "Fabric-AzureDevops-Extension " ,
422+ "1.2.0 " ,
423+ " host-app/fabric-azuredevops-extension/1.2.0" ,
424+ ),
425+ ("Invalid-App " , "1.0.0" , "" ),
370426 ],
371427)
372428def test_do_request_user_agent_header (
373429 mock_context ,
374430 mock_auth ,
375431 mock_request ,
376432 mock_system ,
377- mock_machine ,
378433 mock_release ,
434+ mock_python_version ,
379435 host_app_env ,
436+ host_app_version_env ,
380437 expected_suffix ,
381438 monkeypatch ,
382439):
@@ -386,6 +443,13 @@ def test_do_request_user_agent_header(
386443 else :
387444 monkeypatch .delenv (fab_constant .FAB_HOST_APP_ENV_VAR , raising = False )
388445
446+ if host_app_version_env is not None :
447+ monkeypatch .setenv (
448+ fab_constant .FAB_HOST_APP_VERSION_ENV_VAR , host_app_version_env
449+ )
450+ else :
451+ monkeypatch .delenv (fab_constant .FAB_HOST_APP_VERSION_ENV_VAR , raising = False )
452+
389453 # Configure mocks
390454 mock_auth .return_value .get_access_token .return_value = "dummy-token"
391455 mock_context .return_value .command = "test-command"
@@ -418,7 +482,7 @@ class DummyResponse:
418482
419483 base_user_agent = (
420484 f"{ fab_constant .API_USER_AGENT } /{ fab_constant .FAB_VERSION } "
421- f"(test-command; Linux; x86_64; 5.4.0)"
485+ f"(test-command; Linux/ 5.4.0; Python/3.11.5 )"
422486 )
423487 expected_user_agent = base_user_agent + expected_suffix
424488
0 commit comments