diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-09 07:53:04 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-09 07:53:04 -0500 |
| commit | 8ae33333b0fc0ca0876681dbcd54f962b89328fe (patch) | |
| tree | c0ca7144f2082cf3ad88bca27508707642686f84 /Omni/Task.hs | |
| parent | 04986e2fc5c8863672c2a84e644777505878318b (diff) | |
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.
Diffstat (limited to 'Omni/Task.hs')
| -rw-r--r-- | Omni/Task.hs | 17 |
1 files changed, 12 insertions, 5 deletions
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 |
