删除任务链(drafts/confirmations/tasks/attempts)、creator 运营链(策略/事件/操作/会话/消息/监听器/素材/关系)、runtime_use_lease 机制及其 API/UI;taskstate 包与对应测试一并移除。
79 lines
3.2 KiB
Go
79 lines
3.2 KiB
Go
package creator
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCreatorPureCoverageGuards(t *testing.T) {
|
|
if _, err := decodeCommentCheckpoint(`{"cursor":"missing-work-key"}`); !errors.Is(err, ErrInvalid) {
|
|
t.Fatalf("invalid empty checkpoint: %v", err)
|
|
}
|
|
if value, err := decodeCommentCheckpoint(`{"work_key":"work","cursor":"cursor"}`); err != nil || value.WorkKey != "work" || value.Cursor != "cursor" {
|
|
t.Fatalf("valid checkpoint: %+v %v", value, err)
|
|
}
|
|
}
|
|
|
|
func TestCreatorSchedulingAndActionPredicates(t *testing.T) {
|
|
now := time.Now().UTC()
|
|
if next, reason := NextMetricAtValue(nil, now, SettingsUpdate{}); !next.IsZero() || reason != "published_at_pending_verification" {
|
|
t.Fatalf("pending metric schedule: %v %q", next, reason)
|
|
}
|
|
published := now.Add(-time.Hour)
|
|
input := SettingsUpdate{MetricInitialIntervalSeconds: 60, MetricMaxIntervalSeconds: 3600, MetricMultiplier: 2, MetricAgeSeconds: 7200}
|
|
if next, reason := NextMetricAtValue(&published, now, input); next.IsZero() || reason != "" {
|
|
t.Fatalf("metric schedule: %v %q", next, reason)
|
|
}
|
|
if coalesceReason("value", "fallback") != "value" || coalesceReason("", "fallback") != "fallback" {
|
|
t.Fatal("coalesceReason did not choose the expected value")
|
|
}
|
|
}
|
|
|
|
func TestCreatorPaginationGuards(t *testing.T) {
|
|
items, err := collectPagesFromCursor(context.Background(), "", func(_ context.Context, cursor string) ([]string, string, bool, error) {
|
|
if cursor != "" {
|
|
t.Fatalf("unexpected cursor %q", cursor)
|
|
}
|
|
return []string{"one"}, "", false, nil
|
|
}, nil)
|
|
if err != nil || len(items) != 1 {
|
|
t.Fatalf("single page: %v %v", items, err)
|
|
}
|
|
for name, fetch := range map[string]func(context.Context, string) ([]string, string, bool, error){
|
|
"missing cursor": func(context.Context, string) ([]string, string, bool, error) { return nil, "", true, nil },
|
|
"repeated cursor": func(context.Context, string) ([]string, string, bool, error) { return nil, "same", true, nil },
|
|
} {
|
|
_, err := collectPagesFromCursor(context.Background(), "same", fetch, nil)
|
|
if !errors.Is(err, ErrInvalid) {
|
|
t.Fatalf("%s: %v", name, err)
|
|
}
|
|
}
|
|
_, err = collectPagesFromCursor(context.Background(), "", func(context.Context, string) ([]string, string, bool, error) {
|
|
return nil, "next", true, errors.New("fetch failed")
|
|
}, nil)
|
|
if err == nil || err.Error() != "fetch failed" {
|
|
t.Fatalf("fetch failure: %v", err)
|
|
}
|
|
_, err = collectPagesFromCursor(context.Background(), "", func(context.Context, string) ([]string, string, bool, error) {
|
|
return []string{"one"}, "next", true, nil
|
|
}, func([]string, string, bool) error { return errors.New("save failed") })
|
|
if err == nil || err.Error() != "save failed" {
|
|
t.Fatalf("after-page failure: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestConfiguredBailianWithoutStore(t *testing.T) {
|
|
var client *ConfiguredBailian
|
|
if _, err := client.Generate(context.Background(), "instruction", "input"); !errors.Is(err, ErrUnavailable) {
|
|
t.Fatalf("nil Generate: %v", err)
|
|
}
|
|
if _, _, err := client.MatchTheme(context.Background(), "title", "body", "topic"); !errors.Is(err, ErrUnavailable) {
|
|
t.Fatalf("nil MatchTheme: %v", err)
|
|
}
|
|
if _, _, err := client.MatchLead(context.Background(), "work", "comment", "requirement"); !errors.Is(err, ErrUnavailable) {
|
|
t.Fatalf("nil MatchLead: %v", err)
|
|
}
|
|
}
|