Repository navigation
test(approval): 补齐有界授权作用域匹配与消费核验的单元测试 - #521
Merged
Qiyuanqiii merged 3 commits intoOct 30, 2026
Merged
Qiyuanqiii merged 3 commits into
Qiyuanqiii merged 3 commits into
Conversation
internal/approval 是审批账本的核心安全原语,但 bounded_grant.go 与 SessionGrant/CreateGrantRequest/RevokeGrantRequest 的校验矩阵此前没有 单元测试(包覆盖率 24.9%)。本 PR 仅新增测试,无生产代码改动: - boundedGrantPermission 权限白名单(command_runtime/command_process × ask/auto/full,及 workspace_access 历史路径) - MatchesBoundedGrantScope 全字段绑定校验(逐字段漂移拒绝) - CheckBoundedConsumption 消费核验:作用域漂移、显式撤销否决、过期、 ordinal 超用、以及"额度耗尽型撤销"的合法终局用例 - SessionGrant.Validate 有界/遗留(legacy)一致性、TTL≤15min、 MaxUses≤8、撤销元数据一致性等边界 - GrantConsumption/Record/DecisionRequest 校验与指纹辅助函数绑定 包覆盖率 24.9% → 87.6%。与 CWNU-Open-Source-Community#517(privatefile/workspaceidentity)互补, 不触碰其文件。
Member
Author
OpenCodeReview delegate 模式评审报告
结论:APPROVE(1 处文档准确性问题已当场修正)核查记录(非局部论断均已建立调用点证据)
未覆盖说明
|
独立评审(与 internal/store 调用方逐行核对)提出的三项加固: - GrantConsumptionFingerprint 逐字段绑定差分测试,消除 fixture 与 期望同源导致的永真盲区(该指纹守护持久化消费行的防篡改绑定) - SessionGrant.Validate 接受侧上边界:MaxUses=8、ExpiresAt 恰为 +15min(防 > → >= 型 off-by-one 回归) - CheckBoundedConsumption 增加 now 越过 ExpiresAt 的拒绝路径; ComputerUseAppScope 增加 4 个字段的漂移差分
Member
Author
评审后续:独立评审通过 + 三项加固(b983db5)在 OpenCodeReview delegate 模式评审(见上条评论)之外,又完成了一轮独立评审:以
更正:此前评论中"12 个测试函数、约 70 个子用例"计数有误(少报)。实测:新增文件 14 个测试函数;全包 144 个用例(18 顶层 + 126 子用例),覆盖率 24.9% → 87.6%(基线在 merge_base 已知未覆盖(留作后续): |
The pending rejection cases started from an approved record, so each kept another invalid field and could pass after a guard was removed. Build a valid pending record first, then mutate one decision field at a time. Add the equality boundaries for both expiry comparisons, since the implementation uses strict Before checks. Split record fingerprint drift per decision field, and cover all fourteen ComputerUseAppScope bindings.
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.
Summary
internal/approval补齐审批账本核心安全原语的单元测试。仅新增internal/approval/bounded_grant_test.go,无任何生产代码改动。boundedGrantPermission权限白名单(command_runtime/command_process×ask/auto/full,以及workspace_access历史路径);MatchesBoundedGrantScope全字段绑定校验(17 个绑定字段逐一漂移拒绝);CheckBoundedConsumption消费核验:作用域漂移、消费绑定篡改、显式撤销否决、now越过过期时间、use ordinal 超限,以及"额度耗尽型撤销"(approval_store)的合法终局用例;SessionGrant.Validate有界/遗留(legacy)一致性、TTL ≤ 15 分钟、MaxUses ≤ 8 的双侧边界(含MaxUses=8与ExpiresAt恰为 +15min 的接受侧)、撤销元数据一致性等路径;CreateGrantRequest.Normalize/RevokeGrantRequest.Normalize规范化与边界;GrantConsumption.Validate与GrantConsumptionFingerprint逐字段绑定差分、Record.Validate决策状态、DecisionRequest.Normalizedeny 路径,以及RecordFingerprint、ComputerUseAppScope.Fingerprint等指纹辅助函数的参数绑定。b58f898实测)。新增文件含 14 个测试函数;internal/approval全包共 144 个用例(18 个顶层 + 126 个表驱动子用例)。test(privatefile, workspaceidentity))互补,不触碰其文件。Validation
go test -count=1 ./internal/approval/→ok cyberagent-workbench/internal/approval(Go 1.26.10,与 go.mod 一致)go vet ./internal/approval/...gofmt全包干净go test -count=1 ./...(全仓回归:本 PR 仅新增一个测试文件,只影响internal/approval包编译;全量回归交由 CI 执行。本地 Windows 无 cgo,-race亦由 CI Linux 侧覆盖)Surface governance
N/A — no Surface change(纯测试新增)。
Audit