fix: P0 计分根因 + 奖牌结算/奖牌通道 + 身份口径改回证件号 + 19 条 P1(dev_0.1.8)
## P0:双通道项目重复发布跳分(45→85→收敛) results.rank 一列同时充当「个人名次输出」「手工名次输入」「榜单数据源」, 团体手工通道把个人名次当团体名次又按团体表发一遍分。 - 新增 channel_ranks(每个计分通道各自持久化名次,发布时全量重建) 与 channel_manual_ranks(按单位录入的团体手工名次,故意不挂通道外键, 避免规则包重导时级联删掉录入数据) - results.rank 语义收窄为「只表示个人名次」,只由 scope=athlete 通道写回; 团体手工名次的来源改为 TeamRanks 优先、团体报名项兜底, 个人报名项的名次绝不进团体通道 - writeLedgerTx 内重建 channel_ranks;buildRanked / export.loadRanked / realtime.loadRanked 三份同源 SQL 一起改读新表 - 回归:发布两次流水与名次逐字节一致(domain + httpapi 各一条,含变异验证) ## 奖牌结算开关与奖牌通道(P1(5),新功能) - events.award_medals + 通道 count_to_medals / count_to_team_medals (迁移默认 1,升级不改变既有榜单) - 单位榜入选 = 小项结算奖牌 && 通道发奖牌 && 前三名 &&(团体项目 || 个人奖牌并入单位) - 个人榜只取个人通道;金牌榜与积分榜同源同数据、按通道过滤独立计算 - 前端:小项「该项启用奖牌结算」、通道「发奖牌/个人奖牌并入单位金牌榜」、 录入页新增「团体名次」区块(含新接口 GET/PUT .../team-ranks) ## 身份口径改回证件号(P1(15),推翻第三十六轮) - 匹配顺序恢复 证件号 → 号码布 → 姓名+单位;新增 athleteByIDCard - 同表重复证件号 = 同一人报多个组别(notices 提示,不报错); 只有「同证件号 + 同小项同组别」才是真重复(conflicts[].duplicate) - 补齐后端缺失但前端/文档已在依赖的三处契约 ## 其余 P1 - 安全:会话撤销断开 ws、实时层按角色裁剪、整库快照限流(含 hello 路径, 被限流的请求挂起并由心跳兜底补发,不丢刷新) - 错误分级:手填名次非正数 / gender / 组别年龄 / 导出不存在的小项与单位 / 积分模板 awardRanks → 400 或 404,不再 500 - 算分一致性:破纪录加分看得失状态;批量退赛·恢复·移出、作废成绩、 报名导入改状态一律无条件重算推榜(不受延迟结算约束,与实时模式逐字节等价) - 配置改动触发重算:通道 / 小项参数 / 积分模板 - 升级自愈:channel_ranks 空而已有已发布成绩时,启动时一次性全量重算 (服务对外监听之前完成,避免升级后奖牌榜全 0) - 示例数据模式下破坏性操作被阻断,不再假成功 - Console:修复「只剩一块屏」后屏幕监听器被永久摘掉 - 大屏模板引擎:嵌套深度与体积安全阀,任何输入都不抛异常 ## 文档 - docs/:使用手册(奖牌开关、奖牌通道、团体名次、枚举列留空口径)、 常见问题(奖牌排查、升级后奖牌榜为 0、历史重放已知限制)、 部署指南、上线检查清单 - 版本 dev_0.1.7 → dev_0.1.8(console/package.json 同步) 自检:服务端 13 包 ×2 全绿;前端 vue-tsc + 449 例 ×2 + pnpm build; Console 35 例 + 语法检查。
This commit is contained in:
1 parent
53a0cb225c
commit
45edfbeb71
115 files changed
+10104
-755
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { renderTemplate } from '../template'
|
||||
import { MAX_TEMPLATE_DEPTH, MAX_TEMPLATE_SOURCE_LENGTH, renderTemplate } from '../template'
|
||||
|
||||
// 设计稿 §10.1 的「边界/性能」组:单文件上限是 1 MiB(§6.2),引擎不能在这个量级上炸或卡死。
|
||||
// 后面几组钉住审查 [11-1] 要求的安全阀:嵌套太深 / 体积太大一律降级成结构化 error,不抛异常。
|
||||
|
||||
test('1 MiB 量级的模板能正常渲染', () => {
|
||||
const filler = 'x'.repeat(1024)
|
||||
@@ -47,3 +48,76 @@ test('深嵌套 #each/#if(30 层)不炸,作用域逐层正确', () => {
|
||||
assert.equal(result.error, null)
|
||||
assert.equal(result.html, `n${depth - 1}`)
|
||||
})
|
||||
|
||||
test('10 层嵌套 #if 渲染正确,没有警告(人工模板的正常量级)', () => {
|
||||
const depth = 10
|
||||
const source = '{{#if ok}}'.repeat(depth) + '{{ title }}' + '{{/if}}'.repeat(depth)
|
||||
|
||||
const result = renderTemplate(source, { ok: true, title: '十层' })
|
||||
assert.equal(result.error, null)
|
||||
assert.equal(result.html, '十层')
|
||||
assert.deepEqual(result.warnings, [])
|
||||
})
|
||||
|
||||
test(`正好 ${MAX_TEMPLATE_DEPTH} 层照常渲染,多一层降级成 too-deep`, () => {
|
||||
const openTag = '{{#if ok}}'
|
||||
const wrap = (depth: number): string =>
|
||||
openTag.repeat(depth) + 'x' + '{{/if}}'.repeat(depth)
|
||||
|
||||
const atLimit = renderTemplate(wrap(MAX_TEMPLATE_DEPTH), { ok: true })
|
||||
assert.equal(atLimit.error, null)
|
||||
assert.equal(atLimit.html, 'x')
|
||||
|
||||
const overLimit = renderTemplate(wrap(MAX_TEMPLATE_DEPTH + 1), { ok: true })
|
||||
assert.equal(overLimit.error?.code, 'too-deep')
|
||||
// 位置指向超出的那个 {{#if}}(全在一行)
|
||||
assert.equal(overLimit.error?.line, 1)
|
||||
assert.equal(overLimit.error?.offset, MAX_TEMPLATE_DEPTH * openTag.length)
|
||||
assert.equal(overLimit.error?.column, overLimit.error!.offset + 1)
|
||||
assert.ok(overLimit.error?.message.includes(String(MAX_TEMPLATE_DEPTH)))
|
||||
assert.equal(overLimit.html, '')
|
||||
assert.deepEqual(overLimit.warnings, [])
|
||||
})
|
||||
|
||||
test('审查 [11-1] 的复现输入(3000 层 {{#if}},约 48 KB)不抛异常,降级为 too-deep', () => {
|
||||
const depth = 3000
|
||||
const source = '{{#if a}}'.repeat(depth) + 'x' + '{{/if}}'.repeat(depth)
|
||||
|
||||
assert.doesNotThrow(() => renderTemplate(source, { a: true }))
|
||||
|
||||
const result = renderTemplate(source, { a: true })
|
||||
assert.equal(result.error?.code, 'too-deep')
|
||||
assert.equal(result.html, '')
|
||||
assert.deepEqual(result.warnings, [])
|
||||
})
|
||||
|
||||
test('超深 {{#each}} 同样降级(两种块共用同一个层数计数器)', () => {
|
||||
const depth = MAX_TEMPLATE_DEPTH + 1
|
||||
const source = '{{#each rows}}'.repeat(depth) + 'x' + '{{/each}}'.repeat(depth)
|
||||
|
||||
assert.doesNotThrow(() => renderTemplate(source, { rows: [] }))
|
||||
assert.equal(renderTemplate(source, { rows: [] }).error?.code, 'too-deep')
|
||||
})
|
||||
|
||||
test(`体积超过 ${MAX_TEMPLATE_SOURCE_LENGTH}:不解析、不抛异常,降级为 too-large`, () => {
|
||||
const source = `{{ a }}${'x'.repeat(MAX_TEMPLATE_SOURCE_LENGTH)}`
|
||||
|
||||
assert.doesNotThrow(() => renderTemplate(source, { a: 1 }))
|
||||
|
||||
const result = renderTemplate(source, { a: 1 })
|
||||
assert.equal(result.error?.code, 'too-large')
|
||||
assert.equal(result.error?.line, 1)
|
||||
assert.equal(result.error?.column, 1)
|
||||
assert.equal(result.error?.offset, 0)
|
||||
assert.equal(result.html, '')
|
||||
assert.deepEqual(result.warnings, [])
|
||||
})
|
||||
|
||||
test('体积正好等于上限:照常解析(上限是「超过才拒」)', () => {
|
||||
const source = '{{ a }}'.padEnd(MAX_TEMPLATE_SOURCE_LENGTH, 'x')
|
||||
assert.equal(source.length, MAX_TEMPLATE_SOURCE_LENGTH)
|
||||
|
||||
const result = renderTemplate(source, { a: 1 })
|
||||
assert.equal(result.error, null)
|
||||
assert.equal(result.html.startsWith('1'), true)
|
||||
})
|
||||
Reference in new issue
Block a user