@secrez/fs 1.1.1 → 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/coverage.report CHANGED
@@ -1,203 +1,260 @@
1
+  WARN  Unsupported engine: wanted: {"node":">=22.23.4"} (current: {"node":"v22.14.0","pnpm":"9.6.0"})
1
2
 
2
- > @secrez/fs@1.0.7 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
 
6
7
 
7
8
  #DataCache
8
- ✓ should initialize a dataCache
9
- ✓ should put and get data
10
- ✓ should load data from disk, if any
11
- ✓ should not load if no data
12
- ✓ should load plaintext data from disk, if any
13
- ✓ should load encrypted data from disk, if any
9
+ ✔ should initialize a dataCache
10
+ ✔ should put and get data
11
+ ✔ should load data from disk, if any
12
+ ✔ should not load if no data
13
+ ✔ should load plaintext data from disk, if any
14
+ ✔ should load encrypted data from disk, if any
14
15
 
15
16
  #ExternalFs
16
17
  getNormalizedPath
17
- ✓ should normalize "~/fileSystems"
18
- ✓ should normalize "~"
19
- ✓ should normalize "/var"
18
+ ✔ should normalize "~/fileSystems"
19
+ ✔ should normalize "~"
20
+ ✔ should normalize "/var"
20
21
  fileCompletion
21
- ✓ should return a list of files
22
- ✓ should return a list of only directories
23
- ✓ should return a list of only files
24
- ✓ should return the file itself, if it is not a directory
25
- ✓ should return the list of the files satisfying wildcards
26
- ✓ should return an empty list if the files does not exist
22
+ ✔ should return a list of files
23
+ ✔ should return a list of only directories
24
+ ✔ should return a list of only files
25
+ ✔ should return the file itself, if it is not a directory
26
+ ✔ should return the list of the files satisfying wildcards
27
+ ✔ should return an empty list if the files does not exist
27
28
  getVersionedBasename
28
- ✓ should version a file
29
+ ✔ should version a file
29
30
  isDir
30
- ✓ should confirm that "utils" is a dir
31
- ✓ should return that "config.test.js" is not a dir
32
- ✓ should return that a not-existent file is not a dir
31
+ ✔ should confirm that "utils" is a dir
32
+ ✔ should return that "config.test.js" is not a dir
33
+ ✔ should return that a not-existent file is not a dir
33
34
  isFile
34
- ✓ should return that "config.test.js" is a file
35
- ✓ should confirm that "utils" is not a file
36
- ✓ should return that a not-existent file is not a dir
35
+ ✔ should return that "config.test.js" is a file
36
+ ✔ should confirm that "utils" is not a file
37
+ ✔ should return that a not-existent file is not a dir
37
38
 
38
39
  #FileCipher
39
40
  encrypt/decrypt external file
40
- ✓ should encrypt a file using a specific password
41
- ✓ should encrypt a file using a shared key
42
- ✓ should encrypt a file using user's own public key
41
+ ✔ should encrypt a file using a specific password (v2)
42
+ ✔ should decrypt v1 password-encrypted files
43
+ ✔ should encrypt a file using a shared key
44
+ ✔ should encrypt a file using user's own public key
43
45
 
44
46
  #FsUtils
45
47
  preParseCommandLine
46
- ✓ should preParse a command line
47
- ✓ should preParse a command line with escaped pars
48
- ✓ should preParse a command line using quotes for params
48
+ ✔ should preParse a command line
49
+ ✔ should preParse a command line with escaped pars
50
+ ✔ should preParse a command line using quotes for params
49
51
  parseCommandLine
50
- ✓ should parse a command line with definitions
51
- ✓ should return a {} w/out definitions
52
- ✓ should return a {} w/out params
53
- ✓ should return an _unknown if not supported option is passed
52
+ ✔ should parse a command line with definitions
53
+ ✔ should return a {} w/out definitions
54
+ ✔ should return a {} w/out params
55
+ ✔ should return an _unknown if not supported option is passed
54
56
  filterLs
55
- ✓ should filter an array of files and return itself
56
- ✓ should filter an array of files starting from "te"
57
- ✓ should filter an array of files of type .log
58
- ✓ should filter an array of files and find the folders
59
- ✓ should get all the files
60
- ✓ should return an empty array if nothing is found
61
- ✓ should return an empty array if parameters are missed or empty
62
- ✓ should return all the list array if files are missed
57
+ ✔ should filter an array of files and return itself
58
+ ✔ should filter an array of files starting from "te"
59
+ ✔ should filter an array of files of type .log
60
+ ✔ should filter an array of files and find the folders
61
+ ✔ should get all the files
62
+ ✔ should return an empty array if nothing is found
63
+ ✔ should return an empty array if parameters are missed or empty
64
+ ✔ should return all the list array if files are missed
63
65
 
64
66
  #GitConflictChecker
65
- ✓ should detect non-git repository
66
- ✓ should return null status for non-git repository
67
- ✓ should not detect conflict risk in non-git repository
68
- with real GitHub repository
69
- ✓ should detect git repository
70
- ✓ should get git status when up to date with remote (3471ms)
71
- ✓ should detect conflict risk when behind remote (5794ms)
72
- ✓ should get warning message for conflict risk
73
- ✓ should not show alert again after user proceeds (3582ms)
74
- ✓ should reset cache
67
+ ✔ should detect non-git repository
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
74
+ ✔ should not detect conflict risk in non-git repository
75
+ with local git repository
76
+ ✔ should detect git repository
77
+ ✔ should get git status when up to date with remote (153ms)
78
+ ✔ should detect conflict risk when behind remote (281ms)
79
+ ✔ should get warning message for conflict risk
80
+ ✔ should not show alert again after user proceeds (154ms)
81
+ ✔ should reset cache
75
82
 
76
83
  #InternalFs
77
84
  #constructor
78
- ✓ should instantiate the internal file system and initialize it
79
- ✓ should initialize the internal fs
80
- ✓ should throw if passing not a Secrez instance
85
+ ✔ should instantiate the internal file system and initialize it
86
+ ✔ should initialize the internal fs
87
+ ✔ should throw if passing not a Secrez instance
81
88
  getFullPath
82
- ✓ should return the fullPath of an entry
89
+ ✔ should return the fullPath of an entry
83
90
  normalizePath
84
- ✓ should normalize a path
85
- ✓ should throw if the path is empty, is not a string or is longer than 255 chars
91
+ ✔ should normalize a path
92
+ ✔ should throw if the path is empty, is not a string or is longer than 255 chars
86
93
  getNormalizedPath
87
- ✓ should normalize a path
94
+ ✔ should normalize a path
88
95
  make
89
- ✓ should create directories and files
90
- ✓ should throw trying to re-add the same entry
96
+ ✔ should create directories and files
97
+ ✔ should throw trying to re-add the same entry
91
98
  change
92
- ✓ should create directories and files and update them
93
- ✓ should return an error
94
- ✓ should move files between datasets
99
+ ✔ should create directories and files and update them
100
+ ✔ should return an error
101
+ ✔ should move files between datasets
95
102
  remove
96
- ✓ should remove a file from the tree
103
+ ✔ should remove a file from the tree
97
104
  load
98
- ✓ should create directories and files and loading a tree from disk
99
- ✓ should create directories and files, and load a tree from disk
100
- ✓ should create directories and files, delete everything and loading a tree from disk
101
- ✓ should compress and reload an empty set of entries
105
+ ✔ should create directories and files and loading a tree from disk
106
+ ✔ should create directories and files, and load a tree from disk
107
+ ✔ should create directories and files, delete everything and loading a tree from disk
108
+ ✔ should compress and reload an empty set of entries
102
109
  #getFileList
103
- ✓ should get the current folder dir
110
+ ✔ should get the current folder dir
104
111
 
105
112
  #Node
106
113
  #constructor
107
- ✓ should instantiate the Node
108
- ✓ should throw if passing a rot without required parameters
109
- ✓ should throw if not passing an object
110
- ✓ should throw if not passing wrong type
114
+ ✔ should instantiate the Node
115
+ ✔ should throw if passing a rot without required parameters
116
+ ✔ should throw if not passing an object
117
+ ✔ should throw if not passing wrong type
111
118
  #getName && #getFile && #getContent && getOptions
112
- ✓ should get name, file and options
113
- ✓ should throw if version not found
119
+ ✔ should get name, file and options
120
+ ✔ should throw if version not found
114
121
  #getFindRe
115
- ✓ should get a re to check a filepath
122
+ ✔ should get a re to check a filepath
116
123
  #getNames
117
- ✓ should get the names of all children
118
- ✓ should throw if trying to get children of a file
124
+ ✔ should get the names of all children
125
+ ✔ should throw if trying to get children of a file
119
126
  #find
120
- ✓ should find all childrens satisfying criterias
127
+ ✔ should find all childrens satisfying criterias
121
128
  #add
122
- ✓ should add children to root
123
- ✓ should throw if node is a file
129
+ ✔ should add children to root
130
+ ✔ should throw if node is a file
124
131
  #move
125
- ✓ should rename a node
126
- ✓ should move a node
127
- ✓ should throw trying to move root
128
- ✓ should throw trying to modify a node with different id
132
+ ✔ should rename a node
133
+ ✔ should move a node
134
+ ✔ should throw trying to move root
135
+ ✔ should throw trying to modify a node with different id
129
136
  #remove
130
- ✓ should remove a node
131
- ✓ should remove itself
132
- ✓ should throw trying to remove root
137
+ ✔ should remove a node
138
+ ✔ should remove itself
139
+ ✔ should throw trying to remove root
133
140
  #toCompressedJSON && Node#fromJSON
134
- ✓ should prepare a json for saving
135
- ✓ should build an index from a json file
141
+ ✔ should prepare a json for saving
142
+ ✔ should build an index from a json file
136
143
  #getChildFromPath
137
- ✓ should find a node starting from a path
138
- ✓ should find the last ancestor starting from a path
139
- ✓ should throw if the path is incorrect or does not exist
140
- ✓ should throw if looking for last ancestor and find existent node
144
+ ✔ should find a node starting from a path
145
+ ✔ should find the last ancestor starting from a path
146
+ ✔ should throw if the path is incorrect or does not exist
147
+ ✔ should throw if looking for last ancestor and find existent node
141
148
  #getPathToChild
142
- ✓ should find a node starting from a path
143
- ✓ should throw if child is not a Node
144
- ✓ should throw if child belows to another tree
149
+ ✔ should find a node starting from a path
150
+ ✔ should throw if child is not a Node
151
+ ✔ should throw if child belows to another tree
145
152
  #findDirectChildByName && #findChildById
146
- ✓ should find a direct child by name and by id
147
- ✓ should throw if looking for child of a file
148
- ✓ should throw if looking for child of a file
153
+ ✔ should find a direct child by name and by id
154
+ ✔ should throw if looking for child of a file
155
+ ✔ should throw if looking for child of a file
149
156
 
150
157
  #Tree
151
158
  #constructor
152
- ✓ should instantiate the Tree
153
- ✓ should throw if passing not an Secrez instance
159
+ ✔ should instantiate the Tree
160
+ ✔ should throw if passing not an Secrez instance
154
161
  #load
155
- ✓ should load an empty Tree
156
- ✓ should do nothing if already loaded
162
+ ✔ should load an empty Tree
163
+ ✔ should do nothing if already loaded
157
164
  getEntryDetails
158
- ✓ should return the entry details of a node
165
+ ✔ should return the entry details of a node
159
166
  #Fix
160
- ✓ should load a tree with tags (52ms)
161
- 1) should simulate a conflict in the repo and recover lost entries when a valid tree exists
162
- ✓ should simulate a lost index in the repo and recover the entries when no valid tree is found (73ms)
167
+ ✔ should load a tree with tags
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)
163
170
  Multi data sets
164
- ✓ should load the trees of two data sets
171
+ ✔ should load the trees of two data sets
165
172
 
166
173
 
167
- 106 passing (44s)
168
- 1 failing
174
+ 110 passing (4s)
175
+ 3 failing
169
176
 
170
- 1) #Tree
171
- #Fix
172
- should simulate a conflict in the repo and recover lost entries when a valid tree exists:
177
+ 1) #GitConflictChecker
178
+ should reuse a hard block without checking git again:
173
179
 
174
- AssertionError: expected [ '/B/D/g', '/B/b', '/E/L/N', …(1) ] to deeply equal [ '/B/D/g', '/B/b', '/E/L/N', '/E/c' ]
180
+ AssertionError: expected { hasRisk: true, …(4) } to equal { Object (hasRisk, riskType, ...) }
175
181
  + expected - actual
176
182
 
177
- [
178
- "/B/D/g"
179
- "/B/b"
180
- "/E/L/N"
181
- - "/REC_20251009101127/d"
182
- + "/E/c"
183
- ]
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
+ }
184
202
 
185
- at Context.<anonymous> (test/Tree.test.js:306:14)
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)
186
242
 
187
243
 
188
244
 
189
245
  -----------------------|---------|----------|---------|---------|-----------------------------------
190
246
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
191
247
  -----------------------|---------|----------|---------|---------|-----------------------------------
192
- All files | 81.85 | 67.77 | 86.27 | 81.52 |
193
- DataCache.js | 89.41 | 74.07 | 90.9 | 89.28 | 17-23,122-123,149
248
+ All files | 83.39 | 70.34 | 88.19 | 83.09 |
249
+ DataCache.js | 89.53 | 74.07 | 90.9 | 89.41 | 18-24,123-124,150
194
250
  ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
195
- FileCipher.js | 88.63 | 73.33 | 100 | 88.63 | 8,52,80,85,94
251
+ FileCipher.js | 88.05 | 73.8 | 100 | 88.05 | 9,39,76,85,91,95,131,136
196
252
  FsUtils.js | 100 | 100 | 100 | 100 |
197
- GitConflictChecker.js | 72.81 | 61.9 | 90 | 72.81 | ...95,204,222,254,259,277,289,308
198
- InternalFs.js | 85.09 | 71.87 | 85.18 | 84.98 | ...33,344,364,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
199
255
  Messages.js | 100 | 100 | 100 | 100 |
200
256
  Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
201
- Tree.js | 90.19 | 74.09 | 86.48 | 89.91 | ...39,466,476,530,622,630,661-672
257
+ Tree.js | 89.91 | 74.09 | 86.48 | 89.63 | ...44,471,481,535,627,635,666-677
258
+ fileCipherLegacy.js | 100 | 100 | 100 | 100 |
202
259
  -----------------------|---------|----------|---------|---------|-----------------------------------
203
260
   ELIFECYCLE  Test failed. See above for more details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secrez/fs",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,13 +8,13 @@
8
8
  "dependencies": {
9
9
  "@secrez/core": "~1.1.1",
10
10
  "@secrez/crypto": "~1.1.1",
11
- "@secrez/utils": "~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.4",
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",
@@ -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 {