Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions agent-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -2743,8 +2743,9 @@ variable (see makunbound)"))
(map-put! agent-shell--state :resume-session-id session-id))
(when fork-session-id
(map-put! agent-shell--state :fork-session-id fork-session-id))
(when session-strategy
(setq-local agent-shell-session-strategy session-strategy))
;; Snapshot the strategy also in case it was dynamically re-bound
(setq-local agent-shell-session-strategy
(or session-strategy agent-shell-session-strategy))
;; Show deferred welcome text,
;; but first wipe buffer content.
(let ((inhibit-read-only t))
Expand Down
35 changes: 35 additions & 0 deletions tests/agent-shell-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,41 @@ code block content
(when (and test-buffer (buffer-live-p test-buffer))
(kill-buffer test-buffer)))))

(ert-deftest agent-shell--start-snapshots-dynamic-session-strategy ()
"Starting a shell should localize the effective session strategy."
(let ((test-buffer nil)
(shell-buffer nil)
(fake-process (start-process "fake-agent" nil "cat"))
(config (list (cons :buffer-name "test-agent")
(cons :client-maker
(lambda (_buf)
(list (cons :command "cat")))))))
(unwind-protect
(cl-letf (((symbol-function 'shell-maker-start)
(lambda (_config &rest _args)
(setq test-buffer (get-buffer-create "*test-agent-shell*"))
(with-current-buffer test-buffer
(setq major-mode 'agent-shell-mode))
test-buffer))
((symbol-function 'shell-maker--process) (lambda () fake-process))
((symbol-function 'shell-maker-finish-output) #'ignore)
((symbol-function 'agent-shell--handle) #'ignore)
(agent-shell-file-completion-enabled nil))
(let ((agent-shell-session-strategy 'latest))
(let ((agent-shell-session-strategy 'prompt))
(setq shell-buffer (agent-shell--start :config config
:no-focus t
:new-session t))))
(should (local-variable-p 'agent-shell-session-strategy shell-buffer))
(should (eq (buffer-local-value 'agent-shell-session-strategy shell-buffer)
'prompt)))
(when (process-live-p fake-process)
(delete-process fake-process))
(when (and shell-buffer (buffer-live-p shell-buffer))
(kill-buffer shell-buffer))
(when (and test-buffer (buffer-live-p test-buffer))
(kill-buffer test-buffer)))))

(ert-deftest agent-shell--initiate-session-prefers-list-and-load-when-supported ()
"Test `agent-shell--initiate-session' prefers session/list + session/load."
(with-temp-buffer
Expand Down