87f97a2f9b
build / build (push) Successful in 1m7s
详情使用共享主表字典,稀疏修改所选字段并保留原始问答及旧复核审计。 月周统计提供文本和下拉双入口;每租户每周一份持久草稿,按技能六节双语模板真实预填。 加入幂等自动保存、冲突保留、未知响应重试、切周及离开保护和schema58非破坏降级保护。 验证:完整make verify、隔离PostgreSQL全mirror竞态回归、真实恢复库浏览器验收通过。 浏览器实测字段精确读回、月周双输入、模板预填、MD/CSV、自动保存、冲突、失败重试与API重启恢复。 未连接或改写DobotAI生产源库,未运行付费模型;提交时尚未部署。
44 lines
1.9 KiB
Go
44 lines
1.9 KiB
Go
package qaopsmirror
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWeeklyDraftDurablyRoundTripsOneDraftPerWeekWithoutReadSideEffects(t *testing.T) {
|
|
p := mirrorFixture(t)
|
|
s := NewStore(p, "fixture-weekly-editor")
|
|
ctx := context.Background()
|
|
now := time.Date(2026, 10, 19, 12, 0, 0, 0, time.UTC)
|
|
empty, e := s.ReadWeeklyDraft(ctx, "2026-W41", now)
|
|
if e != nil || empty.Revision != 0 || empty.Week != "2026-W41" || empty.Markdown != "" {
|
|
t.Fatalf("missing week must be a read-only empty draft, not unavailable/fabricated content: %+v %v", empty, e)
|
|
}
|
|
var rows int
|
|
if e = p.QueryRow(ctx, `SELECT count(*) FROM qa_ops_weekly_drafts WHERE tenant_key=$1`, s.tenant).Scan(&rows); e != nil || rows != 0 {
|
|
t.Fatal("viewing a week created a draft", e)
|
|
}
|
|
q := WeeklyDraftRequest{BaseRevision: 0, Nonce: "fixture_weekly_editor_0001", Markdown: "# Edited report\n\n中文正文,English text\n<script>not executable</script>\n"}
|
|
receipt, e := s.SaveWeeklyDraft(ctx, "2026-W41", q, "fixture-admin", now)
|
|
if e != nil || receipt.Draft.Revision != 1 || receipt.Replayed {
|
|
t.Fatalf("autosave rejected: %+v %v", receipt, e)
|
|
}
|
|
fresh, e := NewStore(p, s.tenant).ReadWeeklyDraft(ctx, "2026-W41", now)
|
|
if e != nil || fresh.Markdown != q.Markdown || fresh.Revision != 1 || fresh.UpdatedAt == nil {
|
|
t.Fatalf("reopened editor lost exact content: %+v %v", fresh, e)
|
|
}
|
|
other, e := s.ReadWeeklyDraft(ctx, "2026-W40", now)
|
|
if e != nil || other.Revision != 0 || other.Markdown != "" {
|
|
t.Fatal("week contents contaminated", e)
|
|
}
|
|
tenant, e := NewStore(p, "fixture-other-tenant").ReadWeeklyDraft(ctx, "2026-W41", now)
|
|
if e != nil || tenant.Revision != 0 {
|
|
t.Fatal("tenant isolation failed", e)
|
|
}
|
|
replay, e := s.SaveWeeklyDraft(ctx, "2026-W41", q, "fixture-admin", now)
|
|
if e != nil || !replay.Replayed || replay.Draft.Revision != 1 {
|
|
t.Fatal("same autosave retry must recover its existing receipt", e)
|
|
}
|
|
}
|