forked from trpc-group/trpc-agent-go
-
Notifications
You must be signed in to change notification settings - Fork 0
test(toolpolicy): cover deny audit records #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XnLemon
wants to merge
1
commit into
main
Choose a base branch
from
codex/phase2-tool-deny-audit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assertions don't verify
UserIDHash, despite it being set in the test'sAuditContext.The test populates
UserIDHashviaplatform.UserIDHash(...)(Line 85), andapplyAuditContextis known to copy it onto the audit record, but the validation block (Lines 103-114) never checksrecord.UserIDHash. This leaves a real regression path (e.g. hash function change, empty-string leak, or accidental exposure of the raw external user ID) uncaught. The PR objective explicitly calls out "user" as part of the expected audit context.As per path instructions, "Whether assertions are strong enough to ensure the intended behavior is actually verified" should be checked for
**/*_test.gofiles.🐛 Proposed fix
if record.TenantID != "tenant" || record.AppID != "app" || record.Channel != "wecom" || record.BindingID != "binding" || record.SessionID != "session" || record.InternalUserID != "internal-user" || + record.UserIDHash != platform.UserIDHash("tenant", "wecom", "external-user") || record.RequestID != "request-1" || record.AgentName != "agent" || record.ToolName != "shell" || record.Decision != string(tool.PermissionActionDeny) { t.Fatalf("unexpected audit record: %+v", record) }中文
断言未验证
UserIDHash,尽管测试的AuditContext中已设置该值。测试在第 85 行通过
platform.UserIDHash(...)设置了UserIDHash,且已知applyAuditContext会将其复制到审计记录,但第 103-114 行的校验块从未检查record.UserIDHash。这会导致真实的回归路径(例如哈希函数变更、空字符串泄漏,或意外暴露原始外部用户 ID)无法被捕获。PR 目标中明确提到"user"是预期审计上下文的一部分。根据路径指令,
**/*_test.go文件应检查"断言是否足够严格以确保预期行为得到实际验证"。📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions