Files
codex/codex-rs/memories/write/src/extensions/ad_hoc_tests.rs
T
jif-oaiGitHubchatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
ff27d01676 feat: seed ad-hoc memory extension instructions (#20606)
## Summary

Ad-hoc memory notes are written under `memories/extensions/ad_hoc/`, but
the consolidation agent only knows how to interpret an extension when
the extension folder has an `instructions.md`. Seed those instructions
from the memories write pipeline so an enabled memories startup creates
the expected ad-hoc extension layout automatically.

This also moves extension-specific write behavior behind a dedicated
`memories/write/src/extensions/` module. `ad_hoc` owns the seeded
instructions template, while the existing resource-retention cleanup
lives in its own `prune` module so future memory extensions can add
their own write-side setup without growing a flat helper file.

## Changes

- Seed `memories/extensions/ad_hoc/instructions.md` during eligible
memory startup without overwriting an existing file.
- Store the ad-hoc instructions template under
`memories/write/templates/extensions/ad_hoc/`, keeping ownership in
`codex-memories-write`.
- Split memory extension support into `extensions::ad_hoc` and
`extensions::prune`.
- Keep the existing old-resource pruning behavior unchanged.

## Verification

- `cargo test -p codex-memories-write`
- `bazel build //codex-rs/memories/write:write`

---------

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
2026-05-01 14:43:58 +02:00

37 lines
1.1 KiB
Rust

use super::*;
use crate::memory_extensions_root;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
#[tokio::test]
async fn seeds_instructions_without_overwriting_existing_file() {
let codex_home = TempDir::new().expect("create temp codex home");
let memory_root = codex_home.path().join("memories");
let instructions_path = memory_extensions_root(&memory_root).join("ad_hoc/instructions.md");
seed_instructions(&memory_root)
.await
.expect("seed ad-hoc instructions");
assert_eq!(
tokio::fs::read_to_string(&instructions_path)
.await
.expect("read seeded ad-hoc instructions"),
INSTRUCTIONS
);
tokio::fs::write(&instructions_path, "custom instructions")
.await
.expect("write custom instructions");
seed_instructions(&memory_root)
.await
.expect("seed ad-hoc instructions again");
assert_eq!(
tokio::fs::read_to_string(&instructions_path)
.await
.expect("read custom ad-hoc instructions"),
"custom instructions"
);
}