Add client-side user setting for agent commit attribution (#9323)
This commit is contained in:
@@ -827,6 +827,10 @@ impl From<GqlWorkspaceSettings> for WorkspaceSettings {
|
||||
.map(|denylist| denylist.to_predicates()),
|
||||
}
|
||||
}),
|
||||
enable_warp_attribution: gql_workspace_settings
|
||||
.ambient_agent_settings
|
||||
.map(|s| s.enable_warp_attribution.into())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1456,6 +1456,16 @@ impl UserWorkspaces {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the team-level agent attribution setting.
|
||||
///
|
||||
/// Use this to decide whether the user's attribution toggle should be locked
|
||||
/// (`Enable`/`Disable`) or editable (`RespectUserSetting`).
|
||||
pub fn get_agent_attribution_setting(&self) -> AdminEnablementSetting {
|
||||
self.current_team()
|
||||
.map(|team| team.organization_settings.enable_warp_attribution.clone())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Returns only the organization-specific codebase context enablement setting.
|
||||
/// Do not use this function to determine whether codebase context is generally enabled --
|
||||
/// use `is_codebase_context_enabled` instead.
|
||||
|
||||
@@ -614,6 +614,108 @@ fn test_joining_team_moves_objects() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_agent_attribution_default_with_no_workspace() {
|
||||
App::test((), |mut app| async move {
|
||||
initialize_app(
|
||||
&mut app,
|
||||
CachedResources { workspaces: vec![] },
|
||||
Arc::new(MockTeamClient::new()),
|
||||
Arc::new(MockWorkspaceClient::new()),
|
||||
);
|
||||
|
||||
app.read(|ctx| {
|
||||
let setting = UserWorkspaces::as_ref(ctx).get_agent_attribution_setting();
|
||||
assert_eq!(
|
||||
setting,
|
||||
AdminEnablementSetting::RespectUserSetting,
|
||||
"attribution should default to RespectUserSetting when there is no workspace"
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_agent_attribution_forced_on_by_team() {
|
||||
let mut team = team_for_test();
|
||||
team.organization_settings.enable_warp_attribution = AdminEnablementSetting::Enable;
|
||||
let workspace = workspace_for_test(&team);
|
||||
|
||||
App::test((), |mut app| async move {
|
||||
initialize_app(
|
||||
&mut app,
|
||||
CachedResources {
|
||||
workspaces: vec![workspace],
|
||||
},
|
||||
Arc::new(MockTeamClient::new()),
|
||||
Arc::new(MockWorkspaceClient::new()),
|
||||
);
|
||||
|
||||
app.read(|ctx| {
|
||||
let setting = UserWorkspaces::as_ref(ctx).get_agent_attribution_setting();
|
||||
assert_eq!(
|
||||
setting,
|
||||
AdminEnablementSetting::Enable,
|
||||
"attribution should be Enable when forced on by the team"
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_agent_attribution_forced_off_by_team() {
|
||||
let mut team = team_for_test();
|
||||
team.organization_settings.enable_warp_attribution = AdminEnablementSetting::Disable;
|
||||
let workspace = workspace_for_test(&team);
|
||||
|
||||
App::test((), |mut app| async move {
|
||||
initialize_app(
|
||||
&mut app,
|
||||
CachedResources {
|
||||
workspaces: vec![workspace],
|
||||
},
|
||||
Arc::new(MockTeamClient::new()),
|
||||
Arc::new(MockWorkspaceClient::new()),
|
||||
);
|
||||
|
||||
app.read(|ctx| {
|
||||
let setting = UserWorkspaces::as_ref(ctx).get_agent_attribution_setting();
|
||||
assert_eq!(
|
||||
setting,
|
||||
AdminEnablementSetting::Disable,
|
||||
"attribution should be Disable when forced off by the team"
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_agent_attribution_respects_user_setting() {
|
||||
let mut team = team_for_test();
|
||||
team.organization_settings.enable_warp_attribution = AdminEnablementSetting::RespectUserSetting;
|
||||
let workspace = workspace_for_test(&team);
|
||||
|
||||
App::test((), |mut app| async move {
|
||||
initialize_app(
|
||||
&mut app,
|
||||
CachedResources {
|
||||
workspaces: vec![workspace],
|
||||
},
|
||||
Arc::new(MockTeamClient::new()),
|
||||
Arc::new(MockWorkspaceClient::new()),
|
||||
);
|
||||
|
||||
app.read(|ctx| {
|
||||
let setting = UserWorkspaces::as_ref(ctx).get_agent_attribution_setting();
|
||||
assert_eq!(
|
||||
setting,
|
||||
AdminEnablementSetting::RespectUserSetting,
|
||||
"attribution should be RespectUserSetting when the team defers to user preference"
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_leaving_team_moves_objects() {
|
||||
let _flag = FeatureFlag::SharedWithMe.override_enabled(true);
|
||||
|
||||
@@ -774,4 +774,8 @@ pub struct WorkspaceSettings {
|
||||
pub addon_credits_settings: AddonCreditsSettings,
|
||||
pub codebase_context_settings: CodebaseContextSettings,
|
||||
pub sandboxed_agent_settings: Option<SandboxedAgentSettings>,
|
||||
/// The team-level agent attribution setting. When `Enable` or `Disable`, the
|
||||
/// user toggle is locked. When `RespectUserSetting` (or absent), the user can choose.
|
||||
#[serde(default)]
|
||||
pub enable_warp_attribution: AdminEnablementSetting,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user