修复构建阻塞与过期测试,补 npm test 入口 (WORK-20) - #1
Closed
lbtsm wants to merge 5 commits into
Closed
Conversation
src/chain/xrp/xrp.ts imports 'xrpl' but the package was never declared in package.json, so tsc reported TS2307 and npm run typecheck / npm run build always exited 2 — unusable as a CI gate even though tsc still emitted output. Declared as a runtime dependency rather than excluding the file from the build: xrp.ts is the start of a real XRP send path, not dead code, so keeping it in the compile scope is what preserves the type safety. xrpl@5.0.0 requires node >=20.19.0; this project runs Node 22. The lock diff is purely additive (xrpl's own subtree) — no existing package was upgraded, so the 14 known audit findings are untouched and stay out of scope here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The old test read src/chain/sol/handler.ts as a string and asserted that 13 exact source lines appeared in it. handler.ts has since moved 'from' to publicKeyToBytes() and the numeric fields to normalizeEventNumberHex(), so every one of those assertions was stale and the test failed on main. Rather than refresh the string literals — which would only buy time until the next refactor — the test now drives SolEventHandler.crossOut / crossIn and asserts the mos row that actually gets persisted: base58 vs raw-bytes shape for user/from, even-length unprefixed hex for chain ids and amounts, the '00' defaults when optional CrossIn fields are absent, the RefundEvent flag, the unsupported-bridgeMint alarm path, and the bridge api query. It survives a rename and it fails when the mapping is wrong, which the text version could not distinguish. Stubs replace the module exports (insertMos / requestBridgeData / alarm), the same technique mysql_duplicate_test.js already uses, so no network or database is touched. No business code was changed — the assertions were brought up to the source, not the reverse. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
test/ held 7 standalone Node assert scripts with no way to run them as a set:
package.json had no test script, and most of them require('../app/...') so they
silently fail unless the tree is built first.
scripts/run-tests.sh builds, then runs each script as its own process, prints
PASS/FAIL per file plus a total, and exits non-zero if any failed — so it can
gate CI. Output of passing tests is swallowed and only failures are echoed,
because these scripts are very chatty on stdout.
No test framework: the scripts are top-level asserts, not node:test cases, so
'exit 0 means pass' is the whole contract and jest/mocha/vitest would each
require rewriting all 7. SKIP_BUILD=1 reuses an existing app/ build.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
WORK-20 assumed src/chain/xrp/xrp.ts was live code worth keeping in the type-check scope, so 2caeef9 declared xrpl to make the tree compile. The repo owner has since confirmed the file is not wanted: it was unfinished local scratch work (no caller anywhere in src/, no xrp branch in chain.ts) that the runtime happened to capture in the baseline commit. Deleting it removes the TS2307 at its source, so the xrpl dependency is no longer needed either. package-lock.json is restored byte-for-byte to main's version, which keeps the npm audit surface exactly as it was. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Owner
Author
|
历史里带了 XRP 钱包 seed,改用干净分支重开:#2(内容完全相同)。本分支即将删除。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修掉 WORK-20 里的三个仓库自身阻塞点:
typecheck/build现在能干净退出,npm test一次跑完 7 个测试。分支基于
c482cb1 chore(agent): baseline — uncommitted work from the local directory——那是 Multica runtime 把本地工作目录里尚未提交的改动固化成的一个提交,不是我写的,内容是src/chain/sol/sync.ts、src/utils/time.ts、test/sol_sync_retry_test.js、以及新增的src/chain/xrp/xrp.ts。合并前请先确认
c482cb1里前三个文件的改动是否本来就要进 main;xrp.ts已按仓库 owner 的裁决在86daf54里删除(见下)。由此还得出一个和 issue 描述不同的事实:
xrp.ts在origin/main上根本不存在。我在临时 worktree 里验证过origin/main的tsc --noEmit退出码是 0——构建阻塞完全来自这份本地未提交的 WIP,不是 main 上的存量问题。问题 2、3 则是 main 上真实存在的(main 上那个过期测试同样失败,也同样没有 test 脚本)。建议用 squash 合并:
xrp.ts里带着一个硬编码的 XRP 钱包 seed,虽然文件已删,但仍留在本分支的历史提交c482cb1里。squash 只把最终 diff 落到 main,能避免把它带进主干历史。1. 删掉
xrp.ts与xrpl依赖(2caeef9→86daf54)src/chain/xrp/xrp.ts:1导入xrpl,但package.json从未声明它,tsc报 TS2307,typecheck/build恒为 exit 2(noEmitOnError=false,所以产物照出,但退出码不能当门禁)。一开始按 issue 的默认做法在
2caeef9里把xrpl加进了dependencies。仓库 owner 随后确认该文件不需要,所以86daf54把它连同依赖一起删掉了:src/chain/xrp/xrp.ts(全仓库没有任何模块引用它,chain.ts里也没有 xrp 分支,删除不影响任何运行路径)dependencies移除xrplpackage-lock.json逐字节还原成 main 的版本净效果:本 PR 相对 main 完全不碰
package-lock.json,npm audit的 14 个漏洞面原样不动;TS2307 从根上消失,不需要靠加依赖或改 tsconfig 来绕。2. 过期测试改成行为断言(
f4dd61c)test/sol_handler_saved_fields_test.js原本把handler.ts当纯文本读进来,断言 13 行源码原文出现过。handler.ts重构后from走publicKeyToBytes()、数值字段走normalizeEventNumberHex(),那 13 条断言全部过期(issue 只点了from一条,实际不止)。没有去刷新字符串字面量——那只能撑到下一次重构。改成驱动
SolEventHandler.crossOut/crossIn,断言真正落库的那行 mos 记录,共 8 个用例:crossOut全字段:user的 base58 与from的 32 字节原文、链 id / 金额的偶数长度无前缀 hex、tokenAmount/amountOut取自source_amount、bridgeAmount仍是十进制串、sourceAmount字段不得回归,外加 Log 信封(EventId 98 / Topic)和 bridge api 的请求参数(checksum 后的 EVM 地址、按 decimals 还原的金额、affiliate)to_token全零时回落到配置的 native 地址bridgeMint:只报警、不落库crossIn全字段 / 可选字段缺失时的"00"默认值与toToken回落到 bridge mintRefundEvent打isrefund没有改任何业务代码,是把断言对齐到源码,不是反过来。
用的 stub 手法和
mysql_duplicate_test.js已有的一致——替换模块导出(insertMos/requestBridgeData/alarm),不碰网络和数据库。做过变异验证:把编译产物里的
data.set("from", publicKeyToBytes(...))改回normalizeEventValue(...),新测试失败(actual: 'mosv35...'vsexpected: [Array]),改回来又通过——它确实能抓住原测试想守的那个回归,而原来的文本断言分辨不了。3. 加
npm test入口(5b9dbfd)新增
scripts/run-tests.sh+"test": "bash scripts/run-tests.sh"。先 build(多数测试require("../app/...")),再逐个子进程跑,打印每个文件的 PASS/FAIL 加总计,有失败就退出非零,可以直接当 CI 门禁。通过的测试输出被吞掉、只回显失败的(这些脚本 stdout 很吵)。SKIP_BUILD=1可复用已有app/。按 issue 的约束没有引入任何测试框架,也没有改用
node --test——这 7 个脚本是顶层 assert 风格而非node:test用例,换框架等于全部重写。失败路径也验证过:临时塞一个必失败的测试,runner 报
FAIL+7 passed, 1 failed, 8 total,退出码 1。验收结果
四条全绿,真实命令输出贴在 issue 评论里。
npm run typechecknpm run buildapp/17 个 js 对应src/17 个 tsnpm testgit status.multica/、.agent_context/、.claude/、CLAUDE.md),非本次改动影响面
package.json只多一行testscript,package-lock.json零改动)。src/chain/xrp/xrp.ts:src/内无人引用,chain.ts无 xrp 分支,运行路径不受影响。test/sol_handler_saved_fields_test.js从「读源码文本」变成「跑真实 handler」,会 stub 模块导出;同一进程内跑完会还原。src/业务代码、CI / 发布配置均未改动。未做(在 issue 划定的边界内)
npm audit的 14 个漏洞升级。package.json里那个eslintscript 依旧是空指望)。config.json和两个*.local。