From 8ae33333b0fc0ca0876681dbcd54f962b89328fe Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 9 Nov 2025 07:53:04 -0500 Subject: Protect production task database from tests and add migration - Add TASK_TEST_MODE environment variable to use separate test database - All file operations now use getTasksFilePath to respect test mode - Tests use .tasks/tasks-test.jsonl instead of production database - Add automatic migration from old task format (taskProject field) to new format - Migrated tasks convert taskProject to WorkTask type with empty parent - Old [Text] dependencies converted to [Dependency] with Blocks type - Restore actual tasks from commit 3bf1691 (were lost during testing) This prevents accidental data loss when running tests and provides backward compatibility for existing task databases. --- Omni/Task.hs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Omni/Task.hs') diff --git a/Omni/Task.hs b/Omni/Task.hs index 571c72e..f10ae25 100644 --- a/Omni/Task.hs +++ b/Omni/Task.hs @@ -13,6 +13,7 @@ import qualified Omni.Namespace as Namespace import Omni.Task.Core import qualified Omni.Test as Test import System.Directory (doesFileExist, removeFile) +import System.Environment (setEnv) main :: IO () main = Cli.main plan @@ -165,18 +166,24 @@ unitTests :: Test.Tree unitTests = Test.group "Unit tests" - [ Test.unit "can create task" <| do - -- Clean up before test - exists <- doesFileExist ".tasks/tasks.jsonl" - when exists <| removeFile ".tasks/tasks.jsonl" - + [ Test.unit "setup test database" <| do + -- Set up test mode for all tests + setEnv "TASK_TEST_MODE" "1" + + -- Clean up test database before all tests + let testFile = ".tasks/tasks-test.jsonl" + exists <- doesFileExist testFile + when exists <| removeFile testFile initTaskDb + True Test.@?= True, + Test.unit "can create task" <| do task <- createTask "Test task" WorkTask Nothing Nothing [] taskTitle task Test.@?= "Test task" taskType task Test.@?= WorkTask taskStatus task Test.@?= Open null (taskDependencies task) Test.@?= True, Test.unit "can list tasks" <| do + _ <- createTask "Test task for list" WorkTask Nothing Nothing [] tasks <- listTasks Nothing Nothing not (null tasks) Test.@?= True, Test.unit "ready tasks exclude blocked ones" <| do -- cgit v1.2.3