From d4887c93c1e8bf84aa77f5deedd078135bef1181 Mon Sep 17 00:00:00 2001 From: Nathan Thillairajah Date: Tue, 17 Nov 2026 11:24:22 -0500 Subject: [PATCH 1/3] bl apps: say community sharing is off on workstations without it On a Blox workstation that hasn't opted in to community sharing (no BL_APPS_COMMUNITY_SHARING=enabled), `bl apps community list` fell back to a local login the workstation never has and reported `auth_required` or `org_required`. Agents read that as a login problem and went looking for workarounds, such as the skill's relay fallback, that end in a 403. `list` now refuses up front with `community_sharing_unavailable_through_proxy`, the same code grant and revoke already use, and both messages point to `bl apps visibility APP_ID workspace` as the way to let others open the app. Co-authored-by: Mark S Co-Authored-By: Claude Opus 5.5 --- src/bl/apps.rs | 115 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 13 deletions(-) diff --git a/src/bl/apps.rs b/src/bl/apps.rs index c832825..820b356 100644 --- a/src/bl/apps.rs +++ b/src/bl/apps.rs @@ -490,7 +490,8 @@ pub fn command() -> Command { .long_about( "List the Buzz communities your linked Buzz identity has joined, with the \ COMMUNITY_ID that `bl apps community grant` takes. Needs `bl auth login`, except on a \ - Blox workstation set up for community sharing.", + Blox workstation set up for community sharing. Other Blox workstations \ + can't share with communities and say so.", ), ), ) @@ -718,7 +719,10 @@ pub fn run(matches: &ArgMatches) -> Result<()> { } fn dispatch(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { - if !uses_proxy_auth(matches) && !lists_communities_through_proxy(matches) { + if !uses_proxy_auth(matches) + && !lists_communities_through_proxy(matches) + && !refuses_community_list_on_this_workstation(matches) + { runner::ensure_org_configured(config)?; } match matches.subcommand() { @@ -1662,6 +1666,18 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { .subcommand() .context("expected community grant, revoke or list")?; if action == "list" { + // Without the opt-in, `list` would fall back to a local login that a + // workstation never has, and report `auth_required` or `org_required` + // as if logging in would help. Say sharing is off here instead. + if apps_on_blox() && !community_sharing_through_proxy() { + return Err(community_sharing_unavailable( + "APP_ID", + format!( + "Share an app with its workspace instead: {}", + workspace_visibility_command("APP_ID") + ), + )); + } return run_community_list(config); } let app_id = action_matches @@ -1679,16 +1695,10 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { if proxy_auth_for_url(base_url) && !community_sharing_through_proxy() { // This only runs on a Blox workstation, where the agent can't log in or // pick another ingress, so the owner's way forward is the browser. - let next_action = community_share_and_manage_step(app_id); - let mut error = CliFailure::new( - exit_codes::GENERAL, - "community_sharing_unavailable_through_proxy", - format!( - "Community sharing isn't available through this Blox workstation's proxy.\nnext_action: {next_action}" - ), - ); - error.next_action = Some(json!(next_action)); - return Err(anyhow::Error::new(error)); + return Err(community_sharing_unavailable( + app_id, + community_share_and_manage_step(app_id), + )); } let (client, credential) = control_plane_context(config, action_matches)?; // Kgoose replaces the session with a credential bound to the owner, app and @@ -1811,11 +1821,21 @@ fn proxied_joined_communities_service_url(config: &SkillsConfig) -> Option bool { +fn is_community_list(matches: &ArgMatches) -> bool { matches .subcommand() .filter(|(name, _)| *name == "community") .is_some_and(|(_, community)| community.subcommand_name() == Some("list")) +} + +// `run_community` refuses `list` on an Apps workstation without the opt-in; +// let it, rather than stopping first on a local org the workstation never has. +fn refuses_community_list_on_this_workstation(matches: &ArgMatches) -> bool { + is_community_list(matches) && apps_on_blox() && !community_sharing_through_proxy() +} + +fn lists_communities_through_proxy(matches: &ArgMatches) -> bool { + is_community_list(matches) && community_sharing_through_proxy() && super::workspace::workstation_base_url() .ok() @@ -3257,6 +3277,30 @@ fn is_blox_control_plane_url(url: &url::Url) -> bool { .is_some_and(|configured| configured.origin() == url.origin()) } +// A Blox workstation the operator set up for Apps: Roxy authenticates the +// control plane, and the agent can't log in. +fn apps_on_blox() -> bool { + on_blox() && std::env::var(APPS_BASE_URL_ENV_VAR).is_ok_and(|url| !url.trim().is_empty()) +} + +fn workspace_visibility_command(app_id: &str) -> String { + format!("bl apps visibility {app_id} workspace") +} + +fn community_sharing_unavailable(app_id: &str, next_action: String) -> anyhow::Error { + let mut error = CliFailure::new( + exit_codes::GENERAL, + "community_sharing_unavailable_through_proxy", + format!( + "Community sharing isn't available on this Blox workstation. To let everyone in the \ + app's workspace open it, run `{}`.\nnext_action: {next_action}", + workspace_visibility_command(app_id) + ), + ); + error.next_action = Some(json!(next_action)); + anyhow::Error::new(error) +} + fn community_sharing_through_proxy() -> bool { std::env::var(APPS_COMMUNITY_SHARING_ENV_VAR).as_deref() == Ok("enabled") } @@ -9986,6 +10030,11 @@ mod tests { ); let next_action = error["next_action"].as_str().unwrap(); assert!(next_action.contains("Share & manage"), "{next_action}"); + let message = error["error"]["message"].as_str().unwrap(); + assert!( + message.contains("bl apps visibility my-app workspace"), + "{message}" + ); // A workstation agent can't log in or choose another base URL. for advice in ["bl auth login", "--base-url"] { assert!(!next_action.contains(advice), "{next_action}"); @@ -10141,6 +10190,46 @@ mod tests { } } + #[test] + fn bl_apps_community_list_says_sharing_is_off_on_an_apps_workstation_without_the_opt_in() { + // An Apps workstation that hasn't opted in (bb-block) can't list + // communities. Say so instead of reporting a login the agent can't do. + for value in [None, Some(""), Some("true"), Some("disabled")] { + let kgoose = ProcessServer::start(vec![]); + let control_plane = ProcessServer::start(vec![]); + let mut command = process_command( + &kgoose, + &control_plane, + &["apps", "community", "list", "--json"], + "apps-e2e-only.unused", + ); + command + .env("BL_APPS_E2E_PROXY", "true") + .env(APPS_BASE_URL_ENV_VAR, "http://compose.mesh.example") + .env("BL_TOOLS_BASE_URL", &kgoose.base_url); + if let Some(value) = value { + command.env(APPS_COMMUNITY_SHARING_ENV_VAR, value); + } + let output = command.output().expect("run community list process"); + assert_eq!(output.status.code(), Some(exit_codes::GENERAL), "{value:?}"); + let error = process_error(&output); + assert_eq!( + error["error"]["code"], + "community_sharing_unavailable_through_proxy" + ); + let next_action = error["next_action"].as_str().unwrap(); + assert!( + next_action.contains("bl apps visibility APP_ID workspace"), + "{next_action}" + ); + for advice in ["bl auth login", "--base-url"] { + assert!(!error.to_string().contains(advice), "{error}"); + } + assert!(kgoose.finish().is_empty(), "{value:?}"); + assert!(control_plane.finish().is_empty()); + } + } + #[test] fn bl_apps_community_list_stays_off_the_blox_proxy_without_the_exact_opt_in() { for value in [None, Some(""), Some("true"), Some("disabled")] { From eeb23415ff9e9475230ecb8a4ea21cfe0b5ce35d Mon Sep 17 00:00:00 2001 From: Nathan Thillairajah Date: Tue, 17 Nov 2026 12:31:54 -0500 Subject: [PATCH 2/3] bl apps: point the community refusal at workspace visibility only Where a workstation can't share with communities, Share & manage can't either, so sending the owner there was another dead end. The refusal from community list, grant and revoke now names only `bl apps visibility APP_ID workspace`. Co-authored-by: Mark S Co-Authored-By: Claude Opus 5.5 --- src/bl/apps.rs | 155 ++++++++++++++++++------------------------------- 1 file changed, 58 insertions(+), 97 deletions(-) diff --git a/src/bl/apps.rs b/src/bl/apps.rs index 820b356..55cf066 100644 --- a/src/bl/apps.rs +++ b/src/bl/apps.rs @@ -1080,12 +1080,6 @@ fn share_and_manage_step(portal: Option<&url::Url>, app_id: &str) -> String { } } -fn community_share_and_manage_step(app_id: &str) -> String { - // An unusable origin only drops the link; the failure it decorates stands. - let portal = configured_management_portal(None).ok().flatten(); - share_and_manage_step(portal.as_ref(), app_id) -} - fn build_app_handoff( app_id: &str, portal: Option<&url::Url>, @@ -1670,13 +1664,7 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { // workstation never has, and report `auth_required` or `org_required` // as if logging in would help. Say sharing is off here instead. if apps_on_blox() && !community_sharing_through_proxy() { - return Err(community_sharing_unavailable( - "APP_ID", - format!( - "Share an app with its workspace instead: {}", - workspace_visibility_command("APP_ID") - ), - )); + return Err(community_sharing_unavailable("APP_ID")); } return run_community_list(config); } @@ -1694,11 +1682,8 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { // the owner credential the proxy forwards, so stop before any request. if proxy_auth_for_url(base_url) && !community_sharing_through_proxy() { // This only runs on a Blox workstation, where the agent can't log in or - // pick another ingress, so the owner's way forward is the browser. - return Err(community_sharing_unavailable( - app_id, - community_share_and_manage_step(app_id), - )); + // pick another ingress. Workspace visibility is the way to widen access. + return Err(community_sharing_unavailable(app_id)); } let (client, credential) = control_plane_context(config, action_matches)?; // Kgoose replaces the session with a credential bound to the owner, app and @@ -3287,14 +3272,16 @@ fn workspace_visibility_command(app_id: &str) -> String { format!("bl apps visibility {app_id} workspace") } -fn community_sharing_unavailable(app_id: &str, next_action: String) -> anyhow::Error { +fn community_sharing_unavailable(app_id: &str) -> anyhow::Error { + let next_action = format!( + "To let everyone in the app's workspace open it, run `{}`.", + workspace_visibility_command(app_id) + ); let mut error = CliFailure::new( exit_codes::GENERAL, "community_sharing_unavailable_through_proxy", format!( - "Community sharing isn't available on this Blox workstation. To let everyone in the \ - app's workspace open it, run `{}`.\nnext_action: {next_action}", - workspace_visibility_command(app_id) + "Community sharing isn't available on this Blox workstation.\nnext_action: {next_action}" ), ); error.next_action = Some(json!(next_action)); @@ -10029,11 +10016,9 @@ mod tests { "community_sharing_unavailable_through_proxy" ); let next_action = error["next_action"].as_str().unwrap(); - assert!(next_action.contains("Share & manage"), "{next_action}"); - let message = error["error"]["message"].as_str().unwrap(); assert!( - message.contains("bl apps visibility my-app workspace"), - "{message}" + next_action.contains("bl apps visibility my-app workspace"), + "{next_action}" ); // A workstation agent can't log in or choose another base URL. for advice in ["bl auth login", "--base-url"] { @@ -10345,77 +10330,53 @@ mod tests { } #[test] - fn bl_apps_community_proxy_refusal_links_share_and_manage_when_the_portal_is_known() { - let auth_server = ProcessServer::start(vec![]); - let control_plane = ProcessServer::start(vec![]); - let output = process_command( - &auth_server, - &control_plane, - &[ - "apps", - "community", - "grant", - "my-app", - "buzz-alpha", - "--json", - ], - "apps-e2e-only.unused", - ) - .env("BL_APPS_E2E_PROXY", "true") - .env(APPS_BASE_URL_ENV_VAR, "http://compose.mesh.example") - .env("BL_APPS_MANAGEMENT_BASE_URL", "https://app.builderlab.xyz") - .output() - .expect("run proxied community process"); - let error = process_error(&output); - assert_eq!( - error["error"]["code"], - "community_sharing_unavailable_through_proxy" - ); - let next_action = error["next_action"].as_str().unwrap(); - // The portal only opens an app's dialog when it also gets the workspace. - assert!(next_action.contains( - "Open Share & manage at https://app.builderlab.xyz/hosted-apps and choose my-app." - )); - assert!(!next_action.contains("app=")); - assert!(error["error"]["message"] - .as_str() - .unwrap() - .contains(next_action)); - assert!(auth_server.finish().is_empty()); - assert!(control_plane.finish().is_empty()); - } - - #[test] - fn bl_apps_community_proxy_refusal_points_to_the_browser_dialog_without_a_portal() { - let auth_server = ProcessServer::start(vec![]); - let control_plane = ProcessServer::start(vec![]); - let output = process_command( - &auth_server, - &control_plane, - &[ - "apps", - "community", - "grant", - "my-app", - "buzz-alpha", - "--json", - ], - "apps-e2e-only.unused", - ) - .env("BL_APPS_E2E_PROXY", "true") - .env(APPS_BASE_URL_ENV_VAR, "http://compose.mesh.example") - .output() - .expect("run proxied community process"); - let error = process_error(&output); - let next_action = error["next_action"].as_str().unwrap(); - assert!(next_action.contains( - "Open Hosted Apps in the BuilderLab portal and use Share & manage on my-app." - )); - assert!(!next_action.contains("https://")); - assert!(error["error"]["message"] - .as_str() - .unwrap() - .contains(next_action)); + fn bl_apps_community_proxy_refusal_points_to_workspace_visibility_not_the_portal() { + // Share & manage can't share with communities where the workstation + // can't either, so the refusal names workspace visibility even when the + // portal is known. + for portal in [Some("https://app.builderlab.xyz"), None] { + let auth_server = ProcessServer::start(vec![]); + let control_plane = ProcessServer::start(vec![]); + let mut command = process_command( + &auth_server, + &control_plane, + &[ + "apps", + "community", + "grant", + "my-app", + "buzz-alpha", + "--json", + ], + "apps-e2e-only.unused", + ); + command + .env("BL_APPS_E2E_PROXY", "true") + .env(APPS_BASE_URL_ENV_VAR, "http://compose.mesh.example"); + if let Some(portal) = portal { + command.env("BL_APPS_MANAGEMENT_BASE_URL", portal); + } + let output = command.output().expect("run proxied community process"); + let error = process_error(&output); + assert_eq!( + error["error"]["code"], + "community_sharing_unavailable_through_proxy" + ); + let next_action = error["next_action"].as_str().unwrap(); + assert_eq!( + next_action, + "To let everyone in the app's workspace open it, run \ + `bl apps visibility my-app workspace`.", + "{portal:?}" + ); + assert!(!next_action.contains("Share & manage"), "{portal:?}"); + assert!(error["error"]["message"] + .as_str() + .unwrap() + .contains(next_action)); + assert!(auth_server.finish().is_empty()); + assert!(control_plane.finish().is_empty()); + } } #[test] From 359048810beaa9806bf64b562440248f7ad68662 Mon Sep 17 00:00:00 2001 From: Nathan Thillairajah Date: Tue, 17 Nov 2026 16:05:50 -0500 Subject: [PATCH 3/3] Don't suggest widening access when a revoke is refused A revoke narrows access, so pointing it at workspace visibility sends the user the wrong way. Grant and list keep the visibility advice. Co-Authored-By: Claude Opus 5.5 --- src/bl/apps.rs | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/bl/apps.rs b/src/bl/apps.rs index 55cf066..155c3c3 100644 --- a/src/bl/apps.rs +++ b/src/bl/apps.rs @@ -1664,7 +1664,7 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { // workstation never has, and report `auth_required` or `org_required` // as if logging in would help. Say sharing is off here instead. if apps_on_blox() && !community_sharing_through_proxy() { - return Err(community_sharing_unavailable("APP_ID")); + return Err(community_sharing_unavailable(Some("APP_ID"))); } return run_community_list(config); } @@ -1682,8 +1682,10 @@ fn run_community(config: &SkillsConfig, matches: &ArgMatches) -> Result<()> { // the owner credential the proxy forwards, so stop before any request. if proxy_auth_for_url(base_url) && !community_sharing_through_proxy() { // This only runs on a Blox workstation, where the agent can't log in or - // pick another ingress. Workspace visibility is the way to widen access. - return Err(community_sharing_unavailable(app_id)); + // pick another ingress. Workspace visibility is the way to widen access, + // so only a grant points there; widening is the opposite of a revoke. + let widen = (action == "grant").then_some(app_id.as_str()); + return Err(community_sharing_unavailable(widen)); } let (client, credential) = control_plane_context(config, action_matches)?; // Kgoose replaces the session with a credential bound to the owner, app and @@ -3272,7 +3274,17 @@ fn workspace_visibility_command(app_id: &str) -> String { format!("bl apps visibility {app_id} workspace") } -fn community_sharing_unavailable(app_id: &str) -> anyhow::Error { +/// `widen_app_id` names the app to suggest workspace visibility for. Pass `None` +/// when the user is narrowing access (a revoke), where widening would be wrong. +fn community_sharing_unavailable(widen_app_id: Option<&str>) -> anyhow::Error { + let message = "Community sharing isn't available on this Blox workstation."; + let Some(app_id) = widen_app_id else { + return anyhow::Error::new(CliFailure::new( + exit_codes::GENERAL, + "community_sharing_unavailable_through_proxy", + message.to_string(), + )); + }; let next_action = format!( "To let everyone in the app's workspace open it, run `{}`.", workspace_visibility_command(app_id) @@ -3280,9 +3292,7 @@ fn community_sharing_unavailable(app_id: &str) -> anyhow::Error { let mut error = CliFailure::new( exit_codes::GENERAL, "community_sharing_unavailable_through_proxy", - format!( - "Community sharing isn't available on this Blox workstation.\nnext_action: {next_action}" - ), + format!("{message}\nnext_action: {next_action}"), ); error.next_action = Some(json!(next_action)); anyhow::Error::new(error) @@ -10015,18 +10025,24 @@ mod tests { error["error"]["code"], "community_sharing_unavailable_through_proxy" ); - let next_action = error["next_action"].as_str().unwrap(); - assert!( - next_action.contains("bl apps visibility my-app workspace"), - "{next_action}" - ); - // A workstation agent can't log in or choose another base URL. - for advice in ["bl auth login", "--base-url"] { - assert!(!next_action.contains(advice), "{next_action}"); + let message = error["error"]["message"].as_str().unwrap(); + if action == "grant" { + let next_action = error["next_action"].as_str().unwrap(); assert!( - !error["error"]["message"].as_str().unwrap().contains(advice), - "{error}" + next_action.contains("bl apps visibility my-app workspace"), + "{next_action}" ); + } else { + // Widening to the workspace is the opposite of a revoke. + assert!(error["next_action"].is_null(), "{error}"); + assert!(!message.contains("bl apps visibility"), "{message}"); + } + // A workstation agent can't log in or choose another base URL. + for advice in ["bl auth login", "--base-url"] { + assert!(!message.contains(advice), "{error}"); + if let Some(next_action) = error["next_action"].as_str() { + assert!(!next_action.contains(advice), "{next_action}"); + } } assert!(auth_server.finish().is_empty()); assert!(control_plane.finish().is_empty());