Skip to content

Commit 31f230e

Browse files
authored
fix(tui): cycle to real workspaces instead of a phantom "default" (#4126)
`cycle_workspace` hardcoded "default" when entering the named-workspace scope from the "all" scope (and when wrapping around). This assumed the server-provided `workspace_names` list always contains "default" and lists it first. That assumption does not hold: the TUI populates `workspace_names` from `ListWorkspaces`, which is membership-scoped per principal. A non-admin user who is not a member of the "default" workspace receives a list that omits it entirely. In that case, after one full cycle the scope indicator lands on "default" — a workspace that does not exist in the list — and the next cycle finds no match, flipping straight back to "all". The user can never return to any of their real workspaces by cycling. Enter the named scope at `workspace_names.first()` instead, and only when at least one workspace is known. The stale `current_workspace = "default"` writes in the "all" branches are dropped since `current_workspace` is unused while `all_workspaces` is set. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
1 parent bfa68b2 commit 31f230e

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

  • crates/openshell-tui/src

‎crates/openshell-tui/src/app.rs‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,16 @@ impl App {
12151215

12161216
pub fn cycle_workspace(&mut self) {
12171217
if self.all_workspaces {
1218-
self.all_workspaces = false;
1219-
self.current_workspace = "default".to_string();
1218+
// Leaving "all" scope: return to the first known named workspace.
1219+
// The workspace list is server-provided and membership-scoped, so
1220+
// it is not guaranteed to contain (or start with) "default"; only
1221+
// enter named scope when at least one workspace is known.
1222+
if let Some(first) = self.workspace_names.first() {
1223+
self.all_workspaces = false;
1224+
self.current_workspace = first.clone();
1225+
}
12201226
} else if self.workspace_names.is_empty() {
12211227
self.all_workspaces = true;
1222-
self.current_workspace = "default".to_string();
12231228
} else {
12241229
let current_idx = self
12251230
.workspace_names
@@ -1231,7 +1236,6 @@ impl App {
12311236
}
12321237
_ => {
12331238
self.all_workspaces = true;
1234-
self.current_workspace = "default".to_string();
12351239
}
12361240
}
12371241
}
@@ -4177,6 +4181,36 @@ mod tests {
41774181
assert_eq!(app.current_workspace, "default");
41784182
}
41794183

4184+
#[tokio::test]
4185+
async fn cycle_workspace_without_default_stays_on_real_workspaces() {
4186+
// The workspace list is server-provided and membership-scoped, so a
4187+
// non-admin principal may have no "default" workspace visible.
4188+
let mut app = test_app();
4189+
app.workspace_names = vec!["team-a".to_string(), "team-b".to_string()];
4190+
app.current_workspace = "team-a".to_string();
4191+
app.all_workspaces = false;
4192+
4193+
// Collect every named-scope selection across several full cycles. Each
4194+
// named scope must be a workspace that actually exists in the list;
4195+
// the cursor must never land on a phantom "default".
4196+
let mut named_scopes = Vec::new();
4197+
for _ in 0..8 {
4198+
if !app.all_workspaces {
4199+
assert!(
4200+
app.workspace_names.contains(&app.current_workspace),
4201+
"cycled to '{}', which is not a known workspace",
4202+
app.current_workspace
4203+
);
4204+
named_scopes.push(app.current_workspace.clone());
4205+
}
4206+
app.cycle_workspace();
4207+
}
4208+
4209+
// Both real workspaces must be reachable by repeated cycling.
4210+
assert!(named_scopes.iter().any(|w| w == "team-a"));
4211+
assert!(named_scopes.iter().any(|w| w == "team-b"));
4212+
}
4213+
41804214
// -- selected_sandbox_workspace ----------------------------------------
41814215

41824216
#[test]

0 commit comments

Comments
 (0)