7fa1809682
- Added support for external markdown synchronization in ArticleEditorCanvas.vue. - Implemented a new function to sync markdown from props, ensuring the editor reflects external changes. - Introduced a removeOutlineSection function in TemplateWizardView.vue to manage outline sections dynamically. - Updated UI components to improve user experience, including replacing a-input with a-textarea for better text handling. - Refactored CSS styles for a cleaner layout and improved responsiveness in TemplateWizardView.vue. - Enhanced LLM generation requests to include response format options in ark.go and client.go. - Updated template assist logic to enforce structured outline outputs in template_assist.go. - Added tests for outline result decoding and prompt generation to ensure robustness. - Created migration scripts to update prompt templates with new writing requirements for top X articles.
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeOutlineResultAcceptsWrappedObject(t *testing.T) {
|
|
raw := `{"outline":[{"outline":"网站列表","children":[{"outline":"竞品 A"}]}]}`
|
|
|
|
result, err := decodeOutlineResult(raw)
|
|
if err != nil {
|
|
t.Fatalf("decodeOutlineResult() error = %v", err)
|
|
}
|
|
if len(result) != 1 || result[0].Outline != "网站列表" {
|
|
t.Fatalf("decodeOutlineResult() = %#v, want outline payload", result)
|
|
}
|
|
if len(result[0].Children) != 1 || result[0].Children[0].Outline != "竞品 A" {
|
|
t.Fatalf("decodeOutlineResult() children = %#v, want child outline", result[0].Children)
|
|
}
|
|
}
|
|
|
|
func TestDecodeOutlineResultExtractsArrayFromNarrativeText(t *testing.T) {
|
|
raw := "以下是整理后的结果:\n```json\n[\n {\"outline\":\"文章关键要点\",\"children\":[{\"outline\":\"要点 1\"}]}\n]\n```\n请直接使用。"
|
|
|
|
result, err := decodeOutlineResult(raw)
|
|
if err != nil {
|
|
t.Fatalf("decodeOutlineResult() error = %v", err)
|
|
}
|
|
if len(result) != 1 || result[0].Outline != "文章关键要点" {
|
|
t.Fatalf("decodeOutlineResult() = %#v, want extracted array payload", result)
|
|
}
|
|
}
|
|
|
|
func TestDecodeOutlineResultExtractsInnerArrayFromMalformedWrapper(t *testing.T) {
|
|
raw := "结果如下:{\n[\n {\"outline\":\"常见问题\"}\n]\n}"
|
|
|
|
result, err := decodeOutlineResult(raw)
|
|
if err != nil {
|
|
t.Fatalf("decodeOutlineResult() error = %v", err)
|
|
}
|
|
if len(result) != 1 || result[0].Outline != "常见问题" {
|
|
t.Fatalf("decodeOutlineResult() = %#v, want inner array payload", result)
|
|
}
|
|
}
|
|
|
|
func TestBuildOutlinePromptForConfiguredTemplateForcesOutlineObject(t *testing.T) {
|
|
template := "你正在为文章生成大纲。\n标题: {{title}}\n已选段落: {{outline_sections}}"
|
|
|
|
prompt := buildOutlinePrompt("recommendation_list", "推荐类模板", OutlineTaskRequest{
|
|
Locale: "zh-CN",
|
|
Title: "测试标题",
|
|
OutlineSections: []string{"引言", "文章关键要点"},
|
|
}, &template)
|
|
|
|
if !strings.Contains(prompt, `{"outline":[...]}`) {
|
|
t.Fatalf("buildOutlinePrompt() = %q, want fixed outline object instruction", prompt)
|
|
}
|
|
if !strings.Contains(prompt, "JSON 输出示例") {
|
|
t.Fatalf("buildOutlinePrompt() = %q, want JSON example", prompt)
|
|
}
|
|
if !strings.Contains(prompt, "不要返回纯数组") {
|
|
t.Fatalf("buildOutlinePrompt() = %q, want pure-array prohibition", prompt)
|
|
}
|
|
}
|