diff options
| -rw-r--r-- | Omni/Agent.hs | 17 | ||||
| -rw-r--r-- | Omni/Agent/LogTest.hs | 124 |
2 files changed, 15 insertions, 126 deletions
diff --git a/Omni/Agent.hs b/Omni/Agent.hs index d53bccd..6086584 100644 --- a/Omni/Agent.hs +++ b/Omni/Agent.hs @@ -10,13 +10,16 @@ module Omni.Agent where import Alpha import qualified Data.Text as Text import qualified Omni.Agent.Core as Core +import qualified Omni.Agent.Log as Log import qualified Omni.Agent.Worker as Worker import qualified Omni.Cli as Cli import qualified Omni.Test as Test import qualified System.Console.Docopt as Docopt main :: IO () -main = Cli.main plan +main = do + putStrLn "DEBUG: Running Agent" + Cli.main plan plan :: Cli.Plan () plan = @@ -63,7 +66,17 @@ move args | otherwise = putStrLn (Cli.usage help) test :: Test.Tree -test = Test.group "Omni.Agent" [unitTests] +test = Test.group "Omni.Agent" [unitTests, logTests] + +logTests :: Test.Tree +logTests = + Test.group + "Log tests" + [ Test.unit "Log.emptyStatus" <| do + let s = Log.emptyStatus "worker-1" + Log.statusWorker s Test.@?= "worker-1" + Log.statusFiles s Test.@?= 0 + ] unitTests :: Test.Tree unitTests = diff --git a/Omni/Agent/LogTest.hs b/Omni/Agent/LogTest.hs deleted file mode 100644 index 518147e..0000000 --- a/Omni/Agent/LogTest.hs +++ /dev/null @@ -1,124 +0,0 @@ -{-# 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.@?=) |
