71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
package workbench
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/Tencent/WeKnora/internal/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestLongCompositionKeepsEveryAcceptedCharacter(t *testing.T) {
|
||
|
|
s, ctx, job, model := generationHarness(t)
|
||
|
|
s.models = generationModelStub{model: model, parameters: types.ModelParameters{ContextWindow: 4096, MaxOutputTokens: 512}}
|
||
|
|
job.Action = "compose"
|
||
|
|
d := TaskData{AgentID: "agent", Segments: []Segment{
|
||
|
|
{ID: "a", Title: "基础", Status: "accepted", Content: strings.Repeat("已采用的完整正文。", 2000)},
|
||
|
|
{ID: "skip", Title: "废弃", Status: "skipped", Content: "这段不应出现在成稿"},
|
||
|
|
{ID: "b", Title: "进阶", Status: "accepted", Content: "最后一段也必须保留"},
|
||
|
|
}}
|
||
|
|
accepted, _ := acceptedManuscript(d)
|
||
|
|
d.Quality = &QualityReport{Passed: true, Summary: "通过", ManuscriptHash: manuscriptHash(accepted)}
|
||
|
|
r := &Resource{Data: asJSON(d)}
|
||
|
|
if err := s.executeTask(ctx, job, r, ActionRequest{}); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
got, _ := decode[TaskData](r.Data)
|
||
|
|
if r.Status != "completed" || len(model.messages) != 0 || !strings.Contains(got.Composed, d.Segments[0].Content) || !strings.Contains(got.Composed, d.Segments[2].Content) || strings.Contains(got.Composed, "这段不应") {
|
||
|
|
t.Fatal("long composition lost or invented text")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestReviewWindowsCoverEverySegmentAndBoundary(t *testing.T) {
|
||
|
|
s, ctx, _, model := generationHarness(t)
|
||
|
|
s.models = generationModelStub{model: model, parameters: types.ModelParameters{ContextWindow: 4096, MaxOutputTokens: 512}}
|
||
|
|
c, err := s.prepareCompletion(ctx, "agent", qualitySystem, "")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
rows := []Segment{}
|
||
|
|
for _, id := range []string{"a", "b", "c", "d", "e", "f"} {
|
||
|
|
rows = append(rows, Segment{ID: id, Title: id, Content: strings.Repeat("完整正文。", 140)})
|
||
|
|
}
|
||
|
|
windows, err := manuscriptWindows(c, rows, "")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if len(windows) < 2 {
|
||
|
|
t.Fatal("expected multiple review windows")
|
||
|
|
}
|
||
|
|
seen := map[string]bool{}
|
||
|
|
for i, window := range windows {
|
||
|
|
for _, seg := range window {
|
||
|
|
seen[seg.ID] = true
|
||
|
|
}
|
||
|
|
if i > 0 && windows[i-1][len(windows[i-1])-1].ID != window[0].ID {
|
||
|
|
t.Fatal("missing boundary overlap")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(seen) != len(rows) {
|
||
|
|
t.Fatal("unreviewed accepted segment")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestMergedQualityKeepsBlockingVerdictAndCurrentHash(t *testing.T) {
|
||
|
|
rows := []Segment{{ID: "a", Content: "正文"}, {ID: "b", Content: "后文"}}
|
||
|
|
issue := QualityIssue{SegmentIDs: []string{"b"}, Severity: "blocking", Problem: "先修冲突", Suggestion: "修正前提"}
|
||
|
|
report, err := mergeQualityReports([]QualityReport{{Passed: true, Summary: "第一组通过"}, {Passed: false, Summary: "第二组冲突", Issues: []QualityIssue{issue, issue}}}, rows)
|
||
|
|
if err != nil || report.Passed || len(report.Issues) != 1 || report.ManuscriptHash != manuscriptHash(rows) {
|
||
|
|
t.Fatalf("invalid merged report: %+v %v", report, err)
|
||
|
|
}
|
||
|
|
}
|