@@ -142,9 +142,47 @@ as the top-level structure."
142142 "agent_end normalizes trailing whitespace to single newline."
143143 (with-temp-buffer
144144 (pi-coding-agent-chat-mode)
145- (pi-coding-agent--append-to-chat "Some response")
146- (pi-coding-agent--display-agent-end)
147- (should (string-suffix-p "response\n" (buffer-string)))))
145+ (let ((pi-coding-agent-show-return-timestamp nil))
146+ (pi-coding-agent--append-to-chat "Some response")
147+ (pi-coding-agent--display-agent-end)
148+ (should (string-suffix-p "response\n" (buffer-string))))))
149+
150+ (ert-deftest pi-coding-agent-test-return-timestamp-appended-when-idle ()
151+ "agent_end appends a local timestamp line when the turn settles to idle."
152+ (with-temp-buffer
153+ (pi-coding-agent-chat-mode)
154+ (let ((pi-coding-agent-show-return-timestamp t)
155+ (pi-coding-agent-return-timestamp-format "%H:%M:%S"))
156+ (setq pi-coding-agent--status 'idle)
157+ (pi-coding-agent--append-to-chat "Some response")
158+ (pi-coding-agent--display-agent-end)
159+ ;; Trailing line is a HH:MM:SS timestamp carrying the return marker prop.
160+ (should (string-match-p "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\n\\'"
161+ (buffer-string)))
162+ (goto-char (point-max))
163+ (forward-line -1)
164+ (should (get-text-property (point)
165+ 'pi-coding-agent-return-timestamp)))))
166+
167+ (ert-deftest pi-coding-agent-test-return-timestamp-suppressed-when-disabled ()
168+ "No timestamp is added when `pi-coding-agent-show-return-timestamp' is nil."
169+ (with-temp-buffer
170+ (pi-coding-agent-chat-mode)
171+ (let ((pi-coding-agent-show-return-timestamp nil))
172+ (setq pi-coding-agent--status 'idle)
173+ (pi-coding-agent--append-to-chat "Some response")
174+ (pi-coding-agent--display-agent-end)
175+ (should (string-suffix-p "response\n" (buffer-string))))))
176+
177+ (ert-deftest pi-coding-agent-test-return-timestamp-suppressed-when-retrying ()
178+ "No timestamp is added when the turn will continue (status not idle)."
179+ (with-temp-buffer
180+ (pi-coding-agent-chat-mode)
181+ (let ((pi-coding-agent-show-return-timestamp t))
182+ (setq pi-coding-agent--status 'sending)
183+ (pi-coding-agent--append-to-chat "Some response")
184+ (pi-coding-agent--display-agent-end)
185+ (should (string-suffix-p "response\n" (buffer-string))))))
148186
149187(ert-deftest pi-coding-agent-test-spacing-blank-line-after-user-header ()
150188 "User header has a blank line after setext underline."
@@ -532,25 +570,27 @@ agent_end + next section's leading newline must not create triple newlines."
532570 ;; Turn 1: user + assistant
533571 (pi-coding-agent--display-user-message "Hi")
534572 (pi-coding-agent--display-agent-start)
535- (pi-coding-agent--display-message-delta "Hello!")
536- (pi-coding-agent--render-complete-message)
537- (pi-coding-agent--display-agent-end)
538- ;; Turn 2: user message
539- (setq pi-coding-agent--assistant-header-shown nil)
540- (pi-coding-agent--display-user-message "Bye")
541- ;; Should never have triple newlines (which would be two blank lines)
542- (should-not (string-match-p "\n\n\n" (buffer-string)))))
573+ (let ((pi-coding-agent-show-return-timestamp nil))
574+ (pi-coding-agent--display-message-delta "Hello!")
575+ (pi-coding-agent--render-complete-message)
576+ (pi-coding-agent--display-agent-end)
577+ ;; Turn 2: user message
578+ (setq pi-coding-agent--assistant-header-shown nil)
579+ (pi-coding-agent--display-user-message "Bye")
580+ ;; Should never have triple newlines (which would be two blank lines)
581+ (should-not (string-match-p "\n\n\n" (buffer-string))))))
543582
544583(ert-deftest pi-coding-agent-test-spacing-single-blank-line-before-compaction ()
545584 "Only one blank line between agent response and compaction header."
546585 (with-temp-buffer
547586 (pi-coding-agent-chat-mode)
548587 (pi-coding-agent--display-agent-start)
549- (pi-coding-agent--display-message-delta "Some response.")
550- (pi-coding-agent--render-complete-message)
551- (pi-coding-agent--display-agent-end)
552- (pi-coding-agent--display-compaction-result 50000 "Summary.")
553- (should-not (string-match-p "\n\n\n" (buffer-string)))))
588+ (let ((pi-coding-agent-show-return-timestamp nil))
589+ (pi-coding-agent--display-message-delta "Some response.")
590+ (pi-coding-agent--render-complete-message)
591+ (pi-coding-agent--display-agent-end)
592+ (pi-coding-agent--display-compaction-result 50000 "Summary.")
593+ (should-not (string-match-p "\n\n\n" (buffer-string))))))
554594
555595(ert-deftest pi-coding-agent-test-spacing-no-double-blank-between-tools ()
556596 "Consecutive tools have single blank line between them."
0 commit comments