Skip to content

Conversation

@cnlangzi
Copy link
Owner

@cnlangzi cnlangzi commented Jan 10, 2026

Summary by Sourcery

Add bot kind information to validation results and propagate it through bot IP verification and unknown classification paths.

New Features:

  • Extend Result struct with a BotKind field to expose the kind of bot in validation responses.

Enhancements:

  • Populate the new BotKind field across all validation result paths, including verified, failed, and unknown outcomes.

- 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
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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 field

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Extend Result with a BotKind field and update all Result constructors to set it consistently.
  • Add Kind BotKind field to the Result struct alongside existing metadata.
  • Initialize Kind to KindUnknown in all StatusUnknown result paths within Validate, including browser, suspicious, and default unknown UA cases.
  • Propagate bot.Kind into Result in verifyIP for successful IP matches, successful RDNS verification, and failed verification results so the bot type is always carried in the result.
validator.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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, 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link

github-actions bot commented Jan 10, 2026

Benchmark Results

BenchmarkFindBotByUA_Hit_First             	  950623	      1098 ns/op	       7 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_First-4           	 4127269	       496.4 ns/op	       5 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_First-8           	 3905007	       516.4 ns/op	       3 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_Middle            	 1357848	      1135 ns/op	       9 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_Middle-4          	--- FAIL: BenchmarkFindBotByUA_Hit_Middle-4
BenchmarkFindBotByUA_Hit_Middle-8          	 2318547	       516.2 ns/op	       7 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_Last              	 1368595	       943.2 ns/op	       7 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_Last-4            	 3526147	       399.5 ns/op	       3 B/op	       0 allocs/op
BenchmarkFindBotByUA_Hit_Last-8            	 2445685	       532.5 ns/op	       5 B/op	       0 allocs/op
BenchmarkFindBotByUA_Miss                  	  521001	      2374 ns/op	      21 B/op	       0 allocs/op
BenchmarkFindBotByUA_Miss-4                	 1403199	       850.8 ns/op	       9 B/op	       0 allocs/op
BenchmarkFindBotByUA_Miss-8                	 1389402	       882.0 ns/op	       8 B/op	       0 allocs/op
BenchmarkFindBotByUA_CaseSensitive         	 1511844	       681.9 ns/op	       3 B/op	       0 allocs/op
BenchmarkFindBotByUA_CaseSensitive-4       	 2922649	       399.3 ns/op	       4 B/op	       0 allocs/op
BenchmarkFindBotByUA_CaseSensitive-8       	 4573208	       504.0 ns/op	       4 B/op	       0 allocs/op
BenchmarkValidate_KnownBot_IPHit           	 1000000	      1048 ns/op	       5 B/op	       0 allocs/op
BenchmarkValidate_KnownBot_IPHit-4         	 2495899	       504.0 ns/op	       5 B/op	       0 allocs/op
BenchmarkValidate_KnownBot_IPHit-8         	 4259494	       255.6 ns/op	       2 B/op	       0 allocs/op
BenchmarkValidate_Browser                  	  228160	      5358 ns/op	      38 B/op	       0 allocs/op
BenchmarkValidate_Browser-4                	  587696	      1966 ns/op	      20 B/op	       0 allocs/op
BenchmarkValidate_Browser-8                	  610316	      2019 ns/op	      23 B/op	       0 allocs/op
BenchmarkContainsWord                      	73940614	        16.49 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsWord-4                    	74044465	        16.22 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsWord-8                    	74134474	        16.21 ns/op	       0 B/op	       0 allocs/op
BenchmarkValidate_WithBotUA                	 1000000	      1156 ns/op	       3 B/op	       0 allocs/op
BenchmarkValidate_WithBotUA-4              	--- FAIL: BenchmarkValidate_WithBotUA-4
BenchmarkValidate_WithBotUA-8              	 2758392	       455.8 ns/op	       6 B/op	       0 allocs/op
BenchmarkValidate_WithBotUA_IPMismatch     	  808068	      1509 ns/op	      14 B/op	       0 allocs/op
BenchmarkValidate_WithBotUA_IPMismatch-4   	 2139152	       536.0 ns/op	       6 B/op	       0 allocs/op
BenchmarkValidate_WithBotUA_IPMismatch-8   	 2225612	       548.6 ns/op	       4 B/op	       0 allocs/op
BenchmarkValidate_BrowserUA                	  267963	      4160 ns/op	      33 B/op	       0 allocs/op
BenchmarkValidate_BrowserUA-4              	  853142	      1461 ns/op	      18 B/op	       0 allocs/op
BenchmarkValidate_BrowserUA-8              	  807524	      1477 ns/op	      15 B/op	       0 allocs/op
BenchmarkValidate_UnknownBotUA             	 7911297	       148.5 ns/op	       1 B/op	       0 allocs/op
BenchmarkValidate_UnknownBotUA-4           	22789129	        53.68 ns/op	       0 B/op	       0 allocs/op
BenchmarkValidate_UnknownBotUA-8           	20824597	        60.99 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsIP                        	55954902	      1122 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsIP-4                      	--- FAIL: BenchmarkContainsIP-4
BenchmarkContainsIP-8                      	100000000	        11.61 ns/op	       0 B/op	       0 allocs/op
BenchmarkFindBotByUA                       	  815152	      1552 ns/op	      22 B/op	       0 allocs/op
BenchmarkFindBotByUA-4                     	 2105128	       565.9 ns/op	       4 B/op	       0 allocs/op
BenchmarkFindBotByUA-8                     	 2057026	       583.3 ns/op	       5 B/op	       0 allocs/op
BenchmarkClassifyUA                        	 2258346	       522.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkClassifyUA-4                      	 5055380	       238.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkClassifyUA-8                      	 5059609	       238.5 ns/op	       0 B/op	       0 allocs/op
Benchmark_MixedTraffic                     	  474187	      2551 ns/op	      10 B/op	       0 allocs/op
Benchmark_MixedTraffic-4                   	 1328059	       910.8 ns/op	       8 B/op	       0 allocs/op
Benchmark_MixedTraffic-8                   	 1289991	       909.8 ns/op	       8 B/op	       0 allocs/op
BenchmarkReload                            	     832	   1376140 ns/op	  662328 B/op	    6435 allocs/op
BenchmarkReload-4                          	     960	   1265211 ns/op	  670244 B/op	    6469 allocs/op
BenchmarkReload-8                          	     956	   1253478 ns/op	  666042 B/op	    6440 allocs/op
PASS
ok  	github.com/cnlangzi/knownbots	141.106s

- 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
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

❌ Patch coverage is 62.68657% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.03%. Comparing base (f2b10fc) to head (1d89687).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
bot.go 52.17% 11 Missing ⚠️
validator.go 40.00% 8 Missing and 1 partial ⚠️
embed.go 83.33% 0 Missing and 2 partials ⚠️
parser/parser_github.go 80.00% 0 Missing and 1 partial ⚠️
parser/parser_google.go 66.66% 0 Missing and 1 partial ⚠️
parser/parser_openai.go 83.33% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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
@cnlangzi cnlangzi merged commit 7760bfb into main Jan 10, 2026
3 checks passed
@cnlangzi cnlangzi deleted the fix/botkind branch January 10, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants