gitforest 0.1.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/.bunignore +7 -0
- package/.github/workflows/ci.yml +73 -0
- package/CLAUDE.md +111 -0
- package/CONTRIBUTING.md +145 -0
- package/README.md +168 -0
- package/bun.lock +267 -0
- package/bunfig.toml +15 -0
- package/cli +0 -0
- package/config/gitforest.example.yaml +94 -0
- package/docs/ai/IMPROVEMENT_PLAN.md +341 -0
- package/docs/ai/VERIFICATION_REPORT.md +87 -0
- package/docs/ai/architecture.md +169 -0
- package/docs/ai/checks/check-2025-12-02-tests.md +40 -0
- package/docs/ai/checks/check-2025-12-02.md +55 -0
- package/docs/ai/checks/test-verification-report.md +85 -0
- package/docs/ai/implementation-guide.md +776 -0
- package/docs/ai/research/gitty-codebase-analysis.md +221 -0
- package/docs/ai/tickets/GENERAL-sitrep.md +30 -0
- package/docs/ai/tickets/TASK-database-tests-sitrep.md +25 -0
- package/docs/ai/tickets/TASK-deprecated-functions-sitrep.md +28 -0
- package/docs/ai/tickets/TASK-detail-modal-sitrep.md +28 -0
- package/docs/ai/tickets/TASK-filter-overlay-sitrep.md +24 -0
- package/docs/ai/tickets/TASK-github-service-sitrep.md +32 -0
- package/docs/ai/tickets/TASK-github-token-sitrep.md +51 -0
- package/docs/ai/tickets/TASK-hascommits-sitrep.md +35 -0
- package/docs/ai/tickets/TASK-keybindings-sitrep.md +26 -0
- package/docs/ai/tickets/TASK-layout-sitrep.md +25 -0
- package/docs/ai/tickets/TASK-markdown-sitrep.md +28 -0
- package/docs/ai/tickets/TASK-project-item-sitrep.md +79 -0
- package/docs/ai/tickets/TASK-sitrep.md +28 -0
- package/docs/ai/tickets/TASK-state-sitrep.md +26 -0
- package/docs/ai/tickets/TASK-types-sitrep.md +25 -0
- package/docs/ai/tickets/TASK-unified-item-fix-sitrep.md +26 -0
- package/docs/ai/tickets/TKT-001-sitrep.md +24 -0
- package/docs/ai/tickets/TKT-002-sitrep.md +25 -0
- package/docs/ai/tickets/TKT-003-git-service-refactoring-complete.md +46 -0
- package/docs/ai/tickets/TKT-003-git-service-refactoring-plan.md +135 -0
- package/docs/ai/tickets/TKT-003-sitrep.md +26 -0
- package/docs/ai/tickets/TKT-004-sitrep.md +27 -0
- package/docs/ai/tickets/TKT-005-sitrep.md +25 -0
- package/docs/ai/tickets/TKT-006-sitrep.md +26 -0
- package/docs/ai/tickets/TKT-007-sitrep.md +30 -0
- package/docs/ai/tickets/TKT-008-sitrep.md +32 -0
- package/docs/ai/tickets/TKT-009-sitrep.md +27 -0
- package/docs/ai/tickets/TKT-010-sitrep.md +27 -0
- package/docs/ai/tickets/TKT-011-sitrep.md +26 -0
- package/docs/ai/tickets/TKT-012-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-actions-sitrep.md +28 -0
- package/docs/ai/tickets/sitreps/TASK-actions-test-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-app-integration-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-background-fetch-sitrep.md +24 -0
- package/docs/ai/tickets/sitreps/TASK-background-fetch-test-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-batch-tests-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-bun-test-sitrep.md +26 -0
- package/docs/ai/tickets/sitreps/TASK-cache-tests-sitrep.md +30 -0
- package/docs/ai/tickets/sitreps/TASK-cli-tests-sitrep.md +28 -0
- package/docs/ai/tickets/sitreps/TASK-clone-error-handling-sitrep.md +26 -0
- package/docs/ai/tickets/sitreps/TASK-commands-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-component-tests-1-sitrep.md +30 -0
- package/docs/ai/tickets/sitreps/TASK-configloader-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-confirm-dialog-test-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-coverage-sitrep.md +95 -0
- package/docs/ai/tickets/sitreps/TASK-database-tests-summary.md +61 -0
- package/docs/ai/tickets/sitreps/TASK-error-boundary-sitrep.md +30 -0
- package/docs/ai/tickets/sitreps/TASK-error-tests-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-errors-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-extract-reducer-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-filter-overlay-test-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-final-verification-sitrep.md +28 -0
- package/docs/ai/tickets/sitreps/TASK-fix-all-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-fix-hooks-sitrep.md +26 -0
- package/docs/ai/tickets/sitreps/TASK-fix-remaining-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-fix-test-failures-sitrep.md +26 -0
- package/docs/ai/tickets/sitreps/TASK-fix-tests-sitrep.md +24 -0
- package/docs/ai/tickets/sitreps/TASK-formatters-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-git-timeouts-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-github-cache-test-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-githubcli-tests-sitrep.md +24 -0
- package/docs/ai/tickets/sitreps/TASK-gitstatus-tests-sitrep.md +24 -0
- package/docs/ai/tickets/sitreps/TASK-hooks-isolation-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-keybindings-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-layout-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-mock-factories-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-modal-tests-sitrep.md +32 -0
- package/docs/ai/tickets/sitreps/TASK-processbatch-fix-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-projectlist-tests-sitrep.md +30 -0
- package/docs/ai/tickets/sitreps/TASK-projectutils-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-scanner-tests-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-select-all-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-shell-error-handling-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-store-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-test-fixes-sitrep.md +26 -0
- package/docs/ai/tickets/sitreps/TASK-test-summary-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-test-verification-sitrep.md +27 -0
- package/docs/ai/tickets/sitreps/TASK-testsuite-sitrep.md +75 -0
- package/docs/ai/tickets/sitreps/TASK-unified-reducer-tests-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-unified-repos-test-sitrep.md +29 -0
- package/docs/ai/tickets/sitreps/TASK-unified-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-useprojects-tests-sitrep.md +25 -0
- package/docs/ai/tickets/sitreps/TASK-utility-tests-sitrep.md +32 -0
- package/docs/ai/tickets/sitreps/TKT-003-git-service-refactoring-sitrep.md +64 -0
- package/docs/ai/tkt-001-fix-database-error.md +217 -0
- package/docs/ai/ui-enhancement-plan.md +562 -0
- package/package.json +50 -0
- package/src/app.tsx +43 -0
- package/src/cli/config.ts +94 -0
- package/src/cli/formatters.ts +632 -0
- package/src/cli/index.ts +583 -0
- package/src/components/CloneDialog.tsx +137 -0
- package/src/components/ColumnHeader.tsx +128 -0
- package/src/components/CommandPalette.tsx +120 -0
- package/src/components/ConfirmDialog.tsx +105 -0
- package/src/components/ErrorBoundary.tsx +128 -0
- package/src/components/FilterBar.tsx +71 -0
- package/src/components/FilterOptionsOverlay.tsx +131 -0
- package/src/components/HelpOverlay.tsx +120 -0
- package/src/components/Layout.tsx +379 -0
- package/src/components/MarkdownRenderer.tsx +127 -0
- package/src/components/ProgressBar.tsx +53 -0
- package/src/components/ProjectItem.tsx +143 -0
- package/src/components/ProjectList.tsx +90 -0
- package/src/components/RepoDetailModal.tsx +367 -0
- package/src/components/StatusBar.tsx +188 -0
- package/src/components/UnifiedProjectItem.tsx +436 -0
- package/src/components/ViewModeIndicator.tsx +37 -0
- package/src/components/onboarding/CompleteStep.tsx +82 -0
- package/src/components/onboarding/DirectoriesStep.test.tsx +52 -0
- package/src/components/onboarding/DirectoriesStep.tsx +847 -0
- package/src/components/onboarding/DirectoriesStep.unit.test.ts +345 -0
- package/src/components/onboarding/GitHubAuthStep.tsx +268 -0
- package/src/components/onboarding/OnboardingWizard.tsx +130 -0
- package/src/components/onboarding/WelcomeStep.tsx +69 -0
- package/src/config/loader.ts +263 -0
- package/src/config/onboarding.ts +67 -0
- package/src/constants.ts +96 -0
- package/src/db/index.ts +147 -0
- package/src/db/schema.ts +70 -0
- package/src/git/commands.ts +283 -0
- package/src/git/index.ts +2 -0
- package/src/git/operations.ts +93 -0
- package/src/git/service.ts +539 -0
- package/src/git/status.ts +84 -0
- package/src/git/types.ts +5 -0
- package/src/github/auth.ts +311 -0
- package/src/github/cache.ts +231 -0
- package/src/github/cli.ts +22 -0
- package/src/github/unified.ts +415 -0
- package/src/hooks/useBackgroundFetch.ts +76 -0
- package/src/hooks/useConfirmDialogActions.ts +120 -0
- package/src/hooks/useKeyBindings.ts +656 -0
- package/src/hooks/useProjects.ts +47 -0
- package/src/hooks/useUnifiedRepos.ts +317 -0
- package/src/index.tsx +494 -0
- package/src/operations/batch.ts +280 -0
- package/src/operations/commands.ts +140 -0
- package/src/operations/index.ts +37 -0
- package/src/scanner/index.ts +424 -0
- package/src/scanner/markers.ts +43 -0
- package/src/scanner/submodules.ts +61 -0
- package/src/services/git.ts +484 -0
- package/src/services/github.ts +676 -0
- package/src/services/index.ts +28 -0
- package/src/services/types.ts +99 -0
- package/src/state/actions.ts +175 -0
- package/src/state/reducer.ts +294 -0
- package/src/state/store.tsx +216 -0
- package/src/state/types.ts +8 -0
- package/src/types/index.ts +383 -0
- package/src/ui/theme.ts +44 -0
- package/src/utils/array.ts +14 -0
- package/src/utils/debug.ts +38 -0
- package/src/utils/errors.ts +17 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/markdown.ts +230 -0
- package/src/utils/project-utils.ts +129 -0
- package/src/utils/rate-limiter.ts +134 -0
- package/src/utils/retry.ts +147 -0
- package/src/utils/timeout.ts +56 -0
- package/test/integration/app.isolated.tsx +240 -0
- package/test/integration/cli-commands.test.ts +287 -0
- package/test/integration/cli-validation.test.ts +264 -0
- package/test/integration/git-operations.test.ts +218 -0
- package/test/integration/scanner.test.ts +228 -0
- package/test/preload.ts +18 -0
- package/test/unit/cli/commands.test.ts +13 -0
- package/test/unit/cli/formatters.test.ts +1116 -0
- package/test/unit/cli/github-commands.test.ts +12 -0
- package/test/unit/components/CloneDialog.test.tsx +240 -0
- package/test/unit/components/ColumnHeader.test.tsx +128 -0
- package/test/unit/components/CommandPalette.test.tsx +355 -0
- package/test/unit/components/ConfirmDialog.test.tsx +111 -0
- package/test/unit/components/ErrorBoundary.test.tsx +139 -0
- package/test/unit/components/FilterBar.test.tsx +43 -0
- package/test/unit/components/FilterOptionsOverlay.test.tsx +197 -0
- package/test/unit/components/HelpOverlay.test.tsx +90 -0
- package/test/unit/components/Layout.test.tsx +328 -0
- package/test/unit/components/MarkdownRenderer.test.tsx +45 -0
- package/test/unit/components/ProgressBar.test.tsx +138 -0
- package/test/unit/components/ProjectItem.test.tsx +182 -0
- package/test/unit/components/ProjectList.test.tsx +311 -0
- package/test/unit/components/RepoDetailModal.test.tsx +445 -0
- package/test/unit/components/StatusBar.test.tsx +112 -0
- package/test/unit/components/UnifiedProjectItem.test.tsx +618 -0
- package/test/unit/components/ViewModeIndicator.test.tsx +137 -0
- package/test/unit/components/test-utils.tsx +63 -0
- package/test/unit/config/loader.test.ts +692 -0
- package/test/unit/db/database.test.ts +978 -0
- package/test/unit/db/index.test.ts +314 -0
- package/test/unit/fixtures/setup.ts +186 -0
- package/test/unit/git/commands-untested.test.ts +205 -0
- package/test/unit/git/commands.test.ts +269 -0
- package/test/unit/git/operations.test.ts +322 -0
- package/test/unit/git/status.test.ts +219 -0
- package/test/unit/github/auth.test.ts +317 -0
- package/test/unit/github/cache.test.ts +1028 -0
- package/test/unit/github/cli.test.ts +135 -0
- package/test/unit/github/unified.test.ts +1201 -0
- package/test/unit/graceful-shutdown.test.ts +83 -0
- package/test/unit/hooks/useBackgroundFetch.test.tsx +239 -0
- package/test/unit/hooks/useConfirmDialogActions.test.tsx +81 -0
- package/test/unit/hooks/useKeyBindings.isolated.ts +715 -0
- package/test/unit/hooks/useProjects.test.tsx +186 -0
- package/test/unit/hooks/useUnifiedRepos-simple.test.tsx +115 -0
- package/test/unit/hooks/useUnifiedRepos.test.tsx +177 -0
- package/test/unit/mocks/config.ts +109 -0
- package/test/unit/mocks/git-service.ts +274 -0
- package/test/unit/mocks/github-service.ts +250 -0
- package/test/unit/mocks/index.ts +72 -0
- package/test/unit/mocks/project.ts +148 -0
- package/test/unit/mocks/state-mocks.ts +187 -0
- package/test/unit/mocks/unified.ts +169 -0
- package/test/unit/operations/batch.test.ts +216 -0
- package/test/unit/operations/commands.test.ts +550 -0
- package/test/unit/scanner/errors.test.ts +297 -0
- package/test/unit/scanner/index.test.ts +1011 -0
- package/test/unit/scanner/markers.test.ts +150 -0
- package/test/unit/scanner/submodules.test.ts +99 -0
- package/test/unit/services/git-errors.test.ts +190 -0
- package/test/unit/services/git.test.ts +442 -0
- package/test/unit/services/github-errors.test.ts +293 -0
- package/test/unit/services/github.test.ts +200 -0
- package/test/unit/state/actions.test.ts +217 -0
- package/test/unit/state/reducer.test.ts +745 -0
- package/test/unit/state/store.test.tsx +711 -0
- package/test/unit/types/commands.test.ts +220 -0
- package/test/unit/types/schema.test.ts +179 -0
- package/test/unit/utils/array.test.ts +73 -0
- package/test/unit/utils/debug.test.ts +23 -0
- package/test/unit/utils/errors.test.ts +295 -0
- package/test/unit/utils/markdown.test.ts +163 -0
- package/test/unit/utils/project-utils.test.ts +756 -0
- package/test/unit/utils/rate-limiter.test.ts +256 -0
- package/test/unit/utils/retry.test.ts +165 -0
- package/test/unit/utils/strip-ansi.ts +13 -0
- package/test/unit/utils/timeout.test.ts +93 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for useProjects hook
|
|
3
|
+
*
|
|
4
|
+
* These tests focus on testing the helper functions (sortProjects, filterProjects)
|
|
5
|
+
* that are used by the hook, since they can be tested in isolation.
|
|
6
|
+
*
|
|
7
|
+
* The hook itself requires rendering in a React component context,
|
|
8
|
+
* which is done separately in integration tests.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, test, expect } from "bun:test";
|
|
12
|
+
import { sortProjects, filterProjects } from "../../../src/utils/project-utils.ts";
|
|
13
|
+
import {
|
|
14
|
+
createMockProject,
|
|
15
|
+
createDirtyProject,
|
|
16
|
+
createAheadProject,
|
|
17
|
+
createNonGitProject,
|
|
18
|
+
} from "../mocks/index.ts";
|
|
19
|
+
|
|
20
|
+
describe("useProjects helpers", () => {
|
|
21
|
+
describe("sortProjects", () => {
|
|
22
|
+
test("sorts by name ascending", () => {
|
|
23
|
+
const projects = [
|
|
24
|
+
createMockProject({ name: "zebra" }),
|
|
25
|
+
createMockProject({ name: "alpha" }),
|
|
26
|
+
createMockProject({ name: "mango" }),
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const sorted = sortProjects(projects, "name", "asc");
|
|
30
|
+
|
|
31
|
+
expect(sorted[0]?.name).toBe("alpha");
|
|
32
|
+
expect(sorted[1]?.name).toBe("mango");
|
|
33
|
+
expect(sorted[2]?.name).toBe("zebra");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("sorts by name descending", () => {
|
|
37
|
+
const projects = [
|
|
38
|
+
createMockProject({ name: "alpha" }),
|
|
39
|
+
createMockProject({ name: "zebra" }),
|
|
40
|
+
createMockProject({ name: "mango" }),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const sorted = sortProjects(projects, "name", "desc");
|
|
44
|
+
|
|
45
|
+
expect(sorted[0]?.name).toBe("zebra");
|
|
46
|
+
expect(sorted[1]?.name).toBe("mango");
|
|
47
|
+
expect(sorted[2]?.name).toBe("alpha");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("sorts by status (dirty repos first)", () => {
|
|
51
|
+
const projects = [
|
|
52
|
+
createMockProject({ name: "clean" }),
|
|
53
|
+
createDirtyProject("dirty"),
|
|
54
|
+
createAheadProject("ahead"),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const sorted = sortProjects(projects, "status", "desc");
|
|
58
|
+
|
|
59
|
+
// Dirty should come first, then ahead, then clean
|
|
60
|
+
expect(sorted[0]?.name).toBe("dirty");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("sorts by status (ahead repos before clean)", () => {
|
|
64
|
+
const projects = [
|
|
65
|
+
createMockProject({ name: "clean" }),
|
|
66
|
+
createAheadProject("ahead"),
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const sorted = sortProjects(projects, "status", "desc");
|
|
70
|
+
|
|
71
|
+
expect(sorted[0]?.name).toBe("ahead");
|
|
72
|
+
expect(sorted[1]?.name).toBe("clean");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("non-git projects sort last by status", () => {
|
|
76
|
+
const projects = [
|
|
77
|
+
createNonGitProject("non-git"),
|
|
78
|
+
createMockProject({ name: "git" }),
|
|
79
|
+
createDirtyProject("dirty"),
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const sorted = sortProjects(projects, "status", "desc");
|
|
83
|
+
|
|
84
|
+
// Non-git should be last
|
|
85
|
+
expect(sorted[sorted.length - 1]?.name).toBe("non-git");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("sorts by lastActivity with recent first (desc)", () => {
|
|
89
|
+
const now = new Date();
|
|
90
|
+
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
|
91
|
+
const lastWeek = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
|
92
|
+
|
|
93
|
+
const projects = [
|
|
94
|
+
createMockProject({ name: "old", status: { ...createMockProject().status!, lastLocalCommit: lastWeek } }),
|
|
95
|
+
createMockProject({ name: "recent", status: { ...createMockProject().status!, lastLocalCommit: now } }),
|
|
96
|
+
createMockProject({ name: "yesterday", status: { ...createMockProject().status!, lastLocalCommit: yesterday } }),
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const sorted = sortProjects(projects, "lastActivity", "desc");
|
|
100
|
+
|
|
101
|
+
expect(sorted[0]?.name).toBe("recent");
|
|
102
|
+
expect(sorted[1]?.name).toBe("yesterday");
|
|
103
|
+
expect(sorted[2]?.name).toBe("old");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("sorts by lastActivity with oldest first (asc)", () => {
|
|
107
|
+
const now = new Date();
|
|
108
|
+
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
|
109
|
+
const lastWeek = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
|
|
110
|
+
|
|
111
|
+
const projects = [
|
|
112
|
+
createMockProject({ name: "recent", status: { ...createMockProject().status!, lastLocalCommit: now } }),
|
|
113
|
+
createMockProject({ name: "old", status: { ...createMockProject().status!, lastLocalCommit: lastWeek } }),
|
|
114
|
+
createMockProject({ name: "yesterday", status: { ...createMockProject().status!, lastLocalCommit: yesterday } }),
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
const sorted = sortProjects(projects, "lastActivity", "asc");
|
|
118
|
+
|
|
119
|
+
expect(sorted[0]?.name).toBe("old");
|
|
120
|
+
expect(sorted[1]?.name).toBe("yesterday");
|
|
121
|
+
expect(sorted[2]?.name).toBe("recent");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("filterProjects", () => {
|
|
126
|
+
test("filters by name", () => {
|
|
127
|
+
const projects = [
|
|
128
|
+
createMockProject({ name: "my-project" }),
|
|
129
|
+
createMockProject({ name: "other-project" }),
|
|
130
|
+
createMockProject({ name: "my-app" }),
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
const filtered = filterProjects(projects, "my");
|
|
134
|
+
|
|
135
|
+
expect(filtered).toHaveLength(2);
|
|
136
|
+
expect(filtered.map((p) => p.name)).toContain("my-project");
|
|
137
|
+
expect(filtered.map((p) => p.name)).toContain("my-app");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("filters by path", () => {
|
|
141
|
+
const projects = [
|
|
142
|
+
createMockProject({ name: "project1", path: "/home/user/code/project1" }),
|
|
143
|
+
createMockProject({ name: "project2", path: "/home/user/work/project2" }),
|
|
144
|
+
createMockProject({ name: "project3", path: "/home/user/code/project3" }),
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const filtered = filterProjects(projects, "code");
|
|
148
|
+
|
|
149
|
+
expect(filtered).toHaveLength(2);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("filters case-insensitively", () => {
|
|
153
|
+
const projects = [
|
|
154
|
+
createMockProject({ name: "MyProject" }),
|
|
155
|
+
createMockProject({ name: "other" }),
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const filtered = filterProjects(projects, "myproject");
|
|
159
|
+
|
|
160
|
+
expect(filtered).toHaveLength(1);
|
|
161
|
+
expect(filtered[0]?.name).toBe("MyProject");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("returns all projects when filter is empty", () => {
|
|
165
|
+
const projects = [
|
|
166
|
+
createMockProject({ name: "project1" }),
|
|
167
|
+
createMockProject({ name: "project2" }),
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
const filtered = filterProjects(projects, "");
|
|
171
|
+
|
|
172
|
+
expect(filtered).toHaveLength(2);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("returns empty array when no matches", () => {
|
|
176
|
+
const projects = [
|
|
177
|
+
createMockProject({ name: "project1" }),
|
|
178
|
+
createMockProject({ name: "project2" }),
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const filtered = filterProjects(projects, "nonexistent");
|
|
182
|
+
|
|
183
|
+
expect(filtered).toHaveLength(0);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple tests for useUnifiedRepos related functionality
|
|
3
|
+
*
|
|
4
|
+
* These tests focus on helper functions that can be tested in isolation.
|
|
5
|
+
* The actual hook behavior is tested in integration tests.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, test, expect } from "bun:test";
|
|
9
|
+
import { createUnifiedView } from "../../../src/github/unified.ts";
|
|
10
|
+
import type { Project, GitHubRepoInfo } from "../../../src/types/index";
|
|
11
|
+
|
|
12
|
+
// Test helpers
|
|
13
|
+
function createMockProject(name: string, remoteUrl?: string): Project {
|
|
14
|
+
return {
|
|
15
|
+
id: `project-${name}`,
|
|
16
|
+
name,
|
|
17
|
+
path: `/test/${name}`,
|
|
18
|
+
type: "git",
|
|
19
|
+
lastScanned: new Date(),
|
|
20
|
+
lastModified: new Date(),
|
|
21
|
+
status: {
|
|
22
|
+
hasUnstagedChanges: false,
|
|
23
|
+
hasStagedChanges: false,
|
|
24
|
+
hasUntrackedFiles: false,
|
|
25
|
+
modifiedCount: 0,
|
|
26
|
+
stagedCount: 0,
|
|
27
|
+
untrackedCount: 0,
|
|
28
|
+
currentBranch: "main",
|
|
29
|
+
trackingBranch: "origin/main",
|
|
30
|
+
unpushedCommits: 0,
|
|
31
|
+
unpulledCommits: 0,
|
|
32
|
+
hasRemote: true,
|
|
33
|
+
remoteUrl: remoteUrl ?? `git@github.com:user/${name}.git`,
|
|
34
|
+
lastLocalCommit: new Date(),
|
|
35
|
+
lastRemoteActivity: new Date(),
|
|
36
|
+
hasCommits: true,
|
|
37
|
+
isDirty: false,
|
|
38
|
+
isAhead: false,
|
|
39
|
+
isBehind: false,
|
|
40
|
+
isOutOfSync: false,
|
|
41
|
+
},
|
|
42
|
+
projectMarker: null,
|
|
43
|
+
submodule: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createMockGitHubRepo(name: string, owner = "user"): GitHubRepoInfo {
|
|
48
|
+
return {
|
|
49
|
+
name,
|
|
50
|
+
fullName: `${owner}/${name}`,
|
|
51
|
+
owner,
|
|
52
|
+
description: `Test repo ${name}`,
|
|
53
|
+
htmlUrl: `https://github.com/${owner}/${name}`,
|
|
54
|
+
sshUrl: `git@github.com:${owner}/${name}.git`,
|
|
55
|
+
cloneUrl: `https://github.com/${owner}/${name}.git`,
|
|
56
|
+
isPrivate: false,
|
|
57
|
+
isArchived: false,
|
|
58
|
+
isFork: false,
|
|
59
|
+
pushedAt: new Date(),
|
|
60
|
+
updatedAt: new Date(),
|
|
61
|
+
defaultBranch: "main",
|
|
62
|
+
language: "TypeScript",
|
|
63
|
+
size: 1024,
|
|
64
|
+
stargazersCount: 10,
|
|
65
|
+
forksCount: 5,
|
|
66
|
+
openIssuesCount: 2,
|
|
67
|
+
watchersCount: 15,
|
|
68
|
+
topics: ["typescript", "test"],
|
|
69
|
+
license: "MIT",
|
|
70
|
+
hasIssues: true,
|
|
71
|
+
hasWiki: true,
|
|
72
|
+
hasDiscussions: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("useUnifiedRepos - Simple", () => {
|
|
77
|
+
describe("createUnifiedView", () => {
|
|
78
|
+
test("creates unified view from projects and github repos", () => {
|
|
79
|
+
const projects = [createMockProject("test-repo")];
|
|
80
|
+
const githubRepos = [createMockGitHubRepo("test-repo")];
|
|
81
|
+
|
|
82
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
83
|
+
|
|
84
|
+
expect(unified).toHaveLength(1);
|
|
85
|
+
expect(unified[0]?.name).toBe("test-repo");
|
|
86
|
+
expect(unified[0]?.isCloned).toBe(true);
|
|
87
|
+
expect(unified[0]?.isOnGitHub).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("handles empty inputs", () => {
|
|
91
|
+
const unified = createUnifiedView([], []);
|
|
92
|
+
expect(unified).toHaveLength(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("local only project has isOnGitHub false", () => {
|
|
96
|
+
const projects = [createMockProject("local-only")];
|
|
97
|
+
|
|
98
|
+
const unified = createUnifiedView(projects, []);
|
|
99
|
+
|
|
100
|
+
expect(unified).toHaveLength(1);
|
|
101
|
+
expect(unified[0]?.isCloned).toBe(true);
|
|
102
|
+
expect(unified[0]?.isOnGitHub).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("github only repo has isCloned false", () => {
|
|
106
|
+
const githubRepos = [createMockGitHubRepo("github-only")];
|
|
107
|
+
|
|
108
|
+
const unified = createUnifiedView([], githubRepos);
|
|
109
|
+
|
|
110
|
+
expect(unified).toHaveLength(1);
|
|
111
|
+
expect(unified[0]?.isCloned).toBe(false);
|
|
112
|
+
expect(unified[0]?.isOnGitHub).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for useUnifiedRepos hook
|
|
3
|
+
*
|
|
4
|
+
* These tests focus on testing the createUnifiedView helper function
|
|
5
|
+
* which can be tested in isolation without React rendering.
|
|
6
|
+
*
|
|
7
|
+
* The hook itself requires rendering in a React component context,
|
|
8
|
+
* which is done separately in integration tests.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, test, expect } from "bun:test";
|
|
12
|
+
import { createUnifiedView } from "../../../src/github/unified.ts";
|
|
13
|
+
import type { Project, GitHubRepoInfo } from "../../../src/types/index";
|
|
14
|
+
|
|
15
|
+
// Test helpers
|
|
16
|
+
function createMockProject(name: string, remoteUrl?: string): Project {
|
|
17
|
+
return {
|
|
18
|
+
id: `project-${name}`,
|
|
19
|
+
name,
|
|
20
|
+
path: `/test/${name}`,
|
|
21
|
+
type: "git",
|
|
22
|
+
lastScanned: new Date(),
|
|
23
|
+
lastModified: new Date(),
|
|
24
|
+
status: {
|
|
25
|
+
hasUnstagedChanges: false,
|
|
26
|
+
hasStagedChanges: false,
|
|
27
|
+
hasUntrackedFiles: false,
|
|
28
|
+
modifiedCount: 0,
|
|
29
|
+
stagedCount: 0,
|
|
30
|
+
untrackedCount: 0,
|
|
31
|
+
currentBranch: "main",
|
|
32
|
+
trackingBranch: "origin/main",
|
|
33
|
+
unpushedCommits: 0,
|
|
34
|
+
unpulledCommits: 0,
|
|
35
|
+
hasRemote: true,
|
|
36
|
+
remoteUrl: remoteUrl ?? `git@github.com:user/${name}.git`,
|
|
37
|
+
lastLocalCommit: new Date(),
|
|
38
|
+
lastRemoteActivity: new Date(),
|
|
39
|
+
hasCommits: true,
|
|
40
|
+
isDirty: false,
|
|
41
|
+
isAhead: false,
|
|
42
|
+
isBehind: false,
|
|
43
|
+
isOutOfSync: false,
|
|
44
|
+
},
|
|
45
|
+
projectMarker: null,
|
|
46
|
+
submodule: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createMockGitHubRepo(name: string, owner = "user"): GitHubRepoInfo {
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
fullName: `${owner}/${name}`,
|
|
54
|
+
owner,
|
|
55
|
+
description: `Test repo ${name}`,
|
|
56
|
+
htmlUrl: `https://github.com/${owner}/${name}`,
|
|
57
|
+
sshUrl: `git@github.com:${owner}/${name}.git`,
|
|
58
|
+
cloneUrl: `https://github.com/${owner}/${name}.git`,
|
|
59
|
+
isPrivate: false,
|
|
60
|
+
isArchived: false,
|
|
61
|
+
isFork: false,
|
|
62
|
+
pushedAt: new Date(),
|
|
63
|
+
updatedAt: new Date(),
|
|
64
|
+
defaultBranch: "main",
|
|
65
|
+
language: "TypeScript",
|
|
66
|
+
size: 1024,
|
|
67
|
+
stargazersCount: 10,
|
|
68
|
+
forksCount: 5,
|
|
69
|
+
openIssuesCount: 2,
|
|
70
|
+
watchersCount: 15,
|
|
71
|
+
topics: ["typescript", "test"],
|
|
72
|
+
license: "MIT",
|
|
73
|
+
hasIssues: true,
|
|
74
|
+
hasWiki: true,
|
|
75
|
+
hasDiscussions: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
describe("createUnifiedView", () => {
|
|
80
|
+
test("matches local projects with GitHub repos", () => {
|
|
81
|
+
const projects = [createMockProject("my-repo")];
|
|
82
|
+
const githubRepos = [createMockGitHubRepo("my-repo")];
|
|
83
|
+
|
|
84
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
85
|
+
|
|
86
|
+
expect(unified).toHaveLength(1);
|
|
87
|
+
expect(unified[0]?.name).toBe("my-repo");
|
|
88
|
+
expect(unified[0]?.local).toBeDefined();
|
|
89
|
+
expect(unified[0]?.github).toBeDefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("identifies local-only projects", () => {
|
|
93
|
+
const projects = [createMockProject("local-only")];
|
|
94
|
+
const githubRepos: GitHubRepoInfo[] = [];
|
|
95
|
+
|
|
96
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
97
|
+
|
|
98
|
+
expect(unified).toHaveLength(1);
|
|
99
|
+
expect(unified[0]?.name).toBe("local-only");
|
|
100
|
+
expect(unified[0]?.local).toBeDefined();
|
|
101
|
+
expect(unified[0]?.github).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("identifies GitHub-only repos", () => {
|
|
105
|
+
const projects: Project[] = [];
|
|
106
|
+
const githubRepos = [createMockGitHubRepo("github-only")];
|
|
107
|
+
|
|
108
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
109
|
+
|
|
110
|
+
expect(unified).toHaveLength(1);
|
|
111
|
+
expect(unified[0]?.name).toBe("github-only");
|
|
112
|
+
expect(unified[0]?.local).toBeNull();
|
|
113
|
+
expect(unified[0]?.github).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("handles mixed projects correctly", () => {
|
|
117
|
+
const projects = [
|
|
118
|
+
createMockProject("matched"),
|
|
119
|
+
createMockProject("local-only"),
|
|
120
|
+
];
|
|
121
|
+
const githubRepos = [
|
|
122
|
+
createMockGitHubRepo("matched"),
|
|
123
|
+
createMockGitHubRepo("github-only"),
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
127
|
+
|
|
128
|
+
expect(unified).toHaveLength(3);
|
|
129
|
+
|
|
130
|
+
const matched = unified.find(u => u.name === "matched");
|
|
131
|
+
expect(matched?.local).toBeDefined();
|
|
132
|
+
expect(matched?.github).toBeDefined();
|
|
133
|
+
|
|
134
|
+
const localOnly = unified.find(u => u.name === "local-only");
|
|
135
|
+
expect(localOnly?.local).toBeDefined();
|
|
136
|
+
expect(localOnly?.github).toBeNull();
|
|
137
|
+
|
|
138
|
+
const githubOnly = unified.find(u => u.name === "github-only");
|
|
139
|
+
expect(githubOnly?.local).toBeNull();
|
|
140
|
+
expect(githubOnly?.github).toBeDefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("matches HTTPS remote URLs", () => {
|
|
144
|
+
const projects = [createMockProject("https-repo", "https://github.com/user/https-repo.git")];
|
|
145
|
+
const githubRepos = [createMockGitHubRepo("https-repo")];
|
|
146
|
+
|
|
147
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
148
|
+
|
|
149
|
+
expect(unified).toHaveLength(1);
|
|
150
|
+
expect(unified[0]?.local).toBeDefined();
|
|
151
|
+
expect(unified[0]?.github).toBeDefined();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("handles case-insensitive matching", () => {
|
|
155
|
+
const projects = [createMockProject("MyRepo", "git@github.com:User/MyRepo.git")];
|
|
156
|
+
const githubRepos = [createMockGitHubRepo("myrepo", "user")];
|
|
157
|
+
|
|
158
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
159
|
+
|
|
160
|
+
// The matching should work regardless of case
|
|
161
|
+
expect(unified.length).toBeGreaterThanOrEqual(1);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("handles multiple GitHub repos with same name but different owners", () => {
|
|
165
|
+
const projects: Project[] = [];
|
|
166
|
+
const githubRepos = [
|
|
167
|
+
createMockGitHubRepo("common-name", "owner1"),
|
|
168
|
+
createMockGitHubRepo("common-name", "owner2"),
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const unified = createUnifiedView(projects, githubRepos);
|
|
172
|
+
|
|
173
|
+
expect(unified).toHaveLength(2);
|
|
174
|
+
expect(unified[0]?.github?.owner).toBe("owner1");
|
|
175
|
+
expect(unified[1]?.github?.owner).toBe("owner2");
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock factory for configuration objects
|
|
3
|
+
* Provides configurable mocks for GitforestConfig and related types
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
GitforestConfig,
|
|
8
|
+
DirectoryConfig,
|
|
9
|
+
CommandConfig
|
|
10
|
+
} from "../../../src/types/index";
|
|
11
|
+
import { GitforestConfigSchema } from "../../../src/types/index";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a mock directory config
|
|
15
|
+
*/
|
|
16
|
+
export function createMockDirectoryConfig(overrides?: Partial<DirectoryConfig>): DirectoryConfig {
|
|
17
|
+
return {
|
|
18
|
+
path: overrides?.path ?? "/test/projects",
|
|
19
|
+
maxDepth: overrides?.maxDepth ?? 2,
|
|
20
|
+
label: overrides?.label ?? "Test Projects",
|
|
21
|
+
...overrides,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a mock command config
|
|
27
|
+
*/
|
|
28
|
+
export function createMockCommandConfig(overrides?: Partial<CommandConfig>): CommandConfig {
|
|
29
|
+
const key = overrides?.key ?? "t";
|
|
30
|
+
|
|
31
|
+
const config: CommandConfig = {
|
|
32
|
+
name: overrides?.name ?? "Test Command",
|
|
33
|
+
key,
|
|
34
|
+
command: overrides?.command ?? "echo 'test command'",
|
|
35
|
+
confirm: overrides?.confirm ?? false,
|
|
36
|
+
background: overrides?.background ?? false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Merge overrides to ensure we respect any provided values
|
|
40
|
+
return { ...config, ...overrides };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a mock GitforestConfig
|
|
45
|
+
*/
|
|
46
|
+
export function createMockConfig(overrides?: Partial<GitforestConfig>): GitforestConfig {
|
|
47
|
+
const baseConfig: GitforestConfig = {
|
|
48
|
+
directories: overrides?.directories ?? [
|
|
49
|
+
createMockDirectoryConfig(),
|
|
50
|
+
],
|
|
51
|
+
scan: overrides?.scan ?? {
|
|
52
|
+
ignore: ["node_modules", ".git", "vendor", "__pycache__", "target", "dist", "build"],
|
|
53
|
+
includeHidden: false,
|
|
54
|
+
concurrency: 5,
|
|
55
|
+
},
|
|
56
|
+
github: overrides?.github ?? {
|
|
57
|
+
defaultVisibility: "private",
|
|
58
|
+
},
|
|
59
|
+
display: overrides?.display ?? {
|
|
60
|
+
showSubmodules: true,
|
|
61
|
+
showNonGitProjects: true,
|
|
62
|
+
sortBy: "status",
|
|
63
|
+
sortDirection: "desc",
|
|
64
|
+
},
|
|
65
|
+
cache: overrides?.cache ?? {
|
|
66
|
+
ttlSeconds: 300,
|
|
67
|
+
githubTtlSeconds: 600,
|
|
68
|
+
enableBackgroundRefresh: true,
|
|
69
|
+
backgroundRefreshIntervalSeconds: 300,
|
|
70
|
+
},
|
|
71
|
+
commands: overrides?.commands ?? [],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Validate the config against the schema
|
|
75
|
+
const validated = GitforestConfigSchema.parse({ ...baseConfig, ...overrides });
|
|
76
|
+
return validated;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a minimal config with just one directory
|
|
81
|
+
*/
|
|
82
|
+
export function createMinimalConfig(path?: string): GitforestConfig {
|
|
83
|
+
return createMockConfig({
|
|
84
|
+
directories: [
|
|
85
|
+
createMockDirectoryConfig({ path: path ?? "/test/projects" }),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Create a config with custom commands
|
|
92
|
+
*/
|
|
93
|
+
export function createConfigWithCommands(commands: CommandConfig[]): GitforestConfig {
|
|
94
|
+
return createMockConfig({ commands });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create a config with multiple directories
|
|
99
|
+
*/
|
|
100
|
+
export function createMultiDirectoryConfig(paths: string[]): GitforestConfig {
|
|
101
|
+
return createMockConfig({
|
|
102
|
+
directories: paths.map((path, index) =>
|
|
103
|
+
createMockDirectoryConfig({
|
|
104
|
+
path,
|
|
105
|
+
label: `Directory ${index + 1}`
|
|
106
|
+
})
|
|
107
|
+
),
|
|
108
|
+
});
|
|
109
|
+
}
|