fix: 审查修复波次(P0x4 + P1x30+)
- domain/rules: 计分与排名解耦、破纪录按组别、tieBreak 生效、调整分不丢、移除 aggregate 假能力 - realtime: 新建 internal/dto,快照三项契约对齐,/ws 只认会话身份 - httpapi: 流水幂等、standings 整表载荷、广播接线、强制改密、XFF 防伪造、records 写入、审计、赛事包内容、发布前备份、result.points、实例列表 - web: FormData 上传、YAML 解析、快照归一化、大屏解析层、bootstrap 降级、访客判定、主题切换 - console: 优雅关闭握手、中文化、免验证改管理员账号、选屏与日志轮转修复 - docs: 用户文档三份 + README - 主代理: 破纪录加分接线(levels 未加载导致恒 0)
This commit is contained in:
1 parent
8dae63ee70
commit
7f9701c465
61 files changed
+3844
-333
No files matched your search
@@ -191,7 +191,7 @@ func TestScopeAndLedgerAttribution(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// TestAggregateChannel 覆盖预留的 aggregate 通道:先汇总、再排名。
|
||||
// TestAggregateChannel 覆盖 aggregate 通道:先按主体汇总(求和)、再排名。
|
||||
func TestAggregateChannel(t *testing.T) {
|
||||
build := func() ([]Entry, []Result) {
|
||||
return fixture([]participant{
|
||||
@@ -202,19 +202,12 @@ func TestAggregateChannel(t *testing.T) {
|
||||
}
|
||||
cases := []struct {
|
||||
name string
|
||||
method AggregateMethod
|
||||
compare CompareMode
|
||||
wantA float64
|
||||
wantB float64
|
||||
}{
|
||||
{"sum 升序", AggregateSum, CompareAsc, 15, 10},
|
||||
{"avg 升序", AggregateAvg, CompareAsc, 15, 10},
|
||||
{"max 升序", AggregateMax, CompareAsc, 15, 10},
|
||||
{"min 升序", AggregateMin, CompareAsc, 15, 10},
|
||||
{"count 降序", AggregateCount, CompareDesc, 15, 10},
|
||||
{"count 升序", AggregateCount, CompareAsc, 10, 15},
|
||||
{"sum 降序", AggregateSum, CompareDesc, 10, 15},
|
||||
{"默认方法按 sum", "", CompareAsc, 15, 10},
|
||||
{"求和后升序", CompareAsc, 15, 10},
|
||||
{"求和后降序", CompareDesc, 10, 15},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -223,7 +216,7 @@ func TestAggregateChannel(t *testing.T) {
|
||||
ev.Compare = tc.compare
|
||||
es := mustScore(t, EventScoreInput{
|
||||
Event: ev, Category: testCategory(),
|
||||
Channels: []ScoreChannel{teamAggregateChannel(2, tc.method)},
|
||||
Channels: []ScoreChannel{teamAggregateChannel(2)},
|
||||
Profiles: map[int64]ScoringProfile{2: teamTop6()},
|
||||
Entries: entries, Results: results,
|
||||
})
|
||||
@@ -242,7 +235,7 @@ func TestAggregateChannel(t *testing.T) {
|
||||
})
|
||||
es := mustScore(t, EventScoreInput{
|
||||
Event: teamEvent(1), Category: testCategory(),
|
||||
Channels: []ScoreChannel{teamAggregateChannel(2, AggregateSum)},
|
||||
Channels: []ScoreChannel{teamAggregateChannel(2)},
|
||||
Profiles: map[int64]ScoringProfile{2: teamTop6()},
|
||||
Entries: entries, Results: results,
|
||||
})
|
||||
@@ -320,7 +313,7 @@ func TestDraftState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestScoredFlagAndNoChannels 验证「只排名不计分」与「没有通道」都不产生流水。
|
||||
// TestScoredFlagAndNoChannels 验证「只排名不计分」:不产生流水,但必须照样产出名次。
|
||||
func TestScoredFlagAndNoChannels(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -342,13 +335,50 @@ func TestScoredFlagAndNoChannels(t *testing.T) {
|
||||
Profiles: map[int64]ScoringProfile{1: individualTop6()},
|
||||
Entries: entries, Results: results,
|
||||
})
|
||||
if len(es.Ledger) != 0 || len(es.Ranked) != 0 {
|
||||
t.Fatalf("流水/名次应为空,实际 %d/%d", len(es.Ledger), len(es.Ranked))
|
||||
if len(es.Ledger) != 0 {
|
||||
t.Fatalf("只排名不计分不应产生流水,实际 %d 条: %+v", len(es.Ledger), es.Ledger)
|
||||
}
|
||||
if len(es.Ranked) != 3 {
|
||||
t.Fatalf("名次条数 = %d,期望 3(排名与计分解耦)", len(es.Ranked))
|
||||
}
|
||||
for _, rr := range es.Ranked {
|
||||
if rr.Points != 0 {
|
||||
t.Errorf("只排名不计分时 Points = %v,期望 0", rr.Points)
|
||||
}
|
||||
}
|
||||
if ranks := rankByEntry(es.Ranked); ranks[1] != 1 || ranks[2] != 2 || ranks[3] != 3 {
|
||||
t.Fatalf("名次 = %v,期望 1/2/3", ranks)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRankOnlyRespectsResultMode 验证没有通道时按小项自身的录入方式排名(manual 直接读录入名次)。
|
||||
func TestRankOnlyRespectsResultMode(t *testing.T) {
|
||||
ps := lineup(3)
|
||||
for i := range ps {
|
||||
ps[i].noValue = true
|
||||
}
|
||||
ps[0].rank, ps[1].rank, ps[2].rank = 2, 3, 1
|
||||
entries, results := fixture(ps)
|
||||
|
||||
ev := individualEvent(1)
|
||||
ev.Scored = false
|
||||
ev.ResultMode = ResultModeManual
|
||||
ev.Compare = CompareNone
|
||||
es := mustScore(t, EventScoreInput{
|
||||
Event: ev, Category: testCategory(),
|
||||
Entries: entries, Results: results,
|
||||
})
|
||||
if len(es.Ledger) != 0 {
|
||||
t.Fatalf("只排名不计分不应产生流水,实际 %d 条", len(es.Ledger))
|
||||
}
|
||||
ranks := rankByEntry(es.Ranked)
|
||||
if ranks[3] != 1 || ranks[1] != 2 || ranks[2] != 3 {
|
||||
t.Fatalf("名次 = %v,期望 entry3→1 / entry1→2 / entry2→3", ranks)
|
||||
}
|
||||
}
|
||||
|
||||
// TestScoreEventErrors 覆盖配置类错误,避免错配置静默算错分。
|
||||
func TestScoreEventErrors(t *testing.T) {
|
||||
entries, results := fixture(lineup(1))
|
||||
@@ -376,7 +406,7 @@ func TestScoreEventErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
noCompareAgg := noCompare
|
||||
noCompareAgg.Channels = []ScoreChannel{teamAggregateChannel(1, AggregateSum)}
|
||||
noCompareAgg.Channels = []ScoreChannel{teamAggregateChannel(1)}
|
||||
if _, err := ScoreEvent(noCompareAgg); !errors.Is(err, ErrCompareRequired) {
|
||||
t.Errorf("聚合 compare=none 错误 = %v,期望 ErrCompareRequired", err)
|
||||
}
|
||||
@@ -599,3 +629,25 @@ func TestMissingResultOrEntry(t *testing.T) {
|
||||
assertEntryPoints(t, pointsByEntry(es.Ledger), []float64{10, 8, 0})
|
||||
})
|
||||
}
|
||||
|
||||
// TestNoChannelsSkipsRecordBonus 验证「0 个通道 = 只排名不计分」:
|
||||
// 即使项目 scored=true 且破了纪录,也不写任何流水(破纪录加分也跳过)。
|
||||
func TestNoChannelsSkipsRecordBonus(t *testing.T) {
|
||||
entries, results := fixture(lineup(2))
|
||||
cfg := bonusConfig(RecordBonusMax)
|
||||
es := mustScore(t, EventScoreInput{
|
||||
Event: individualEvent(1), Category: testCategory(),
|
||||
Entries: entries, Results: results,
|
||||
RecordBonus: &cfg,
|
||||
RecordBreaks: []RecordBreak{{
|
||||
ID: 1, EventID: 1, EntryID: 1, AthleteID: 101, TeamID: 1001,
|
||||
Level: "meet", State: RecordBreakApproved,
|
||||
}},
|
||||
})
|
||||
if len(es.Ledger) != 0 {
|
||||
t.Fatalf("没有通道时不应产生流水,实际 %d 条: %+v", len(es.Ledger), es.Ledger)
|
||||
}
|
||||
if len(es.Ranked) != 2 {
|
||||
t.Fatalf("名次条数 = %d,期望 2", len(es.Ranked))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user