详情使用共享主表字典,稀疏修改所选字段并保留原始问答及旧复核审计。 月周统计提供文本和下拉双入口;每租户每周一份持久草稿,按技能六节双语模板真实预填。 加入幂等自动保存、冲突保留、未知响应重试、切周及离开保护和schema58非破坏降级保护。 验证:完整make verify、隔离PostgreSQL全mirror竞态回归、真实恢复库浏览器验收通过。 浏览器实测字段精确读回、月周双输入、模板预填、MD/CSV、自动保存、冲突、失败重试与API重启恢复。 未连接或改写DobotAI生产源库,未运行付费模型;提交时尚未部署。
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package qaopsmirror
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"knowledge-governance/internal/dobotaiops"
|
||||
pg "knowledge-governance/internal/platform/postgres"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWeeklyPrefillUsesRealMasterDashboardAndDoesNotOverwriteExistingDraft(t *testing.T) {
|
||||
p := mirrorFixture(t)
|
||||
ctx := context.Background()
|
||||
s := NewStore(p, "fixture-weekly-prefill")
|
||||
queue := pg.NewStore(p)
|
||||
source := &fixtureSource{rows: []dobotaiops.MirrorRecord{fixtureEntry("prefill-event", "existing answer")}}
|
||||
job := claimMirrorJob(t, s, queue, "prefill-source")
|
||||
if e := s.HandleSync(ctx, *job, func(context.Context) (Source, error) { return source, nil }); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := queue.Complete(ctx, job.ID, job.LeaseOwner, time.Now()); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
record, e := s.GetMasterRecord(ctx, s.tenant, "prefill-event")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
year, weekNumber := record.AskedAt.In(dashboardLocation).ISOWeek()
|
||||
week := fmt.Sprintf("%04d-W%02d", year, weekNumber)
|
||||
now := time.Now()
|
||||
start, end, e := weeklyDraftBounds(week, now)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
data, e := s.ReadMasterDashboard(ctx, dobotaiops.RecordQuery{Window: dobotaiops.Window{TenantKey: s.tenant, Start: start, End: end}})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
q := WeeklyDraftPrefillRequest{Nonce: "fixture_prefill_week_0001"}
|
||||
receipt, e := s.PrefillWeeklyDraft(ctx, week, q, "fixture-admin", now)
|
||||
if e != nil {
|
||||
t.Fatalf("real-source prefill unavailable: %v", e)
|
||||
}
|
||||
if receipt.Draft.Revision != 1 || !strings.Contains(receipt.Draft.Markdown, fmt.Sprintf("问题总数:%d", data.TotalIssues)) || !strings.Contains(receipt.Draft.Markdown, fmt.Sprintf("New This Week: %d", data.NewThisWeek)) {
|
||||
t.Fatal("prefill was not generated from matching master cutoff")
|
||||
}
|
||||
var seed map[string]any
|
||||
if json.Unmarshal(receipt.Draft.Seed, &seed) != nil || seed["source"] != "governance-master" || seed["week"] != week {
|
||||
t.Fatal("prefill source provenance missing")
|
||||
}
|
||||
edit := WeeklyDraftRequest{BaseRevision: 1, Nonce: "fixture_prefill_user_0002", Markdown: receipt.Draft.Markdown + "\n用户亲写内容,不许替换\n"}
|
||||
if _, e = s.SaveWeeklyDraft(ctx, week, edit, "fixture-admin", now); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.PrefillWeeklyDraft(ctx, week, WeeklyDraftPrefillRequest{BaseRevision: 1, Nonce: "fixture_prefill_stale_0003"}, "fixture-admin", now); e == nil {
|
||||
t.Fatal("stale regeneration silently replaced edited content")
|
||||
}
|
||||
fresh, e := s.ReadWeeklyDraft(ctx, week, now)
|
||||
if e != nil || fresh.Revision != 2 || fresh.Markdown != edit.Markdown {
|
||||
t.Fatal("prefill or stale request overwrote user input", e)
|
||||
}
|
||||
replay, e := s.PrefillWeeklyDraft(ctx, week, q, "fixture-admin", now)
|
||||
if e != nil || !replay.Replayed || replay.Draft.Revision != 1 {
|
||||
t.Fatal("prefill retry must return its exact historical receipt", e)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user