Created
May 25, 2026 15:21
-
-
Save xenodium/c3f9ce717eef920ccf289971ec968e0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require 'agent-shell-ui) | |
| (ert-deftest agent-shell-markdown-fragment-tool-call-body-survives-toggle () | |
| ;; Regression for PR #597: a tool-call fragment with label-left | |
| ;; \" done run \", label-right \"Find the first commit date\" and | |
| ;; a body of two console-fenced blocks (matching the shape | |
| ;; agent-shell emits on a real tool_call_update) must render under | |
| ;; the experimental markdown renderer without dropping the | |
| ;; `invisible' property the UI layer puts on collapsed bodies. | |
| ;; Two checks: | |
| ;; 1. after the initial insert+render, every body char is | |
| ;; `invisible t' (fragment was created with `:expanded nil'); | |
| ;; 2. after `agent-shell-ui-toggle-fragment-at-point' makes it | |
| ;; visible, every body char is `invisible nil'; | |
| ;; 3. after toggling back to collapsed, every body char is | |
| ;; `invisible t' again. | |
| ;; A leak in any of these phases reproduces the user-reported | |
| ;; \"all tool use are expanded\" symptom. | |
| (let ((agent-shell--experimental-renderer t)) | |
| (with-temp-buffer | |
| (let* ((body "```console | |
| git log --reverse --format=\"%ai %s\" | head -1 | |
| ``` | |
| ```console | |
| 2025-09-14 11:45:17 +0100 Adding initial version | |
| ``` | |
| ") | |
| (range (agent-shell-ui-update-fragment | |
| (agent-shell-ui-make-fragment-model | |
| :namespace-id "ns" :block-id "tool" | |
| :label-left " done run " | |
| :label-right "Find the first commit date" | |
| :body body) | |
| :expanded nil :no-undo t))) | |
| ;; Run the experimental renderer on the body, mirroring how | |
| ;; `agent-shell--update-fragment' dispatches after inserting. | |
| (save-restriction | |
| (let ((inhibit-read-only t)) | |
| (narrow-to-region (map-nested-elt range '(:body :start)) | |
| (map-nested-elt range '(:body :end))) | |
| (agent-shell-markdown-replace-markup) | |
| (widen)))) | |
| (cl-labels ((body-range () | |
| (save-excursion | |
| (goto-char (point-min)) | |
| (let ((m (text-property-search-forward | |
| 'agent-shell-ui-section 'body t))) | |
| (cons (prop-match-beginning m) | |
| (prop-match-end m))))) | |
| (indicator-glyph () | |
| (save-excursion | |
| (goto-char (point-min)) | |
| (let ((m (text-property-search-forward | |
| 'agent-shell-ui-section 'indicator t))) | |
| (buffer-substring-no-properties | |
| (prop-match-beginning m) | |
| (1+ (prop-match-beginning m)))))) | |
| (fragment-state () | |
| (save-excursion | |
| (goto-char (point-min)) | |
| (let ((m (text-property-search-forward | |
| 'agent-shell-ui-state nil))) | |
| (get-text-property (prop-match-beginning m) | |
| 'agent-shell-ui-state)))) | |
| (assert-collapsed-state (expected-invisible expected-collapsed expected-glyph phase) | |
| (let* ((range (body-range)) | |
| (state (fragment-state)) | |
| (glyph (indicator-glyph)) | |
| (leaks 0)) | |
| (cl-loop for pos from (car range) below (cdr range) | |
| unless (eq (get-text-property pos 'invisible) | |
| expected-invisible) | |
| do (setq leaks (1+ leaks))) | |
| (should (= 0 leaks)) | |
| (should (eq (map-elt state :collapsed) | |
| expected-collapsed)) | |
| (should (equal glyph expected-glyph)) | |
| (princ (format " %s: body chars=%d invisible-leaks=%d state:collapsed=%S indicator=%S\n" | |
| phase (- (cdr range) (car range)) | |
| leaks (map-elt state :collapsed) | |
| glyph))))) | |
| ;; (1) Initial state: `:expanded nil' → body invisible, | |
| ;; `:collapsed t' in state, `▶' indicator. | |
| (assert-collapsed-state t t "▶" "after insert+render") | |
| ;; (2) Toggle — body becomes visible, `:collapsed nil', `▼'. | |
| (goto-char (point-min)) | |
| (search-forward "Find the first commit date") | |
| (backward-char) | |
| (agent-shell-ui-toggle-fragment-at-point) | |
| (assert-collapsed-state nil nil "▼" "after first toggle (expand)") | |
| ;; (3) Toggle again — back to collapsed, `▶'. | |
| (agent-shell-ui-toggle-fragment-at-point) | |
| (assert-collapsed-state t t "▶" "after second toggle (collapse)"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment