@@ -316,6 +316,64 @@ async def test_get_cloud_control_plane_client_uses_oauth_token(config_manager):
316316 assert client .headers .get ("Authorization" ) == "Bearer oauth-control-123"
317317
318318
319+ @pytest .mark .asyncio
320+ async def test_get_cloud_control_plane_client_with_workspace (config_manager ):
321+ """Control plane client passes X-Workspace-ID header when workspace is provided."""
322+ cfg = config_manager .load_config ()
323+ cfg .cloud_host = "https://cloud.example.test"
324+ cfg .cloud_api_key = "bmc_test_key_123"
325+ config_manager .save_config (cfg )
326+
327+ async with get_cloud_control_plane_client (workspace = "tenant-abc" ) as client :
328+ assert client .headers .get ("X-Workspace-ID" ) == "tenant-abc"
329+
330+ # Without workspace, header should not be present
331+ async with get_cloud_control_plane_client () as client :
332+ assert "X-Workspace-ID" not in client .headers
333+
334+
335+ @pytest .mark .asyncio
336+ async def test_get_client_auto_resolves_workspace_from_project_config (config_manager ):
337+ """get_client resolves workspace from project entry when not explicitly passed."""
338+ cfg = config_manager .load_config ()
339+ cfg .cloud_host = "https://cloud.example.test"
340+ cfg .cloud_api_key = "bmc_test_key_123"
341+ cfg .set_project_mode ("research" , ProjectMode .CLOUD )
342+ cfg .projects ["research" ].workspace_id = "tenant-from-config"
343+ config_manager .save_config (cfg )
344+
345+ async with get_client (project_name = "research" ) as client :
346+ assert client .headers .get ("X-Workspace-ID" ) == "tenant-from-config"
347+
348+
349+ @pytest .mark .asyncio
350+ async def test_get_client_auto_resolves_workspace_from_default (config_manager ):
351+ """get_client falls back to default_workspace when project has no workspace_id."""
352+ cfg = config_manager .load_config ()
353+ cfg .cloud_host = "https://cloud.example.test"
354+ cfg .cloud_api_key = "bmc_test_key_123"
355+ cfg .set_project_mode ("research" , ProjectMode .CLOUD )
356+ cfg .default_workspace = "default-tenant-456"
357+ config_manager .save_config (cfg )
358+
359+ async with get_client (project_name = "research" ) as client :
360+ assert client .headers .get ("X-Workspace-ID" ) == "default-tenant-456"
361+
362+
363+ @pytest .mark .asyncio
364+ async def test_get_client_explicit_workspace_overrides_config (config_manager ):
365+ """Explicit workspace param takes priority over project config."""
366+ cfg = config_manager .load_config ()
367+ cfg .cloud_host = "https://cloud.example.test"
368+ cfg .cloud_api_key = "bmc_test_key_123"
369+ cfg .set_project_mode ("research" , ProjectMode .CLOUD )
370+ cfg .projects ["research" ].workspace_id = "tenant-from-config"
371+ config_manager .save_config (cfg )
372+
373+ async with get_client (project_name = "research" , workspace = "explicit-tenant" ) as client :
374+ assert client .headers .get ("X-Workspace-ID" ) == "explicit-tenant"
375+
376+
319377@pytest .mark .asyncio
320378async def test_get_cloud_control_plane_client_raises_without_credentials (config_manager ):
321379 cfg = config_manager .load_config ()
0 commit comments