refactor: update cursor request handling and improve parent request management

- Changed `run_id` to `request_id` in `CursorParent` struct for clarity.
- Enhanced the `prepare` function to handle parent requests asynchronously, ensuring proper error handling for active runs.
- Updated database interactions to include `cursor_request_id` for better tracking of requests.
- Added tests to verify the behavior of reused cursor request IDs and their mapping to distinct executions.
This commit is contained in:
leookun
2026-08-26 01:46:30 +08:00
parent ae31757635
commit 847e92c7ea
20 changed files with 271 additions and 57 deletions
+43
View File
@@ -0,0 +1,43 @@
use std::borrow::Cow;
use cursor_server::store::Store;
use sqlx::{migrate::Migrator, sqlite::SqliteConnectOptions, Row};
#[tokio::test]
async fn version_two_database_upgrades_with_cursor_request_mapping() {
let directory = tempfile::tempdir().unwrap();
let database = directory.path().join("upgrade.db");
let pool = sqlx::SqlitePool::connect_with(
SqliteConnectOptions::new()
.filename(&database)
.create_if_missing(true),
)
.await
.unwrap();
let all = sqlx::migrate!("./migrations");
let prior = Migrator {
migrations: Cow::Owned(
all.iter()
.filter(|migration| migration.version <= 2)
.cloned()
.collect(),
),
ignore_missing: false,
locking: true,
no_tx: false,
};
prior.run(&pool).await.unwrap();
drop(pool);
let store = Store::connect(&format!("sqlite://{}", database.display()))
.await
.unwrap();
let columns = sqlx::query("PRAGMA table_info(runs)")
.fetch_all(store.pool())
.await
.unwrap();
assert!(columns
.iter()
.any(|column| column.get::<String, _>("name") == "cursor_request_id"));
}