diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-04 01:50:34 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-04 01:50:34 +0300 |
| commit | 831894facfc1339f819b42c3339668154121d24f (patch) | |
| tree | 3a49bad36a65341f6296b9f3d568317e15b6c21a /tests | |
| parent | e0fb8ca6fa55acaa72902a15c5468cbe2787ddf7 (diff) | |
refactor: make workspace api ids stable
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/api_ping.rs | 117 | ||||
| -rw-r--r-- | tests/cli_wrapper.rs | 116 |
2 files changed, 171 insertions, 62 deletions
diff --git a/tests/api_ping.rs b/tests/api_ping.rs index 94e1e3f9..fd113917 100644 --- a/tests/api_ping.rs +++ b/tests/api_ping.rs @@ -227,11 +227,18 @@ fn workspace_list_and_create_round_trip() { ); assert_eq!(created["id"], "req_3"); assert_eq!(created["result"]["type"], "workspace_info"); - assert_eq!(created["result"]["workspace"]["workspace_id"], "1"); + let workspace_id = created["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + let active_tab_id = created["result"]["workspace"]["active_tab_id"] + .as_str() + .unwrap() + .to_string(); assert_eq!(created["result"]["workspace"]["number"], 1); assert_eq!(created["result"]["workspace"]["focused"], true); assert_eq!(created["result"]["workspace"]["tab_count"], 1); - assert_eq!(created["result"]["workspace"]["active_tab_id"], "1:1"); + assert_eq!(active_tab_id, format!("{workspace_id}:1")); let listed = send_request( &socket_path, @@ -239,13 +246,16 @@ fn workspace_list_and_create_round_trip() { ); let workspaces = listed["result"]["workspaces"].as_array().unwrap(); assert_eq!(workspaces.len(), 1); - assert_eq!(workspaces[0]["workspace_id"], "1"); + assert_eq!(workspaces[0]["workspace_id"], workspace_id); let fetched = send_request( &socket_path, - r#"{"id":"req_5","method":"workspace.get","params":{"workspace_id":"1"}}"#, + &format!( + r#"{{"id":"req_5","method":"workspace.get","params":{{"workspace_id":"{}"}}}}"#, + workspace_id + ), ); - assert_eq!(fetched["result"]["workspace"]["workspace_id"], "1"); + assert_eq!(fetched["result"]["workspace"]["workspace_id"], workspace_id); let panes = send_request( &socket_path, @@ -253,8 +263,8 @@ fn workspace_list_and_create_round_trip() { ); let panes = panes["result"]["panes"].as_array().unwrap(); assert_eq!(panes.len(), 1); - assert_eq!(panes[0]["workspace_id"], "1"); - assert_eq!(panes[0]["tab_id"], "1:1"); + assert_eq!(panes[0]["workspace_id"], workspace_id); + assert_eq!(panes[0]["tab_id"], active_tab_id); let pane_id = panes[0]["pane_id"].as_str().unwrap().to_string(); let pane = send_request( @@ -274,7 +284,7 @@ fn workspace_list_and_create_round_trip() { ), ); assert_eq!(read["result"]["read"]["pane_id"], pane_id); - assert_eq!(read["result"]["read"]["tab_id"], "1:1"); + assert_eq!(read["result"]["read"]["tab_id"], active_tab_id); assert!(read["result"]["read"]["text"].is_string()); let send_text = send_request( @@ -368,47 +378,77 @@ fn tab_methods_round_trip_over_socket() { base.display() ), ); - assert_eq!(created["result"]["workspace"]["active_tab_id"], "1:1"); + let workspace_id = created["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + let first_tab_id = created["result"]["workspace"]["active_tab_id"] + .as_str() + .unwrap() + .to_string(); + assert_eq!(first_tab_id, format!("{workspace_id}:1")); let tab_created = send_request( &socket_path, - r#"{"id":"req_t2","method":"tab.create","params":{"workspace_id":"1","focus":true}}"#, + &format!( + r#"{{"id":"req_t2","method":"tab.create","params":{{"workspace_id":"{}","focus":true}}}}"#, + workspace_id + ), ); assert_eq!(tab_created["result"]["type"], "tab_info"); - assert_eq!(tab_created["result"]["tab"]["tab_id"], "1:2"); + let second_tab_id = tab_created["result"]["tab"]["tab_id"] + .as_str() + .unwrap() + .to_string(); + assert_eq!(second_tab_id, format!("{workspace_id}:2")); assert_eq!(tab_created["result"]["tab"]["focused"], true); let tab_list = send_request( &socket_path, - r#"{"id":"req_t3","method":"tab.list","params":{"workspace_id":"1"}}"#, + &format!( + r#"{{"id":"req_t3","method":"tab.list","params":{{"workspace_id":"{}"}}}}"#, + workspace_id + ), ); let tabs = tab_list["result"]["tabs"].as_array().unwrap(); assert_eq!(tabs.len(), 2); - assert_eq!(tabs[0]["tab_id"], "1:1"); - assert_eq!(tabs[1]["tab_id"], "1:2"); + assert_eq!(tabs[0]["tab_id"], first_tab_id); + assert_eq!(tabs[1]["tab_id"], second_tab_id); let tab_get = send_request( &socket_path, - r#"{"id":"req_t4","method":"tab.get","params":{"tab_id":"1:2"}}"#, + &format!( + r#"{{"id":"req_t4","method":"tab.get","params":{{"tab_id":"{}"}}}}"#, + second_tab_id + ), ); - assert_eq!(tab_get["result"]["tab"]["tab_id"], "1:2"); + assert_eq!(tab_get["result"]["tab"]["tab_id"], second_tab_id); let renamed = send_request( &socket_path, - r#"{"id":"req_t5","method":"tab.rename","params":{"tab_id":"1:2","label":"logs"}}"#, + &format!( + r#"{{"id":"req_t5","method":"tab.rename","params":{{"tab_id":"{}","label":"logs"}}}}"#, + second_tab_id + ), ); assert_eq!(renamed["result"]["tab"]["label"], "logs"); let focused = send_request( &socket_path, - r#"{"id":"req_t6","method":"tab.focus","params":{"tab_id":"1:1"}}"#, + &format!( + r#"{{"id":"req_t6","method":"tab.focus","params":{{"tab_id":"{}"}}}}"#, + first_tab_id + ), ); - assert_eq!(focused["result"]["tab"]["tab_id"], "1:1"); + assert_eq!(focused["result"]["tab"]["tab_id"], first_tab_id); assert_eq!(focused["result"]["tab"]["focused"], true); let closed = send_request( &socket_path, - r#"{"id":"req_t7","method":"tab.close","params":{"tab_id":"1:2"}}"#, + &format!( + r#"{{"id":"req_t7","method":"tab.close","params":{{"tab_id":"{}"}}}}"#, + second_tab_id + ), ); assert_eq!(closed["result"]["type"], "ok"); @@ -480,10 +520,11 @@ fn events_subscribe_streams_lifecycle_and_agent_events() { let workspace_focused = wait_for_event(&mut reader, "workspace_focused", Duration::from_secs(2)); assert_eq!(workspace_focused["data"]["workspace_id"], workspace_id); + let first_tab_id = format!("{workspace_id}:1"); let tab_created = wait_for_event(&mut reader, "tab_created", Duration::from_secs(2)); - assert_eq!(tab_created["data"]["tab"]["tab_id"], "1:1"); + assert_eq!(tab_created["data"]["tab"]["tab_id"], first_tab_id); let tab_focused = wait_for_event(&mut reader, "tab_focused", Duration::from_secs(2)); - assert_eq!(tab_focused["data"]["tab_id"], "1:1"); + assert_eq!(tab_focused["data"]["tab_id"], first_tab_id); let pane_created = wait_for_event(&mut reader, "pane_created", Duration::from_secs(2)); let pane_id = pane_created["data"]["pane"]["pane_id"] .as_str() @@ -520,24 +561,35 @@ fn events_subscribe_streams_lifecycle_and_agent_events() { workspace_id ), ); - assert_eq!(new_tab["result"]["tab"]["tab_id"], "1:2"); + let second_tab_id = new_tab["result"]["tab"]["tab_id"] + .as_str() + .unwrap() + .to_string(); + assert_eq!(second_tab_id, format!("{workspace_id}:2")); let created_tab_event = wait_for_event(&mut reader, "tab_created", Duration::from_secs(2)); - assert_eq!(created_tab_event["data"]["tab"]["tab_id"], "1:2"); + assert_eq!(created_tab_event["data"]["tab"]["tab_id"], second_tab_id); let focused_tab_event = wait_for_event(&mut reader, "tab_focused", Duration::from_secs(2)); - assert_eq!(focused_tab_event["data"]["tab_id"], "1:2"); + assert_eq!(focused_tab_event["data"]["tab_id"], second_tab_id); let renamed_tab = send_request( &socket_path, - r#"{"id":"req_l5","method":"tab.rename","params":{"tab_id":"1:2","label":"logs"}}"#, + &format!( + r#"{{"id":"req_l5","method":"tab.rename","params":{{"tab_id":"{}","label":"logs"}}}}"#, + second_tab_id + ), ); assert_eq!(renamed_tab["result"]["tab"]["label"], "logs"); let renamed_event = wait_for_event(&mut reader, "tab_renamed", Duration::from_secs(2)); - assert_eq!(renamed_event["data"]["tab_id"], "1:2"); + assert_eq!(renamed_event["data"]["tab_id"], second_tab_id); assert_eq!(renamed_event["data"]["label"], "logs"); + let second_pane_id = format!("{}-1", workspace_id); let split = send_request( &socket_path, - r#"{"id":"req_l6","method":"pane.split","params":{"target_pane_id":"1-2","direction":"right","focus":true}}"#, + &format!( + r#"{{"id":"req_l6","method":"pane.split","params":{{"target_pane_id":"{}","direction":"right","focus":true}}}}"#, + second_pane_id + ), ); let split_pane_id = split["result"]["pane"]["pane_id"] .as_str() @@ -559,11 +611,14 @@ fn events_subscribe_streams_lifecycle_and_agent_events() { let closed_tab = send_request( &socket_path, - r#"{"id":"req_l8","method":"tab.close","params":{"tab_id":"1:2"}}"#, + &format!( + r#"{{"id":"req_l8","method":"tab.close","params":{{"tab_id":"{}"}}}}"#, + second_tab_id + ), ); assert_eq!(closed_tab["result"]["type"], "ok"); let tab_closed = wait_for_event(&mut reader, "tab_closed", Duration::from_secs(2)); - assert_eq!(tab_closed["data"]["tab_id"], "1:2"); + assert_eq!(tab_closed["data"]["tab_id"], second_tab_id); let closed_ws = send_request( &socket_path, @@ -992,7 +1047,7 @@ fn events_subscribe_streams_output_and_agent_state_events() { base.display() ), ); - assert_eq!(created["result"]["workspace"]["workspace_id"], "1"); + assert!(created["result"]["workspace"]["workspace_id"].is_string()); let panes = send_request( &socket_path, diff --git a/tests/cli_wrapper.rs b/tests/cli_wrapper.rs index 18588605..190ae70c 100644 --- a/tests/cli_wrapper.rs +++ b/tests/cli_wrapper.rs @@ -153,7 +153,10 @@ fn workspace_and_pane_management_commands_work() { ); assert!(created.status.success()); let created_json: serde_json::Value = serde_json::from_slice(&created.stdout).unwrap(); - assert_eq!(created_json["result"]["workspace"]["workspace_id"], "1"); + let workspace_id = created_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); let panes = run_cli(&socket_path, &["pane", "list", "--workspace", "1"]); assert!(panes.status.success()); @@ -182,15 +185,18 @@ fn workspace_and_pane_management_commands_work() { let closed_json: serde_json::Value = serde_json::from_slice(&closed.stdout).unwrap(); assert_eq!(closed_json["result"]["type"], "ok"); - let renamed = run_cli(&socket_path, &["workspace", "rename", "1", "demo"]); + let renamed = run_cli( + &socket_path, + &["workspace", "rename", &workspace_id, "demo"], + ); assert!(renamed.status.success()); let renamed_json: serde_json::Value = serde_json::from_slice(&renamed.stdout).unwrap(); assert_eq!(renamed_json["result"]["workspace"]["label"], "demo"); - let focused = run_cli(&socket_path, &["workspace", "focus", "1"]); + let focused = run_cli(&socket_path, &["workspace", "focus", &workspace_id]); assert!(focused.status.success()); - let closed_workspace = run_cli(&socket_path, &["workspace", "close", "1"]); + let closed_workspace = run_cli(&socket_path, &["workspace", "close", &workspace_id]); assert!(closed_workspace.status.success()); let closed_workspace_json: serde_json::Value = serde_json::from_slice(&closed_workspace.stdout).unwrap(); @@ -214,13 +220,29 @@ fn tab_management_commands_work() { &["workspace", "create", "--cwd", base.to_str().unwrap()], ); assert!(created.status.success()); + let created_json: serde_json::Value = serde_json::from_slice(&created.stdout).unwrap(); + let workspace_id = created_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + let first_tab_id = created_json["result"]["workspace"]["active_tab_id"] + .as_str() + .unwrap() + .to_string(); - let created_tab = run_cli(&socket_path, &["tab", "create", "--workspace", "1"]); + let created_tab = run_cli( + &socket_path, + &["tab", "create", "--workspace", &workspace_id], + ); assert!(created_tab.status.success()); let created_tab_json: serde_json::Value = serde_json::from_slice(&created_tab.stdout).unwrap(); - assert_eq!(created_tab_json["result"]["tab"]["tab_id"], "1:2"); + let second_tab_id = created_tab_json["result"]["tab"]["tab_id"] + .as_str() + .unwrap() + .to_string(); + assert_eq!(second_tab_id, format!("{workspace_id}:2")); - let listed_tabs = run_cli(&socket_path, &["tab", "list", "--workspace", "1"]); + let listed_tabs = run_cli(&socket_path, &["tab", "list", "--workspace", &workspace_id]); assert!(listed_tabs.status.success()); let listed_tabs_json: serde_json::Value = serde_json::from_slice(&listed_tabs.stdout).unwrap(); assert_eq!( @@ -228,22 +250,22 @@ fn tab_management_commands_work() { 2 ); - let renamed_tab = run_cli(&socket_path, &["tab", "rename", "1:2", "logs"]); + let renamed_tab = run_cli(&socket_path, &["tab", "rename", &second_tab_id, "logs"]); assert!(renamed_tab.status.success()); let renamed_tab_json: serde_json::Value = serde_json::from_slice(&renamed_tab.stdout).unwrap(); assert_eq!(renamed_tab_json["result"]["tab"]["label"], "logs"); - let focused_tab = run_cli(&socket_path, &["tab", "focus", "1:1"]); + let focused_tab = run_cli(&socket_path, &["tab", "focus", &first_tab_id]); assert!(focused_tab.status.success()); let focused_tab_json: serde_json::Value = serde_json::from_slice(&focused_tab.stdout).unwrap(); - assert_eq!(focused_tab_json["result"]["tab"]["tab_id"], "1:1"); + assert_eq!(focused_tab_json["result"]["tab"]["tab_id"], first_tab_id); - let tab_get = run_cli(&socket_path, &["tab", "get", "1:2"]); + let tab_get = run_cli(&socket_path, &["tab", "get", &second_tab_id]); assert!(tab_get.status.success()); let tab_get_json: serde_json::Value = serde_json::from_slice(&tab_get.stdout).unwrap(); - assert_eq!(tab_get_json["result"]["tab"]["tab_id"], "1:2"); + assert_eq!(tab_get_json["result"]["tab"]["tab_id"], second_tab_id); - let closed_tab = run_cli(&socket_path, &["tab", "close", "1:2"]); + let closed_tab = run_cli(&socket_path, &["tab", "close", &second_tab_id]); assert!(closed_tab.status.success()); let closed_tab_json: serde_json::Value = serde_json::from_slice(&closed_tab.stdout).unwrap(); assert_eq!(closed_tab_json["result"]["type"], "ok"); @@ -268,7 +290,7 @@ fn pane_run_read_and_wait_commands_work() { base.display() ), ); - assert_eq!(created["result"]["workspace"]["workspace_id"], "1"); + assert!(created["result"]["workspace"]["workspace_id"].is_string()); let create = run_cli( &socket_path, @@ -436,7 +458,7 @@ fn closing_workspace_terminates_processes_inside_it() { } #[test] -fn ids_are_compact_and_positional() { +fn workspace_ids_are_stable_and_pane_numbers_stay_compact() { let base = unique_test_dir(); let config_home = base.join("config"); let runtime_dir = base.join("runtime"); @@ -450,45 +472,68 @@ fn ids_are_compact_and_positional() { &["workspace", "create", "--cwd", base.to_str().unwrap()], ); assert!(ws1.status.success()); + let ws1_json: serde_json::Value = serde_json::from_slice(&ws1.stdout).unwrap(); + let ws1_id = ws1_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); let split_12 = run_cli( &socket_path, &["pane", "split", "1-1", "--direction", "right", "--no-focus"], ); let split_12_json: serde_json::Value = serde_json::from_slice(&split_12.stdout).unwrap(); - assert_eq!(split_12_json["result"]["pane"]["pane_id"], "1-2"); + assert_eq!( + split_12_json["result"]["pane"]["pane_id"], + format!("{ws1_id}-2") + ); let split_13 = run_cli( &socket_path, &["pane", "split", "1-1", "--direction", "down", "--no-focus"], ); let split_13_json: serde_json::Value = serde_json::from_slice(&split_13.stdout).unwrap(); - assert_eq!(split_13_json["result"]["pane"]["pane_id"], "1-3"); + assert_eq!( + split_13_json["result"]["pane"]["pane_id"], + format!("{ws1_id}-3") + ); let ws2 = run_cli( &socket_path, &["workspace", "create", "--cwd", "/tmp", "--no-focus"], ); let ws2_json: serde_json::Value = serde_json::from_slice(&ws2.stdout).unwrap(); - assert_eq!(ws2_json["result"]["workspace"]["workspace_id"], "2"); + let ws2_id = ws2_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + assert_ne!(ws2_id, ws1_id); - let ws2_focus = run_cli(&socket_path, &["workspace", "focus", "2"]); + let ws2_focus = run_cli(&socket_path, &["workspace", "focus", &ws2_id]); assert!(ws2_focus.status.success()); let ws2_split = run_cli( &socket_path, &["pane", "split", "2-1", "--direction", "right", "--no-focus"], ); let ws2_split_json: serde_json::Value = serde_json::from_slice(&ws2_split.stdout).unwrap(); - assert_eq!(ws2_split_json["result"]["pane"]["pane_id"], "2-2"); + assert_eq!( + ws2_split_json["result"]["pane"]["pane_id"], + format!("{ws2_id}-2") + ); let ws3 = run_cli( &socket_path, &["workspace", "create", "--cwd", "/", "--no-focus"], ); let ws3_json: serde_json::Value = serde_json::from_slice(&ws3.stdout).unwrap(); - assert_eq!(ws3_json["result"]["workspace"]["workspace_id"], "3"); + let ws3_id = ws3_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + assert_ne!(ws3_id, ws1_id); + assert_ne!(ws3_id, ws2_id); - let close_ws2 = run_cli(&socket_path, &["workspace", "close", "2"]); + let close_ws2 = run_cli(&socket_path, &["workspace", "close", &ws2_id]); assert!(close_ws2.status.success()); let workspaces = run_cli(&socket_path, &["workspace", "list"]); @@ -499,22 +544,31 @@ fn ids_are_compact_and_positional() { .iter() .map(|ws| ws["workspace_id"].as_str().unwrap().to_string()) .collect(); - assert_eq!(ids, vec!["1".to_string(), "2".to_string()]); + assert_eq!(ids, vec![ws1_id.clone(), ws3_id.clone()]); let new_ws = run_cli( &socket_path, &["workspace", "create", "--cwd", "/var/tmp", "--no-focus"], ); let new_ws_json: serde_json::Value = serde_json::from_slice(&new_ws.stdout).unwrap(); - assert_eq!(new_ws_json["result"]["workspace"]["workspace_id"], "3"); + let new_ws_id = new_ws_json["result"]["workspace"]["workspace_id"] + .as_str() + .unwrap() + .to_string(); + assert_ne!(new_ws_id, ws1_id); + assert_ne!(new_ws_id, ws2_id); + assert_ne!(new_ws_id, ws3_id); - let ws3_panes = run_cli(&socket_path, &["pane", "list", "--workspace", "3"]); + let ws3_panes = run_cli(&socket_path, &["pane", "list", "--workspace", &ws3_id]); let ws3_panes_json: serde_json::Value = serde_json::from_slice(&ws3_panes.stdout).unwrap(); - assert_eq!(ws3_panes_json["result"]["panes"][0]["pane_id"], "3-1"); + assert_eq!( + ws3_panes_json["result"]["panes"][0]["pane_id"], + format!("{ws3_id}-1") + ); - let close_middle = run_cli(&socket_path, &["pane", "close", "1-2"]); + let close_middle = run_cli(&socket_path, &["pane", "close", &format!("{ws1_id}-2")]); assert!(close_middle.status.success()); - let ws1_panes = run_cli(&socket_path, &["pane", "list", "--workspace", "1"]); + let ws1_panes = run_cli(&socket_path, &["pane", "list", "--workspace", &ws1_id]); let ws1_panes_json: serde_json::Value = serde_json::from_slice(&ws1_panes.stdout).unwrap(); let pane_ids: Vec<String> = ws1_panes_json["result"]["panes"] .as_array() @@ -522,7 +576,7 @@ fn ids_are_compact_and_positional() { .iter() .map(|pane| pane["pane_id"].as_str().unwrap().to_string()) .collect(); - assert_eq!(pane_ids, vec!["1-1".to_string(), "1-2".to_string()]); + assert_eq!(pane_ids, vec![format!("{ws1_id}-1"), format!("{ws1_id}-2")]); cleanup_spawned_herdr(herdr, base); } @@ -544,7 +598,7 @@ fn pane_shell_gets_herdr_socket_and_pane_env() { base.display() ), ); - assert_eq!(created["result"]["workspace"]["workspace_id"], "1"); + assert!(created["result"]["workspace"]["workspace_id"].is_string()); let env_capture = base.join("pane-env.txt"); let ran = run_cli( @@ -643,7 +697,7 @@ fn wait_agent_state_exits_when_state_matches() { base.display() ), ); - assert_eq!(created["result"]["workspace"]["workspace_id"], "1"); + assert!(created["result"]["workspace"]["workspace_id"].is_string()); let start_pi = run_cli(&socket_path, &["pane", "run", "1-1", "pi"]); assert!(start_pi.status.success()); |
