pushwork 2.0.0-a.sub.1 → 2.0.0-preview.2

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 (234) hide show
  1. package/dist/branches.d.ts +20 -0
  2. package/dist/branches.d.ts.map +1 -0
  3. package/dist/branches.js +111 -0
  4. package/dist/branches.js.map +1 -0
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +245 -270
  8. package/dist/cli.js.map +1 -1
  9. package/dist/config.d.ts +17 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +84 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/fs-tree.d.ts +6 -0
  14. package/dist/fs-tree.d.ts.map +1 -0
  15. package/dist/fs-tree.js +99 -0
  16. package/dist/fs-tree.js.map +1 -0
  17. package/dist/ignore.d.ts +6 -0
  18. package/dist/ignore.d.ts.map +1 -0
  19. package/dist/ignore.js +74 -0
  20. package/dist/ignore.js.map +1 -0
  21. package/dist/index.d.ts +8 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +35 -4
  24. package/dist/index.js.map +1 -1
  25. package/dist/log.d.ts +3 -0
  26. package/dist/log.d.ts.map +1 -0
  27. package/dist/log.js +14 -0
  28. package/dist/log.js.map +1 -0
  29. package/dist/pushwork.d.ts +129 -0
  30. package/dist/pushwork.d.ts.map +1 -0
  31. package/dist/pushwork.js +1062 -0
  32. package/dist/pushwork.js.map +1 -0
  33. package/dist/repo.d.ts +14 -0
  34. package/dist/repo.d.ts.map +1 -0
  35. package/dist/repo.js +60 -0
  36. package/dist/repo.js.map +1 -0
  37. package/dist/shapes/custom.d.ts +3 -0
  38. package/dist/shapes/custom.d.ts.map +1 -0
  39. package/dist/shapes/custom.js +57 -0
  40. package/dist/shapes/custom.js.map +1 -0
  41. package/dist/shapes/file.d.ts +20 -0
  42. package/dist/shapes/file.d.ts.map +1 -0
  43. package/dist/shapes/file.js +140 -0
  44. package/dist/shapes/file.js.map +1 -0
  45. package/dist/shapes/index.d.ts +10 -0
  46. package/dist/shapes/index.d.ts.map +1 -0
  47. package/dist/shapes/index.js +35 -0
  48. package/dist/shapes/index.js.map +1 -0
  49. package/dist/shapes/patchwork-folder.d.ts +3 -0
  50. package/dist/shapes/patchwork-folder.d.ts.map +1 -0
  51. package/dist/shapes/patchwork-folder.js +160 -0
  52. package/dist/shapes/patchwork-folder.js.map +1 -0
  53. package/dist/shapes/types.d.ts +38 -0
  54. package/dist/shapes/types.d.ts.map +1 -0
  55. package/dist/shapes/types.js +52 -0
  56. package/dist/shapes/types.js.map +1 -0
  57. package/dist/shapes/vfs.d.ts +3 -0
  58. package/dist/shapes/vfs.d.ts.map +1 -0
  59. package/dist/shapes/vfs.js +92 -0
  60. package/dist/shapes/vfs.js.map +1 -0
  61. package/dist/stash.d.ts +23 -0
  62. package/dist/stash.d.ts.map +1 -0
  63. package/dist/stash.js +118 -0
  64. package/dist/stash.js.map +1 -0
  65. package/dist/version.d.ts +11 -0
  66. package/dist/version.d.ts.map +1 -0
  67. package/dist/version.js +93 -0
  68. package/dist/version.js.map +1 -0
  69. package/package.json +19 -48
  70. package/patches/@automerge__automerge-repo@2.6.0-subduction.15.patch +26 -0
  71. package/.prettierrc +0 -9
  72. package/ARCHITECTURE-ACCORDING-TO-CLAUDE.md +0 -248
  73. package/CLAUDE.md +0 -141
  74. package/README.md +0 -221
  75. package/babel.config.js +0 -5
  76. package/dist/cli/commands.d.ts +0 -71
  77. package/dist/cli/commands.d.ts.map +0 -1
  78. package/dist/cli/commands.js +0 -794
  79. package/dist/cli/commands.js.map +0 -1
  80. package/dist/cli/index.d.ts +0 -2
  81. package/dist/cli/index.d.ts.map +0 -1
  82. package/dist/cli/index.js +0 -19
  83. package/dist/cli/index.js.map +0 -1
  84. package/dist/commands.d.ts +0 -61
  85. package/dist/commands.d.ts.map +0 -1
  86. package/dist/commands.js +0 -861
  87. package/dist/commands.js.map +0 -1
  88. package/dist/config/index.d.ts +0 -71
  89. package/dist/config/index.d.ts.map +0 -1
  90. package/dist/config/index.js +0 -314
  91. package/dist/config/index.js.map +0 -1
  92. package/dist/core/change-detection.d.ts +0 -80
  93. package/dist/core/change-detection.d.ts.map +0 -1
  94. package/dist/core/change-detection.js +0 -523
  95. package/dist/core/change-detection.js.map +0 -1
  96. package/dist/core/config.d.ts +0 -81
  97. package/dist/core/config.d.ts.map +0 -1
  98. package/dist/core/config.js +0 -258
  99. package/dist/core/config.js.map +0 -1
  100. package/dist/core/index.d.ts +0 -6
  101. package/dist/core/index.d.ts.map +0 -1
  102. package/dist/core/index.js +0 -6
  103. package/dist/core/index.js.map +0 -1
  104. package/dist/core/move-detection.d.ts +0 -34
  105. package/dist/core/move-detection.d.ts.map +0 -1
  106. package/dist/core/move-detection.js +0 -121
  107. package/dist/core/move-detection.js.map +0 -1
  108. package/dist/core/snapshot.d.ts +0 -105
  109. package/dist/core/snapshot.d.ts.map +0 -1
  110. package/dist/core/snapshot.js +0 -217
  111. package/dist/core/snapshot.js.map +0 -1
  112. package/dist/core/sync-engine.d.ts +0 -157
  113. package/dist/core/sync-engine.d.ts.map +0 -1
  114. package/dist/core/sync-engine.js +0 -1379
  115. package/dist/core/sync-engine.js.map +0 -1
  116. package/dist/types/config.d.ts +0 -99
  117. package/dist/types/config.d.ts.map +0 -1
  118. package/dist/types/config.js +0 -5
  119. package/dist/types/config.js.map +0 -1
  120. package/dist/types/documents.d.ts +0 -88
  121. package/dist/types/documents.d.ts.map +0 -1
  122. package/dist/types/documents.js +0 -20
  123. package/dist/types/documents.js.map +0 -1
  124. package/dist/types/index.d.ts +0 -4
  125. package/dist/types/index.d.ts.map +0 -1
  126. package/dist/types/index.js +0 -4
  127. package/dist/types/index.js.map +0 -1
  128. package/dist/types/snapshot.d.ts +0 -64
  129. package/dist/types/snapshot.d.ts.map +0 -1
  130. package/dist/types/snapshot.js +0 -2
  131. package/dist/types/snapshot.js.map +0 -1
  132. package/dist/utils/content-similarity.d.ts +0 -53
  133. package/dist/utils/content-similarity.d.ts.map +0 -1
  134. package/dist/utils/content-similarity.js +0 -155
  135. package/dist/utils/content-similarity.js.map +0 -1
  136. package/dist/utils/content.d.ts +0 -10
  137. package/dist/utils/content.d.ts.map +0 -1
  138. package/dist/utils/content.js +0 -31
  139. package/dist/utils/content.js.map +0 -1
  140. package/dist/utils/directory.d.ts +0 -24
  141. package/dist/utils/directory.d.ts.map +0 -1
  142. package/dist/utils/directory.js +0 -52
  143. package/dist/utils/directory.js.map +0 -1
  144. package/dist/utils/fs.d.ts +0 -74
  145. package/dist/utils/fs.d.ts.map +0 -1
  146. package/dist/utils/fs.js +0 -248
  147. package/dist/utils/fs.js.map +0 -1
  148. package/dist/utils/index.d.ts +0 -5
  149. package/dist/utils/index.d.ts.map +0 -1
  150. package/dist/utils/index.js +0 -5
  151. package/dist/utils/index.js.map +0 -1
  152. package/dist/utils/mime-types.d.ts +0 -13
  153. package/dist/utils/mime-types.d.ts.map +0 -1
  154. package/dist/utils/mime-types.js +0 -209
  155. package/dist/utils/mime-types.js.map +0 -1
  156. package/dist/utils/network-sync.d.ts +0 -36
  157. package/dist/utils/network-sync.d.ts.map +0 -1
  158. package/dist/utils/network-sync.js +0 -250
  159. package/dist/utils/network-sync.js.map +0 -1
  160. package/dist/utils/node-polyfills.d.ts +0 -9
  161. package/dist/utils/node-polyfills.d.ts.map +0 -1
  162. package/dist/utils/node-polyfills.js +0 -9
  163. package/dist/utils/node-polyfills.js.map +0 -1
  164. package/dist/utils/output.d.ts +0 -129
  165. package/dist/utils/output.d.ts.map +0 -1
  166. package/dist/utils/output.js +0 -368
  167. package/dist/utils/output.js.map +0 -1
  168. package/dist/utils/repo-factory.d.ts +0 -13
  169. package/dist/utils/repo-factory.d.ts.map +0 -1
  170. package/dist/utils/repo-factory.js +0 -46
  171. package/dist/utils/repo-factory.js.map +0 -1
  172. package/dist/utils/string-similarity.d.ts +0 -14
  173. package/dist/utils/string-similarity.d.ts.map +0 -1
  174. package/dist/utils/string-similarity.js +0 -39
  175. package/dist/utils/string-similarity.js.map +0 -1
  176. package/dist/utils/text-diff.d.ts +0 -37
  177. package/dist/utils/text-diff.d.ts.map +0 -1
  178. package/dist/utils/text-diff.js +0 -93
  179. package/dist/utils/text-diff.js.map +0 -1
  180. package/dist/utils/trace.d.ts +0 -19
  181. package/dist/utils/trace.d.ts.map +0 -1
  182. package/dist/utils/trace.js +0 -63
  183. package/dist/utils/trace.js.map +0 -1
  184. package/src/cli.ts +0 -442
  185. package/src/commands.ts +0 -1134
  186. package/src/core/change-detection.ts +0 -712
  187. package/src/core/config.ts +0 -313
  188. package/src/core/index.ts +0 -5
  189. package/src/core/move-detection.ts +0 -169
  190. package/src/core/snapshot.ts +0 -275
  191. package/src/core/sync-engine.ts +0 -1795
  192. package/src/index.ts +0 -4
  193. package/src/types/config.ts +0 -111
  194. package/src/types/documents.ts +0 -91
  195. package/src/types/index.ts +0 -3
  196. package/src/types/snapshot.ts +0 -67
  197. package/src/utils/content.ts +0 -34
  198. package/src/utils/directory.ts +0 -73
  199. package/src/utils/fs.ts +0 -297
  200. package/src/utils/index.ts +0 -4
  201. package/src/utils/mime-types.ts +0 -244
  202. package/src/utils/network-sync.ts +0 -319
  203. package/src/utils/node-polyfills.ts +0 -8
  204. package/src/utils/output.ts +0 -450
  205. package/src/utils/repo-factory.ts +0 -73
  206. package/src/utils/string-similarity.ts +0 -54
  207. package/src/utils/text-diff.ts +0 -101
  208. package/src/utils/trace.ts +0 -70
  209. package/test/integration/README.md +0 -328
  210. package/test/integration/clone-test.sh +0 -310
  211. package/test/integration/conflict-resolution-test.sh +0 -309
  212. package/test/integration/debug-both-nested.sh +0 -74
  213. package/test/integration/debug-concurrent-nested.sh +0 -87
  214. package/test/integration/debug-nested.sh +0 -73
  215. package/test/integration/deletion-behavior-test.sh +0 -487
  216. package/test/integration/deletion-sync-test-simple.sh +0 -193
  217. package/test/integration/deletion-sync-test.sh +0 -297
  218. package/test/integration/exclude-patterns.test.ts +0 -144
  219. package/test/integration/full-integration-test.sh +0 -363
  220. package/test/integration/fuzzer.test.ts +0 -818
  221. package/test/integration/in-memory-sync.test.ts +0 -830
  222. package/test/integration/init-sync.test.ts +0 -89
  223. package/test/integration/manual-sync-test.sh +0 -84
  224. package/test/integration/sync-deletion.test.ts +0 -280
  225. package/test/integration/sync-flow.test.ts +0 -291
  226. package/test/jest.setup.ts +0 -34
  227. package/test/run-tests.sh +0 -225
  228. package/test/unit/deletion-behavior.test.ts +0 -249
  229. package/test/unit/enhanced-mime-detection.test.ts +0 -244
  230. package/test/unit/snapshot.test.ts +0 -404
  231. package/test/unit/sync-convergence.test.ts +0 -298
  232. package/test/unit/sync-timing.test.ts +0 -134
  233. package/test/unit/utils.test.ts +0 -366
  234. package/tsconfig.json +0 -23
@@ -1,70 +0,0 @@
1
- import { out } from "./output.js";
2
-
3
- /**
4
- * Global tracing state
5
- */
6
- let tracingEnabled = false;
7
-
8
- /**
9
- * Enable or disable tracing
10
- */
11
- export function setTracingEnabled(enabled: boolean): void {
12
- tracingEnabled = enabled;
13
- }
14
-
15
- /**
16
- * Check if tracing is enabled
17
- */
18
- export function isTracingEnabled(): boolean {
19
- return tracingEnabled;
20
- }
21
-
22
- /**
23
- * Trace a span of work by outputting to console
24
- * Works for both sync and async functions
25
- * Only outputs if tracing is enabled
26
- *
27
- * Usage:
28
- * await span("operation", async () => { ... })
29
- * span("operation", () => { ... })
30
- */
31
- export function span<T>(
32
- name: string,
33
- fn: () => T | Promise<T>
34
- ): T | Promise<T> {
35
- if (!tracingEnabled) {
36
- return fn();
37
- }
38
-
39
- const start = performance.now();
40
- const result = fn();
41
-
42
- // Check if it's a promise (async)
43
- if (result instanceof Promise) {
44
- return result.then((value) => {
45
- const duration = performance.now() - start;
46
- out.taskLine(`${name} (${formatDuration(duration)})`, true);
47
- return value;
48
- }) as T;
49
- }
50
-
51
- // Sync case
52
- const duration = performance.now() - start;
53
- out.taskLine(`${name} (${formatDuration(duration)})`, true);
54
- return result;
55
- }
56
-
57
- /**
58
- * Format duration for display
59
- */
60
- function formatDuration(ms: number): string {
61
- if (ms < 1) {
62
- return `${ms.toFixed(2)}ms`;
63
- } else if (ms < 1000) {
64
- return `${Math.round(ms)}ms`;
65
- } else if (ms < 2000) {
66
- return `${(ms / 1000).toFixed(2)}s`;
67
- } else {
68
- return `${(ms / 1000).toFixed(1)}s`;
69
- }
70
- }
@@ -1,328 +0,0 @@
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.
@@ -1,310 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Focused Clone Functionality Test for Pushwork
4
- # Tests the clone command with various sync server configurations
5
-
6
- set -e
7
-
8
- # Colors for output
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m'
14
-
15
- # Test configuration
16
- TEST_DIR="/tmp/pushwork-clone-test"
17
- PUSHWORK_CMD="node $(pwd)/dist/cli.js"
18
- CUSTOM_SYNC_SERVER="ws://localhost:3030"
19
- CUSTOM_STORAGE_ID="1d89eba7-f7a4-4e8e-80f2-5f4e2406f507"
20
-
21
- # Helper functions
22
- log_info() {
23
- echo -e "${BLUE}[INFO]${NC} $1"
24
- }
25
-
26
- log_success() {
27
- echo -e "${GREEN}[PASS]${NC} $1"
28
- }
29
-
30
- log_error() {
31
- echo -e "${RED}[FAIL]${NC} $1"
32
- }
33
-
34
- log_test() {
35
- echo -e "${YELLOW}[TEST]${NC} $1"
36
- }
37
-
38
- # Cleanup function
39
- cleanup() {
40
- log_info "Cleaning up test directory..."
41
- rm -rf "$TEST_DIR"
42
- }
43
-
44
- # Setup function
45
- setup() {
46
- log_info "Setting up clone test environment..."
47
-
48
- # Build the project
49
- log_info "Building pushwork..."
50
- npm run build
51
-
52
- # Clean up and create test directory
53
- rm -rf "$TEST_DIR"
54
- mkdir -p "$TEST_DIR"
55
- cd "$TEST_DIR"
56
-
57
- log_info "Test directory: $TEST_DIR"
58
- }
59
-
60
- # Create a test repository to clone from
61
- create_test_repo() {
62
- log_info "Creating test repository..."
63
-
64
- mkdir source-repo
65
- cd source-repo
66
-
67
- # Add some test files
68
- echo "Hello from source repo" > hello.txt
69
- echo "# Test Repository" > README.md
70
- mkdir -p docs
71
- echo "Documentation content" > docs/guide.md
72
-
73
- # Initialize with default settings
74
- $PUSHWORK_CMD init .
75
-
76
- cd ..
77
-
78
- log_success "Test repository created"
79
- }
80
-
81
- # Test clone functionality
82
- test_clone_functionality() {
83
- log_info "=== Testing Clone Functionality ==="
84
-
85
- cd source-repo
86
-
87
- # Get the root URL from the repository
88
- if [ -f .pushwork/snapshot.json ]; then
89
- ROOT_URL=$($PUSHWORK_CMD url .)
90
-
91
- if [ -n "$ROOT_URL" ]; then
92
- cd ..
93
-
94
- log_test "Clone with default settings"
95
- if $PUSHWORK_CMD clone "$ROOT_URL" clone-default; then
96
- log_success "Clone with default settings"
97
-
98
- # Verify cloned content
99
- if [ -f clone-default/hello.txt ] && [ -f clone-default/README.md ]; then
100
- log_success "Cloned files are present"
101
- else
102
- log_error "Cloned files are missing"
103
- fi
104
-
105
- # Check configuration
106
- if [ -f clone-default/.pushwork/config.json ]; then
107
- if grep -q "wss://sync3.automerge.org" clone-default/.pushwork/config.json; then
108
- log_success "Default sync server in config"
109
- else
110
- log_error "Default sync server not found in config"
111
- fi
112
- fi
113
- else
114
- log_error "Clone with default settings failed"
115
- fi
116
-
117
- log_test "Clone with custom sync server"
118
- if $PUSHWORK_CMD clone "$ROOT_URL" clone-custom --sync-server "$CUSTOM_SYNC_SERVER" --sync-server-storage-id "$CUSTOM_STORAGE_ID"; then
119
- log_success "Clone with custom sync server"
120
-
121
- # Verify custom configuration
122
- if [ -f clone-custom/.pushwork/config.json ]; then
123
- if grep -q "$CUSTOM_SYNC_SERVER" clone-custom/.pushwork/config.json; then
124
- log_success "Custom sync server in config"
125
- else
126
- log_error "Custom sync server not found in config"
127
- fi
128
-
129
- if grep -q "$CUSTOM_STORAGE_ID" clone-custom/.pushwork/config.json; then
130
- log_success "Custom storage ID in config"
131
- else
132
- log_error "Custom storage ID not found in config"
133
- fi
134
- fi
135
- else
136
- log_error "Clone with custom sync server failed"
137
- fi
138
-
139
- # Test error cases
140
- log_test "Clone with incomplete sync server options"
141
-
142
- # Only sync server (should fail)
143
- if $PUSHWORK_CMD clone "$ROOT_URL" clone-fail1 --sync-server "$CUSTOM_SYNC_SERVER" 2>/dev/null; then
144
- log_error "Clone with only sync-server should have failed"
145
- else
146
- log_success "Clone correctly failed with only sync-server"
147
- fi
148
-
149
- # Only storage ID (should fail)
150
- if $PUSHWORK_CMD clone "$ROOT_URL" clone-fail2 --sync-server-storage-id "$CUSTOM_STORAGE_ID" 2>/dev/null; then
151
- log_error "Clone with only storage-id should have failed"
152
- else
153
- log_success "Clone correctly failed with only storage-id"
154
- fi
155
-
156
- # Test force overwrite
157
- mkdir -p existing-dir
158
- echo "existing content" > existing-dir/existing.txt
159
-
160
- log_test "Clone to non-empty directory without force"
161
- if $PUSHWORK_CMD clone "$ROOT_URL" existing-dir 2>/dev/null; then
162
- log_error "Clone to non-empty directory should have failed"
163
- else
164
- log_success "Clone correctly failed for non-empty directory"
165
- fi
166
-
167
- log_test "Clone to non-empty directory with force"
168
- if $PUSHWORK_CMD clone "$ROOT_URL" existing-dir --force; then
169
- log_success "Clone with force succeeded"
170
-
171
- # Check that original files were replaced
172
- if [ -f existing-dir/hello.txt ]; then
173
- log_success "Force clone replaced existing content"
174
- else
175
- log_error "Force clone did not replace content properly"
176
- fi
177
- else
178
- log_error "Clone with force failed"
179
- fi
180
-
181
- else
182
- log_error "No valid root URL found"
183
- fi
184
- else
185
- log_error "Snapshot missing - repository not properly initialized"
186
- fi
187
-
188
- cd ..
189
- }
190
-
191
- # Test status commands in cloned directories
192
- test_cloned_directory_status() {
193
- log_info "=== Testing Status in Cloned Directories ==="
194
-
195
- if [ -d clone-default ]; then
196
- cd clone-default
197
-
198
- log_test "Status in cloned directory"
199
- if $PUSHWORK_CMD status; then
200
- log_success "Status command works in cloned directory"
201
- else
202
- log_error "Status command failed in cloned directory"
203
- fi
204
-
205
- # Make some changes and test
206
- echo "Modified in clone" >> hello.txt
207
- echo "New file in clone" > new-file.txt
208
-
209
- log_test "Status after changes in clone"
210
- if $PUSHWORK_CMD status; then
211
- log_success "Status shows changes in clone"
212
- else
213
- log_error "Status failed to show changes"
214
- fi
215
-
216
- log_test "Diff in cloned directory"
217
- if $PUSHWORK_CMD diff --name-only; then
218
- log_success "Diff command works in cloned directory"
219
- else
220
- log_error "Diff command failed in cloned directory"
221
- fi
222
-
223
- cd ..
224
- else
225
- log_error "Clone directory not available for status testing"
226
- fi
227
- }
228
-
229
- # Compare configurations between source and cloned repos
230
- compare_configurations() {
231
- log_info "=== Comparing Configurations ==="
232
-
233
- if [ -f source-repo/.pushwork/config.json ] && [ -f clone-default/.pushwork/config.json ]; then
234
- log_test "Comparing default clone configuration"
235
-
236
- if command -v jq &> /dev/null; then
237
- SOURCE_SYNC_SERVER=$(jq -r '.sync_server' source-repo/.pushwork/config.json 2>/dev/null || echo "")
238
- CLONE_SYNC_SERVER=$(jq -r '.sync_server' clone-default/.pushwork/config.json 2>/dev/null || echo "")
239
-
240
- if [ "$SOURCE_SYNC_SERVER" = "$CLONE_SYNC_SERVER" ]; then
241
- log_success "Sync server matches between source and clone"
242
- else
243
- log_error "Sync server differs: source=[$SOURCE_SYNC_SERVER] clone=[$CLONE_SYNC_SERVER]"
244
- fi
245
- else
246
- log_success "Sync server comparison (jq not available)"
247
- fi
248
- fi
249
-
250
- if [ -f clone-custom/.pushwork/config.json ]; then
251
- log_test "Verifying custom clone configuration"
252
-
253
- if command -v jq &> /dev/null; then
254
- CUSTOM_CLONE_SERVER=$(jq -r '.sync_server' clone-custom/.pushwork/config.json 2>/dev/null || echo "")
255
- CUSTOM_CLONE_STORAGE=$(jq -r '.sync_server_storage_id' clone-custom/.pushwork/config.json 2>/dev/null || echo "")
256
-
257
- if [ "$CUSTOM_CLONE_SERVER" = "$CUSTOM_SYNC_SERVER" ]; then
258
- log_success "Custom sync server correctly set in clone"
259
- else
260
- log_error "Custom sync server incorrect: expected=[$CUSTOM_SYNC_SERVER] actual=[$CUSTOM_CLONE_SERVER]"
261
- fi
262
-
263
- if [ "$CUSTOM_CLONE_STORAGE" = "$CUSTOM_STORAGE_ID" ]; then
264
- log_success "Custom storage ID correctly set in clone"
265
- else
266
- log_error "Custom storage ID incorrect: expected=[$CUSTOM_STORAGE_ID] actual=[$CUSTOM_CLONE_STORAGE]"
267
- fi
268
- else
269
- log_success "Custom configuration verification (jq not available)"
270
- fi
271
- fi
272
- }
273
-
274
- # Main test execution
275
- main() {
276
- echo "======================================"
277
- echo "Pushwork Clone Functionality Test"
278
- echo "======================================"
279
-
280
- # Trap cleanup on exit
281
- trap cleanup EXIT
282
-
283
- # Setup
284
- setup
285
-
286
- # Create test repository
287
- create_test_repo
288
-
289
- # Run clone tests
290
- test_clone_functionality
291
- test_cloned_directory_status
292
- compare_configurations
293
-
294
- echo ""
295
- echo "======================================"
296
- echo "Clone Test Complete"
297
- echo "======================================"
298
-
299
- log_success "All clone functionality tests completed!"
300
- }
301
-
302
- # Check dependencies
303
- if ! command -v jq &> /dev/null; then
304
- log_warning "jq is not installed - some configuration tests will be skipped"
305
- echo "To install jq: brew install jq (macOS) or apt-get install jq (Ubuntu)"
306
- echo ""
307
- fi
308
-
309
- # Run the tests
310
- main "$@"