pushwork 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.
Files changed (184) hide show
  1. package/README.md +460 -0
  2. package/dist/browser/browser-sync-engine.d.ts +64 -0
  3. package/dist/browser/browser-sync-engine.d.ts.map +1 -0
  4. package/dist/browser/browser-sync-engine.js +303 -0
  5. package/dist/browser/browser-sync-engine.js.map +1 -0
  6. package/dist/browser/filesystem-adapter.d.ts +84 -0
  7. package/dist/browser/filesystem-adapter.d.ts.map +1 -0
  8. package/dist/browser/filesystem-adapter.js +413 -0
  9. package/dist/browser/filesystem-adapter.js.map +1 -0
  10. package/dist/browser/index.d.ts +36 -0
  11. package/dist/browser/index.d.ts.map +1 -0
  12. package/dist/browser/index.js +90 -0
  13. package/dist/browser/index.js.map +1 -0
  14. package/dist/browser/types.d.ts +70 -0
  15. package/dist/browser/types.d.ts.map +1 -0
  16. package/dist/browser/types.js +6 -0
  17. package/dist/browser/types.js.map +1 -0
  18. package/dist/cli/commands.d.ts +71 -0
  19. package/dist/cli/commands.d.ts.map +1 -0
  20. package/dist/cli/commands.js +794 -0
  21. package/dist/cli/commands.js.map +1 -0
  22. package/dist/cli/index.d.ts +2 -0
  23. package/dist/cli/index.d.ts.map +1 -0
  24. package/dist/cli/index.js +19 -0
  25. package/dist/cli/index.js.map +1 -0
  26. package/dist/cli.d.ts +3 -0
  27. package/dist/cli.d.ts.map +1 -0
  28. package/dist/cli.js +199 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/config/index.d.ts +71 -0
  31. package/dist/config/index.d.ts.map +1 -0
  32. package/dist/config/index.js +314 -0
  33. package/dist/config/index.js.map +1 -0
  34. package/dist/core/change-detection.d.ts +78 -0
  35. package/dist/core/change-detection.d.ts.map +1 -0
  36. package/dist/core/change-detection.js +370 -0
  37. package/dist/core/change-detection.js.map +1 -0
  38. package/dist/core/index.d.ts +5 -0
  39. package/dist/core/index.d.ts.map +1 -0
  40. package/dist/core/index.js +22 -0
  41. package/dist/core/index.js.map +1 -0
  42. package/dist/core/isomorphic-snapshot.d.ts +58 -0
  43. package/dist/core/isomorphic-snapshot.d.ts.map +1 -0
  44. package/dist/core/isomorphic-snapshot.js +204 -0
  45. package/dist/core/isomorphic-snapshot.js.map +1 -0
  46. package/dist/core/move-detection.d.ts +72 -0
  47. package/dist/core/move-detection.d.ts.map +1 -0
  48. package/dist/core/move-detection.js +200 -0
  49. package/dist/core/move-detection.js.map +1 -0
  50. package/dist/core/snapshot.d.ts +109 -0
  51. package/dist/core/snapshot.d.ts.map +1 -0
  52. package/dist/core/snapshot.js +263 -0
  53. package/dist/core/snapshot.js.map +1 -0
  54. package/dist/core/sync-engine.d.ts +110 -0
  55. package/dist/core/sync-engine.d.ts.map +1 -0
  56. package/dist/core/sync-engine.js +817 -0
  57. package/dist/core/sync-engine.js.map +1 -0
  58. package/dist/index.d.ts +6 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +27 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/platform/browser-filesystem.d.ts +26 -0
  63. package/dist/platform/browser-filesystem.d.ts.map +1 -0
  64. package/dist/platform/browser-filesystem.js +91 -0
  65. package/dist/platform/browser-filesystem.js.map +1 -0
  66. package/dist/platform/filesystem.d.ts +29 -0
  67. package/dist/platform/filesystem.d.ts.map +1 -0
  68. package/dist/platform/filesystem.js +65 -0
  69. package/dist/platform/filesystem.js.map +1 -0
  70. package/dist/platform/node-filesystem.d.ts +21 -0
  71. package/dist/platform/node-filesystem.d.ts.map +1 -0
  72. package/dist/platform/node-filesystem.js +93 -0
  73. package/dist/platform/node-filesystem.js.map +1 -0
  74. package/dist/types/config.d.ts +119 -0
  75. package/dist/types/config.d.ts.map +1 -0
  76. package/dist/types/config.js +3 -0
  77. package/dist/types/config.js.map +1 -0
  78. package/dist/types/documents.d.ts +70 -0
  79. package/dist/types/documents.d.ts.map +1 -0
  80. package/dist/types/documents.js +23 -0
  81. package/dist/types/documents.js.map +1 -0
  82. package/dist/types/index.d.ts +4 -0
  83. package/dist/types/index.d.ts.map +1 -0
  84. package/dist/types/index.js +23 -0
  85. package/dist/types/index.js.map +1 -0
  86. package/dist/types/snapshot.d.ts +81 -0
  87. package/dist/types/snapshot.d.ts.map +1 -0
  88. package/dist/types/snapshot.js +17 -0
  89. package/dist/types/snapshot.js.map +1 -0
  90. package/dist/utils/content-similarity.d.ts +53 -0
  91. package/dist/utils/content-similarity.d.ts.map +1 -0
  92. package/dist/utils/content-similarity.js +155 -0
  93. package/dist/utils/content-similarity.js.map +1 -0
  94. package/dist/utils/content.d.ts +5 -0
  95. package/dist/utils/content.d.ts.map +1 -0
  96. package/dist/utils/content.js +30 -0
  97. package/dist/utils/content.js.map +1 -0
  98. package/dist/utils/fs-browser.d.ts +57 -0
  99. package/dist/utils/fs-browser.d.ts.map +1 -0
  100. package/dist/utils/fs-browser.js +311 -0
  101. package/dist/utils/fs-browser.js.map +1 -0
  102. package/dist/utils/fs-node.d.ts +53 -0
  103. package/dist/utils/fs-node.d.ts.map +1 -0
  104. package/dist/utils/fs-node.js +220 -0
  105. package/dist/utils/fs-node.js.map +1 -0
  106. package/dist/utils/fs.d.ts +62 -0
  107. package/dist/utils/fs.d.ts.map +1 -0
  108. package/dist/utils/fs.js +293 -0
  109. package/dist/utils/fs.js.map +1 -0
  110. package/dist/utils/index.d.ts +4 -0
  111. package/dist/utils/index.d.ts.map +1 -0
  112. package/dist/utils/index.js +23 -0
  113. package/dist/utils/index.js.map +1 -0
  114. package/dist/utils/isomorphic.d.ts +29 -0
  115. package/dist/utils/isomorphic.d.ts.map +1 -0
  116. package/dist/utils/isomorphic.js +139 -0
  117. package/dist/utils/isomorphic.js.map +1 -0
  118. package/dist/utils/mime-types.d.ts +13 -0
  119. package/dist/utils/mime-types.d.ts.map +1 -0
  120. package/dist/utils/mime-types.js +240 -0
  121. package/dist/utils/mime-types.js.map +1 -0
  122. package/dist/utils/network-sync.d.ts +12 -0
  123. package/dist/utils/network-sync.d.ts.map +1 -0
  124. package/dist/utils/network-sync.js +149 -0
  125. package/dist/utils/network-sync.js.map +1 -0
  126. package/dist/utils/pure.d.ts +25 -0
  127. package/dist/utils/pure.d.ts.map +1 -0
  128. package/dist/utils/pure.js +112 -0
  129. package/dist/utils/pure.js.map +1 -0
  130. package/dist/utils/repo-factory.d.ts +11 -0
  131. package/dist/utils/repo-factory.d.ts.map +1 -0
  132. package/dist/utils/repo-factory.js +77 -0
  133. package/dist/utils/repo-factory.js.map +1 -0
  134. package/package.json +83 -0
  135. package/src/cli/commands.ts +1053 -0
  136. package/src/cli/index.ts +2 -0
  137. package/src/cli.ts +287 -0
  138. package/src/config/index.ts +334 -0
  139. package/src/core/change-detection.ts +484 -0
  140. package/src/core/index.ts +5 -0
  141. package/src/core/move-detection.ts +269 -0
  142. package/src/core/snapshot.ts +285 -0
  143. package/src/core/sync-engine.ts +1167 -0
  144. package/src/index.ts +14 -0
  145. package/src/types/config.ts +130 -0
  146. package/src/types/documents.ts +72 -0
  147. package/src/types/index.ts +8 -0
  148. package/src/types/snapshot.ts +88 -0
  149. package/src/utils/content-similarity.ts +194 -0
  150. package/src/utils/content.ts +28 -0
  151. package/src/utils/fs.ts +289 -0
  152. package/src/utils/index.ts +8 -0
  153. package/src/utils/mime-types.ts +236 -0
  154. package/src/utils/network-sync.ts +153 -0
  155. package/src/utils/repo-factory.ts +58 -0
  156. package/test/README-TESTING-GAPS.md +174 -0
  157. package/test/integration/README.md +328 -0
  158. package/test/integration/clone-test.sh +310 -0
  159. package/test/integration/conflict-resolution-test.sh +309 -0
  160. package/test/integration/deletion-behavior-test.sh +487 -0
  161. package/test/integration/deletion-sync-test-simple.sh +193 -0
  162. package/test/integration/deletion-sync-test.sh +297 -0
  163. package/test/integration/exclude-patterns.test.ts +152 -0
  164. package/test/integration/full-integration-test.sh +363 -0
  165. package/test/integration/sync-deletion.test.ts +339 -0
  166. package/test/integration/sync-flow.test.ts +309 -0
  167. package/test/run-tests.sh +225 -0
  168. package/test/unit/content-similarity.test.ts +236 -0
  169. package/test/unit/deletion-behavior.test.ts +260 -0
  170. package/test/unit/enhanced-mime-detection.test.ts +266 -0
  171. package/test/unit/snapshot.test.ts +431 -0
  172. package/test/unit/sync-timing.test.ts +178 -0
  173. package/test/unit/utils.test.ts +368 -0
  174. package/tools/browser-sync/README.md +116 -0
  175. package/tools/browser-sync/package.json +44 -0
  176. package/tools/browser-sync/patchwork.json +1 -0
  177. package/tools/browser-sync/pnpm-lock.yaml +4202 -0
  178. package/tools/browser-sync/src/components/BrowserSyncTool.tsx +599 -0
  179. package/tools/browser-sync/src/index.ts +20 -0
  180. package/tools/browser-sync/src/polyfills.ts +31 -0
  181. package/tools/browser-sync/src/styles.css +290 -0
  182. package/tools/browser-sync/src/types.ts +27 -0
  183. package/tools/browser-sync/vite.config.ts +25 -0
  184. package/tsconfig.json +22 -0
@@ -0,0 +1,58 @@
1
+ import { Repo, StorageId } from "@automerge/automerge-repo";
2
+ import { NodeFSStorageAdapter } from "@automerge/automerge-repo-storage-nodefs";
3
+ import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket";
4
+ import * as path from "path";
5
+ import chalk from "chalk";
6
+ import { ConfigManager } from "../config";
7
+
8
+ export interface RepoFactoryOptions {
9
+ enableNetwork?: boolean;
10
+ syncServer?: string;
11
+ syncServerStorageId?: string;
12
+ }
13
+
14
+ /**
15
+ * Create an Automerge repository with configuration-based setup
16
+ */
17
+ export async function createRepo(
18
+ workingDir: string,
19
+ options: RepoFactoryOptions = {}
20
+ ): Promise<Repo> {
21
+ const configManager = new ConfigManager(workingDir);
22
+ const config = await configManager.getMerged();
23
+
24
+ const syncToolDir = path.join(workingDir, ".pushwork");
25
+ const storage = new NodeFSStorageAdapter(path.join(syncToolDir, "automerge"));
26
+
27
+ const repoConfig: any = { storage };
28
+
29
+ // Determine network settings - options override config
30
+ const enableNetwork = options.enableNetwork ?? true;
31
+ const syncServer = options.syncServer ?? config.sync_server;
32
+ const syncServerStorageId =
33
+ options.syncServerStorageId ?? config.sync_server_storage_id;
34
+
35
+ // Add network adapter only if explicitly enabled and sync server is configured
36
+ if (enableNetwork && syncServer) {
37
+ const networkAdapter = new BrowserWebSocketClientAdapter(syncServer);
38
+ repoConfig.network = [networkAdapter];
39
+ repoConfig.enableRemoteHeadsGossiping = true;
40
+ console.log(chalk.gray(` ✓ Network sync enabled: ${syncServer}`));
41
+ } else {
42
+ console.log(chalk.gray(" ✓ Local-only mode (network sync disabled)"));
43
+ }
44
+
45
+ const repo = new Repo(repoConfig);
46
+
47
+ // Subscribe to the sync server storage for network sync
48
+ if (enableNetwork && syncServer && syncServerStorageId) {
49
+ repo.subscribeToRemotes([syncServerStorageId as StorageId]);
50
+ console.log(
51
+ chalk.gray(
52
+ ` ✓ Subscribed to sync server storage: ${syncServerStorageId}`
53
+ )
54
+ );
55
+ }
56
+
57
+ return repo;
58
+ }
@@ -0,0 +1,174 @@
1
+ # Testing Gaps Analysis
2
+
3
+ ## Overview
4
+
5
+ This document outlines the testing gaps identified in the autosync codebase, particularly around the major architectural changes implemented for directory document management and text CRDT support.
6
+
7
+ ## Current Test Coverage
8
+
9
+ ✅ **Well Tested:**
10
+
11
+ - File system utilities (`test/unit/utils.test.ts`) - 89 test cases
12
+ - Snapshot management (`test/unit/snapshot.test.ts`) - Comprehensive coverage
13
+ - Content similarity (`test/unit/content-similarity.test.ts`) - Move detection logic
14
+ - Integration scenarios (`test/integration/*.test.ts`) - File operations, exclude patterns
15
+
16
+ ## Critical Testing Gaps
17
+
18
+ ### 1. SyncEngine Core Logic (HIGH PRIORITY)
19
+
20
+ **Status:** ❌ No direct unit tests
21
+ **Impact:** Core synchronization logic untested
22
+
23
+ **Missing Coverage:**
24
+
25
+ - `sync()` method with various file scenarios
26
+ - `applyLocalChangeToRemote()` / `applyRemoteChangeToLocal()`
27
+ - Bidirectional sync flow
28
+ - Error handling during sync operations
29
+ - Dry run mode functionality
30
+
31
+ ### 2. Directory Document Management (HIGH PRIORITY)
32
+
33
+ **Status:** ❌ No tests for new feature
34
+ **Impact:** New architectural feature completely untested
35
+
36
+ **Missing Coverage:**
37
+
38
+ - `addFileToRootDirectory()` - Adding files to directory structure
39
+ - `removeFileFromRootDirectory()` - Removing files from directory structure
40
+ - `setRootDirectoryUrl()` - Root directory URL persistence
41
+ - Directory structure synchronization between peers
42
+ - Root directory document creation during init
43
+
44
+ ### 3. Text CRDT Implementation (MEDIUM PRIORITY)
45
+
46
+ **Status:** ❌ No tests for new feature
47
+ **Impact:** New text handling functionality untested
48
+
49
+ **Missing Coverage:**
50
+
51
+ - `isTextContent()` method logic (simplified version)
52
+ - Text files using `updateText()` vs binary files using direct assignment
53
+ - Mixed content operations in single sync
54
+ - Text CRDT conflict resolution behavior
55
+
56
+ ### 4. CLI Command Integration (MEDIUM PRIORITY)
57
+
58
+ **Status:** ❌ No end-to-end CLI tests
59
+ **Impact:** User-facing functionality untested
60
+
61
+ **Missing Coverage:**
62
+
63
+ - `init` command with directory document creation
64
+ - `sync` command full bidirectional flow
65
+ - `status`, `diff`, `log` command accuracy
66
+ - Error handling in CLI commands
67
+ - `--dry-run` flag functionality
68
+
69
+ ### 5. Automerge Repository Integration (LOW PRIORITY)
70
+
71
+ **Status:** ❌ No Automerge-specific tests
72
+ **Impact:** Repository lifecycle and document management untested
73
+
74
+ **Missing Coverage:**
75
+
76
+ - Document creation and updates
77
+ - Repository shutdown behavior
78
+ - Document head tracking accuracy
79
+ - Network synchronization (mocked)
80
+
81
+ ## Technical Challenges
82
+
83
+ ### Jest + ES Modules Issue
84
+
85
+ **Problem:** `@automerge/automerge-repo` uses ES modules that Jest struggles to handle
86
+ **Error:** `SyntaxError: Unexpected token 'export'`
87
+
88
+ **Attempted Solutions:**
89
+
90
+ - Modified Jest `transformIgnorePatterns`
91
+ - Added ES module configuration
92
+ - All attempts failed due to complex dependency chain
93
+
94
+ ### Recommended Solutions
95
+
96
+ #### Option 1: Integration Testing Approach
97
+
98
+ Create integration tests that test the full flow without mocking Automerge:
99
+
100
+ ```typescript
101
+ // test/integration/sync-engine-integration.test.ts
102
+ // Test real sync operations with actual Automerge repositories
103
+ // Focus on end-to-end behavior rather than unit testing
104
+ ```
105
+
106
+ #### Option 2: Mock-Heavy Unit Testing
107
+
108
+ Create comprehensive mocks for Automerge dependencies:
109
+
110
+ ```typescript
111
+ // Heavy mocking of @automerge/automerge-repo
112
+ // Test SyncEngine logic in isolation
113
+ // More fragile but allows unit testing
114
+ ```
115
+
116
+ #### Option 3: Test Configuration Update
117
+
118
+ Update Jest/test environment to properly handle ES modules:
119
+
120
+ - Migrate to newer Jest version with better ES module support
121
+ - Or switch to alternative test runner (Vitest, etc.)
122
+
123
+ ## Immediate Actions Taken
124
+
125
+ ### Comprehensive `isTextContent()` Testing
126
+
127
+ Since this is a pure function, it can be tested independently:
128
+
129
+ ```typescript
130
+ // Manual testing confirmed:
131
+ // ✅ Strings identified as text
132
+ // ✅ Uint8Array identified as binary
133
+ // ✅ Edge cases handled correctly
134
+ ```
135
+
136
+ ### Manual Integration Testing
137
+
138
+ Verified through manual CLI testing:
139
+
140
+ - ✅ Directory document management working
141
+ - ✅ Root directory URL persistence
142
+ - ✅ File creation/deletion updates directory structure
143
+ - ✅ Text files using updateText(), binary files using direct assignment
144
+
145
+ ## Recommendations
146
+
147
+ ### Short Term (Implemented)
148
+
149
+ 1. ✅ Document testing gaps (this file)
150
+ 2. ✅ Manual testing of critical functionality
151
+ 3. ✅ Existing test suite still passing (89 tests)
152
+
153
+ ### Medium Term (Future Work)
154
+
155
+ 1. **Integration Test Suite:** Create `test/integration/sync-engine-e2e.test.ts`
156
+ 2. **CLI Testing:** Add end-to-end CLI command testing
157
+ 3. **Mock Strategy:** Develop proper Automerge mocking approach
158
+
159
+ ### Long Term (Future Work)
160
+
161
+ 1. **Test Environment Upgrade:** Resolve ES module handling
162
+ 2. **Comprehensive Unit Tests:** Full SyncEngine unit test coverage
163
+ 3. **Property-Based Testing:** Add property testing for sync operations
164
+
165
+ ## Current Test Status
166
+
167
+ - **Total Tests:** 89 passing
168
+ - **Test Suites:** 5 passing
169
+ - **Coverage:** High for utilities, medium for integration, low for core sync logic
170
+ - **Critical Features:** Manually verified but not automatically tested
171
+
172
+ ## Conclusion
173
+
174
+ While we've identified significant testing gaps around the new features, the existing test suite provides confidence in the foundation. The new features have been manually tested and are working correctly. Future development should prioritize integration testing to cover the areas where unit testing is blocked by ES module issues.
@@ -0,0 +1,328 @@
1
+ # Integration Tests
2
+
3
+ This directory contains comprehensive integration tests for the pushwork sync tool.
4
+
5
+ ## Quick Start
6
+
7
+ From the project root directory:
8
+
9
+ ```bash
10
+ # Run all tests with the test runner
11
+ ./test/run-tests.sh
12
+
13
+ # Run specific test suites
14
+ ./test/run-tests.sh clone # Clone functionality tests
15
+ ./test/run-tests.sh conflict # CRDT conflict resolution tests
16
+ ./test/run-tests.sh full # Full integration tests
17
+ ./test/run-tests.sh unit # Unit tests
18
+ ```
19
+
20
+ ## Test Scripts
21
+
22
+ ### 1. Test Runner (`../run-tests.sh`)
23
+
24
+ Main entry point for running all tests. Provides:
25
+
26
+ - Dependency checking
27
+ - Multiple test suite options
28
+ - Consistent output formatting
29
+ - Error handling
30
+
31
+ ### 2. Full Integration Test (`full-integration-test.sh`)
32
+
33
+ Comprehensive test suite covering all major functionality:
34
+
35
+ **Features Tested:**
36
+
37
+ - ✅ Help commands for all CLI commands
38
+ - ✅ Init with default and custom sync servers
39
+ - ✅ Clone with default and custom sync servers
40
+ - ✅ Status, diff, commit, and sync operations
41
+ - ✅ Error handling and parameter validation
42
+ - ✅ File operations (create, modify, delete)
43
+ - ✅ Bidirectional sync scenarios
44
+
45
+ **Test Sections:**
46
+
47
+ 1. Help Commands - Verify all --help options work
48
+ 2. Init Functionality - Test directory initialization
49
+ 3. Status Functionality - Test status reporting
50
+ 4. Commit Functionality - Test local commits
51
+ 5. Sync Functionality - Test sync operations
52
+ 6. Diff Functionality - Test change detection
53
+ 7. Clone Functionality - Test cloning repositories
54
+ 8. Bidirectional Sync - Test multi-directory sync
55
+ 9. File Operations - Test various file types and operations
56
+
57
+ ### 3. Clone Test (`clone-test.sh`)
58
+
59
+ Focused test suite specifically for clone functionality:
60
+
61
+ **Features Tested:**
62
+
63
+ - ✅ Clone with default sync server settings
64
+ - ✅ Clone with custom sync server and storage ID
65
+ - ✅ Parameter validation (sync server options must be used together)
66
+ - ✅ Force overwrite functionality
67
+ - ✅ Configuration verification in cloned repositories
68
+ - ✅ Error handling for invalid scenarios
69
+ - ✅ Status and diff operations in cloned directories
70
+
71
+ **Test Sections:**
72
+
73
+ 1. Clone Functionality - All clone scenarios
74
+ 2. Cloned Directory Status - Operations in cloned repos
75
+ 3. Configuration Comparison - Verify settings propagation
76
+
77
+ ### 4. CRDT Conflict Resolution Test (`conflict-resolution-test.sh`)
78
+
79
+ Specialized test demonstrating pushwork's excellent CRDT-based conflict resolution capabilities:
80
+
81
+ **Features Tested:**
82
+
83
+ - ✅ Create repository with initial document
84
+ - ✅ Clone repository to second location
85
+ - ✅ Make simultaneous conflicting edits on both sides
86
+ - ✅ Verify CRDT text merging preserves ALL changes
87
+ - ✅ Validate that no data is lost during conflicts
88
+ - ✅ Confirm true collaborative editing capabilities
89
+
90
+ **Test Scenario:**
91
+
92
+ 1. Alice creates a document with baseline content
93
+ 2. Bob clones Alice's repository
94
+ 3. Both users make different additions to the same file simultaneously
95
+ 4. Alice syncs her changes first
96
+ 5. Bob syncs his changes (CRDT merging occurs)
97
+ 6. Final sync rounds ensure eventual consistency
98
+ 7. **Result**: Bob's repository contains BOTH Alice's AND Bob's changes
99
+ 8. **Demonstrates**: True CRDT collaborative editing without data loss
100
+
101
+ **Key Findings:**
102
+
103
+ - ✅ Pushwork uses character-level CRDT text merging
104
+ - ✅ Both users' contributions are preserved automatically
105
+ - ✅ No manual conflict resolution required
106
+ - ✅ Immediate convergence to consistent state
107
+ - ✅ Sync timing issue has been resolved
108
+ - Repositories eventually converge to consistent state
109
+
110
+ ## Test Configuration
111
+
112
+ ### Required Dependencies
113
+
114
+ - **Node.js** - For running pushwork CLI
115
+ - **npm** - For building the project
116
+
117
+ ### Optional Dependencies
118
+
119
+ - **jq** - For advanced JSON parsing in configuration tests (tests will be skipped if not available)
120
+
121
+ Install jq (optional):
122
+
123
+ ```bash
124
+ # macOS
125
+ brew install jq
126
+
127
+ # Ubuntu/Debian
128
+ sudo apt-get install jq
129
+
130
+ # Other platforms
131
+ # See: https://stedolan.github.io/jq/download/
132
+ ```
133
+
134
+ ### Test Environment
135
+
136
+ - Tests run in isolated temporary directories
137
+ - Automatic cleanup on completion
138
+ - No modification of project files
139
+ - Safe to run multiple times
140
+
141
+ ### Test Parameters
142
+
143
+ ```bash
144
+ # Default test configuration
145
+ TEST_DIR="/tmp/pushwork-*-test"
146
+ CUSTOM_SYNC_SERVER="ws://localhost:3030"
147
+ CUSTOM_STORAGE_ID="1d89eba7-f7a4-4e8e-80f2-5f4e2406f507"
148
+ ```
149
+
150
+ ## Understanding Test Output
151
+
152
+ ### Log Levels
153
+
154
+ - 🔵 **[INFO]** - General information
155
+ - 🟡 **[TEST]** - Test being executed
156
+ - 🟢 **[PASS]** - Test passed
157
+ - 🔴 **[FAIL]** - Test failed
158
+ - 🟡 **[WARN]** - Warning (non-critical)
159
+
160
+ ### Test Results
161
+
162
+ Each test script provides a summary:
163
+
164
+ ```
165
+ ======================================
166
+ Test Results Summary
167
+ ======================================
168
+ Tests Run: 45
169
+ Tests Passed: 43
170
+ Tests Failed: 2
171
+ ```
172
+
173
+ ## Running Individual Tests
174
+
175
+ ### Full Integration Test
176
+
177
+ ```bash
178
+ ./test/integration/full-integration-test.sh
179
+ ```
180
+
181
+ ### Clone Test
182
+
183
+ ```bash
184
+ ./test/integration/clone-test.sh
185
+ ```
186
+
187
+ ### With Verbose Output
188
+
189
+ ```bash
190
+ # Remove `> /dev/null 2>&1` redirections in scripts for verbose output
191
+ # Or modify the log functions to always show output
192
+ ```
193
+
194
+ ## Test Coverage
195
+
196
+ ### ✅ Covered Functionality
197
+
198
+ - All CLI commands and help output
199
+ - Directory initialization (init)
200
+ - Repository cloning (clone) - **NEW**
201
+ - Sync operations (sync, status, diff, commit)
202
+ - Parameter validation
203
+ - Error handling for common scenarios
204
+ - File operations and change detection
205
+ - Configuration management
206
+ - Custom sync server support - **NEW**
207
+
208
+ ### ⚠️ Known Limitations
209
+
210
+ - Network sync requires actual connectivity
211
+ - Some tests skip when dependencies missing (jq)
212
+ - Limited testing of concurrent operations
213
+ - Performance testing not included
214
+
215
+ ## Troubleshooting
216
+
217
+ ### Common Issues
218
+
219
+ **"jq: command not found"**
220
+
221
+ ```bash
222
+ # Install jq (see dependencies section above)
223
+ brew install jq # macOS
224
+ ```
225
+
226
+ **"Permission denied"**
227
+
228
+ ```bash
229
+ # Make scripts executable
230
+ chmod +x test/integration/*.sh
231
+ chmod +x test/run-tests.sh
232
+ ```
233
+
234
+ **"Not in project directory"**
235
+
236
+ ```bash
237
+ # Run from project root where package.json exists
238
+ cd /path/to/pushwork
239
+ ./test/run-tests.sh
240
+ ```
241
+
242
+ **Tests failing unexpectedly**
243
+
244
+ ```bash
245
+ # Check if project builds
246
+ npm run build
247
+
248
+ # Check if CLI works
249
+ node dist/cli.js --help
250
+ ```
251
+
252
+ ### Debug Mode
253
+
254
+ To see more detailed output, modify the test scripts to remove output redirection:
255
+
256
+ ```bash
257
+ # Change this:
258
+ if $PUSHWORK_CMD init . > /dev/null 2>&1; then
259
+
260
+ # To this:
261
+ if $PUSHWORK_CMD init .; then
262
+ ```
263
+
264
+ ## Adding New Tests
265
+
266
+ ### Test Script Template
267
+
268
+ ```bash
269
+ #!/bin/bash
270
+ set -e
271
+
272
+ # Test configuration
273
+ TEST_DIR="/tmp/my-test"
274
+ PUSHWORK_CMD="node $(pwd)/dist/cli.js"
275
+
276
+ # Colors and logging functions
277
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
278
+ BLUE='\033[0;34m'; NC='\033[0m'
279
+
280
+ log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
281
+ log_success() { echo -e "${GREEN}[PASS]${NC} $1"; }
282
+ log_error() { echo -e "${RED}[FAIL]${NC} $1"; }
283
+ log_test() { echo -e "${YELLOW}[TEST]${NC} $1"; }
284
+
285
+ # Cleanup
286
+ cleanup() { rm -rf "$TEST_DIR"; }
287
+ trap cleanup EXIT
288
+
289
+ # Test logic here
290
+ setup_test_environment
291
+ run_tests
292
+ ```
293
+
294
+ ### Guidelines
295
+
296
+ 1. Use consistent naming patterns
297
+ 2. Include both positive and negative test cases
298
+ 3. Test error conditions thoroughly
299
+ 4. Provide clear test descriptions
300
+ 5. Clean up resources properly
301
+ 6. Use the established logging format
302
+
303
+ ## Integration with CI/CD
304
+
305
+ These tests are designed to be run in automated environments:
306
+
307
+ ```bash
308
+ # In your CI pipeline
309
+ ./test/run-tests.sh full
310
+ ```
311
+
312
+ Exit codes:
313
+
314
+ - `0` - All tests passed
315
+ - `1` - Some tests failed
316
+ - Non-zero - Setup or dependency errors
317
+
318
+ ## Contributing
319
+
320
+ When adding new features to pushwork:
321
+
322
+ 1. **Add integration tests** for new CLI commands
323
+ 2. **Update existing tests** if command behavior changes
324
+ 3. **Test error scenarios** - not just happy paths
325
+ 4. **Document test coverage** in this README
326
+ 5. **Verify tests pass** before submitting PRs
327
+
328
+ The integration tests serve as both testing and documentation for how the CLI should behave.