-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add BotKind field to Result struct #7
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
Conversation
- Add Kind BotKind field to Result struct for bot classification - Update verifyIP method to include Kind in Result - Update Validate method to return Kind for all code paths PiperOrigin-RevId: 444be48 Change-Id: I444be4899d4df73b26c4dec1a6b66413fa9bb9fb
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a new BotKind field to the Result struct and ensures all Result construction sites populate it appropriately, defaulting to KindUnknown for non-bot or unclassified cases and propagating bot.Kind for IP-verified results. Class diagram for updated Result struct with BotKind fieldclassDiagram
class Result {
+string Name
+BotKind Kind
+ResultStatus Status
+bool IsBot
+bool IsVerified
+ValidatorError Error
}
class Bot {
+string Name
+BotKind Kind
+bool RDNS
+bool ContainsIP(ipStr string) bool
+bool VerifyRDNS(ipStr string) bool
}
class BotKind {
<<enumeration>>
KindUnknown
KindSearchEngine
KindMonitoring
KindSocialMedia
KindOther
}
class ResultStatus {
<<enumeration>>
StatusUnknown
StatusVerified
StatusFailed
}
class Validator {
+Result Validate(ua string, ip string)
+Result verifyIP(bot Bot, ipStr string)
}
Result --> BotKind : uses
Bot --> BotKind : uses
Result --> ResultStatus : uses
Validator --> Result : creates
Validator --> Bot : verifies via
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - I've left some high level feedback:
- For the non-bot / browser flows in
Validate,Kindis always set toKindUnknown; ifBotKindis meant to describe only bots, consider using a distinct "none" or zero value for non-bot results to distinguish "unknown bot kind" from "not a bot". - In
verifyIP, theResultliterals for the two verified branches are now identical except for theStatusfield; consider factoring a small helper or common constructor to avoid repeating{Name: bot.Name, Kind: bot.Kind, ...}and keep future additions toResultcentralized.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- For the non-bot / browser flows in `Validate`, `Kind` is always set to `KindUnknown`; if `BotKind` is meant to describe only bots, consider using a distinct "none" or zero value for non-bot results to distinguish "unknown bot kind" from "not a bot".
- In `verifyIP`, the `Result` literals for the two verified branches are now identical except for the `Status` field; consider factoring a small helper or common constructor to avoid repeating `{Name: bot.Name, Kind: bot.Kind, ...}` and keep future additions to `Result` centralized.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Benchmark Results |
- Rename Result.Name to BotName for clarity - Rename Result.Kind to BotKind for clarity - Avoid naming conflicts in broader contexts like HTTP middleware PiperOrigin-RevId: 487826b Change-Id: I487826bfb1304bcf1ed9fb19b1742d7db7aeee21
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7 +/- ##
==========================================
- Coverage 77.25% 75.03% -2.23%
==========================================
Files 14 14
Lines 664 645 -19
==========================================
- Hits 513 484 -29
- Misses 107 117 +10
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Change ResultStatus from string to int (1=verified, 2=pending, 3=failed, 0=unknown) - Remove IsVerified field from Result (use Status==StatusVerified instead) - Add VerifyStatus to Bot for RDNS verification result differentiation - Update verifyIP to return StatusPending for network errors - Rename Result.Name/Kind to BotName/BotKind for clarity PiperOrigin-RevId: 1082df5 Change-Id: I1082df5315b073451f55a0903ba512c2104971a5
- Remove VerifyStatus type, use ResultStatus instead - VerifyRDNS returns StatusVerified/StatusPending/StatusFailed directly - Simplifies type system PiperOrigin-RevId: 4394bc2 Change-Id: I4394bc220b766bf06fae9cf60326896631159cfb
- Remove Bot.SetCustom method, use bot.custom.Store directly - Do not add to fail cache on network error (allow retry) - Remove TestBotSetCustom test (covered by direct usage) PiperOrigin-RevId: 6ba03ac Change-Id: I6ba03ac36242ceda990c091c093314b6d255eba2
- No PTR records = StatusFailed (deterministic failure) - Network error = StatusPending (may retry) PiperOrigin-RevId: 4d72a09 Change-Id: I4d72a09530f62e8d026d2ba6b7653f1bbbf69198
The UA matching is case-sensitive by design. This benchmark now tests the correct behavior with proper casing. PiperOrigin-RevId: a851b70 Change-Id: Ia851b70ec962e60e8ee8568d10cbbac6403e5fa1
- Rename benchmark bots to TestBot1-40 to avoid conflicts with built-in bot configurations - Add defer v.Close() to all benchmarks - Rename CaseInsensitive benchmark to CaseSensitive - Update test assertions to use correct Status values PiperOrigin-RevId: 48a5ee6 Change-Id: I48a5ee613c3837c189cb09762e1e1735abb6966e
- Add botConfig struct in bot.go for YAML parsing - Add googleIPResponse, openaiIPResponse, githubIPResponse, stripeIPResponse - Improves code consistency and maintainability PiperOrigin-RevId: 71d2d61 Change-Id: I71d2d61c1ca605fd158cd4427d6d87fd537fd1a1
- Rename OpenAIStyleParser to OpenAIParser - Rename *IPResponse to *Response (IP is redundant in parser package) - Update test function names accordingly PiperOrigin-RevId: 0679ce2 Change-Id: I0679ce29b0c2c51d2136520812c28ab29aa9b46d
Summary by Sourcery
Add bot kind information to validation results and propagate it through bot IP verification and unknown classification paths.
New Features:
Enhancements: