From 9841d3fdf1f8eebb318a9e37a10ebc903d104782 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 27 Mar 2024 05:48:23 +1100 Subject: [PATCH] fix(kernel): Do not increase counter if store_history=false (#20848) Fixes https://github.com/denoland/deno/issues/20847 Co-authored-by: Nathan Whitaker --- cli/tools/jupyter/jupyter_msg.rs | 8 ++++++++ cli/tools/jupyter/server.rs | 4 +++- tests/integration/jupyter_tests.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cli/tools/jupyter/jupyter_msg.rs b/cli/tools/jupyter/jupyter_msg.rs index 8b302bdd8f..60703e3656 100644 --- a/cli/tools/jupyter/jupyter_msg.rs +++ b/cli/tools/jupyter/jupyter_msg.rs @@ -160,6 +160,14 @@ impl JupyterMessage { self.header["msg_type"].as_str().unwrap_or("") } + pub(crate) fn store_history(&self) -> bool { + self.content["store_history"].as_bool().unwrap_or(true) + } + + pub(crate) fn silent(&self) -> bool { + self.content["silent"].as_bool().unwrap_or(false) + } + pub(crate) fn code(&self) -> &str { self.content["code"].as_str().unwrap_or("") } diff --git a/cli/tools/jupyter/server.rs b/cli/tools/jupyter/server.rs index f6218956da..cd02b9891e 100644 --- a/cli/tools/jupyter/server.rs +++ b/cli/tools/jupyter/server.rs @@ -341,7 +341,9 @@ impl JupyterServer { msg: JupyterMessage, connection: &mut Connection, ) -> Result<(), AnyError> { - self.execution_count += 1; + if !msg.silent() && msg.store_history() { + self.execution_count += 1; + } *self.last_execution_request.borrow_mut() = Some(msg.clone()); msg diff --git a/tests/integration/jupyter_tests.rs b/tests/integration/jupyter_tests.rs index 29636f305f..02695c595e 100644 --- a/tests/integration/jupyter_tests.rs +++ b/tests/integration/jupyter_tests.rs @@ -533,3 +533,31 @@ async fn jupyter_execute_request() -> Result<()> { Ok(()) } + +#[tokio::test] +async fn jupyter_store_history_false() -> Result<()> { + let (_ctx, client, _process) = setup().await; + client + .send( + Shell, + "execute_request", + json!({ + "silent": false, + "store_history": false, + "code": "console.log(\"asdf\")" + }), + ) + .await?; + + let reply = client.recv(Shell).await?; + assert_eq!(reply.header.msg_type, "execute_reply"); + assert_eq_subset( + reply.content, + json!({ + "status": "ok", + "execution_count": 0, + }), + ); + + Ok(()) +}