summaryrefslogtreecommitdiff
path: root/Omni/Agent/LogTest.hs
blob: 0d085b17faaf515817e5d1a9336e63741485eeb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- : out agent-log-test
module Omni.Agent.LogTest where

import Alpha
import Omni.Agent.Log
import qualified Omni.Test as Test

main :: IO ()
main = Test.run tests

tests :: Test.Tree
tests =
  Test.group
    "Omni.Agent.Log"
    [ Test.unit "Parse LogEntry" testParse,
      Test.unit "Format LogEntry" testFormat
    ]

testParse :: IO ()
testParse = do
  let json = "{\"message\": \"executing 1 tools in 1 batch(es)\", \"batches\": [[\"grep\"]]}"
  let expected =
        LogEntry
          { leMessage = "executing 1 tools in 1 batch(es)",
            leLevel = Nothing,
            leToolName = Nothing,
            leBatches = Just [["grep"]],
            leMethod = Nothing,
            lePath = Nothing
          }
  parseLine json @?= Just expected

testFormat :: IO ()
testFormat = do
  let entry =
        LogEntry
          { leMessage = "executing 1 tools in 1 batch(es)",
            leLevel = Nothing,
            leToolName = Nothing,
            leBatches = Just [["grep"]],
            leMethod = Nothing,
            lePath = Nothing
          }
  format entry @?= Just "🤖  THOUGHT: Planning tool execution (grep)"

  let entry2 =
        LogEntry
          { leMessage = "some random log",
            leLevel = Nothing,
            leToolName = Nothing,
            leBatches = Nothing,
            leMethod = Nothing,
            lePath = Nothing
          }
  format entry2 @?= Nothing

  let entry3 =
        LogEntry
          { leMessage = "some error",
            leLevel = Just "error",
            leToolName = Nothing,
            leBatches = Nothing,
            leMethod = Nothing,
            lePath = Nothing
          }
  format entry3 @?= Just "❌  ERROR: some error"

(@?=) :: (Eq a, Show a) => a -> a -> IO ()
(@?=) = (Test.@?=)