Files
codex/codex-rs/thread-store/src/local/test_support.rs
pakrym-oai a8488fec5e Revert state DB injection and agent graph store (#21481)
## Why

Reverts #20689 to restore the previous optional state DB plumbing. The
conflict resolution keeps the newer installation ID and session/thread
identity changes that landed after #20689, while removing the mandatory
state DB and agent graph store dependency from ThreadManager
construction.

## What changed

- Restored `Option<StateDbHandle>` through app-server, MCP server,
prompt debug, and test entry points.
- Removed the `codex-core` dependency on `codex-agent-graph-store` and
reverted descendant lookup back to the existing state DB path when
available.
- Kept newer `installation_id` forwarding by passing it beside the
optional DB handle.
- Kept local thread-name updates working when the optional state DB
handle is absent.

## Validation

- `git diff --check`
- `cargo test -p codex-thread-store`
- `cargo test -p codex-state -p codex-rollout -p
codex-app-server-protocol`
- Attempted `env CARGO_INCREMENTAL=0 cargo test -p codex-core -p
codex-app-server -p codex-app-server-client -p codex-mcp-server -p
codex-thread-manager-sample -p codex-tui`; blocked locally by a rustc
ICE while compiling `v8 v146.4.0` with `rustc 1.93.0 (254b59607
2026-01-19)` on `aarch64-apple-darwin`.
2026-05-06 22:48:29 -07:00

108 lines
2.7 KiB
Rust

use std::fs;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use codex_rollout::ARCHIVED_SESSIONS_SUBDIR;
use uuid::Uuid;
use super::LocalThreadStoreConfig;
pub(super) fn test_config(codex_home: &Path) -> LocalThreadStoreConfig {
LocalThreadStoreConfig {
codex_home: codex_home.to_path_buf(),
sqlite_home: codex_home.to_path_buf(),
default_model_provider_id: "test-provider".to_string(),
}
}
pub(super) fn write_session_file(root: &Path, ts: &str, uuid: Uuid) -> std::io::Result<PathBuf> {
write_session_file_with(
root,
root.join("sessions/2025/01/03"),
ts,
uuid,
"Hello from user",
Some("test-provider"),
)
}
pub(super) fn write_archived_session_file(
root: &Path,
ts: &str,
uuid: Uuid,
) -> std::io::Result<PathBuf> {
write_session_file_with(
root,
root.join(ARCHIVED_SESSIONS_SUBDIR),
ts,
uuid,
"Archived user message",
Some("test-provider"),
)
}
pub(super) fn write_session_file_with(
root: &Path,
day_dir: PathBuf,
ts: &str,
uuid: Uuid,
first_user_message: &str,
model_provider: Option<&str>,
) -> std::io::Result<PathBuf> {
write_session_file_with_fork(
root,
day_dir,
ts,
uuid,
first_user_message,
model_provider,
/*forked_from_id*/ None,
)
}
pub(super) fn write_session_file_with_fork(
root: &Path,
day_dir: PathBuf,
ts: &str,
uuid: Uuid,
first_user_message: &str,
model_provider: Option<&str>,
forked_from_id: Option<Uuid>,
) -> std::io::Result<PathBuf> {
fs::create_dir_all(&day_dir)?;
let path = day_dir.join(format!("rollout-{ts}-{uuid}.jsonl"));
let mut file = fs::File::create(&path)?;
let meta = serde_json::json!({
"timestamp": ts,
"type": "session_meta",
"payload": {
"id": uuid,
"forked_from_id": forked_from_id,
"timestamp": ts,
"cwd": root,
"originator": "test_originator",
"cli_version": "test_version",
"source": "cli",
"model_provider": model_provider,
"git": {
"commit_hash": "abcdef",
"branch": "main",
"repository_url": "https://example.com/repo.git"
}
},
});
writeln!(file, "{meta}")?;
let user_event = serde_json::json!({
"timestamp": ts,
"type": "event_msg",
"payload": {
"type": "user_message",
"message": first_user_message,
"kind": "plain",
},
});
writeln!(file, "{user_event}")?;
Ok(path)
}