I have looked into eshell and make-term source and narrowed down the
range of the issue somewhat.
If I evaluate the test code from eshell buffer, process-environment
lose "TEST=1234" inside make-term function as below.
(defun make-term (name program &optional startfile &rest switches)
(let ((buffer (get-buffer-create (concat "*" name "*"))))
(cond ((not (term-check-proc buffer))
;; Here, process-environemnt still have "TEST=1234"
(with-current-buffer buffer
;; Here, process-environemnt lost "TEST=1234"
(term-mode))
(term-exec buffer name program startfile switches)))
buffer))
I still don't know why but process-environment lost some values when
creating new buffer with 'get-buffer-create' function.
You can test this as below:
1-1) emacs -Q
1-2) evaluate below code.
(let ((process-environment (cons "TEST=1234" process-environment)))
(get-buffer-create "test-buffer")
(switch-to-buffer "test-buffer")
(member "TEST=1234" process-environment))
1-3) you can see "TEST=1234" is a member of process-environment in new buffer.
2-1) emacs -Q
2-2) M-x eshell
2-3) evaluate below code in eshell buffer.
(let ((process-environment (cons "TEST=1234" process-environment)))
(get-buffer-create "test-buffer")
(switch-to-buffer "test-buffer")
(member "TEST=1234" process-environment))
2-4) you can see "TEST=1234" is lost from process-environment.
You can also test this simply as below.
3-1) emacs -Q
3-2) M-x eshell
3-3) evaluate below code in eshell buffer.
(let ((process-environment (cons "TEST=1234" process-environment)))
(with-temp-buffer
(member "TEST=1234" process-environment)))
3-4) you can see "TEST=1234" is lost from process-environment.