ad67fe1ebe
Let the planner return a clarify/chat intent that asks 2-4 targeted questions (imageCount 0) when essentials are missing, instead of forging ahead. Tighten prompt guidance to preserve user wording and stated reference-image roles, avoid inventing copy/specs, keep durable brand constraints, and treat vague taste feedback as clarification. Also fix the generation heartbeat goroutine to stop cleanly via defer, add research-query fallbacks, and refresh image-only capability copy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package piagent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"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))
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|