From 2bb14758bd2bca3673119380182245e72c763138 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Wed, 7 Oct 2026 00:21:24 +0800 Subject: [PATCH] =?UTF-8?q?M3=20=E8=A1=A5=E6=B5=8B=EF=BC=9A=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=20BigInt=20=E7=9A=84=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E4=B8=8A=E6=95=B0=E5=AD=97=E7=9A=84=E6=98=BE=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=88=A4=E6=97=A0=E6=B3=95=E6=A0=B8=E5=AF=B9=EF=BC=8C?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=8F=96=E5=80=BC=E5=92=8C=E5=85=B6=E4=BD=99?= =?UTF-8?q?=E6=A0=B8=E5=AF=B9=E9=A1=B9=E7=85=A7=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 较早的浏览器没有 BigInt(或不认 \p{…})时,显示规则的渲染走不了:只有数字的显示文字判「无法核对显示文字」并写明 原因,整段核对脚本不能因此出错。node 里载入时把 BigInt 遮掉验证这一点;跳过原因的措辞照文案规范改。 --- backend/tests/test_bundle_shown.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/backend/tests/test_bundle_shown.py b/backend/tests/test_bundle_shown.py index 780e032e..0d0a688b 100644 --- a/backend/tests/test_bundle_shown.py +++ b/backend/tests/test_bundle_shown.py @@ -33,16 +33,17 @@ from app.engine.evidence import RenderError, _Snapshots, render_cell, render_num NODE = shutil.which("node") VERIFIER = Path(app.bundle.__file__).parent / "verifier.js" -pytestmark = pytest.mark.skipif(NODE is None, reason="没有 node,跑不了页面上的核对脚本") +pytestmark = pytest.mark.skipif(NODE is None, reason="没有 node,无法执行页面上的核对脚本") -#: 载入 verifier.js(在 node 里没有 document,它把核对用的纯函数交给 module.exports),按 stdin 交来的任务算 +#: 载入 verifier.js(在 node 里没有 document,它把核对用的纯函数交给 module.exports),按 stdin 交来的任务算。 +#: noBigInt:载入时把 BigInt 遮掉,当作较早的浏览器 HARNESS = r""" const fs = require('fs') const { createHash } = require('crypto') -const mod = { exports: {} } -new Function('module', fs.readFileSync(process.argv[1], 'utf8'))(mod) -const v = mod.exports const input = JSON.parse(fs.readFileSync(0, 'utf8')) +const mod = { exports: {} } +new Function('module', 'BigInt', fs.readFileSync(process.argv[1], 'utf8'))(mod, input.noBigInt ? undefined : BigInt) +const v = mod.exports function render(c) { try { @@ -356,6 +357,19 @@ def test_an_unknown_cell_display_version_cannot_pass(): assert all(n["result"] == "pass" for n in got["numbers"] if n["ref"].startswith("m:")) +def test_a_browser_without_bigint_cannot_check_numbers_but_still_checks_the_rest(): + """较早的浏览器没有 BigInt:数字的显示文字判无法核对(写明原因),文字取值照常核对,别的核对项不受影响,脚本不出错。""" + from tests.bundle_samples import formats_bundle + + bundle = formats_bundle() + got = node("verify", data=bundle, seal=bundle["meta"]["manifest_hash"], noBigInt=True) + assert all(r == "pass" for key in ("events", "manifest", "artifacts", "chain", "meta") for r in got[key]) + texts = {"v:Q1.r0.region", "v:Q1.r1.region", "v:Q1.r0.paid_at"} + assert all(n["result"] == "pass" for n in got["numbers"] if n["ref"] in texts) + assert all(n["result"] == "na" and n["reason"] == "无法核对显示文字:这个浏览器不支持按系统的显示规则重新渲染(缺少 BigInt 或 " + "Unicode 正则)" for n in got["numbers"] if n["ref"] not in texts) + + def test_every_sample_page_still_passes_its_display_check(): """check-bundle 的样本页(tests/bundle_samples.py)原样导出:每个核对得到出处的数字和取值,显示文字都核对通过; 没有一项因为显示文字不通过或核对不了。"""