refactor(db): 收窄连接管理器 interface,开出驱动 seam - #15
Merged
Conversation
候选 6:DatabaseConnectionManager 是全仓库最深的编排(连接池生命周期、 USE 与查询同连接检出、LIMIT 策略解析),此前零测试覆盖——构造函数 硬编码 mysql.createPool,没有 seam 可换;公共面还挂着零调用方的成员 和不可达选项。 - 新增窄接口 PoolLike/ConnectionLike(mysql2 Pool 结构兼容), 构造函数接受可选 pool factory——第二个 adapter(fake pool)证明 seam 为真,与既有 stub QueryFn 先例同构 - 收窄公共面:getPool/getConnectionIds 私有化、getConfig 删除、 QueryOptions 删不可达的 limit/timeout(limit 用 cfg.queryLimit、 timeout 固定 30000)、QueryOutput.rows 边界收窄为 SqlRow - workspace 构造函数接受可选 manager——补 executeMutationWithApproval 的 executed 分支测试(此前只能测 validate/rejected) - 新增 db-manager.test.ts:fake pool 覆盖 USE→query 检出编排、LIMIT 注入、错误路径与全部元数据查询
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.
候选 6:DatabaseConnectionManager 收窄 interface,开出驱动 seam
变更内容
PoolLike/ConnectionLike(mysql2 Pool 结构兼容,测试 fake 只实现 4 个方法);构造函数接受可选pool factory(默认 mysql2)——驱动 seam 开出getPool/getConnectionIds私有化、getConfig删除(零调用)、QueryOptions删不可达的limit/timeout(limit 走cfg.queryLimit、timeout 固定 30000)、QueryOutput.rows边界收窄为SqlRowworkspace构造函数接受可选 manager 注入db-manager.test.ts(11 例):fake pool 覆盖 USE→query 同连接检出编排、无界 SELECT 的 LIMIT 注入、尾部 LIMIT 不重复、params 透传、未知连接错误、元数据查询、池懒创建复用、destroyworkspace-target.test.ts补executeMutationWithApproval的 executed 分支(此前只能测 validate/rejected)为什么
全仓库最深的编排(连接池生命周期、USE 与查询同连接、LIMIT 解析)此前零覆盖——构造函数硬编码 mysql.createPool,无 seam 可换。两个 adapter(mysql2 pool / fake pool)证明 seam 为真,与既有 stub QueryFn 先例同构,不违背"真实替身"纪律。
验证
npm run check(tsc)通过npm test241 通过(净增 12)npm run lint0 errors(12 warnings 存量)npm run fmt+fmt:check通过