@ronkovic/aad 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +312 -0
  3. package/bin/aad.js +2 -0
  4. package/package.json +78 -0
  5. package/src/__tests__/e2e/pipeline-e2e.test.ts +279 -0
  6. package/src/__tests__/e2e/resume-e2e.test.ts +200 -0
  7. package/src/__tests__/integration/cli-smoke.test.ts +175 -0
  8. package/src/__tests__/integration/pipeline.test.ts +346 -0
  9. package/src/bun-imports.d.ts +14 -0
  10. package/src/main.ts +52 -0
  11. package/src/modules/claude-provider/__tests__/claude-cli.adapter.test.ts +277 -0
  12. package/src/modules/claude-provider/__tests__/claude-sdk-real-env.test.ts +127 -0
  13. package/src/modules/claude-provider/__tests__/claude-sdk.adapter.test.ts +347 -0
  14. package/src/modules/claude-provider/__tests__/effort-strategy.test.ts +212 -0
  15. package/src/modules/claude-provider/__tests__/provider-registry.test.ts +251 -0
  16. package/src/modules/claude-provider/__tests__/retry.test.ts +201 -0
  17. package/src/modules/claude-provider/claude-cli.adapter.ts +156 -0
  18. package/src/modules/claude-provider/claude-provider.port.ts +35 -0
  19. package/src/modules/claude-provider/claude-sdk.adapter.ts +217 -0
  20. package/src/modules/claude-provider/effort-strategy.ts +94 -0
  21. package/src/modules/claude-provider/index.ts +32 -0
  22. package/src/modules/claude-provider/provider-registry.ts +92 -0
  23. package/src/modules/claude-provider/retry.ts +81 -0
  24. package/src/modules/cli/__tests__/app.test.ts +160 -0
  25. package/src/modules/cli/__tests__/cleanup.test.ts +111 -0
  26. package/src/modules/cli/__tests__/commands.test.ts +186 -0
  27. package/src/modules/cli/__tests__/output.test.ts +329 -0
  28. package/src/modules/cli/__tests__/resume.test.ts +324 -0
  29. package/src/modules/cli/__tests__/run.test.ts +168 -0
  30. package/src/modules/cli/__tests__/shutdown.test.ts +168 -0
  31. package/src/modules/cli/__tests__/status.test.ts +144 -0
  32. package/src/modules/cli/app.ts +241 -0
  33. package/src/modules/cli/commands/cleanup.ts +120 -0
  34. package/src/modules/cli/commands/resume.ts +156 -0
  35. package/src/modules/cli/commands/run.ts +322 -0
  36. package/src/modules/cli/commands/status.ts +101 -0
  37. package/src/modules/cli/index.ts +29 -0
  38. package/src/modules/cli/output.ts +256 -0
  39. package/src/modules/cli/shutdown.ts +122 -0
  40. package/src/modules/dashboard/__tests__/api-routes.test.ts +204 -0
  41. package/src/modules/dashboard/__tests__/file-watcher.test.ts +34 -0
  42. package/src/modules/dashboard/__tests__/server.test.ts +120 -0
  43. package/src/modules/dashboard/__tests__/sse-broadcaster.test.ts +163 -0
  44. package/src/modules/dashboard/__tests__/sse-routes.test.ts +58 -0
  45. package/src/modules/dashboard/__tests__/state-aggregator.test.ts +330 -0
  46. package/src/modules/dashboard/index.ts +8 -0
  47. package/src/modules/dashboard/routes/api.ts +84 -0
  48. package/src/modules/dashboard/routes/sse.ts +37 -0
  49. package/src/modules/dashboard/server.ts +111 -0
  50. package/src/modules/dashboard/services/file-watcher.ts +36 -0
  51. package/src/modules/dashboard/services/sse-broadcaster.ts +81 -0
  52. package/src/modules/dashboard/services/state-aggregator.ts +132 -0
  53. package/src/modules/dashboard/ui/dashboard.html +405 -0
  54. package/src/modules/git-workspace/__tests__/branch-manager.test.ts +335 -0
  55. package/src/modules/git-workspace/__tests__/git-exec.test.ts +91 -0
  56. package/src/modules/git-workspace/__tests__/memory-sync.test.ts +273 -0
  57. package/src/modules/git-workspace/__tests__/merge-service.test.ts +286 -0
  58. package/src/modules/git-workspace/__tests__/settings-merge.test.ts +163 -0
  59. package/src/modules/git-workspace/__tests__/worktree-manager.test.ts +247 -0
  60. package/src/modules/git-workspace/branch-manager.ts +191 -0
  61. package/src/modules/git-workspace/git-exec.ts +124 -0
  62. package/src/modules/git-workspace/index.ts +17 -0
  63. package/src/modules/git-workspace/memory-sync.ts +89 -0
  64. package/src/modules/git-workspace/merge-service.ts +156 -0
  65. package/src/modules/git-workspace/settings-merge.ts +95 -0
  66. package/src/modules/git-workspace/worktree-manager.ts +199 -0
  67. package/src/modules/logging/__tests__/log-store.test.ts +242 -0
  68. package/src/modules/logging/__tests__/logger.test.ts +81 -0
  69. package/src/modules/logging/__tests__/sse-transport.test.ts +93 -0
  70. package/src/modules/logging/index.ts +7 -0
  71. package/src/modules/logging/log-store.ts +80 -0
  72. package/src/modules/logging/logger.ts +55 -0
  73. package/src/modules/logging/transports/sse-transport.ts +28 -0
  74. package/src/modules/multi-repo/__tests__/multi-repo-planner.test.ts +93 -0
  75. package/src/modules/multi-repo/__tests__/repo-context.test.ts +79 -0
  76. package/src/modules/multi-repo/index.ts +12 -0
  77. package/src/modules/multi-repo/multi-repo-planner.ts +112 -0
  78. package/src/modules/multi-repo/repo-context.ts +71 -0
  79. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/progress.json +10 -0
  80. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/completed/task-getall-2.json +10 -0
  81. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-1.json +13 -0
  82. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-getall-1.json +10 -0
  83. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-status-change.json +10 -0
  84. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/workers/worker-1.json +5 -0
  85. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/workers/worker-2.json +5 -0
  86. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/progress.json +10 -0
  87. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/completed/task-getall-2.json +10 -0
  88. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-1.json +13 -0
  89. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-getall-1.json +10 -0
  90. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-status-change.json +10 -0
  91. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/workers/worker-1.json +5 -0
  92. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/workers/worker-2.json +5 -0
  93. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/progress.json +10 -0
  94. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/completed/task-getall-2.json +10 -0
  95. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-1.json +13 -0
  96. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-getall-1.json +10 -0
  97. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-status-change.json +10 -0
  98. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/workers/worker-1.json +5 -0
  99. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/workers/worker-2.json +5 -0
  100. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/progress.json +10 -0
  101. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/completed/task-getall-2.json +10 -0
  102. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-1.json +13 -0
  103. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-getall-1.json +10 -0
  104. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-status-change.json +10 -0
  105. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/workers/worker-1.json +5 -0
  106. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/workers/worker-2.json +5 -0
  107. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/progress.json +10 -0
  108. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/completed/task-getall-2.json +10 -0
  109. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-1.json +13 -0
  110. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-getall-1.json +10 -0
  111. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-status-change.json +10 -0
  112. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/workers/worker-1.json +5 -0
  113. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/workers/worker-2.json +5 -0
  114. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/progress.json +10 -0
  115. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/completed/task-getall-2.json +10 -0
  116. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-1.json +13 -0
  117. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-getall-1.json +10 -0
  118. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-status-change.json +10 -0
  119. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/workers/worker-1.json +5 -0
  120. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/workers/worker-2.json +5 -0
  121. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/progress.json +10 -0
  122. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/completed/task-getall-2.json +10 -0
  123. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-1.json +13 -0
  124. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-getall-1.json +10 -0
  125. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-status-change.json +10 -0
  126. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/workers/worker-1.json +5 -0
  127. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/workers/worker-2.json +5 -0
  128. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/progress.json +10 -0
  129. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/completed/task-getall-2.json +10 -0
  130. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-1.json +13 -0
  131. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-getall-1.json +10 -0
  132. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-status-change.json +10 -0
  133. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/workers/worker-1.json +5 -0
  134. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/workers/worker-2.json +5 -0
  135. package/src/modules/persistence/__tests__/file-lock.test.ts +141 -0
  136. package/src/modules/persistence/__tests__/index.test.ts +38 -0
  137. package/src/modules/persistence/__tests__/stores.test.ts +594 -0
  138. package/src/modules/persistence/file-lock.ts +158 -0
  139. package/src/modules/persistence/fs-run-store.ts +73 -0
  140. package/src/modules/persistence/fs-task-store.ts +152 -0
  141. package/src/modules/persistence/fs-worker-store.ts +116 -0
  142. package/src/modules/persistence/in-memory-stores.ts +98 -0
  143. package/src/modules/persistence/index.ts +60 -0
  144. package/src/modules/persistence/stores.port.ts +60 -0
  145. package/src/modules/planning/__tests__/file-conflict-validator.test.ts +256 -0
  146. package/src/modules/planning/__tests__/planning-service.test.ts +366 -0
  147. package/src/modules/planning/__tests__/project-detection.test.ts +707 -0
  148. package/src/modules/planning/file-conflict-validator.ts +135 -0
  149. package/src/modules/planning/index.ts +40 -0
  150. package/src/modules/planning/planning.service.ts +262 -0
  151. package/src/modules/planning/project-detection.ts +525 -0
  152. package/src/modules/plugin/__tests__/plugin-loader.test.ts +83 -0
  153. package/src/modules/plugin/__tests__/plugin-manager.test.ts +187 -0
  154. package/src/modules/plugin/index.ts +3 -0
  155. package/src/modules/plugin/plugin-loader.ts +46 -0
  156. package/src/modules/plugin/plugin-manager.ts +90 -0
  157. package/src/modules/plugin/plugin.types.ts +37 -0
  158. package/src/modules/process-manager/__tests__/process-manager.test.ts +210 -0
  159. package/src/modules/process-manager/__tests__/worker.test.ts +89 -0
  160. package/src/modules/process-manager/index.ts +5 -0
  161. package/src/modules/process-manager/process-manager.ts +193 -0
  162. package/src/modules/process-manager/worker.ts +106 -0
  163. package/src/modules/task-execution/__tests__/default-spawner.test.ts +154 -0
  164. package/src/modules/task-execution/__tests__/executor.test.ts +760 -0
  165. package/src/modules/task-execution/__tests__/implementer-green.test.ts +286 -0
  166. package/src/modules/task-execution/__tests__/merge-phase.test.ts +368 -0
  167. package/src/modules/task-execution/__tests__/reviewer.test.ts +302 -0
  168. package/src/modules/task-execution/__tests__/tester-red.test.ts +281 -0
  169. package/src/modules/task-execution/__tests__/tester-verify.test.ts +313 -0
  170. package/src/modules/task-execution/executor.ts +303 -0
  171. package/src/modules/task-execution/index.ts +45 -0
  172. package/src/modules/task-execution/phases/default-spawner.ts +49 -0
  173. package/src/modules/task-execution/phases/implementer-green.ts +100 -0
  174. package/src/modules/task-execution/phases/merge.ts +122 -0
  175. package/src/modules/task-execution/phases/reviewer.ts +160 -0
  176. package/src/modules/task-execution/phases/tester-red.ts +100 -0
  177. package/src/modules/task-execution/phases/tester-verify.ts +120 -0
  178. package/src/modules/task-queue/__tests__/dependency-resolver.test.ts +456 -0
  179. package/src/modules/task-queue/__tests__/dispatcher.test.ts +824 -0
  180. package/src/modules/task-queue/__tests__/task-plan.test.ts +122 -0
  181. package/src/modules/task-queue/__tests__/task.test.ts +130 -0
  182. package/src/modules/task-queue/dependency-resolver.ts +171 -0
  183. package/src/modules/task-queue/dispatcher.ts +372 -0
  184. package/src/modules/task-queue/index.ts +16 -0
  185. package/src/modules/task-queue/task-plan.ts +40 -0
  186. package/src/modules/task-queue/task.ts +67 -0
  187. package/src/shared/__tests__/config.test.ts +204 -0
  188. package/src/shared/__tests__/errors.test.ts +285 -0
  189. package/src/shared/__tests__/events.test.ts +496 -0
  190. package/src/shared/__tests__/types.test.ts +360 -0
  191. package/src/shared/config.ts +133 -0
  192. package/src/shared/errors.ts +128 -0
  193. package/src/shared/events.ts +171 -0
  194. package/src/shared/types.ts +143 -0
  195. package/tsconfig.json +30 -0
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "runId": "run-latest",
3
+ "parentBranch": "main",
4
+ "totalTasks": 8,
5
+ "pending": 0,
6
+ "running": 0,
7
+ "completed": 8,
8
+ "failed": 0,
9
+ "startTime": "2024-01-03T10:00:00Z"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-2",
3
+ "title": "Task 2",
4
+ "description": "Task 2",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 2,
8
+ "status": "completed",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "taskId": "task-1",
3
+ "title": "FS Test Task",
4
+ "description": "A filesystem test task",
5
+ "filesToModify": [
6
+ "file1.ts",
7
+ "file2.ts"
8
+ ],
9
+ "dependsOn": [],
10
+ "priority": 1,
11
+ "status": "pending",
12
+ "retryCount": 0
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-1",
3
+ "title": "Task 1",
4
+ "description": "Task 1",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-status-change",
3
+ "title": "Task",
4
+ "description": "Task",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-1",
3
+ "status": "idle",
4
+ "currentTask": null
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "runId": "run-latest",
3
+ "parentBranch": "main",
4
+ "totalTasks": 8,
5
+ "pending": 0,
6
+ "running": 0,
7
+ "completed": 8,
8
+ "failed": 0,
9
+ "startTime": "2024-01-03T10:00:00Z"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-2",
3
+ "title": "Task 2",
4
+ "description": "Task 2",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 2,
8
+ "status": "completed",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "taskId": "task-1",
3
+ "title": "FS Test Task",
4
+ "description": "A filesystem test task",
5
+ "filesToModify": [
6
+ "file1.ts",
7
+ "file2.ts"
8
+ ],
9
+ "dependsOn": [],
10
+ "priority": 1,
11
+ "status": "pending",
12
+ "retryCount": 0
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-1",
3
+ "title": "Task 1",
4
+ "description": "Task 1",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-status-change",
3
+ "title": "Task",
4
+ "description": "Task",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-1",
3
+ "status": "idle",
4
+ "currentTask": null
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "runId": "run-latest",
3
+ "parentBranch": "main",
4
+ "totalTasks": 8,
5
+ "pending": 0,
6
+ "running": 0,
7
+ "completed": 8,
8
+ "failed": 0,
9
+ "startTime": "2024-01-03T10:00:00Z"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-2",
3
+ "title": "Task 2",
4
+ "description": "Task 2",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 2,
8
+ "status": "completed",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "taskId": "task-1",
3
+ "title": "FS Test Task",
4
+ "description": "A filesystem test task",
5
+ "filesToModify": [
6
+ "file1.ts",
7
+ "file2.ts"
8
+ ],
9
+ "dependsOn": [],
10
+ "priority": 1,
11
+ "status": "pending",
12
+ "retryCount": 0
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-1",
3
+ "title": "Task 1",
4
+ "description": "Task 1",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-status-change",
3
+ "title": "Task",
4
+ "description": "Task",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-1",
3
+ "status": "idle",
4
+ "currentTask": null
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "runId": "run-latest",
3
+ "parentBranch": "main",
4
+ "totalTasks": 8,
5
+ "pending": 0,
6
+ "running": 0,
7
+ "completed": 8,
8
+ "failed": 0,
9
+ "startTime": "2024-01-03T10:00:00Z"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-2",
3
+ "title": "Task 2",
4
+ "description": "Task 2",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 2,
8
+ "status": "completed",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "taskId": "task-1",
3
+ "title": "FS Test Task",
4
+ "description": "A filesystem test task",
5
+ "filesToModify": [
6
+ "file1.ts",
7
+ "file2.ts"
8
+ ],
9
+ "dependsOn": [],
10
+ "priority": 1,
11
+ "status": "pending",
12
+ "retryCount": 0
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-1",
3
+ "title": "Task 1",
4
+ "description": "Task 1",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-status-change",
3
+ "title": "Task",
4
+ "description": "Task",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-1",
3
+ "status": "idle",
4
+ "currentTask": null
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "runId": "run-latest",
3
+ "parentBranch": "main",
4
+ "totalTasks": 8,
5
+ "pending": 0,
6
+ "running": 0,
7
+ "completed": 8,
8
+ "failed": 0,
9
+ "startTime": "2024-01-03T10:00:00Z"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-2",
3
+ "title": "Task 2",
4
+ "description": "Task 2",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 2,
8
+ "status": "completed",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "taskId": "task-1",
3
+ "title": "FS Test Task",
4
+ "description": "A filesystem test task",
5
+ "filesToModify": [
6
+ "file1.ts",
7
+ "file2.ts"
8
+ ],
9
+ "dependsOn": [],
10
+ "priority": 1,
11
+ "status": "pending",
12
+ "retryCount": 0
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-getall-1",
3
+ "title": "Task 1",
4
+ "description": "Task 1",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "taskId": "task-status-change",
3
+ "title": "Task",
4
+ "description": "Task",
5
+ "filesToModify": [],
6
+ "dependsOn": [],
7
+ "priority": 1,
8
+ "status": "pending",
9
+ "retryCount": 0
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-1",
3
+ "status": "idle",
4
+ "currentTask": null
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "workerId": "worker-2",
3
+ "status": "busy",
4
+ "currentTask": "task-1"
5
+ }
@@ -0,0 +1,141 @@
1
+ import { describe, test, expect, beforeEach, afterEach } from "bun:test";
2
+ import { rm, mkdir } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { FileLock, withFileLock } from "../file-lock";
5
+ import { FileLockError } from "@aad/shared/errors";
6
+
7
+ const TEST_DIR = join(import.meta.dir, ".tmp-file-lock-test");
8
+
9
+ describe("FileLock", () => {
10
+ beforeEach(async () => {
11
+ await rm(TEST_DIR, { recursive: true, force: true });
12
+ await mkdir(TEST_DIR, { recursive: true });
13
+ });
14
+
15
+ afterEach(async () => {
16
+ await rm(TEST_DIR, { recursive: true, force: true });
17
+ });
18
+
19
+ test("acquires and releases lock successfully", async () => {
20
+ const lockDir = join(TEST_DIR, "test-lock");
21
+ const lock = new FileLock({ lockDir });
22
+
23
+ await lock.acquire();
24
+ await lock.release();
25
+
26
+ expect(true).toBe(true);
27
+ });
28
+
29
+ test("allows sequential lock acquisition", async () => {
30
+ const lockDir = join(TEST_DIR, "sequential-lock");
31
+ const lock1 = new FileLock({ lockDir });
32
+ const lock2 = new FileLock({ lockDir });
33
+
34
+ await lock1.acquire();
35
+ await lock1.release();
36
+
37
+ await lock2.acquire();
38
+ await lock2.release();
39
+
40
+ expect(true).toBe(true);
41
+ });
42
+
43
+ test("detects and removes stale locks", async () => {
44
+ const lockDir = join(TEST_DIR, "stale-lock");
45
+
46
+ // Create a stale lock with non-existent PID
47
+ await mkdir(lockDir);
48
+ await Bun.write(join(lockDir, "pid"), "999999");
49
+
50
+ const lock = new FileLock({ lockDir });
51
+ await lock.acquire();
52
+ await lock.release();
53
+
54
+ expect(true).toBe(true);
55
+ });
56
+
57
+ test("withFileLock helper auto-releases", async () => {
58
+ const lockDir = join(TEST_DIR, "helper-lock");
59
+ let executed = false;
60
+
61
+ await withFileLock({ lockDir }, async () => {
62
+ executed = true;
63
+ });
64
+
65
+ expect(executed).toBe(true);
66
+
67
+ // Lock should be released, can acquire again
68
+ const lock = new FileLock({ lockDir });
69
+ await lock.acquire();
70
+ await lock.release();
71
+ });
72
+
73
+ test("withFileLock releases on error", async () => {
74
+ const lockDir = join(TEST_DIR, "error-lock");
75
+
76
+ await expect(
77
+ withFileLock({ lockDir }, async () => {
78
+ throw new Error("Test error");
79
+ })
80
+ ).rejects.toThrow("Test error");
81
+
82
+ // Lock should still be released
83
+ const lock = new FileLock({ lockDir });
84
+ await lock.acquire();
85
+ await lock.release();
86
+ });
87
+
88
+ test("forceRelease removes lock unconditionally", async () => {
89
+ const lockDir = join(TEST_DIR, "force-lock");
90
+ const lock1 = new FileLock({ lockDir });
91
+ const lock2 = new FileLock({ lockDir });
92
+
93
+ await lock1.acquire();
94
+ await lock2.forceRelease();
95
+
96
+ // Lock should be removable after force release
97
+ await lock1.acquire(); // Should not fail
98
+ await lock1.release();
99
+ });
100
+
101
+ test("acquire throws FileLockError on non-EEXIST mkdir failure", async () => {
102
+ // Use a path that cannot be created (nested under a file, not a directory)
103
+ const blockerFile = join(TEST_DIR, "blocker");
104
+ await Bun.write(blockerFile, "not-a-dir");
105
+ const lockDir = join(blockerFile, "impossible-lock");
106
+
107
+ const lock = new FileLock({ lockDir, timeout: 500, retryInterval: 50 });
108
+
109
+ await expect(lock.acquire()).rejects.toThrow(FileLockError);
110
+ });
111
+
112
+ test("forceRelease handles missing lock dir gracefully", async () => {
113
+ const lockDir = join(TEST_DIR, "missing-force-lock");
114
+ const lock = new FileLock({ lockDir });
115
+ // Should not throw even if dir doesn't exist
116
+ await lock.forceRelease();
117
+ });
118
+
119
+ test("release is no-op when not acquired", async () => {
120
+ const lockDir = join(TEST_DIR, "noop-release");
121
+ const lock = new FileLock({ lockDir });
122
+
123
+ // Should not throw
124
+ await lock.release();
125
+ });
126
+
127
+ test("treats non-numeric PID as stale lock", async () => {
128
+ const lockDir = join(TEST_DIR, "bad-pid-lock");
129
+
130
+ // Create lock with non-numeric PID
131
+ await mkdir(lockDir);
132
+ await Bun.write(join(lockDir, "pid"), "not-a-number");
133
+
134
+ const lock = new FileLock({ lockDir });
135
+ // Should treat as stale and acquire successfully
136
+ await lock.acquire();
137
+ await lock.release();
138
+
139
+ expect(true).toBe(true);
140
+ });
141
+ });
@@ -0,0 +1,38 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import { join } from "node:path";
3
+ import { rm, mkdir } from "node:fs/promises";
4
+ import { createStores } from "../index";
5
+
6
+ const TEST_DIR = join(import.meta.dir, `.tmp-index-test-${process.pid}`);
7
+
8
+ describe("createStores factory", () => {
9
+ test('createStores("memory") returns InMemory stores', () => {
10
+ const stores = createStores("memory");
11
+ expect(stores.taskStore).toBeDefined();
12
+ expect(stores.workerStore).toBeDefined();
13
+ expect(stores.runStore).toBeDefined();
14
+ });
15
+
16
+ test('createStores("fs", { basePath }) returns FS stores', async () => {
17
+ await rm(TEST_DIR, { recursive: true, force: true });
18
+ await mkdir(TEST_DIR, { recursive: true });
19
+
20
+ try {
21
+ const stores = createStores("fs", { basePath: TEST_DIR });
22
+ expect(stores.taskStore).toBeDefined();
23
+ expect(stores.workerStore).toBeDefined();
24
+ expect(stores.runStore).toBeDefined();
25
+ } finally {
26
+ await rm(TEST_DIR, { recursive: true, force: true });
27
+ }
28
+ });
29
+
30
+ test('createStores("fs") without basePath throws Error', () => {
31
+ expect(() => createStores("fs")).toThrow("basePath is required for fs mode");
32
+ });
33
+
34
+ test('createStores with unknown mode throws Error', () => {
35
+ // @ts-expect-error testing invalid mode
36
+ expect(() => createStores("unknown")).toThrow("Unknown store mode: unknown");
37
+ });
38
+ });