summaryrefslogtreecommitdiff
path: root/Omni/Agent/LogTest.hs
blob: 518147e16ee66be4a0b53801d05eace44f4adb18 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}

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

import Alpha
import qualified Data.Set as Set
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,
      Test.unit "Update Status" testUpdateStatus,
      Test.unit "Render Status" testRenderStatus
    ]

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,
            leTimestamp = 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,
            leTimestamp = 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,
            leTimestamp = Nothing
          }
  format entry2 @?= Nothing

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

testUpdateStatus :: IO ()
testUpdateStatus = do
  let s0 = initialStatus "worker-1"
  let e1 =
        LogEntry
          { leMessage = "executing 1 tools in 1 batch(es)",
            leLevel = Nothing,
            leToolName = Nothing,
            leBatches = Just [["grep"]],
            leMethod = Nothing,
            lePath = Nothing,
            leTimestamp = Just "12:00:00"
          }
  let s1 = updateStatus e1 s0
  sLastActivity s1 @?= "🤖  THOUGHT: Planning tool execution (grep)"
  sStartTime s1 @?= Just "12:00:00"

  let e2 =
        LogEntry
          { leMessage = "ide-fs",
            leLevel = Nothing,
            leToolName = Nothing,
            leBatches = Nothing,
            leMethod = Just "readFile",
            lePath = Just "/path/to/file",
            leTimestamp = Just "12:00:01"
          }
  let s2 = updateStatus e2 s1
  sLastActivity s2 @?= "📂  READ: /path/to/file"
  Set.member "/path/to/file" (sFiles s2) @?= True
  sStartTime s2 @?= Just "12:00:00" -- Should preserve start time

testRenderStatus :: IO ()
testRenderStatus = do
  let s =
        Status
          { sWorkerName = "worker-1",
            sTaskId = Just "t-123",
            sFiles = Set.fromList ["file1", "file2"],
            sStartTime = Just "12:00",
            sLastActivity = "Running..."
          }
  let output = renderStatus s
  output @?= "[Worker: worker-1] Task: t-123 | Files: 2\nRunning..."

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