@secrez/fs 1.1.0 → 1.1.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.
package/README.md CHANGED
@@ -25,7 +25,7 @@ API documentation
25
25
  - strengthen password-based export encryption in `FileCipher`: new **v2** format (PBKDF2, random salt in file, iterations out of band)
26
26
  - write vault blobs and cache files with mode `0o600` via `VaultPermissions` (FS-1)
27
27
  - add `fileCipherLegacy` module and `FileCipherLegacy` export for **v1** password-encrypted files (import compatibility and test fixtures)
28
- - require Node.js 20 or later (`engines.node >=20.0.0`)
28
+ - require Node.js 22.23.4 or later (`engines.node >=22.23.4`)
29
29
 
30
30
  **1.0.3**
31
31
 
@@ -38,7 +38,7 @@ API documentation
38
38
  ## Test coverage
39
39
 
40
40
  ```
41
- 108 passing (5s)
41
+ 108 passing (2s)
42
42
 
43
43
  -----------------------|---------|----------|---------|---------|-----------------------------------
44
44
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
package/coverage.report CHANGED
@@ -1,5 +1,6 @@
1
+  WARN  Unsupported engine: wanted: {"node":">=22.23.4"} (current: {"node":"v22.14.0","pnpm":"9.6.0"})
1
2
 
2
- > @secrez/fs@1.1.0 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
3
+ > @secrez/fs@1.1.2 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
3
4
  > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
4
5
 
5
6
 
@@ -65,13 +66,18 @@
65
66
  #GitConflictChecker
66
67
  ✔ should detect non-git repository
67
68
  ✔ should return null status for non-git repository
69
+ 1) should reuse a hard block without checking git again
70
+ 2) should reuse a behind-remote warning without checking git again
71
+ ✔ should fetch again after a push refreshes the fingerprint
72
+ ✔ should use the login fingerprint without fetching again
73
+ 3) should check git again when the risk can be bypassed
68
74
  ✔ should not detect conflict risk in non-git repository
69
75
  with local git repository
70
76
  ✔ should detect git repository
71
- ✔ should get git status when up to date with remote (73ms)
72
- ✔ should detect conflict risk when behind remote (164ms)
77
+ ✔ should get git status when up to date with remote (153ms)
78
+ ✔ should detect conflict risk when behind remote (281ms)
73
79
  ✔ should get warning message for conflict risk
74
- ✔ should not show alert again after user proceeds (73ms)
80
+ ✔ should not show alert again after user proceeds (154ms)
75
81
  ✔ should reset cache
76
82
 
77
83
  #InternalFs
@@ -159,41 +165,96 @@
159
165
  ✔ should return the entry details of a node
160
166
  #Fix
161
167
  ✔ should load a tree with tags
162
- 1) should simulate a conflict in the repo and recover lost entries when a valid tree exists
163
- ✔ should simulate a lost index in the repo and recover the entries when no valid tree is found
168
+ ✔ should simulate a conflict in the repo and recover lost entries when a valid tree exists (1116ms)
169
+ ✔ should simulate a lost index in the repo and recover the entries when no valid tree is found (44ms)
164
170
  Multi data sets
165
171
  ✔ should load the trees of two data sets
166
172
 
167
173
 
168
- 107 passing (3s)
169
- 1 failing
174
+ 110 passing (4s)
175
+ 3 failing
170
176
 
171
- 1) #Tree
172
- #Fix
173
- should simulate a conflict in the repo and recover lost entries when a valid tree exists:
174
- RangeError: Invalid count value: -1
175
- at String.repeat (<anonymous>)
176
- at Crypto.getTimestampWithMicroseconds (/Users/francescosullo/Projects/Secrez/secrez/packages/crypto/src/index.js:417:39)
177
- at Secrez.encryptEntry (/Users/francescosullo/Projects/Secrez/secrez/packages/core/src/Secrez.js:228:20)
178
- at Tree.add (src/Tree.js:11:3592)
179
- at InternalFs.make (src/InternalFs.js:4:1671)
180
- at async Context.<anonymous> (test/Tree.test.js:253:7)
177
+ 1) #GitConflictChecker
178
+ should reuse a hard block without checking git again:
179
+
180
+ AssertionError: expected { hasRisk: true, …(4) } to equal { Object (hasRisk, riskType, ...) }
181
+ + expected - actual
182
+
183
+ {
184
+ - "allowBypass": false
185
+ - "hasRisk": true
186
+ - "message": "🚫 Repository State Changed Externally!\n \nThe git repository state has changed since you entered your account.\nThis likely means a 'git pull' or other git operation was performed in another terminal.\n\nSecrez cannot safely read these changes while running.\nFor data integrity, only READ operations and QUIT are allowed."
187
+ - "riskType": "external_change"
188
+ - "status": {
189
+ - "ahead": 0
190
+ - "behind": 0
191
+ - "headCommit": "abc"
192
+ - "localBranch": "main"
193
+ - "remoteBranch": "origin/main"
194
+ - "uncommitted": 0
195
+ - }
196
+ + "allowBypass": true
197
+ + "hasRisk": false
198
+ + "message": [null]
199
+ + "riskType": [null]
200
+ + "status": [null]
201
+ }
202
+
203
+ at Context.<anonymous> (test/GitConflictChecker.test.js:91:12)
204
+
205
+ 2) #GitConflictChecker
206
+ should reuse a behind-remote warning without checking git again:
207
+
208
+ AssertionError: expected { hasRisk: true, …(4) } to equal { Object (hasRisk, riskType, ...) }
209
+ + expected - actual
210
+
211
+ {
212
+ "allowBypass": true
213
+ - "hasRisk": true
214
+ - "message": "⚠️ Git Conflict Risk Detected!\n \nYour local repository is 1 commit(s) behind the remote 'origin/main' branch.\nAny changes you make now could lead to merge conflicts when you try to sync later."
215
+ - "riskType": "behind_remote"
216
+ - "status": {
217
+ - "ahead": 0
218
+ - "behind": 1
219
+ - "headCommit": "abc"
220
+ - "localBranch": "main"
221
+ - "remoteBranch": "origin/main"
222
+ - "uncommitted": 0
223
+ - }
224
+ + "hasRisk": false
225
+ + "message": [null]
226
+ + "riskType": [null]
227
+ + "status": [null]
228
+ }
229
+
230
+ at Context.<anonymous> (test/GitConflictChecker.test.js:117:12)
231
+
232
+ 3) #GitConflictChecker
233
+ should check git again when the risk can be bypassed:
234
+
235
+ AssertionError: expected 1 to equal 2
236
+ + expected - actual
237
+
238
+ -1
239
+ +2
240
+
241
+ at Context.<anonymous> (test/GitConflictChecker.test.js:187:12)
181
242
 
182
243
 
183
244
 
184
245
  -----------------------|---------|----------|---------|---------|-----------------------------------
185
246
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
186
247
  -----------------------|---------|----------|---------|---------|-----------------------------------
187
- All files | 76.07 | 64.36 | 85.62 | 76.01 |
248
+ All files | 83.39 | 70.34 | 88.19 | 83.09 |
188
249
  DataCache.js | 89.53 | 74.07 | 90.9 | 89.41 | 18-24,123-124,150
189
250
  ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
190
251
  FileCipher.js | 88.05 | 73.8 | 100 | 88.05 | 9,39,76,85,91,95,131,136
191
252
  FsUtils.js | 100 | 100 | 100 | 100 |
192
- GitConflictChecker.js | 72.81 | 61.9 | 90 | 72.81 | ...95,204,222,254,259,277,289,308
193
- InternalFs.js | 82.35 | 70.83 | 85.18 | 82.21 | ...64,377-385,423-428,460,470-487
253
+ GitConflictChecker.js | 84.87 | 79.81 | 100 | 84.87 | ...89,199,202,212,215,224,242,323
254
+ InternalFs.js | 87.5 | 73.5 | 88.88 | 87.4 | ...88,333,344,364,423-428,460,471
194
255
  Messages.js | 100 | 100 | 100 | 100 |
195
- Node.js | 65.81 | 53.7 | 78.72 | 65.02 | ...05,644-648,666,669,683-720,729
196
- Tree.js | 70.29 | 57.83 | 81.08 | 70.86 | ...44,471,481,535,627,635,666-677
256
+ Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
257
+ Tree.js | 89.91 | 74.09 | 86.48 | 89.63 | ...44,471,481,535,627,635,666-677
197
258
  fileCipherLegacy.js | 100 | 100 | 100 | 100 |
198
259
  -----------------------|---------|----------|---------|---------|-----------------------------------
199
260
   ELIFECYCLE  Test failed. See above for more details.
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@secrez/fs",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "dependencies": {
9
- "@secrez/core": "~1.1.0",
10
- "@secrez/crypto": "~1.1.0",
11
- "@secrez/utils": "~1.1.0",
9
+ "@secrez/core": "~1.1.1",
10
+ "@secrez/crypto": "~1.1.1",
11
+ "@secrez/utils": "~1.1.2",
12
12
  "command-line-args": "^5.2.1",
13
13
  "fs-extra": "^9.1.0",
14
14
  "lodash": "^4.17.21"
15
15
  },
16
16
  "devDependencies": {
17
- "@secrez/test-helpers": "~2.0.3",
17
+ "@secrez/test-helpers": "~2.0.5",
18
18
  "chai": "^4.5.0",
19
19
  "cross-env": "^7.0.3",
20
20
  "mocha": "^10.8.2",
@@ -31,7 +31,7 @@
31
31
  "email": "francesco@sullo.co"
32
32
  },
33
33
  "engines": {
34
- "node": ">=20.0.0"
34
+ "node": ">=22.23.4"
35
35
  },
36
36
  "scripts": {
37
37
  "all-tests": "find test/** -name '*.test.js' | xargs ./node_modules/.bin/mocha -R spec",
@@ -8,6 +8,10 @@ class GitConflictChecker {
8
8
  this.isGitRepo = null;
9
9
  this.remoteStatus = null;
10
10
  this.initialGitState = null; // Initial state captured at account entry
11
+ this.sessionBlock = null; // Known repo risk kept until Secrez is restarted
12
+ this.sessionBlockAnnounced = false;
13
+ this.entryStatus = null;
14
+ this.hasEntryStatus = false;
11
15
  this.lastCheck = null;
12
16
  this.checkInterval = 30000; // 30 seconds between checks
13
17
  }
@@ -36,6 +40,22 @@ class GitConflictChecker {
36
40
  */
37
41
  async captureInitialState() {
38
42
  const status = await this.getGitStatus();
43
+ this.entryStatus = status;
44
+ this.hasEntryStatus = true;
45
+ if (status && !status.error) {
46
+ this.initialGitState = this.getGitFingerprint(status);
47
+ }
48
+ return status;
49
+ }
50
+
51
+ /**
52
+ * Remember the repo after a push Secrez just made.
53
+ * The next write must fetch again: a commit can land on the remote after this.
54
+ */
55
+ async refreshFingerprint() {
56
+ const status = await this.getGitStatus();
57
+ this.entryStatus = null;
58
+ this.hasEntryStatus = false;
39
59
  if (status && !status.error) {
40
60
  this.initialGitState = this.getGitFingerprint(status);
41
61
  }
@@ -280,9 +300,7 @@ The git repository state has changed since you entered your account.
280
300
  This likely means a 'git pull' or other git operation was performed in another terminal.
281
301
 
282
302
  Secrez cannot safely read these changes while running.
283
- For data integrity, only READ operations and QUIT are allowed.
284
-
285
- Please quit Secrez and re-enter your account to sync with the new repository state.`;
303
+ For data integrity, only READ operations and QUIT are allowed.`;
286
304
  }
287
305
 
288
306
  if (status.error) {
@@ -299,10 +317,7 @@ Any changes you make now might conflict with remote changes that we cannot detec
299
317
  return `⚠️ Git Conflict Risk Detected!
300
318
 
301
319
  Your local repository is ${status.behind} commit(s) behind the remote '${status.remoteBranch}' branch.
302
- Any changes you make now could lead to merge conflicts when you try to sync later.
303
-
304
- Consider quitting Secrez and running in the container:
305
- git pull # to sync with remote changes first`;
320
+ Any changes you make now could lead to merge conflicts when you try to sync later.`;
306
321
  }
307
322
 
308
323
  return null;
@@ -315,6 +330,10 @@ Consider quitting Secrez and running in the container:
315
330
  this.isGitRepo = null;
316
331
  this.remoteStatus = null;
317
332
  this.initialGitState = null;
333
+ this.sessionBlock = null;
334
+ this.sessionBlockAnnounced = false;
335
+ this.entryStatus = null;
336
+ this.hasEntryStatus = false;
318
337
  this.lastCheck = null;
319
338
  }
320
339
  }
package/src/InternalFs.js CHANGED
@@ -465,9 +465,20 @@ class InternalFs {
465
465
  }
466
466
 
467
467
  async checkGitSyncStatus() {
468
- // First, check for external repository changes WITHOUT using cache
469
- // This is critical - we must always get fresh git status to detect external changes
470
- const currentStatus = await this.gitConflictChecker.getGitStatus();
468
+ // Behind-remote and a hard block stay true until Secrez restarts, so later
469
+ // writes reuse the result instead of fetching again.
470
+ if (this.gitConflictChecker.sessionBlock) {
471
+ return this.gitConflictChecker.sessionBlock;
472
+ }
473
+
474
+ let currentStatus;
475
+ if (this.gitConflictChecker.hasEntryStatus) {
476
+ currentStatus = this.gitConflictChecker.entryStatus;
477
+ this.gitConflictChecker.hasEntryStatus = false;
478
+ this.gitConflictChecker.entryStatus = null;
479
+ } else {
480
+ currentStatus = await this.gitConflictChecker.getGitStatus();
481
+ }
471
482
  const riskInfo = this.gitConflictChecker.hasConflictRisk(currentStatus);
472
483
 
473
484
  if (riskInfo.hasRisk) {
@@ -475,13 +486,17 @@ class InternalFs {
475
486
  currentStatus,
476
487
  riskInfo
477
488
  );
478
- return {
489
+ const result = {
479
490
  hasRisk: true,
480
491
  riskType: riskInfo.type,
481
492
  allowBypass: riskInfo.allowBypass,
482
493
  message: warningMessage,
483
494
  status: currentStatus,
484
495
  };
496
+ if (riskInfo.allowBypass === false || riskInfo.type === "behind_remote") {
497
+ this.gitConflictChecker.sessionBlock = result;
498
+ }
499
+ return result;
485
500
  }
486
501
 
487
502
  return {