def test_update_code_execution_result_append(
    context_with_data: CodeExecutorContext,
):
  """Test appending to existing code execution results for an invocation."""
  # First, let's add an initial result for a new invocation to the existing state
  context_with_data._session_state["_code_execution_results"] = {
      "invocationX": [{
          "code": "old_code",
          "result_stdout": "old_out",
          "result_stderr": "old_err",
          "timestamp": 123,
      }]
  }
  context_with_data.update_code_execution_result(
      "invocationX", "new_code", "new_out", "new_err"
  )
  results = context_with_data._session_state["_code_execution_results"][
      "invocationX"
  ]
  assert len(results) == 2
  assert results[1]["code"] == "new_code"
  assert results[1]["result_stdout"] == "new_out"
  assert results[1]["result_stderr"] == "new_err"
Test appending to existing code execution results for an invocation.
tests/unittests/code_executors/test_code_executor_context.py