mirror of
https://github.com/openai/codex.git
synced 2026-09-20 12:47:38 +00:00
Scope code mode cell IDs to the host process
This commit is contained in:
@@ -93,6 +93,7 @@ struct Inner {
|
||||
cells: Mutex<HashMap<CellId, CellHandle>>,
|
||||
delegate: Arc<dyn CodeModeSessionDelegate>,
|
||||
shutting_down: AtomicBool,
|
||||
cell_id_prefix: Option<String>,
|
||||
next_cell_id: AtomicU64,
|
||||
}
|
||||
|
||||
@@ -106,24 +107,38 @@ impl CodeModeService {
|
||||
}
|
||||
|
||||
pub fn with_delegate(delegate: Arc<dyn CodeModeSessionDelegate>) -> Self {
|
||||
Self::with_inner(delegate, None)
|
||||
}
|
||||
|
||||
pub fn with_delegate_and_cell_id_prefix(
|
||||
delegate: Arc<dyn CodeModeSessionDelegate>,
|
||||
cell_id_prefix: String,
|
||||
) -> Self {
|
||||
Self::with_inner(delegate, Some(cell_id_prefix))
|
||||
}
|
||||
|
||||
fn with_inner(
|
||||
delegate: Arc<dyn CodeModeSessionDelegate>,
|
||||
cell_id_prefix: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
inner: Arc::new(Inner {
|
||||
stored_values: Mutex::new(HashMap::new()),
|
||||
cells: Mutex::new(HashMap::new()),
|
||||
delegate,
|
||||
shutting_down: AtomicBool::new(false),
|
||||
cell_id_prefix,
|
||||
next_cell_id: AtomicU64::new(1),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn allocate_cell_id(&self) -> CellId {
|
||||
CellId::new(
|
||||
self.inner
|
||||
.next_cell_id
|
||||
.fetch_add(1, Ordering::Relaxed)
|
||||
.to_string(),
|
||||
)
|
||||
let cell_id = self.inner.next_cell_id.fetch_add(1, Ordering::Relaxed);
|
||||
CellId::new(match &self.inner.cell_id_prefix {
|
||||
Some(prefix) => format!("{prefix}_{cell_id}"),
|
||||
None => cell_id.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn execute(&self, request: ExecuteRequest) -> Result<StartedCell, String> {
|
||||
@@ -823,6 +838,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
cell_id_prefix: None,
|
||||
#[tokio::test]
|
||||
async fn synchronous_exit_returns_successfully() {
|
||||
let service = CodeModeService::new();
|
||||
@@ -853,6 +869,27 @@ mod tests {
|
||||
async fn stored_values_are_shared_between_cells_but_not_sessions() {
|
||||
let first_session = CodeModeService::new();
|
||||
let second_session = CodeModeService::new();
|
||||
#[tokio::test]
|
||||
async fn cell_ids_include_the_configured_host_prefix() {
|
||||
let service = CodeModeService::with_delegate_and_cell_id_prefix(
|
||||
Arc::new(NoopCodeModeSessionDelegate),
|
||||
"host7".to_string(),
|
||||
);
|
||||
|
||||
let response = execute(&service, execute_request("text('done');")).await;
|
||||
|
||||
assert_eq!(
|
||||
response,
|
||||
RuntimeResponse::Result {
|
||||
cell_id: cell_id("host7_1"),
|
||||
content_items: vec![FunctionCallOutputContentItem::InputText {
|
||||
text: "done".to_string(),
|
||||
}],
|
||||
error_text: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
let write_response = execute(
|
||||
&first_session,
|
||||
|
||||
Reference in New Issue
Block a user