gitforest 0.1.0 → 1.0.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.
- package/LICENSE +21 -0
- package/package.json +24 -4
- package/src/github/auth.ts +3 -3
- package/src/utils/debug.ts +4 -4
- package/.bunignore +0 -7
- package/.github/workflows/ci.yml +0 -73
- package/CLAUDE.md +0 -111
- package/CONTRIBUTING.md +0 -145
- package/bun.lock +0 -267
- package/bunfig.toml +0 -15
- package/cli +0 -0
- package/docs/ai/IMPROVEMENT_PLAN.md +0 -341
- package/docs/ai/VERIFICATION_REPORT.md +0 -87
- package/docs/ai/architecture.md +0 -169
- package/docs/ai/checks/check-2025-12-02-tests.md +0 -40
- package/docs/ai/checks/check-2025-12-02.md +0 -55
- package/docs/ai/checks/test-verification-report.md +0 -85
- package/docs/ai/implementation-guide.md +0 -776
- package/docs/ai/research/gitty-codebase-analysis.md +0 -221
- package/docs/ai/tickets/GENERAL-sitrep.md +0 -30
- package/docs/ai/tickets/TASK-database-tests-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-deprecated-functions-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-detail-modal-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-filter-overlay-sitrep.md +0 -24
- package/docs/ai/tickets/TASK-github-service-sitrep.md +0 -32
- package/docs/ai/tickets/TASK-github-token-sitrep.md +0 -51
- package/docs/ai/tickets/TASK-hascommits-sitrep.md +0 -35
- package/docs/ai/tickets/TASK-keybindings-sitrep.md +0 -26
- package/docs/ai/tickets/TASK-layout-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-markdown-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-project-item-sitrep.md +0 -79
- package/docs/ai/tickets/TASK-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-state-sitrep.md +0 -26
- package/docs/ai/tickets/TASK-types-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-unified-item-fix-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-001-sitrep.md +0 -24
- package/docs/ai/tickets/TKT-002-sitrep.md +0 -25
- package/docs/ai/tickets/TKT-003-git-service-refactoring-complete.md +0 -46
- package/docs/ai/tickets/TKT-003-git-service-refactoring-plan.md +0 -135
- package/docs/ai/tickets/TKT-003-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-004-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-005-sitrep.md +0 -25
- package/docs/ai/tickets/TKT-006-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-007-sitrep.md +0 -30
- package/docs/ai/tickets/TKT-008-sitrep.md +0 -32
- package/docs/ai/tickets/TKT-009-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-010-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-011-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-012-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-actions-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-actions-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-app-integration-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-background-fetch-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-background-fetch-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-batch-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-bun-test-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-cache-tests-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-cli-tests-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-clone-error-handling-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-commands-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-component-tests-1-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-configloader-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-confirm-dialog-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-coverage-sitrep.md +0 -95
- package/docs/ai/tickets/sitreps/TASK-database-tests-summary.md +0 -61
- package/docs/ai/tickets/sitreps/TASK-error-boundary-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-error-tests-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-errors-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-extract-reducer-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-filter-overlay-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-final-verification-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-fix-all-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-fix-hooks-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-fix-remaining-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-fix-test-failures-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-fix-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-formatters-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-git-timeouts-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-github-cache-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-githubcli-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-gitstatus-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-hooks-isolation-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-keybindings-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-layout-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-mock-factories-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-modal-tests-sitrep.md +0 -32
- package/docs/ai/tickets/sitreps/TASK-processbatch-fix-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-projectlist-tests-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-projectutils-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-scanner-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-select-all-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-shell-error-handling-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-store-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-test-fixes-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-test-summary-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-test-verification-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-testsuite-sitrep.md +0 -75
- package/docs/ai/tickets/sitreps/TASK-unified-reducer-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-unified-repos-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-unified-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-useprojects-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-utility-tests-sitrep.md +0 -32
- package/docs/ai/tickets/sitreps/TKT-003-git-service-refactoring-sitrep.md +0 -64
- package/docs/ai/tkt-001-fix-database-error.md +0 -217
- package/docs/ai/ui-enhancement-plan.md +0 -562
- package/test/integration/app.isolated.tsx +0 -240
- package/test/integration/cli-commands.test.ts +0 -287
- package/test/integration/cli-validation.test.ts +0 -264
- package/test/integration/git-operations.test.ts +0 -218
- package/test/integration/scanner.test.ts +0 -228
- package/test/preload.ts +0 -18
- package/test/unit/cli/commands.test.ts +0 -13
- package/test/unit/cli/formatters.test.ts +0 -1116
- package/test/unit/cli/github-commands.test.ts +0 -12
- package/test/unit/components/CloneDialog.test.tsx +0 -240
- package/test/unit/components/ColumnHeader.test.tsx +0 -128
- package/test/unit/components/CommandPalette.test.tsx +0 -355
- package/test/unit/components/ConfirmDialog.test.tsx +0 -111
- package/test/unit/components/ErrorBoundary.test.tsx +0 -139
- package/test/unit/components/FilterBar.test.tsx +0 -43
- package/test/unit/components/FilterOptionsOverlay.test.tsx +0 -197
- package/test/unit/components/HelpOverlay.test.tsx +0 -90
- package/test/unit/components/Layout.test.tsx +0 -328
- package/test/unit/components/MarkdownRenderer.test.tsx +0 -45
- package/test/unit/components/ProgressBar.test.tsx +0 -138
- package/test/unit/components/ProjectItem.test.tsx +0 -182
- package/test/unit/components/ProjectList.test.tsx +0 -311
- package/test/unit/components/RepoDetailModal.test.tsx +0 -445
- package/test/unit/components/StatusBar.test.tsx +0 -112
- package/test/unit/components/UnifiedProjectItem.test.tsx +0 -618
- package/test/unit/components/ViewModeIndicator.test.tsx +0 -137
- package/test/unit/components/test-utils.tsx +0 -63
- package/test/unit/config/loader.test.ts +0 -692
- package/test/unit/db/database.test.ts +0 -978
- package/test/unit/db/index.test.ts +0 -314
- package/test/unit/fixtures/setup.ts +0 -186
- package/test/unit/git/commands-untested.test.ts +0 -205
- package/test/unit/git/commands.test.ts +0 -269
- package/test/unit/git/operations.test.ts +0 -322
- package/test/unit/git/status.test.ts +0 -219
- package/test/unit/github/auth.test.ts +0 -317
- package/test/unit/github/cache.test.ts +0 -1028
- package/test/unit/github/cli.test.ts +0 -135
- package/test/unit/github/unified.test.ts +0 -1201
- package/test/unit/graceful-shutdown.test.ts +0 -83
- package/test/unit/hooks/useBackgroundFetch.test.tsx +0 -239
- package/test/unit/hooks/useConfirmDialogActions.test.tsx +0 -81
- package/test/unit/hooks/useKeyBindings.isolated.ts +0 -715
- package/test/unit/hooks/useProjects.test.tsx +0 -186
- package/test/unit/hooks/useUnifiedRepos-simple.test.tsx +0 -115
- package/test/unit/hooks/useUnifiedRepos.test.tsx +0 -177
- package/test/unit/mocks/config.ts +0 -109
- package/test/unit/mocks/git-service.ts +0 -274
- package/test/unit/mocks/github-service.ts +0 -250
- package/test/unit/mocks/index.ts +0 -72
- package/test/unit/mocks/project.ts +0 -148
- package/test/unit/mocks/state-mocks.ts +0 -187
- package/test/unit/mocks/unified.ts +0 -169
- package/test/unit/operations/batch.test.ts +0 -216
- package/test/unit/operations/commands.test.ts +0 -550
- package/test/unit/scanner/errors.test.ts +0 -297
- package/test/unit/scanner/index.test.ts +0 -1011
- package/test/unit/scanner/markers.test.ts +0 -150
- package/test/unit/scanner/submodules.test.ts +0 -99
- package/test/unit/services/git-errors.test.ts +0 -190
- package/test/unit/services/git.test.ts +0 -442
- package/test/unit/services/github-errors.test.ts +0 -293
- package/test/unit/services/github.test.ts +0 -200
- package/test/unit/state/actions.test.ts +0 -217
- package/test/unit/state/reducer.test.ts +0 -745
- package/test/unit/state/store.test.tsx +0 -711
- package/test/unit/types/commands.test.ts +0 -220
- package/test/unit/types/schema.test.ts +0 -179
- package/test/unit/utils/array.test.ts +0 -73
- package/test/unit/utils/debug.test.ts +0 -23
- package/test/unit/utils/errors.test.ts +0 -295
- package/test/unit/utils/markdown.test.ts +0 -163
- package/test/unit/utils/project-utils.test.ts +0 -756
- package/test/unit/utils/rate-limiter.test.ts +0 -256
- package/test/unit/utils/retry.test.ts +0 -165
- package/test/unit/utils/strip-ansi.ts +0 -13
- package/test/unit/utils/timeout.test.ts +0 -93
- package/tsconfig.json +0 -29
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
2
|
-
import { executeCommand, findCommandByKey, batchExecuteCommand } from "../../../src/operations/commands.ts";
|
|
3
|
-
import type { CommandConfig } from "../../../src/types/index.ts";
|
|
4
|
-
import { mkdtemp, rm } from "fs/promises";
|
|
5
|
-
import { tmpdir } from "os";
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
|
|
8
|
-
describe("commands", () => {
|
|
9
|
-
let tempDir: string;
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
tempDir = await mkdtemp(join(tmpdir(), "gitforest-test-"));
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("executeCommand", () => {
|
|
20
|
-
test("executes a simple command successfully", async () => {
|
|
21
|
-
const command: CommandConfig = {
|
|
22
|
-
name: "Echo Test",
|
|
23
|
-
key: "e",
|
|
24
|
-
command: "echo 'hello world'",
|
|
25
|
-
confirm: false,
|
|
26
|
-
background: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const result = await executeCommand(command, tempDir);
|
|
30
|
-
|
|
31
|
-
expect(result.success).toBe(true);
|
|
32
|
-
expect(result.output).toBe("hello world");
|
|
33
|
-
expect(result.command).toBe("Echo Test");
|
|
34
|
-
expect(result.projectPath).toBe(tempDir);
|
|
35
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("executes command in the correct directory", async () => {
|
|
39
|
-
const command: CommandConfig = {
|
|
40
|
-
name: "PWD Test",
|
|
41
|
-
key: "p",
|
|
42
|
-
command: "pwd",
|
|
43
|
-
confirm: false,
|
|
44
|
-
background: false,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const result = await executeCommand(command, tempDir);
|
|
48
|
-
|
|
49
|
-
expect(result.success).toBe(true);
|
|
50
|
-
expect(result.output).toBe(tempDir);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("handles command failure", async () => {
|
|
54
|
-
const command: CommandConfig = {
|
|
55
|
-
name: "Fail Test",
|
|
56
|
-
key: "f",
|
|
57
|
-
command: "exit 1",
|
|
58
|
-
confirm: false,
|
|
59
|
-
background: false,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const result = await executeCommand(command, tempDir);
|
|
63
|
-
|
|
64
|
-
expect(result.success).toBe(false);
|
|
65
|
-
expect(result.error).toBeDefined();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("handles non-existent command", async () => {
|
|
69
|
-
const command: CommandConfig = {
|
|
70
|
-
name: "Bad Command",
|
|
71
|
-
key: "b",
|
|
72
|
-
command: "nonexistent_command_xyz",
|
|
73
|
-
confirm: false,
|
|
74
|
-
background: false,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const result = await executeCommand(command, tempDir);
|
|
78
|
-
|
|
79
|
-
expect(result.success).toBe(false);
|
|
80
|
-
expect(result.error).toBeDefined();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("expands environment variables", async () => {
|
|
84
|
-
process.env.TEST_VAR = "test_value";
|
|
85
|
-
|
|
86
|
-
const command: CommandConfig = {
|
|
87
|
-
name: "Env Test",
|
|
88
|
-
key: "v",
|
|
89
|
-
command: "echo $TEST_VAR",
|
|
90
|
-
confirm: false,
|
|
91
|
-
background: false,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const result = await executeCommand(command, tempDir);
|
|
95
|
-
|
|
96
|
-
expect(result.success).toBe(true);
|
|
97
|
-
expect(result.output).toBe("test_value");
|
|
98
|
-
|
|
99
|
-
delete process.env.TEST_VAR;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("handles background execution", async () => {
|
|
103
|
-
const command: CommandConfig = {
|
|
104
|
-
name: "Background Test",
|
|
105
|
-
key: "g",
|
|
106
|
-
command: "sleep 0.1",
|
|
107
|
-
confirm: false,
|
|
108
|
-
background: true,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const result = await executeCommand(command, tempDir);
|
|
112
|
-
|
|
113
|
-
expect(result.success).toBe(true);
|
|
114
|
-
expect(result.output).toBe("Started in background");
|
|
115
|
-
expect(result.duration).toBeLessThan(100); // Should return immediately
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("returns success: false on command failure", async () => {
|
|
119
|
-
const command: CommandConfig = {
|
|
120
|
-
name: "Fail Command",
|
|
121
|
-
key: "f",
|
|
122
|
-
command: "exit 1",
|
|
123
|
-
confirm: false,
|
|
124
|
-
background: false,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const result = await executeCommand(command, tempDir);
|
|
128
|
-
|
|
129
|
-
expect(result.success).toBe(false);
|
|
130
|
-
expect(result.error).toBeDefined();
|
|
131
|
-
expect(result.error).toContain("Command exited with code 1");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("handles command that exits with non-zero code", async () => {
|
|
135
|
-
const command: CommandConfig = {
|
|
136
|
-
name: "Non-zero Exit",
|
|
137
|
-
key: "n",
|
|
138
|
-
command: "test -f nonexistent.txt",
|
|
139
|
-
confirm: false,
|
|
140
|
-
background: false,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const result = await executeCommand(command, tempDir);
|
|
144
|
-
|
|
145
|
-
expect(result.success).toBe(false);
|
|
146
|
-
expect(result.error).toBeDefined();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("expands $PWD to project path", async () => {
|
|
150
|
-
const command: CommandConfig = {
|
|
151
|
-
name: "PWD Expansion Test",
|
|
152
|
-
key: "p",
|
|
153
|
-
command: "echo $PWD",
|
|
154
|
-
confirm: false,
|
|
155
|
-
background: false,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const result = await executeCommand(command, tempDir);
|
|
159
|
-
|
|
160
|
-
expect(result.success).toBe(true);
|
|
161
|
-
expect(result.output).toBe(tempDir);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("expands other environment variables", async () => {
|
|
165
|
-
process.env.CUSTOM_VAR = "custom_value";
|
|
166
|
-
|
|
167
|
-
const command: CommandConfig = {
|
|
168
|
-
name: "Custom Env Var Test",
|
|
169
|
-
key: "v",
|
|
170
|
-
command: "echo $CUSTOM_VAR",
|
|
171
|
-
confirm: false,
|
|
172
|
-
background: false,
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const result = await executeCommand(command, tempDir);
|
|
176
|
-
|
|
177
|
-
expect(result.success).toBe(true);
|
|
178
|
-
expect(result.output).toBe("custom_value");
|
|
179
|
-
|
|
180
|
-
delete process.env.CUSTOM_VAR;
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test("handles ${VAR} syntax", async () => {
|
|
184
|
-
process.env.BRACKET_VAR = "bracket_value";
|
|
185
|
-
|
|
186
|
-
const command: CommandConfig = {
|
|
187
|
-
name: "Bracket Syntax Test",
|
|
188
|
-
key: "b",
|
|
189
|
-
command: "echo ${BRACKET_VAR}",
|
|
190
|
-
confirm: false,
|
|
191
|
-
background: false,
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const result = await executeCommand(command, tempDir);
|
|
195
|
-
|
|
196
|
-
expect(result.success).toBe(true);
|
|
197
|
-
expect(result.output).toBe("bracket_value");
|
|
198
|
-
|
|
199
|
-
delete process.env.BRACKET_VAR;
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test("handles mixed environment variables", async () => {
|
|
203
|
-
process.env.MIXED_VAR = "mixed";
|
|
204
|
-
|
|
205
|
-
const command: CommandConfig = {
|
|
206
|
-
name: "Mixed Env Test",
|
|
207
|
-
key: "m",
|
|
208
|
-
command: "echo $MIXED_VAR-${PWD}-end",
|
|
209
|
-
confirm: false,
|
|
210
|
-
background: false,
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const result = await executeCommand(command, tempDir);
|
|
214
|
-
|
|
215
|
-
expect(result.success).toBe(true);
|
|
216
|
-
expect(result.output).toBe(`mixed-${tempDir}-end`);
|
|
217
|
-
|
|
218
|
-
delete process.env.MIXED_VAR;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test("handles background mode option override", async () => {
|
|
222
|
-
const command: CommandConfig = {
|
|
223
|
-
name: "Background Override Test",
|
|
224
|
-
key: "o",
|
|
225
|
-
command: "sleep 0.1",
|
|
226
|
-
confirm: false,
|
|
227
|
-
background: false, // Command says not background
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// But override to background
|
|
231
|
-
const result = await executeCommand(command, tempDir, { background: true });
|
|
232
|
-
|
|
233
|
-
expect(result.success).toBe(true);
|
|
234
|
-
expect(result.output).toBe("Started in background");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test("handles command exceptions", async () => {
|
|
238
|
-
const command: CommandConfig = {
|
|
239
|
-
name: "Exception Test",
|
|
240
|
-
key: "x",
|
|
241
|
-
command: "echo 'test' > /root/cannot_write_here.txt",
|
|
242
|
-
confirm: false,
|
|
243
|
-
background: false,
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const result = await executeCommand(command, tempDir);
|
|
247
|
-
|
|
248
|
-
expect(result.success).toBe(false);
|
|
249
|
-
expect(result.error).toBeDefined();
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("measures duration correctly", async () => {
|
|
253
|
-
const command: CommandConfig = {
|
|
254
|
-
name: "Duration Test",
|
|
255
|
-
key: "d",
|
|
256
|
-
command: "sleep 0.2",
|
|
257
|
-
confirm: false,
|
|
258
|
-
background: false,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const result = await executeCommand(command, tempDir);
|
|
262
|
-
|
|
263
|
-
expect(result.success).toBe(true);
|
|
264
|
-
expect(result.duration).toBeGreaterThanOrEqual(200);
|
|
265
|
-
expect(result.duration).toBeLessThan(300);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
test("uses correct working directory", async () => {
|
|
269
|
-
// Create a subdirectory
|
|
270
|
-
const subDir = join(tempDir, "subdir");
|
|
271
|
-
await Bun.$`mkdir -p ${subDir}`;
|
|
272
|
-
|
|
273
|
-
const command: CommandConfig = {
|
|
274
|
-
name: "Working Dir Test",
|
|
275
|
-
key: "w",
|
|
276
|
-
command: "pwd",
|
|
277
|
-
confirm: false,
|
|
278
|
-
background: false,
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
const result = await executeCommand(command, subDir);
|
|
282
|
-
|
|
283
|
-
expect(result.success).toBe(true);
|
|
284
|
-
expect(result.output).toBe(subDir);
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
describe("findCommandByKey", () => {
|
|
289
|
-
const commands: CommandConfig[] = [
|
|
290
|
-
{ name: "Open Editor", key: "e", command: "code .", confirm: false, background: false },
|
|
291
|
-
{ name: "Run Tests", key: "t", command: "bun test", confirm: false, background: false },
|
|
292
|
-
{ name: "Build", key: "b", command: "bun run build", confirm: false, background: false },
|
|
293
|
-
];
|
|
294
|
-
|
|
295
|
-
test("finds command by key", () => {
|
|
296
|
-
const result = findCommandByKey(commands, "t");
|
|
297
|
-
|
|
298
|
-
expect(result).toBeDefined();
|
|
299
|
-
expect(result?.name).toBe("Run Tests");
|
|
300
|
-
expect(result?.command).toBe("bun test");
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test("returns undefined for non-existent key", () => {
|
|
304
|
-
const result = findCommandByKey(commands, "z");
|
|
305
|
-
|
|
306
|
-
expect(result).toBeUndefined();
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
test("handles empty commands array", () => {
|
|
310
|
-
const result = findCommandByKey([], "e");
|
|
311
|
-
|
|
312
|
-
expect(result).toBeUndefined();
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
test("returns first match if duplicates exist", () => {
|
|
316
|
-
const commands: CommandConfig[] = [
|
|
317
|
-
{ name: "First Command", key: "d", command: "echo first", confirm: false, background: false },
|
|
318
|
-
{ name: "Duplicate Command", key: "d", command: "echo duplicate", confirm: false, background: false },
|
|
319
|
-
{ name: "Third Command", key: "t", command: "echo third", confirm: false, background: false },
|
|
320
|
-
];
|
|
321
|
-
|
|
322
|
-
const result = findCommandByKey(commands, "d");
|
|
323
|
-
|
|
324
|
-
expect(result).toBeDefined();
|
|
325
|
-
expect(result?.name).toBe("First Command");
|
|
326
|
-
expect(result?.command).toBe("echo first");
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
test("handles undefined commands array", () => {
|
|
330
|
-
const result = findCommandByKey(undefined as any, "e");
|
|
331
|
-
|
|
332
|
-
expect(result).toBeUndefined();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test("handles null commands array", () => {
|
|
336
|
-
const result = findCommandByKey(null as any, "e");
|
|
337
|
-
|
|
338
|
-
expect(result).toBeUndefined();
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe("batchExecuteCommand", () => {
|
|
343
|
-
test("executes command on multiple projects", async () => {
|
|
344
|
-
// Create multiple temp directories
|
|
345
|
-
const dir1 = await mkdtemp(join(tmpdir(), "gitforest-batch-1-"));
|
|
346
|
-
const dir2 = await mkdtemp(join(tmpdir(), "gitforest-batch-2-"));
|
|
347
|
-
|
|
348
|
-
const command: CommandConfig = {
|
|
349
|
-
name: "Batch Echo",
|
|
350
|
-
key: "e",
|
|
351
|
-
command: "echo 'batch test'",
|
|
352
|
-
confirm: false,
|
|
353
|
-
background: false,
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
const results = await batchExecuteCommand(command, [dir1, dir2]);
|
|
357
|
-
|
|
358
|
-
expect(results).toHaveLength(2);
|
|
359
|
-
expect(results[0]!.success).toBe(true);
|
|
360
|
-
expect(results[1]!.success).toBe(true);
|
|
361
|
-
expect(results[0]!.output).toBe("batch test");
|
|
362
|
-
expect(results[1]!.output).toBe("batch test");
|
|
363
|
-
|
|
364
|
-
// Cleanup
|
|
365
|
-
await rm(dir1, { recursive: true, force: true });
|
|
366
|
-
await rm(dir2, { recursive: true, force: true });
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
test("reports progress", async () => {
|
|
370
|
-
const dir1 = await mkdtemp(join(tmpdir(), "gitforest-progress-1-"));
|
|
371
|
-
const dir2 = await mkdtemp(join(tmpdir(), "gitforest-progress-2-"));
|
|
372
|
-
|
|
373
|
-
const command: CommandConfig = {
|
|
374
|
-
name: "Progress Test",
|
|
375
|
-
key: "p",
|
|
376
|
-
command: "echo 'progress'",
|
|
377
|
-
confirm: false,
|
|
378
|
-
background: false,
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const progressCalls: { current: number; total: number }[] = [];
|
|
382
|
-
|
|
383
|
-
await batchExecuteCommand(command, [dir1, dir2], {
|
|
384
|
-
concurrency: 1,
|
|
385
|
-
onProgress: (current, total) => {
|
|
386
|
-
progressCalls.push({ current, total });
|
|
387
|
-
},
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
expect(progressCalls.length).toBeGreaterThan(0);
|
|
391
|
-
expect(progressCalls[progressCalls.length - 1]!.current).toBe(2);
|
|
392
|
-
expect(progressCalls[progressCalls.length - 1]!.total).toBe(2);
|
|
393
|
-
|
|
394
|
-
// Cleanup
|
|
395
|
-
await rm(dir1, { recursive: true, force: true });
|
|
396
|
-
await rm(dir2, { recursive: true, force: true });
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
test("respects concurrency option", async () => {
|
|
400
|
-
const dirs = await Promise.all(
|
|
401
|
-
Array.from({ length: 5 }, (_, i) => mkdtemp(join(tmpdir(), `gitforest-concurrency-${i}-`)))
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
const command: CommandConfig = {
|
|
405
|
-
name: "Concurrency Test",
|
|
406
|
-
key: "c",
|
|
407
|
-
command: "sleep 0.1",
|
|
408
|
-
confirm: false,
|
|
409
|
-
background: false,
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
const startTime = Date.now();
|
|
413
|
-
const results = await batchExecuteCommand(command, dirs, { concurrency: 2 });
|
|
414
|
-
const duration = Date.now() - startTime;
|
|
415
|
-
|
|
416
|
-
expect(results).toHaveLength(5);
|
|
417
|
-
expect(results.every(r => r.success)).toBe(true);
|
|
418
|
-
// With concurrency 2, should take at least 300ms (3 batches of 2, 2, 1)
|
|
419
|
-
expect(duration).toBeGreaterThanOrEqual(250);
|
|
420
|
-
|
|
421
|
-
// Cleanup
|
|
422
|
-
await Promise.all(dirs.map(dir => rm(dir, { recursive: true, force: true })));
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
test("returns results for all projects", async () => {
|
|
426
|
-
const dirs = await Promise.all(
|
|
427
|
-
Array.from({ length: 3 }, (_, i) => mkdtemp(join(tmpdir(), `gitforest-results-${i}-`)))
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
const command: CommandConfig = {
|
|
431
|
-
name: "Results Test",
|
|
432
|
-
key: "r",
|
|
433
|
-
command: "pwd",
|
|
434
|
-
confirm: false,
|
|
435
|
-
background: false,
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const results = await batchExecuteCommand(command, dirs);
|
|
439
|
-
|
|
440
|
-
expect(results).toHaveLength(3);
|
|
441
|
-
for (let i = 0; i < results.length; i++) {
|
|
442
|
-
const result = results[i]!;
|
|
443
|
-
const dir = dirs[i]!;
|
|
444
|
-
expect(result.success).toBe(true);
|
|
445
|
-
expect(result.projectPath).toBe(dir);
|
|
446
|
-
// Check that output is defined (pwd command should output the directory path)
|
|
447
|
-
const output = result.output;
|
|
448
|
-
expect(output).toBeDefined();
|
|
449
|
-
expect(typeof output).toBe('string');
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Cleanup
|
|
453
|
-
await Promise.all(dirs.map(dir => rm(dir, { recursive: true, force: true })));
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
test("handles mixed success/failure", async () => {
|
|
457
|
-
const dir1 = await mkdtemp(join(tmpdir(), "gitforest-mixed-1-"));
|
|
458
|
-
const dir2 = await mkdtemp(join(tmpdir(), "gitforest-mixed-2-"));
|
|
459
|
-
|
|
460
|
-
const command: CommandConfig = {
|
|
461
|
-
name: "Mixed Results Test",
|
|
462
|
-
key: "m",
|
|
463
|
-
command: "test -d subdir",
|
|
464
|
-
confirm: false,
|
|
465
|
-
background: false,
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// Create subdir in only one of the directories
|
|
469
|
-
await Bun.$`mkdir -p ${join(dir1, "subdir")}`;
|
|
470
|
-
|
|
471
|
-
const results = await batchExecuteCommand(command, [dir1, dir2]);
|
|
472
|
-
|
|
473
|
-
expect(results).toHaveLength(2);
|
|
474
|
-
expect(results[0]!.success).toBe(true); // dir1 has subdir
|
|
475
|
-
expect(results[1]!.success).toBe(false); // dir2 doesn't have subdir
|
|
476
|
-
|
|
477
|
-
// Cleanup
|
|
478
|
-
await rm(dir1, { recursive: true, force: true });
|
|
479
|
-
await rm(dir2, { recursive: true, force: true });
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
test("handles empty project paths array", async () => {
|
|
483
|
-
const command: CommandConfig = {
|
|
484
|
-
name: "Empty Test",
|
|
485
|
-
key: "e",
|
|
486
|
-
command: "echo 'test'",
|
|
487
|
-
confirm: false,
|
|
488
|
-
background: false,
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
const results = await batchExecuteCommand(command, []);
|
|
492
|
-
|
|
493
|
-
expect(results).toHaveLength(0);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
test("handles single project", async () => {
|
|
497
|
-
const dir = await mkdtemp(join(tmpdir(), "gitforest-single-"));
|
|
498
|
-
|
|
499
|
-
const command: CommandConfig = {
|
|
500
|
-
name: "Single Test",
|
|
501
|
-
key: "s",
|
|
502
|
-
command: "echo 'single'",
|
|
503
|
-
confirm: false,
|
|
504
|
-
background: false,
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
const results = await batchExecuteCommand(command, [dir]);
|
|
508
|
-
|
|
509
|
-
expect(results).toHaveLength(1);
|
|
510
|
-
expect(results[0]!.success).toBe(true);
|
|
511
|
-
expect(results[0]!.output).toBe("single");
|
|
512
|
-
|
|
513
|
-
// Cleanup
|
|
514
|
-
await rm(dir, { recursive: true, force: true });
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
test("calls onProgress for each batch", async () => {
|
|
518
|
-
const dirs = await Promise.all(
|
|
519
|
-
Array.from({ length: 7 }, (_, i) => mkdtemp(join(tmpdir(), `gitforest-progress-batch-${i}-`)))
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
const command: CommandConfig = {
|
|
523
|
-
name: "Progress Batch Test",
|
|
524
|
-
key: "p",
|
|
525
|
-
command: "echo 'progress'",
|
|
526
|
-
confirm: false,
|
|
527
|
-
background: false,
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
const progressCalls: { current: number; total: number }[] = [];
|
|
531
|
-
|
|
532
|
-
await batchExecuteCommand(command, dirs, {
|
|
533
|
-
concurrency: 3,
|
|
534
|
-
onProgress: (current, total) => {
|
|
535
|
-
progressCalls.push({ current, total });
|
|
536
|
-
},
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
// Should have 3 progress calls (batches of 3, 3, 1)
|
|
540
|
-
expect(progressCalls).toHaveLength(3);
|
|
541
|
-
expect(progressCalls[0]!.current).toBe(3);
|
|
542
|
-
expect(progressCalls[1]!.current).toBe(6);
|
|
543
|
-
expect(progressCalls[2]!.current).toBe(7);
|
|
544
|
-
expect(progressCalls.every(call => call.total === 7)).toBe(true);
|
|
545
|
-
|
|
546
|
-
// Cleanup
|
|
547
|
-
await Promise.all(dirs.map(dir => rm(dir, { recursive: true, force: true })));
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
});
|