Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Require absolute paths for test SQLite configuration (#34411)

Adam Perry @ OpenAI81e89fa5af13
diff --git a/codex-rs/cli/src/doctor/thread_inventory.rs b/codex-rs/cli/src/doctor/thread_inventory.rs
index 61f69ed49b..52fbd8ba7b 100644
--- a/codex-rs/cli/src/doctor/thread_inventory.rs
+++ b/codex-rs/cli/src/doctor/thread_inventory.rs
@@ -745,6 +745,7 @@ where
mod tests {
use super::*;
use codex_protocol::ThreadId;
+ use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
@@ -1348,11 +1349,10 @@ mod tests {
async fn insert_thread_row(&self, id: &str, rollout_path: &Path, archived: bool) {
let state_db_path = codex_state::state_db_path(self.sqlite_home.path());
- let pool =
- codex_state::SqliteConfig::new_for_testing(self.sqlite_home.path().to_path_buf())
- .open_read_write_pool(&state_db_path)
- .await
- .expect("sqlite pool");
+ let pool = codex_state::SqliteConfig::new_for_testing(self.sqlite_home.path().abs())
+ .open_read_write_pool(&state_db_path)
+ .await
+ .expect("sqlite pool");
sqlx::query(
r#"
INSERT INTO threads (
diff --git a/codex-rs/cli/tests/debug_clear_memories.rs b/codex-rs/cli/tests/debug_clear_memories.rs
index 0ff50053cb..b43a1d936d 100644
--- a/codex-rs/cli/tests/debug_clear_memories.rs
+++ b/codex-rs/cli/tests/debug_clear_memories.rs
@@ -4,6 +4,7 @@ use anyhow::Result;
use codex_state::StateRuntime;
use codex_state::memories_db_path;
use codex_state::state_db_path;
+use codex_utils_absolute_path::test_support::PathExt;
use predicates::str::contains;
use tempfile::TempDir;
@@ -16,7 +17,7 @@ fn codex_command(codex_home: &Path) -> Result<assert_cmd::Command> {
#[tokio::test]
async fn debug_clear_memories_resets_state_and_removes_memory_dir() -> Result<()> {
let codex_home = TempDir::new()?;
- let sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().to_path_buf());
+ let sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().abs());
let runtime =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
drop(runtime);
@@ -139,7 +140,7 @@ INSERT INTO jobs (
#[tokio::test]
async fn debug_clear_memories_resets_memories_db_without_state_db() -> Result<()> {
let codex_home = TempDir::new()?;
- let sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().to_path_buf());
+ let sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().abs());
let runtime =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
runtime.close().await;
diff --git a/codex-rs/state/src/migrations_tests.rs b/codex-rs/state/src/migrations_tests.rs
index 77722f2585..4243211929 100644
--- a/codex-rs/state/src/migrations_tests.rs
+++ b/codex-rs/state/src/migrations_tests.rs
@@ -1,3 +1,4 @@
+use codex_utils_absolute_path::test_support::PathExt;
use sqlx::Connection;
use sqlx::Row;
use sqlx::migrate::Migration;
@@ -35,7 +36,7 @@ async fn recency_migration_backfills_and_seeds_old_binary_inserts() {
let _cleanup = scopeguard::guard(sqlite_home.clone(), |sqlite_home| {
let _ = std::fs::remove_dir_all(sqlite_home);
});
- let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.clone());
+ let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
let pool = sqlite
.open_read_write_pool(&state_db_path(&sqlite_home))
.await
@@ -148,7 +149,7 @@ async fn repairs_recency_migration_that_was_applied_as_version_38() {
let _cleanup = scopeguard::guard(sqlite_home.clone(), |sqlite_home| {
let _ = std::fs::remove_dir_all(sqlite_home);
});
- let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.clone());
+ let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
let pool = sqlite
.open_read_write_pool(&state_db_path(&sqlite_home))
.await
@@ -224,7 +225,7 @@ async fn repair_recency_migration_succeeds_while_another_connection_holds_writer
let _cleanup = scopeguard::guard(sqlite_home.clone(), |sqlite_home| {
let _ = std::fs::remove_dir_all(sqlite_home);
});
- let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.clone());
+ let sqlite = crate::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
let state_path = state_db_path(&sqlite_home);
let pool = sqlite
.open_read_write_pool(&state_path)
diff --git a/codex-rs/state/src/runtime.rs b/codex-rs/state/src/runtime.rs
index d3073df9a2..a80b59a4f8 100644
--- a/codex-rs/state/src/runtime.rs
+++ b/codex-rs/state/src/runtime.rs
@@ -578,6 +578,7 @@ mod tests {
use crate::DB_INIT_METRIC;
use crate::DbTelemetry;
use crate::migrations::STATE_MIGRATOR;
+ use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use sqlx::SqlitePool;
use sqlx::migrate::MigrateError;
@@ -638,7 +639,7 @@ mod tests {
}
async fn open_db_pool(path: &Path) -> SqlitePool {
- crate::SqliteConfig::new_for_testing(path.parent().unwrap_or(path).to_path_buf())
+ crate::SqliteConfig::new_for_testing(path.parent().unwrap_or(path).abs())
.open_read_write_pool(path)
.await
.expect("open sqlite pool")
@@ -651,7 +652,7 @@ mod tests {
.await
.expect("create codex home");
let path = state_db_path(codex_home.as_path());
- let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
+ let pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
.open_read_write_pool(&path)
.await
.expect("open sqlite db");
@@ -676,7 +677,7 @@ mod tests {
.await
.expect("create codex home");
let state_path = state_db_path(codex_home.as_path());
- let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
+ let pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
.open_read_write_pool(&state_path)
.await
.expect("open state db");
@@ -707,7 +708,7 @@ mod tests {
let tolerant_migrator = runtime_state_migrator();
let tolerant_pool = open_state_sqlite(
- &crate::SqliteConfig::new_for_testing(codex_home.clone()),
+ &crate::SqliteConfig::new_for_testing(codex_home.as_path().abs()),
state_path.as_path(),
&tolerant_migrator,
/*telemetry_override*/ None,
diff --git a/codex-rs/state/src/runtime/backfill.rs b/codex-rs/state/src/runtime/backfill.rs
index 629e579ad6..027a9a6f63 100644
--- a/codex-rs/state/src/runtime/backfill.rs
+++ b/codex-rs/state/src/runtime/backfill.rs
@@ -112,6 +112,7 @@ mod tests {
use super::StateRuntime;
use super::test_support::unique_temp_dir;
use chrono::Utc;
+ use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use sqlx::Connection;
@@ -174,7 +175,7 @@ mod tests {
let runtime = StateRuntime::init(codex_home.clone(), "test-provider".to_string())
.await
.expect("initialize runtime");
- let write_pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
+ let write_pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
.open_read_write_pool(&crate::state_db_path(codex_home.as_path()))
.await
.expect("open write pool");
diff --git a/codex-rs/state/src/runtime/logs.rs b/codex-rs/state/src/runtime/logs.rs
index a9ac2dbf7e..7ff179ca78 100644
--- a/codex-rs/state/src/runtime/logs.rs
+++ b/codex-rs/state/src/runtime/logs.rs
@@ -548,6 +548,7 @@ mod tests {
use crate::logs_db_path;
use crate::migrations::LOGS_MIGRATOR;
use chrono::Utc;
+ use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use sqlx::SqlitePool;
use sqlx::migrate::Migrator;
@@ -555,7 +556,7 @@ mod tests {
use std::path::Path;
async fn open_db_pool(path: &Path) -> SqlitePool {
- crate::SqliteConfig::new_for_testing(path.parent().unwrap_or(path).to_path_buf())
+ crate::SqliteConfig::new_for_testing(path.parent().unwrap_or(path).abs())
.open_read_write_pool(path)
.await
.expect("open sqlite pool")
@@ -617,7 +618,7 @@ mod tests {
table_name: LOGS_MIGRATOR.table_name.clone(),
create_schemas: LOGS_MIGRATOR.create_schemas.clone(),
};
- let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
+ let pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
.open_read_write_pool(&logs_path)
.await
.expect("open old logs db");
diff --git a/codex-rs/state/src/runtime/remote_control.rs b/codex-rs/state/src/runtime/remote_control.rs
index 440da87b17..28133f4440 100644
--- a/codex-rs/state/src/runtime/remote_control.rs
+++ b/codex-rs/state/src/runtime/remote_control.rs
@@ -158,6 +158,7 @@ mod tests {
use super::test_support::unique_temp_dir;
use crate::migrations::STATE_MIGRATOR;
use crate::state_db_path;
+ use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use sqlx::migrate::Migrator;
use std::borrow::Cow;
@@ -336,7 +337,7 @@ mod tests {
table_name: STATE_MIGRATOR.table_name.clone(),
create_schemas: STATE_MIGRATOR.create_schemas.clone(),
};
- let pool = crate::SqliteConfig::new_for_testing(codex_home.clone())
+ let pool = crate::SqliteConfig::new_for_testing(codex_home.as_path().abs())
.open_read_write_pool(&state_db_path(codex_home.as_path()))
.await
.expect("open old state db");
diff --git a/codex-rs/state/src/sqlite.rs b/codex-rs/state/src/sqlite.rs
index b8e364f816..4d92c98830 100644
--- a/codex-rs/state/src/sqlite.rs
+++ b/codex-rs/state/src/sqlite.rs
@@ -11,7 +11,6 @@ use sqlx::sqlite::SqliteJournalMode;
use sqlx::sqlite::SqlitePoolOptions;
use sqlx::sqlite::SqliteSynchronous;
use std::path::Path;
-use std::path::PathBuf;
use std::time::Duration;
/// Resolved configuration shared by all Codex SQLite connections.
@@ -25,14 +24,8 @@ impl SqliteConfig {
Self { sqlite_home }
}
- #[expect(
- clippy::expect_used,
- reason = "test sqlite homes must already be absolute"
- )]
- pub fn new_for_testing(sqlite_home: PathBuf) -> Self {
- Self::from_sqlite_home(
- AbsolutePathBuf::try_from(sqlite_home).expect("sqlite home should be absolute"),
- )
+ pub fn new_for_testing(sqlite_home: AbsolutePathBuf) -> Self {
+ Self::from_sqlite_home(sqlite_home)
}
pub fn home(&self) -> &Path {