mirror of
https://github.com/openai/codex.git
synced 2026-11-08 00:36:31 +00:00
## What changed - Consolidate v2 rollout summaries into `memory_summary.md` without generating `raw_memories.md` or requiring `MEMORY.md`. Validate the summary's required sections and size below 10,000 UTF-8 bytes. - Add v2 read instructions for selective history retrieval, evidence-grounded preferences, citations, and explicit memory edits. Split injected instructions into fragments to preserve the complete summary within fragment byte limits. - Record memory citation usage in the store selected by `memories.version`. ## Testing Add coverage for v2 consolidation without a handbook, summary validation, version-isolated memory reads, and resetting both memory versions while preserving threads. GitOrigin-RevId: 1d895fb4a23a973f1a45ba03be07a1f480c10227
67 lines
2.4 KiB
Rust
67 lines
2.4 KiB
Rust
use super::*;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use pretty_assertions::assert_eq;
|
|
use tempfile::tempdir;
|
|
use tokio::fs as tokio_fs;
|
|
|
|
#[tokio::test]
|
|
async fn build_memory_tool_developer_instructions_renders_embedded_template() {
|
|
let temp = tempdir().unwrap();
|
|
let codex_home = AbsolutePathBuf::from_absolute_path(temp.path()).unwrap();
|
|
let memories_dir = codex_home.join("memories");
|
|
tokio_fs::create_dir_all(&memories_dir).await.unwrap();
|
|
tokio_fs::write(
|
|
memories_dir.join("memory_summary.md"),
|
|
"Short memory summary for tests.",
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
let instructions = build_memory_tool_developer_instructions(&codex_home, MemoryVersion::V1)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert!(instructions.contains(&format!(
|
|
"- {}/memory_summary.md (already provided below; do NOT open again)",
|
|
memories_dir.display()
|
|
)));
|
|
assert!(instructions.contains("Short memory summary for tests."));
|
|
assert_eq!(
|
|
instructions
|
|
.matches("========= MEMORY_SUMMARY BEGINS =========")
|
|
.count(),
|
|
1
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn v2_reads_only_its_own_summary_without_falling_back_to_v1()
|
|
-> Result<(), Box<dyn std::error::Error>> {
|
|
let home = tempdir()?;
|
|
let codex_home = AbsolutePathBuf::from_absolute_path(home.path())?;
|
|
let v1 = codex_home.join("memories");
|
|
let v2 = codex_home.join("memories_v2");
|
|
tokio_fs::create_dir_all(&v1).await?;
|
|
tokio_fs::write(v1.join("memory_summary.md"), "v1\nlegacy content").await?;
|
|
assert_eq!(
|
|
build_memory_tool_developer_instructions(&codex_home, MemoryVersion::V2).await,
|
|
None
|
|
);
|
|
tokio_fs::create_dir_all(&v2).await?;
|
|
tokio_fs::write(v2.join("memory_summary.md"), "v1\nnew pipeline content").await?;
|
|
let instructions = build_memory_tool_developer_instructions(&codex_home, MemoryVersion::V2)
|
|
.await
|
|
.expect("v2 instructions");
|
|
assert!(instructions.contains("new pipeline content"));
|
|
assert!(!instructions.contains("legacy content"));
|
|
assert!(instructions.contains("do not retrieve history speculatively"));
|
|
assert!(instructions.contains(&format!("{}/rollout_summaries/", v2.display())));
|
|
assert!(
|
|
build_memory_tool_developer_instructions(&codex_home, MemoryVersion::V1)
|
|
.await
|
|
.expect("v1 instructions")
|
|
.contains("legacy content")
|
|
);
|
|
Ok(())
|
|
}
|