Skip to content

fix: P1 evaluator gating bug, DRY refactors, engine unit tests#9

Merged
Crank-Git merged 1 commit into
mainfrom
fix/eng-review-p1-dry-tests
Apr 11, 2026
Merged

fix: P1 evaluator gating bug, DRY refactors, engine unit tests#9
Crank-Git merged 1 commit into
mainfrom
fix/eng-review-p1-dry-tests

Conversation

@Crank-Git
Copy link
Copy Markdown
Owner

Summary

  • P1 bug fix: evaluator.Evaluate(conn) was gated behind len(results) > 0 in runJSON, causing threshold rules to undercount packets in JSON/SIEM mode. Removed the guard so all packets are evaluated (matches TUI/shard path behavior).
  • DRY refactors: Exported engine.PacketInfo()/PacketTimestamp(), extracted replayThrottler type and wireAlertSinks() helper — eliminates 3 instances of duplicated code across run functions.
  • 11 new engine unit tests: Covers sharding, dirty flush, eviction, ConnChan backpressure, and pcap mode. Engine package coverage up from ~34%.
  • Outside voice fixes: tracker.MakeKey() in tests, redundant PacketTimestamp call eliminated, encMu comment added.

Test plan

  • go build ./... — compiles clean
  • go test ./internal/engine/ — 22 tests pass
  • go test ./cmd/ja4monitor/ — 10 tests pass
  • ja4monitor analyze --json <pcap> with custom threshold rules — verify alerts fire on non-fingerprint packets
  • ja4monitor live <iface> — verify TUI still works after DRY refactors

🤖 Generated with Claude Code

- Fix P1 bug: evaluator.Evaluate(conn) now called unconditionally in
  runJSON so threshold rules count all packets, not just fingerprint-
  producing ones (was already fixed in TUI/shard path, missed here)
- Export PacketInfo/PacketTimestamp from engine package, remove duplicate
  implementations from main.go
- Extract replayThrottler type shared by runJSON and runTUI
- Extract wireAlertSinks helper (was duplicated across 3 run functions)
- Add 11 unit tests for engine core: sharding, dirty flush, eviction,
  ConnChan backpressure, pcap mode
- Fix redundant PacketTimestamp call in replayThrottler
- Use tracker.MakeKey() in tests instead of hardcoded ID strings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Crank-Git Crank-Git merged commit e0dc4aa into main Apr 11, 2026
2 checks passed
Crank-Git added a commit that referenced this pull request May 9, 2026
fix: P1 evaluator gating bug, DRY refactors, engine unit tests
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.

1 participant