Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree with a 3-file patch applied (no upstream history). Patch (crates/gpui_linux/src/linux/wayland/): - serial.rs: add SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; add latest_serial_of() - window.rs: activate() uses keyboard-enter serial (Mutter focus gate) Mutter honors window activation only when the token carries the keyboard- focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial. See docs/tray-window-focus-wayland.md in logiguard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
215 lines
6.3 KiB
Rust
215 lines
6.3 KiB
Rust
use agent::SharedThread;
|
|
use gpui::{BackgroundExecutor, TestAppContext};
|
|
use rpc::proto;
|
|
use uuid::Uuid;
|
|
|
|
use crate::TestServer;
|
|
|
|
#[gpui::test]
|
|
async fn test_share_and_retrieve_thread(
|
|
executor: BackgroundExecutor,
|
|
cx_a: &mut TestAppContext,
|
|
cx_b: &mut TestAppContext,
|
|
) {
|
|
let mut server = TestServer::start(executor.clone()).await;
|
|
let client_a = server.create_client(cx_a, "user_a").await;
|
|
let client_b = server.create_client(cx_b, "user_b").await;
|
|
|
|
executor.run_until_parked();
|
|
|
|
let session_id = Uuid::new_v4().to_string();
|
|
|
|
let original_thread = SharedThread {
|
|
title: "Shared Test Thread".into(),
|
|
messages: vec![],
|
|
updated_at: chrono::Utc::now(),
|
|
model: None,
|
|
version: SharedThread::VERSION.to_string(),
|
|
};
|
|
|
|
let thread_data = original_thread
|
|
.to_bytes()
|
|
.expect("Failed to serialize thread");
|
|
|
|
client_a
|
|
.client()
|
|
.request(proto::ShareAgentThread {
|
|
session_id: session_id.clone(),
|
|
title: original_thread.title.to_string(),
|
|
thread_data,
|
|
})
|
|
.await
|
|
.expect("Failed to share thread");
|
|
|
|
let get_response = client_b
|
|
.client()
|
|
.request(proto::GetSharedAgentThread {
|
|
session_id: session_id.clone(),
|
|
})
|
|
.await
|
|
.expect("Failed to get shared thread");
|
|
|
|
let imported_shared_thread =
|
|
SharedThread::from_bytes(&get_response.thread_data).expect("Failed to deserialize thread");
|
|
|
|
assert_eq!(imported_shared_thread.title, original_thread.title);
|
|
assert_eq!(imported_shared_thread.version, SharedThread::VERSION);
|
|
|
|
let db_thread = imported_shared_thread.to_db_thread();
|
|
|
|
assert!(
|
|
db_thread.title.starts_with("🔗"),
|
|
"Imported thread title should have link prefix"
|
|
);
|
|
assert!(
|
|
db_thread.title.contains("Shared Test Thread"),
|
|
"Imported thread should preserve original title"
|
|
);
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn test_reshare_updates_existing_thread(
|
|
executor: BackgroundExecutor,
|
|
cx_a: &mut TestAppContext,
|
|
cx_b: &mut TestAppContext,
|
|
) {
|
|
let mut server = TestServer::start(executor.clone()).await;
|
|
let client_a = server.create_client(cx_a, "user_a").await;
|
|
let client_b = server.create_client(cx_b, "user_b").await;
|
|
|
|
executor.run_until_parked();
|
|
|
|
let session_id = Uuid::new_v4().to_string();
|
|
|
|
client_a
|
|
.client()
|
|
.request(proto::ShareAgentThread {
|
|
session_id: session_id.clone(),
|
|
title: "Original Title".to_string(),
|
|
thread_data: b"original data".to_vec(),
|
|
})
|
|
.await
|
|
.expect("Failed to share thread");
|
|
|
|
client_a
|
|
.client()
|
|
.request(proto::ShareAgentThread {
|
|
session_id: session_id.clone(),
|
|
title: "Updated Title".to_string(),
|
|
thread_data: b"updated data".to_vec(),
|
|
})
|
|
.await
|
|
.expect("Failed to re-share thread");
|
|
|
|
let get_response = client_b
|
|
.client()
|
|
.request(proto::GetSharedAgentThread {
|
|
session_id: session_id.clone(),
|
|
})
|
|
.await
|
|
.expect("Failed to get shared thread");
|
|
|
|
assert_eq!(get_response.title, "Updated Title");
|
|
assert_eq!(get_response.thread_data, b"updated data".to_vec());
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn test_get_nonexistent_thread(executor: BackgroundExecutor, cx: &mut TestAppContext) {
|
|
let mut server = TestServer::start(executor.clone()).await;
|
|
let client = server.create_client(cx, "user_a").await;
|
|
|
|
executor.run_until_parked();
|
|
|
|
let nonexistent_session_id = Uuid::new_v4().to_string();
|
|
|
|
let result = client
|
|
.client()
|
|
.request(proto::GetSharedAgentThread {
|
|
session_id: nonexistent_session_id,
|
|
})
|
|
.await;
|
|
|
|
assert!(result.is_err(), "Should fail for nonexistent thread");
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn test_sync_imported_thread(
|
|
executor: BackgroundExecutor,
|
|
cx_a: &mut TestAppContext,
|
|
cx_b: &mut TestAppContext,
|
|
) {
|
|
let mut server = TestServer::start(executor.clone()).await;
|
|
let client_a = server.create_client(cx_a, "user_a").await;
|
|
let client_b = server.create_client(cx_b, "user_b").await;
|
|
|
|
executor.run_until_parked();
|
|
|
|
let session_id = Uuid::new_v4().to_string();
|
|
|
|
// User A shares a thread with initial content.
|
|
let initial_thread = SharedThread {
|
|
title: "Initial Title".into(),
|
|
messages: vec![],
|
|
updated_at: chrono::Utc::now(),
|
|
model: None,
|
|
version: SharedThread::VERSION.to_string(),
|
|
};
|
|
|
|
client_a
|
|
.client()
|
|
.request(proto::ShareAgentThread {
|
|
session_id: session_id.clone(),
|
|
title: initial_thread.title.to_string(),
|
|
thread_data: initial_thread.to_bytes().expect("Failed to serialize"),
|
|
})
|
|
.await
|
|
.expect("Failed to share thread");
|
|
|
|
// User B imports the thread.
|
|
let initial_response = client_b
|
|
.client()
|
|
.request(proto::GetSharedAgentThread {
|
|
session_id: session_id.clone(),
|
|
})
|
|
.await
|
|
.expect("Failed to get shared thread");
|
|
|
|
let initial_imported =
|
|
SharedThread::from_bytes(&initial_response.thread_data).expect("Failed to deserialize");
|
|
assert_eq!(initial_imported.title.as_ref(), "Initial Title");
|
|
|
|
// User A updates the shared thread.
|
|
let updated_thread = SharedThread {
|
|
title: "Updated Title".into(),
|
|
messages: vec![],
|
|
updated_at: chrono::Utc::now(),
|
|
model: None,
|
|
version: SharedThread::VERSION.to_string(),
|
|
};
|
|
|
|
client_a
|
|
.client()
|
|
.request(proto::ShareAgentThread {
|
|
session_id: session_id.clone(),
|
|
title: updated_thread.title.to_string(),
|
|
thread_data: updated_thread.to_bytes().expect("Failed to serialize"),
|
|
})
|
|
.await
|
|
.expect("Failed to re-share thread");
|
|
|
|
// User B syncs the imported thread (fetches the latest version).
|
|
let synced_response = client_b
|
|
.client()
|
|
.request(proto::GetSharedAgentThread {
|
|
session_id: session_id.clone(),
|
|
})
|
|
.await
|
|
.expect("Failed to sync shared thread");
|
|
|
|
let synced_thread =
|
|
SharedThread::from_bytes(&synced_response.thread_data).expect("Failed to deserialize");
|
|
|
|
// The synced thread should have the updated title.
|
|
assert_eq!(synced_thread.title.as_ref(), "Updated Title");
|
|
}
|