@@ -15,6 +15,7 @@ import (
1515 "github.com/stretchr/testify/assert"
1616 "github.com/stretchr/testify/require"
1717
18+ "github.com/docker/docker-agent/pkg/tui/components/markdown"
1819 "github.com/docker/docker-agent/pkg/tui/components/spinner"
1920 tuiimage "github.com/docker/docker-agent/pkg/tui/image"
2021 "github.com/docker/docker-agent/pkg/tui/types"
@@ -50,6 +51,42 @@ func TestAssistantMarkdownImageRendersInline(t *testing.T) {
5051 assert .Less (t , strings .Index (view , "chart" ), strings .Index (view , "cagent-image" ), "alt label must immediately precede the image" )
5152}
5253
54+ func TestFailedMarkdownImageLoadCanRetry (t * testing.T ) {
55+ t .Parallel ()
56+
57+ source := "https://example.com/missing.png"
58+ msg := types .Agent (types .MessageTypeAssistant , "assistant" , "" )
59+ mv := New (msg , nil )
60+ mv .loadingImages = map [string ]bool {source : true }
61+
62+ _ , _ = mv .Update (markdownImagesLoadedMsg {
63+ target : mv ,
64+ requested : []tuiimage.MarkdownReference {{Source : source }},
65+ images : map [string ]tuiimage.Inline {},
66+ })
67+
68+ assert .Empty (t , mv .loadingImages , "failed sources must be cleared so SetMessage can retry" )
69+ assert .NotNil (t , mv .loadMarkdownImages (msg ), "a retry fetch must be scheduled" )
70+ }
71+
72+ func TestReplaceMarkdownImagePlaceholdersShiftsCodeBlocksByOriginalLine (t * testing.T ) {
73+ t .Parallel ()
74+
75+ lines := make ([]string , 13 )
76+ lines [3 ] = "TOKENA"
77+ lines [12 ] = "TOKENB"
78+ placeholders := []markdownImagePlaceholder {
79+ {token : "TOKENA" , lines : []string {"a1" , "a2" , "a3" , "a4" , "a5" , "a6" }}, // delta +5
80+ {token : "TOKENB" , lines : []string {"b1" , "b2" , "b3" }}, // delta +2, after the code block
81+ }
82+
83+ _ , adjusted := replaceMarkdownImagePlaceholders (strings .Join (lines , "\n " ), []markdown.CodeBlock {{Line : 10 }}, placeholders )
84+
85+ // Only the placeholder before the code block's original line shifts it.
86+ require .Len (t , adjusted , 1 )
87+ assert .Equal (t , 15 , adjusted [0 ].Line )
88+ }
89+
5390func TestErrorMessageWrapping (t * testing.T ) {
5491 t .Parallel ()
5592
0 commit comments