mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-05 04:07:36 +08:00
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:
@@ -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"));
|
||||
}
|
||||
Reference in New Issue
Block a user