@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,111 @@
1
+ /**
2
+ * Cleanup Command Tests
3
+ */
4
+
5
+ import { describe, test, expect, beforeEach, mock } from "bun:test";
6
+ import type { App } from "../app";
7
+ import { cleanupWorktrees } from "../commands/cleanup";
8
+
9
+ describe("cleanupWorktrees", () => {
10
+ let mockApp: App;
11
+
12
+ beforeEach(() => {
13
+ mockApp = {
14
+ config: {} as any,
15
+ eventBus: {} as any,
16
+ logger: {
17
+ info: mock(() => {}),
18
+ debug: mock(() => {}),
19
+ } as any,
20
+ stores: {} as any,
21
+ dispatcher: {} as any,
22
+ processManager: {} as any,
23
+ planningService: {} as any,
24
+ providerRegistry: {} as any,
25
+ worktreeManager: {
26
+ listWorktrees: mock(async () => [
27
+ {
28
+ path: `${process.cwd()}/.aad/worktrees/task-1`,
29
+ branch: "aad/task-1",
30
+ head: "abc123",
31
+ },
32
+ {
33
+ path: `${process.cwd()}/.aad/worktrees/task-2`,
34
+ branch: "aad/task-2",
35
+ head: "def456",
36
+ },
37
+ ]),
38
+ removeWorktree: mock(async () => {}),
39
+ pruneWorktrees: mock(async () => {}),
40
+ } as any,
41
+ branchManager: {
42
+ cleanupOrphanBranches: mock(async () => ["aad-task-1", "aad-task-2"]),
43
+ } as any,
44
+ mergeService: {} as any,
45
+ pluginManager: { runHook: mock(async (_p: string, d: unknown) => d), deactivateAll: mock(async () => {}), register: mock(async () => {}), loadFromConfig: mock(async () => {}), addHook: mock(() => {}), list: mock(() => []) } as any,
46
+ shutdown: mock(async () => {}),
47
+ };
48
+ });
49
+
50
+ test("cleans up all AAD worktrees", async () => {
51
+ await cleanupWorktrees(mockApp);
52
+
53
+ expect(mockApp.worktreeManager.listWorktrees).toHaveBeenCalled();
54
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledTimes(2);
55
+ expect(mockApp.worktreeManager.pruneWorktrees).toHaveBeenCalled();
56
+ expect(mockApp.branchManager.cleanupOrphanBranches).toHaveBeenCalled();
57
+ });
58
+
59
+ test("cleans up worktrees with force flag", async () => {
60
+ await cleanupWorktrees(mockApp, undefined, true);
61
+
62
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledWith(
63
+ expect.stringContaining(".aad/worktrees"),
64
+ true
65
+ );
66
+ });
67
+
68
+ test("filters worktrees by runId", async () => {
69
+ mockApp.worktreeManager.listWorktrees = mock(async () => [
70
+ {
71
+ path: `${process.cwd()}/.aad/worktrees/run-123/task-1`,
72
+ branch: "aad/run-123/task-1",
73
+ head: "abc123",
74
+ },
75
+ {
76
+ path: `${process.cwd()}/.aad/worktrees/run-456/task-2`,
77
+ branch: "aad/run-456/task-2",
78
+ head: "def456",
79
+ },
80
+ ]);
81
+
82
+ await cleanupWorktrees(mockApp, "run-123");
83
+
84
+ // Should only remove worktrees matching run-123
85
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledTimes(1);
86
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledWith(
87
+ expect.stringContaining("run-123"),
88
+ false
89
+ );
90
+ });
91
+
92
+ test("handles empty worktree list", async () => {
93
+ mockApp.worktreeManager.listWorktrees = mock(async () => []);
94
+
95
+ await cleanupWorktrees(mockApp);
96
+ // Should complete without throwing
97
+ expect(mockApp.worktreeManager.removeWorktree).not.toHaveBeenCalled();
98
+ });
99
+
100
+ test("continues on individual worktree removal failure", async () => {
101
+ mockApp.worktreeManager.removeWorktree = mock(async (path: string) => {
102
+ if (path.includes("task-1")) {
103
+ throw new Error("Failed to remove");
104
+ }
105
+ });
106
+
107
+ await cleanupWorktrees(mockApp);
108
+ // Should have attempted both despite error
109
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledTimes(2);
110
+ });
111
+ });
@@ -0,0 +1,186 @@
1
+ /**
2
+ * CLI Commands Tests (Resume, Status, Cleanup)
3
+ */
4
+
5
+ import { describe, test, expect, mock } from "bun:test";
6
+ import type { App } from "../app";
7
+ import { resumeRun } from "../commands/resume";
8
+ import { displayStatus } from "../commands/status";
9
+ import { cleanupWorktrees } from "../commands/cleanup";
10
+ import { createRunId, createTaskId, type Task, type RunState } from "../../../shared/types";
11
+ import { EventBus } from "../../../shared/events";
12
+
13
+ describe("Resume Command", () => {
14
+ test("resumes run with pending tasks", async () => {
15
+ const mockRunId = createRunId("test-run-id");
16
+ const mockRunState: RunState = {
17
+ runId: mockRunId,
18
+ parentBranch: "main",
19
+ totalTasks: 1,
20
+ pending: 0,
21
+ running: 1,
22
+ completed: 0,
23
+ failed: 0,
24
+ startTime: new Date().toISOString(),
25
+ };
26
+
27
+ const mockTask: Task = {
28
+ taskId: createTaskId("task-test-run-id-1"),
29
+ title: "Test",
30
+ description: "Test",
31
+ filesToModify: [],
32
+ dependsOn: [],
33
+ priority: 1,
34
+ status: "running",
35
+ retryCount: 0,
36
+ };
37
+
38
+ const eventBus = new EventBus();
39
+
40
+ const mockApp: App = {
41
+ eventBus,
42
+ logger: {
43
+ info: mock(() => {}),
44
+ error: mock(() => {}),
45
+ } as any,
46
+ stores: {
47
+ runStore: {
48
+ get: mock(async () => mockRunState),
49
+ } as any,
50
+ taskStore: {
51
+ list: mock(async () => [mockTask]),
52
+ getAll: mock(async () => [mockTask]),
53
+ save: mock(async () => {}),
54
+ } as any,
55
+ } as any,
56
+ dispatcher: {
57
+ initialize: mock(async () => {}),
58
+ start: mock(() => {}),
59
+ } as any,
60
+ processManager: {
61
+ initializePool: mock(async () => {}),
62
+ } as any,
63
+ config: {
64
+ workers: { num: 2, max: 8 },
65
+ timeouts: { claude: 1200, test: 600, staleTask: 5400 },
66
+ } as any,
67
+ shutdown: mock(async () => {}),
68
+ } as any;
69
+
70
+ // Emit run:completed to unblock resumeRun
71
+ setTimeout(() => {
72
+ eventBus.emit({ type: "run:completed", runId: mockRunId });
73
+ }, 10);
74
+
75
+ await resumeRun(mockApp, "test-run-id");
76
+
77
+ expect(mockApp.stores.runStore.get).toHaveBeenCalledTimes(1);
78
+ expect(mockApp.stores.taskStore.save).toHaveBeenCalledTimes(1);
79
+ expect(mockApp.dispatcher.initialize).toHaveBeenCalledTimes(1);
80
+ expect(mockApp.dispatcher.start).toHaveBeenCalledTimes(1);
81
+ expect(mockApp.shutdown).toHaveBeenCalledTimes(1);
82
+ });
83
+ });
84
+
85
+ describe("Status Command", () => {
86
+ test("displays status for existing run", async () => {
87
+ const mockRunId = createRunId("test-run-id");
88
+ const mockRunState: RunState = {
89
+ runId: mockRunId,
90
+ parentBranch: "main",
91
+ totalTasks: 1,
92
+ pending: 0,
93
+ running: 0,
94
+ completed: 1,
95
+ failed: 0,
96
+ startTime: new Date().toISOString(),
97
+ endTime: new Date().toISOString(),
98
+ };
99
+
100
+ const mockApp: App = {
101
+ logger: {
102
+ info: mock(() => {}),
103
+ } as any,
104
+ stores: {
105
+ runStore: {
106
+ get: mock(async () => mockRunState),
107
+ } as any,
108
+ taskStore: {
109
+ getAll: mock(async () => []),
110
+ } as any,
111
+ } as any,
112
+ } as any;
113
+
114
+ await displayStatus(mockApp, "test-run-id");
115
+
116
+ expect(mockApp.stores.runStore.get).toHaveBeenCalledTimes(1);
117
+ expect(mockApp.stores.taskStore.getAll).toHaveBeenCalledTimes(1);
118
+ });
119
+
120
+ test("throws error for non-existent run", async () => {
121
+ const mockApp: App = {
122
+ logger: {
123
+ info: mock(() => {}),
124
+ } as any,
125
+ stores: {
126
+ runStore: {
127
+ get: mock(async () => null),
128
+ } as any,
129
+ } as any,
130
+ } as any;
131
+
132
+ await expect(displayStatus(mockApp, "non-existent")).rejects.toThrow("Run not found");
133
+ });
134
+ });
135
+
136
+ describe("Cleanup Command", () => {
137
+ test("cleans up worktrees and branches", async () => {
138
+ const mockApp: App = {
139
+ logger: {
140
+ info: mock(() => {}),
141
+ debug: mock(() => {}),
142
+ } as any,
143
+ worktreeManager: {
144
+ listWorktrees: mock(async () => [
145
+ { path: `${process.cwd()}/.aad/worktrees/task-1`, branch: "aad/run/task-1" },
146
+ ]),
147
+ removeWorktree: mock(async () => {}),
148
+ pruneWorktrees: mock(async () => {}),
149
+ } as any,
150
+ branchManager: {
151
+ cleanupOrphanBranches: mock(async () => ["aad/run/task-1"]),
152
+ } as any,
153
+ } as any;
154
+
155
+ await cleanupWorktrees(mockApp, undefined, false);
156
+
157
+ expect(mockApp.worktreeManager.listWorktrees).toHaveBeenCalledTimes(1);
158
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledTimes(1);
159
+ expect(mockApp.branchManager.cleanupOrphanBranches).toHaveBeenCalledTimes(1);
160
+ });
161
+
162
+ test("filters by runId when specified", async () => {
163
+ const mockApp: App = {
164
+ logger: {
165
+ info: mock(() => {}),
166
+ debug: mock(() => {}),
167
+ } as any,
168
+ worktreeManager: {
169
+ listWorktrees: mock(async () => [
170
+ { path: `${process.cwd()}/.aad/worktrees/task-run1-1`, branch: "aad/run1/task-1" },
171
+ { path: `${process.cwd()}/.aad/worktrees/task-run2-1`, branch: "aad/run2/task-1" },
172
+ ]),
173
+ removeWorktree: mock(async () => {}),
174
+ pruneWorktrees: mock(async () => {}),
175
+ } as any,
176
+ branchManager: {
177
+ cleanupOrphanBranches: mock(async () => []),
178
+ } as any,
179
+ } as any;
180
+
181
+ await cleanupWorktrees(mockApp, "run1", false);
182
+
183
+ // Should only remove worktrees matching run1
184
+ expect(mockApp.worktreeManager.removeWorktree).toHaveBeenCalledTimes(1);
185
+ });
186
+ });
@@ -0,0 +1,329 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import {
3
+ formatProgress,
4
+ formatTaskTable,
5
+ formatRunStatus,
6
+ formatError,
7
+ formatDuration,
8
+ createSpinner,
9
+ } from "../output";
10
+ import type { ProgressState, Task, RunState } from "@aad/shared/types";
11
+ import { createTaskId, createWorkerId, createRunId } from "@aad/shared/types";
12
+
13
+ describe("formatProgress", () => {
14
+ test("formats progress state with all counts", () => {
15
+ const state: ProgressState = {
16
+ total: 10,
17
+ pending: 2,
18
+ running: 3,
19
+ completed: 4,
20
+ failed: 1,
21
+ };
22
+
23
+ const result = formatProgress(state);
24
+
25
+ expect(result).toContain("40%");
26
+ expect(result).toContain("2 pending");
27
+ expect(result).toContain("3 running");
28
+ expect(result).toContain("4 completed");
29
+ expect(result).toContain("1 failed");
30
+ });
31
+
32
+ test("formats progress state with zero failed", () => {
33
+ const state: ProgressState = {
34
+ total: 10,
35
+ pending: 5,
36
+ running: 2,
37
+ completed: 3,
38
+ failed: 0,
39
+ };
40
+
41
+ const result = formatProgress(state);
42
+
43
+ expect(result).toContain("30%");
44
+ expect(result).not.toContain("failed");
45
+ });
46
+
47
+ test("handles empty progress state", () => {
48
+ const state: ProgressState = {
49
+ total: 0,
50
+ pending: 0,
51
+ running: 0,
52
+ completed: 0,
53
+ failed: 0,
54
+ };
55
+
56
+ const result = formatProgress(state);
57
+
58
+ expect(result).toContain("0%");
59
+ });
60
+
61
+ test("contains ANSI color codes", () => {
62
+ const state: ProgressState = {
63
+ total: 10,
64
+ pending: 2,
65
+ running: 3,
66
+ completed: 4,
67
+ failed: 1,
68
+ };
69
+
70
+ const result = formatProgress(state);
71
+
72
+ // Check for ANSI escape sequences
73
+ expect(result).toMatch(/\x1b\[[0-9;]*m/);
74
+ });
75
+ });
76
+
77
+ describe("formatTaskTable", () => {
78
+ test("formats empty task list", () => {
79
+ const result = formatTaskTable([]);
80
+ expect(result).toContain("No tasks found");
81
+ });
82
+
83
+ test("formats single task", () => {
84
+ const tasks: Task[] = [
85
+ {
86
+ taskId: createTaskId("task-001"),
87
+ title: "Implement feature X",
88
+ description: "Add new feature",
89
+ filesToModify: ["src/main.ts"],
90
+ dependsOn: [],
91
+ priority: 1,
92
+ status: "completed",
93
+ workerId: createWorkerId("worker-001"),
94
+ startTime: "2024-01-01T00:00:00Z",
95
+ endTime: "2024-01-01T00:05:00Z",
96
+ retryCount: 0,
97
+ },
98
+ ];
99
+
100
+ const result = formatTaskTable(tasks);
101
+
102
+ expect(result).toContain("task-001");
103
+ expect(result).toContain("Implement feature X");
104
+ expect(result).toContain("completed");
105
+ expect(result).toContain("worker-0");
106
+ });
107
+
108
+ test("formats multiple tasks", () => {
109
+ const tasks: Task[] = [
110
+ {
111
+ taskId: createTaskId("task-001"),
112
+ title: "Task 1",
113
+ description: "First task",
114
+ filesToModify: [],
115
+ dependsOn: [],
116
+ priority: 1,
117
+ status: "completed",
118
+ retryCount: 0,
119
+ },
120
+ {
121
+ taskId: createTaskId("task-002"),
122
+ title: "Task 2",
123
+ description: "Second task",
124
+ filesToModify: [],
125
+ dependsOn: [],
126
+ priority: 2,
127
+ status: "running",
128
+ workerId: createWorkerId("worker-001"),
129
+ startTime: new Date().toISOString(),
130
+ retryCount: 0,
131
+ },
132
+ ];
133
+
134
+ const result = formatTaskTable(tasks);
135
+
136
+ expect(result).toContain("task-001");
137
+ expect(result).toContain("task-002");
138
+ expect(result).toContain("Task 1");
139
+ expect(result).toContain("Task 2");
140
+ });
141
+
142
+ test("truncates long titles", () => {
143
+ const tasks: Task[] = [
144
+ {
145
+ taskId: createTaskId("task-001"),
146
+ title: "This is a very long task title that should be truncated",
147
+ description: "Test truncation",
148
+ filesToModify: [],
149
+ dependsOn: [],
150
+ priority: 1,
151
+ status: "pending",
152
+ retryCount: 0,
153
+ },
154
+ ];
155
+
156
+ const result = formatTaskTable(tasks);
157
+
158
+ expect(result).toContain("...");
159
+ expect(result.indexOf("This is a very long task title")).toBeGreaterThan(
160
+ -1
161
+ );
162
+ });
163
+
164
+ test("handles task without worker", () => {
165
+ const tasks: Task[] = [
166
+ {
167
+ taskId: createTaskId("task-001"),
168
+ title: "Task without worker",
169
+ description: "Test",
170
+ filesToModify: [],
171
+ dependsOn: [],
172
+ priority: 1,
173
+ status: "pending",
174
+ retryCount: 0,
175
+ },
176
+ ];
177
+
178
+ const result = formatTaskTable(tasks);
179
+
180
+ expect(result).toContain("task-001");
181
+ expect(result).toContain("-"); // Worker column should show "-"
182
+ });
183
+ });
184
+
185
+ describe("formatRunStatus", () => {
186
+ test("formats run state with all fields", () => {
187
+ const state: RunState = {
188
+ runId: createRunId("run-12345"),
189
+ parentBranch: "main",
190
+ totalTasks: 10,
191
+ pending: 2,
192
+ running: 3,
193
+ completed: 4,
194
+ failed: 1,
195
+ startTime: "2024-01-01T00:00:00Z",
196
+ endTime: "2024-01-01T01:00:00Z",
197
+ };
198
+
199
+ const result = formatRunStatus(state);
200
+
201
+ expect(result).toContain("run-12345");
202
+ expect(result).toContain("main");
203
+ expect(result).toContain("40%"); // Progress percentage
204
+ });
205
+
206
+ test("formats ongoing run without endTime", () => {
207
+ const state: RunState = {
208
+ runId: createRunId("run-67890"),
209
+ parentBranch: "feature/test",
210
+ totalTasks: 5,
211
+ pending: 1,
212
+ running: 2,
213
+ completed: 2,
214
+ failed: 0,
215
+ startTime: new Date(Date.now() - 10000).toISOString(), // 10 seconds ago
216
+ };
217
+
218
+ const result = formatRunStatus(state);
219
+
220
+ expect(result).toContain("run-67890");
221
+ expect(result).toContain("feature/test");
222
+ expect(result).toMatch(/\d+s/); // Should show duration in seconds
223
+ });
224
+ });
225
+
226
+ describe("formatError", () => {
227
+ test("formats error with message", () => {
228
+ const error = new Error("Something went wrong");
229
+ const result = formatError(error);
230
+
231
+ expect(result).toContain("Error:");
232
+ expect(result).toContain("Something went wrong");
233
+ });
234
+
235
+ test("formats error with stack trace", () => {
236
+ const error = new Error("Test error");
237
+ Error.captureStackTrace(error);
238
+
239
+ const result = formatError(error);
240
+
241
+ expect(result).toContain("Error:");
242
+ expect(result).toContain("Test error");
243
+ // Stack trace should be included
244
+ expect(result.split("\n").length).toBeGreaterThan(1);
245
+ });
246
+
247
+ test("contains ANSI color codes", () => {
248
+ const error = new Error("Colored error");
249
+ const result = formatError(error);
250
+
251
+ expect(result).toMatch(/\x1b\[[0-9;]*m/);
252
+ });
253
+ });
254
+
255
+ describe("formatDuration", () => {
256
+ test("formats seconds", () => {
257
+ expect(formatDuration(5000)).toBe("5s");
258
+ expect(formatDuration(30000)).toBe("30s");
259
+ expect(formatDuration(59000)).toBe("59s");
260
+ });
261
+
262
+ test("formats minutes and seconds", () => {
263
+ expect(formatDuration(60000)).toBe("1m 0s");
264
+ expect(formatDuration(90000)).toBe("1m 30s");
265
+ expect(formatDuration(3599000)).toBe("59m 59s");
266
+ });
267
+
268
+ test("formats hours and minutes", () => {
269
+ expect(formatDuration(3600000)).toBe("1h 0m");
270
+ expect(formatDuration(5400000)).toBe("1h 30m");
271
+ expect(formatDuration(7200000)).toBe("2h 0m");
272
+ });
273
+
274
+ test("handles zero duration", () => {
275
+ expect(formatDuration(0)).toBe("0s");
276
+ });
277
+
278
+ test("handles negative duration", () => {
279
+ expect(formatDuration(-1000)).toBe("0s");
280
+ });
281
+
282
+ test("handles sub-second duration", () => {
283
+ expect(formatDuration(500)).toBe("0s");
284
+ expect(formatDuration(999)).toBe("0s");
285
+ });
286
+ });
287
+
288
+ describe("createSpinner", () => {
289
+ test("creates spinner object with required methods", () => {
290
+ const spinner = createSpinner("Loading...");
291
+
292
+ expect(spinner).toHaveProperty("start");
293
+ expect(spinner).toHaveProperty("stop");
294
+ expect(spinner).toHaveProperty("succeed");
295
+ expect(spinner).toHaveProperty("fail");
296
+ expect(typeof spinner.start).toBe("function");
297
+ expect(typeof spinner.stop).toBe("function");
298
+ expect(typeof spinner.succeed).toBe("function");
299
+ expect(typeof spinner.fail).toBe("function");
300
+ });
301
+
302
+ test("spinner can be started and stopped", () => {
303
+ const spinner = createSpinner("Processing...");
304
+
305
+ expect(() => spinner.start()).not.toThrow();
306
+ expect(() => spinner.stop()).not.toThrow();
307
+ });
308
+
309
+ test("spinner can succeed with custom message", () => {
310
+ const spinner = createSpinner("Working...");
311
+
312
+ spinner.start();
313
+ expect(() => spinner.succeed("Done!")).not.toThrow();
314
+ });
315
+
316
+ test("spinner can fail with custom message", () => {
317
+ const spinner = createSpinner("Attempting...");
318
+
319
+ spinner.start();
320
+ expect(() => spinner.fail("Failed!")).not.toThrow();
321
+ });
322
+
323
+ test("spinner can succeed without custom message", () => {
324
+ const spinner = createSpinner("Default message");
325
+
326
+ spinner.start();
327
+ expect(() => spinner.succeed()).not.toThrow();
328
+ });
329
+ });