mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
# Summary - implement local ThreadStore archive/unarchive operations - implement local ThreadStore read_thread operation - break up the various ThreadStore local method implementations into separate files - migrate app-server archive/unarchive and core archive fixture to use ThreadStore (but not all read operations yet!) - use the ThreadStore's read operation as a proxy check for thread persistence/existence in the app server code - move all other filesystem operations related to archive (path validation etc) into the local thread store. # Tests - add dedicated local store archive/unarchive tests
88 lines
2.2 KiB
Rust
88 lines
2.2 KiB
Rust
use std::fs;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
use codex_rollout::ARCHIVED_SESSIONS_SUBDIR;
|
|
use codex_rollout::RolloutConfig;
|
|
use uuid::Uuid;
|
|
|
|
pub(super) fn test_config(codex_home: &Path) -> RolloutConfig {
|
|
RolloutConfig {
|
|
codex_home: codex_home.to_path_buf(),
|
|
sqlite_home: codex_home.to_path_buf(),
|
|
cwd: codex_home.to_path_buf(),
|
|
model_provider_id: "test-provider".to_string(),
|
|
generate_memories: true,
|
|
}
|
|
}
|
|
|
|
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> {
|
|
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,
|
|
"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)
|
|
}
|