test(#60): 共享 test-factory(sqlite 真迁移替身)替换 core-api/module-sdk/hello 全部假 D1 - #62
Merged
Conversation
审核 T1:core-api 四套假 D1 无 schema 概念,SQL 子串匹配命中即回手造行, 放过 #56 幻影列类错误。新建 test-factory 用 Node 内置 node:sqlite(零新依赖) 加载 migrations/core/*.sql 真建表,D1 适配器对齐真 D1 形状 (all() 回 results 数组、run() 回 meta.changes/last_row_id、datetime 文本语义、 first() 无行 null、行对象普通原型)。 registry.test.ts 首先换真库并立守护范式: - 种子用户/模块走真 SQL,断言直查真表 - 守护:module_registry 行结构 == 建表列(幻影列/漏列即红) - 守护:真 schema 约束(users UNIQUE(issuer,sub)、manifest_json NOT NULL) Ref #60 Signed-off-by: HandyWote <huangyinghui01@corp.netease.com>
- setup.test:删可记账内存 stub,激活链路走真 instance_config/setup_tokens/ users/audit_log;断言 used_at 为 SQLite datetime 文本(非 ISO) - token.test:删 makeDb 子串匹配 stub;门禁查真 module_registry; 修审核 G1『已停用模块在启停后可再取』——改为同一真库 enabled 0→1 翻转 - auth-routes.test:no-op CORE_DB 换真库,callback JIT 建档真 INSERT users 表, 同 issuer+sub 二次 callback 断言复用同一行(UNIQUE 真生效) - 每处补『查询列↔建表列』守护用例(错位即红,已实证注入幻影列必失败) Ref #60 Signed-off-by: HandyWote <huangyinghui01@corp.netease.com>
审核 T8:storage.test 的 MemoryStatement 恒用 params[0] 当 moduleId 过滤, SDK SQL 漏 WHERE module_id = ? 时假替身仍替被测代码『背锅』过滤 → 测试绿、 真机跨模块数据泄漏。改为真 SQLite 加载 modules 统一迁移 modules/hello/migrations/hello/0001_module_kv.sql 真建表。 - packages/module-sdk/test/test-factory.ts:独立小工厂(与 core-api 版互不 import) - storage.test:删 MemoryStatement/MemoryDatabase/likeToSource,LIKE/ESCAPE 由 真 SQLite 裁决;新增 T8 守护(同 key 两模块直插后 list/get 只回本模块, 漏 WHERE 即红——已实证注入必失败)+ PK 真约束 + 列结构守护 - hello.test:假 D1 换真 module_kv,计数落库断言直查真表 Ref #60 Signed-off-by: HandyWote <huangyinghui01@corp.netease.com>
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.
背景
issue #60 P1 主体:把「假 D1 无 schema 概念」这一测试两张皮(审核报告 §2.1 T1/T8)一次性消灭。
手搓假 D1 用
sql.includes('FROM module_registry')命中即返回手造行、run()对未识别 SQL 一律{success:true}、从不加载真实 migrations——所以 #56 的幻影列registered_at能在「单测全绿」下把线上打到 500;storage.test的MemoryStatement恒用params[0]当 moduleId 过滤,SDK SQL 漏WHERE module_id = ?时替身替被测代码「背锅」过滤,测试绿而真机跨模块数据泄漏。本 PR 用 Node 内置
node:sqlite(Node≥22,零新依赖)加载真实 migrations 真建表 + 最小 D1 适配器替换全部假 D1,测试改走app.request路由级集成。改动
services/core-api/test/test-factory.ts(新)createCoreDb():node:sqlite内存库 + 顺序执行migrations/core/*.sql(0001/0002/0003)真建表;~90 行 D1 适配器对齐真 D1(all()回{results,success,meta}、run()回meta.changes/last_row_id、first()无行 null 且支持first('col')、行转普通对象、datetime('now')文本语义)services/core-api/test/node-builtins.d.ts(新)node:sqlite/node:fs/node:url最小类型声明(core-api 是 Workers 目标,不引@types/node,避免污染全局类型)services/core-api/test/registry.test.tsmakeDb;种子/断言走真 SQL;补 2 条守护用例services/core-api/test/setup.test.tsinstance_config/setup_tokens/users/audit_log;补 3 条守护用例services/core-api/test/token.test.tsmakeDb;门禁查真module_registry;修 G1「已停用模块启停后可再取」为同一真库 0→1 翻转;补守护用例services/core-api/test/auth-routes.test.tsCORE_DB换真库;callback JIT 建档真INSERT users,同issuer+sub二次 callback 断言复用同一行(UNIQUE 真生效);补守护用例packages/module-sdk/test/test-factory.ts(新)modules/hello/migrations/hello/0001_module_kv.sql真建module_kvpackages/module-sdk/test/storage.test.tsMemoryStatement/MemoryDatabase/likeToSource(-193 行);LIKE/ESCAPE 由真 SQLite 裁决;补 T8 守护用例modules/hello/test/hello.test.tsmodule_kv(复用 module-sdk 工厂,hello 本就依赖该包)零新增运行时依赖;未改任何
src/**(真库未暴露源码 SQL/schema 冲突);未碰deploy/**、docs/**。守护用例(「查询列↔建表列」错位即红,已实证)
columns(table)与迁移建表列逐一相等 +SELECT *行键集 ==columns()+ 真约束守护(users UNIQUE(issuer,sub)、manifest_json NOT NULL、setup_tokensPK)。('mod-a','k','a'),('mod-b','k','b')后moduleId='mod-a'的list()必须只回['k']、get('k')必须为'a'——SQL 漏WHERE module_id即红。listModulesSELECT 注入幻影列registered_at→registry.test3 用例红(no such column: registered_at);storage.ts去掉listSql的WHERE module_id = ?→storage.test2 用例红(含 T8 守护用例)。验收对照(issue #60)
createCoreDb();module-sdk/hello 各自独立小工厂;全部加载真迁移app.fetch路由级)app.request走 Hono 路由 + 真实 SQLaudit_log)、一次性 token 消费/重放、JIT 建档复用、启停同库翻转、LIKE/ESCAPE 字面化、UNIQUE/PK/NOT NULL 失败态pnpm -r typecheck && pnpm -r test && pnpm -r build全绿验证(rebase 到
origin/m0/dev后重跑)真实发现(不修,留档)
setup_tokens.token缺NOT NULL(migrations/core/0002_setup_oauth.sql):token TEXT PRIMARY KEY未声明 NOT NULL,SQLite 历史行为允许 TEXT 主键存 NULL。当前源码不会写 NULL,故非现网故障;但真 schema 约束弱于意图,建议后续迁移补NOT NULL(改既有迁移有风险,未在本 PR 动)。setup_tokens.used_by列存在但consumeSetupToken从不写入——死列(非冲突)。Ref #60