2026-07-07 23:15:37 +08:00
package piagent
import (
2026-07-08 10:56:55 +08:00
"encoding/json"
2026-07-07 23:15:37 +08:00
"strings"
"testing"
"unicode/utf8"
"img_infinite_canvas/internal/domain/design"
)
func TestNewCreativeAgentDefaultsToGPT55 ( t * testing . T ) {
agent := NewCreativeAgent ( CreativeAgentOptions {
BaseURL : "http://example.com" ,
APIKey : "test-key" ,
} )
if agent == nil {
t . Fatal ( "expected creative agent" )
}
if agent . model != "gpt-5.5" {
t . Fatalf ( "expected gpt-5.5 default model, got %s" , agent . model )
}
}
func TestAgentMessageContentSummaryDoesNotLeakImageURLs ( t * testing . T ) {
summary := agentMessageContentSummary ( [ ] design . AgentChatMessage {
{
Contents : [ ] design . AgentContent {
{ Type : "text" , Text : strings . Repeat ( "视觉方向" , 200 ) } ,
{ Type : "image" , ImageURL : "https://storage.example.com/private/raw.png" , ImageWidth : 100 , ImageHeight : 200 } ,
} ,
} ,
} )
if strings . Contains ( summary , "storage.example.com" ) || strings . Contains ( summary , "raw.png" ) {
t . Fatalf ( "expected compact image reference without raw URL, got %s" , summary )
}
if utf8 . RuneCountInString ( summary ) > 360 {
t . Fatalf ( "expected compact inline text summary, got %d runes" , utf8 . RuneCountInString ( summary ) )
}
}
2026-07-08 10:56:55 +08:00
func TestResearchContextIncludesPageContentForEveryResult ( t * testing . T ) {
payload , err := json . Marshal ( design . ResearchReport {
Kind : "web_search" ,
Source : "test" ,
Query : "Japanese bakery brand identity" ,
Results : [ ] design . ResearchResult {
{ Title : "Bakery case study" , URL : "https://example.com/one" , Snippet : "Warm handmade identity." , Content : "Detailed first webpage content about packaging, signage, and illustration." } ,
{ Title : "Brand identity notes" , URL : "https://example.com/two" , Snippet : "Soft visual system." , Content : "Detailed second webpage content about colors, typography, and bakery tone." } ,
} ,
} )
if err != nil {
t . Fatal ( err )
}
context := researchContext ( [ ] design . Message {
{ Role : "tool" , Type : "tool" , Title : "Synthesize Skills" , Content : string ( payload ) } ,
} )
for _ , want := range [ ] string {
"Query: Japanese bakery brand identity" ,
"https://example.com/one" ,
"Detailed first webpage content" ,
"https://example.com/two" ,
"Detailed second webpage content" ,
} {
if ! strings . Contains ( context , want ) {
t . Fatalf ( "expected research context to include %q, got %s" , want , context )
}
}
}