Fix the LLM based interactions on issues and alerts and slack conversations as well bot integration tests and refactor for code conciseness#307
Conversation
- Add integration test suites for Discord, Slack, WhatsApp bots - Add agentic chat and anomaly notification tests - Add golden test fixtures for bot responses - Refactor verifyDiscordSignature to use Either do-notation - Use lens-aeson for JSON access in parseReportStats - Replace case statements with Map.lookup in parseVisualizationType - Simplify timeParams using catMaybes pattern
Code Review - PR #307Overall AssessmentStrong PR that adds comprehensive test coverage for bot handlers and includes well-executed refactoring using idiomatic Haskell patterns. The code changes reduce line count by 51 lines while improving clarity. Good use of enabled GHC extensions and ecosystem packages. Code Quality & Best Practices✅ Excellent RefactoringDiscord.hs (lines 422-428): The Either do-notation refactoring is exemplary:
Utils.hs (lines 194):
AI.hs (lines 119-138): Map.lookup pattern is good for:
🔍 Potential Improvements1. Discord.hs - Error Information Loss The refactored -- Current (loses error info):
verifyDiscordSignature :: ByteString -> ByteString -> ByteString -> ByteString -> Bool
verifyDiscordSignature publicKey signatureHex timestamp rawBody = fromRight False $ do
s <- first show $ Base16.decode signatureHex
...
-- Alternative (preserves error for logging):
verifyDiscordSignature :: ByteString -> ByteString -> ByteString -> ByteString -> Either Text Bool
-- Then at call site, log the error before defaulting to FalseThis would aid debugging failed signature verifications in production. 2. Utils.hs - Lens-aeson Usage The -- Current:
parseReportStats json = (getTotal "events", getTotal "errors")
where
getTotal k = fromMaybe 0 $ json ^? key k . key "total" . _Number <&> round
-- More concise using bimap or Bifunctor:
parseReportStats json = bimap getTotal getTotal ("events", "errors")
where getTotal k = fromMaybe 0 $ json ^? key k . key "total" . _Number <&> roundOr even inline with 3. AI.hs - Static Map Construction The vizTypeMap :: Map Text Text
vizTypeMap = Map.fromList [...]
{-# NOINLINE vizTypeMap #-}
parseVisualizationType :: Text -> Maybe Text
parseVisualizationType t = Map.lookup t vizTypeMapOr use import Data.HashMap.Strict qualified as HM
vizTypeMap :: HM.HashMap Text Text
vizTypeMap = HM.fromList [...]
{-# NOINLINE vizTypeMap #-}Test Coverage✅ Strengths
🔍 Suggestions1. Test Helpers - Reduce Duplication
-- Instead of separate extract functions:
extractSlackBlocks :: AE.Value -> Maybe AE.Value
extractSlackBlocks val = val ^? key "blocks"
extractDiscordComponents :: AE.Value -> Maybe AE.Value
extractDiscordComponents val = val ^? key "components"
-- Single parameterized function:
extractKey :: Text -> AE.Value -> Maybe AE.Value
extractKey k val = val ^? key kPerformance Considerations✅ Good Patterns
|
- Rename ChatLLMResponse to LLMResponse for clarity - Remove AIOutputType enum and fold functionality into LLMResponse - Standardize field names across bot integrations (explanation, widgets, timeRange) - Consolidate response parsing functions (parseLLMResponse, parseAgenticResponse) - Update all bot handlers (Slack, Discord, WhatsApp) to use unified types - Simplify anomaly investigation and log explorer AI interactions - Net reduction of 33 lines through better code reuse
PR #307 Code Review: Bot Integration Tests & RefactoringExecutive SummaryStrong PR adding comprehensive bot test coverage (+1735/-739 lines) with excellent idiomatic Haskell refactorings. Recommend merge after addressing 2 high-priority security items. ✅ Excellent Refactorings1. Discord.hs -
|
PR Review: Bot Integration Tests and Code RefactoringOverviewStrong PR with excellent test coverage and idiomatic Haskell refactoring. The use of Either monads, lens-aeson, and Map-based lookups significantly improves code quality. However, there are some critical issues to address. 🔴 Critical Issues1. Race Condition in Discord Thread Migration (
|
| Category | Critical | High | Medium |
|---|---|---|---|
| Bugs | 1 | 2 | 2 |
| Performance | 0 | 0 | 2 |
| Tests | 0 | 0 | 4 |
Recommendation: Fix the race condition and HTTP status issues before merging. The refactoring work is excellent and demonstrates strong understanding of idiomatic Haskell patterns. Test coverage is comprehensive for happy paths but needs error scenario coverage.
Overall: Approve with required changes ✅
Great work on code conciseness - the Either monads, lens-aeson, and Map lookups are exactly the right patterns to use!
|
Review posted - See full details below SummaryPR #307 adds comprehensive bot integration tests and refactors code for conciseness. APPROVE WITH CHANGES ⭐⭐⭐⭐☆ Test coverage improvements are excellent, refactoring demonstrates good use of packages. However, 4 critical issues in security-sensitive code must be addressed before merge. 🔴 CRITICAL - Must Fix Before Merge1. Discord Signature Verification (Security) - src/Pages/Bots/Discord.hs:429-435 2. LLM Cache Key Collision Risk - src/Data/Effectful/LLM.hs:174-180 3. Partial Functions - src/Data/Effectful/LLM.hs:136,204 4. Unsafe Vector Head - src/Pages/Bots/Whatsapp.hs:177-178
|
Code Review - PR #307: Bot Integration Tests & RefactoringSummaryThis PR successfully refactors code for improved conciseness and adds comprehensive test coverage for bot handlers. The refactoring leverages Haskell best practices (Either do-notation, lens-aeson, Map.lookup) effectively. However, there are opportunities for further improvement. ✅ Strengths1. Excellent Refactoring Patterns
2. Security Practices
3. Test Coverage
🔧 Issues & RecommendationsPriority 1: Test Coverage Gaps
Priority 2: Code Conciseness & Performance
Priority 3: Observability
📦 Package UsageGood use of existing packages:
No reimplementations detected - all refactors leverage existing packages appropriately. 🔒 Security Assessment
📊 Metrics
Code conciseness improvement: The refactoring reduces nesting and leverages GHC extensions well. Further gains possible with module-level constants and import cleanup. 🎯 Action Items Before MergeMust-have:
Nice-to-have:
✨ ConclusionRecommendation: Approve with minor changes The refactoring successfully achieves the stated goals and improves code quality. The use of lens-aeson, Either do-notation, and Map.lookup are excellent examples of idiomatic Haskell that reduces LOC while maintaining clarity. Address the test coverage gaps and minor import cleanup to align with the project's code conciseness priorities. Great work on the comprehensive test suite additions! 🚀 |
PR #307 Review: Bot Integration Tests & LLM RefactoringOverviewThis PR adds comprehensive test coverage for bot integrations and refactors code for conciseness. Overall structure is excellent, but several critical issues need attention before merge. 🔴 Critical Issues (Must Fix)1. Empty Messages Vector in
|
Summary
Changes
New Test Files
AgenticSpec.hs- Tests for agentic chat workflowsDiscordSpec.hs- Discord bot handler testsSlackSpec.hs- Slack bot handler testsWhatsappSpec.hs- WhatsApp bot handler testsAnomalyNotificationSpec.hs- Anomaly notification testsBotFixtures.hs/BotTestHelpers.hs- Shared test utilitiesCode Refactoring
Discord.hs: Replaced nested case statements with Either do-notation inverifyDiscordSignatureUtils.hs: Use lens-aeson (^?) for JSON access inparseReportStats, simplifytimeParamswithcatMaybesAI.hs: Replace large case statement withMap.lookupinparseVisualizationTypeTest plan
USE_EXTERNAL_DB=true cabal test integration-tests