@secrez/fs 1.0.6 → 1.0.7

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
@@ -31,21 +31,21 @@ API documentation
31
31
  ## Test coverage
32
32
 
33
33
  ```
34
- 107 passing (39s)
34
+ 107 passing (44s)
35
35
 
36
36
  -----------------------|---------|----------|---------|---------|-----------------------------------
37
- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
37
+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
38
38
  -----------------------|---------|----------|---------|---------|-----------------------------------
39
- All files | 82.26 | 68.89 | 86.66 | 81.93 |
40
- DataCache.js | 89.41 | 74.07 | 90.9 | 89.28 | 17-23,122-123,149
41
- ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
42
- FileCipher.js | 88.63 | 73.33 | 100 | 88.63 | 8,52,80,85,94
43
- FsUtils.js | 100 | 100 | 100 | 100 |
44
- GitConflictChecker.js | 77.21 | 72.6 | 100 | 77.21 | ...16,126,129,138,155,186,199,218
45
- InternalFs.js | 85.37 | 71.87 | 85.18 | 85.25 | ...30,341,361,420-425,457,465-476
46
- Messages.js | 100 | 100 | 100 | 100 |
47
- Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
48
- Tree.js | 89.91 | 74.09 | 86.48 | 89.63 | ...39,466,476,530,622,630,661-672
39
+ All files | 81.78 | 67.77 | 86.27 | 81.44 |
40
+ DataCache.js | 89.41 | 74.07 | 90.9 | 89.28 | 17-23,122-123,149
41
+ ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
42
+ FileCipher.js | 88.63 | 73.33 | 100 | 88.63 | 8,52,80,85,94
43
+ FsUtils.js | 100 | 100 | 100 | 100 |
44
+ GitConflictChecker.js | 72.81 | 61.9 | 90 | 72.81 | ...95,204,222,254,259,277,289,308
45
+ InternalFs.js | 85.09 | 71.87 | 85.18 | 84.98 | ...33,344,364,423-428,460,470-487
46
+ Messages.js | 100 | 100 | 100 | 100 |
47
+ Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
48
+ Tree.js | 89.91 | 74.09 | 86.48 | 89.63 | ...39,466,476,530,622,630,661-672
49
49
  -----------------------|---------|----------|---------|---------|-----------------------------------
50
50
  ```
51
51
 
package/coverage.report CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- > @secrez/fs@1.0.6 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
2
+ > @secrez/fs@1.0.7 test /Users/francescosullo/Projects/Secrez/secrez/packages/fs
3
3
  > cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
4
4
 
5
5
 
@@ -67,10 +67,10 @@
67
67
  ✓ should not detect conflict risk in non-git repository
68
68
  with real GitHub repository
69
69
  ✓ should detect git repository
70
- ✓ should get git status when up to date with remote (3420ms)
71
- ✓ should detect conflict risk when behind remote (5263ms)
70
+ ✓ should get git status when up to date with remote (3471ms)
71
+ ✓ should detect conflict risk when behind remote (5794ms)
72
72
  ✓ should get warning message for conflict risk
73
- ✓ should not show alert again after user proceeds (3456ms)
73
+ ✓ should not show alert again after user proceeds (3582ms)
74
74
  ✓ should reset cache
75
75
 
76
76
  #InternalFs
@@ -157,30 +157,47 @@
157
157
  getEntryDetails
158
158
  ✓ should return the entry details of a node
159
159
  #Fix
160
- ✓ should load a tree with tags
161
- ✓ should simulate a conflict in the repo and recover lost entries when a valid tree exists (1112ms)
162
- ✓ should simulate a lost index in the repo and recover the entries when no valid tree is found (44ms)
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)
163
163
  Multi data sets
164
164
  ✓ should load the trees of two data sets
165
165
 
166
166
 
167
- 107 passing (39s)
167
+ 106 passing (44s)
168
+ 1 failing
169
+
170
+ 1) #Tree
171
+ #Fix
172
+ should simulate a conflict in the repo and recover lost entries when a valid tree exists:
173
+
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' ]
175
+ + expected - actual
176
+
177
+ [
178
+ "/B/D/g"
179
+ "/B/b"
180
+ "/E/L/N"
181
+ - "/REC_20251009101127/d"
182
+ + "/E/c"
183
+ ]
184
+
185
+ at Context.<anonymous> (test/Tree.test.js:306:14)
186
+
187
+
168
188
 
169
189
  -----------------------|---------|----------|---------|---------|-----------------------------------
170
190
  File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
171
191
  -----------------------|---------|----------|---------|---------|-----------------------------------
172
- All files | 82.26 | 68.89 | 86.66 | 81.93 |
192
+ All files | 81.85 | 67.77 | 86.27 | 81.52 |
173
193
  DataCache.js | 89.41 | 74.07 | 90.9 | 89.28 | 17-23,122-123,149
174
194
  ExternalFs.js | 94.02 | 76.92 | 100 | 93.93 | 9,29,35,54
175
195
  FileCipher.js | 88.63 | 73.33 | 100 | 88.63 | 8,52,80,85,94
176
196
  FsUtils.js | 100 | 100 | 100 | 100 |
177
- GitConflictChecker.js | 77.21 | 72.6 | 100 | 77.21 | ...16,126,129,138,155,186,199,218
178
- InternalFs.js | 85.37 | 71.87 | 85.18 | 85.25 | ...30,341,361,420-425,457,465-476
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
179
199
  Messages.js | 100 | 100 | 100 | 100 |
180
200
  Node.js | 66.1 | 54.81 | 78.72 | 65.31 | ...05,644-648,666,669,683-720,729
181
- Tree.js | 89.91 | 74.09 | 86.48 | 89.63 | ...39,466,476,530,622,630,661-672
201
+ Tree.js | 90.19 | 74.09 | 86.48 | 89.91 | ...39,466,476,530,622,630,661-672
182
202
  -----------------------|---------|----------|---------|---------|-----------------------------------
183
-
184
- > @secrez/fs@1.0.6 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/fs
185
- > nyc check-coverage --statements 80 --branches 65 --functions 80 --lines 80
186
-
203
+  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.0.6",
3
+ "version": "1.0.7",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -7,6 +7,7 @@ class GitConflictChecker {
7
7
  this.secrez = secrez;
8
8
  this.isGitRepo = null;
9
9
  this.remoteStatus = null;
10
+ this.initialGitState = null; // Initial state captured at account entry
10
11
  this.lastCheck = null;
11
12
  this.checkInterval = 30000; // 30 seconds between checks
12
13
  }
@@ -30,6 +31,61 @@ class GitConflictChecker {
30
31
  }
31
32
  }
32
33
 
34
+ /**
35
+ * Capture the initial git state when entering the account
36
+ */
37
+ async captureInitialState() {
38
+ const status = await this.getGitStatus();
39
+ if (status && !status.error) {
40
+ this.initialGitState = this.getGitFingerprint(status);
41
+ }
42
+ return status;
43
+ }
44
+
45
+ /**
46
+ * Get a fingerprint of the current git state for comparison
47
+ */
48
+ getGitFingerprint(status) {
49
+ if (!status || status.error) {
50
+ return null;
51
+ }
52
+
53
+ // Create a fingerprint based on the repository state
54
+ return {
55
+ localBranch: status.localBranch,
56
+ remoteBranch: status.remoteBranch,
57
+ headCommit: status.headCommit,
58
+ behind: status.behind,
59
+ ahead: status.ahead,
60
+ uncommitted: status.uncommitted,
61
+ };
62
+ }
63
+
64
+ /**
65
+ * Check if the repository state has changed since initial capture
66
+ */
67
+ hasRepositoryChanged(currentStatus) {
68
+ if (!this.initialGitState || !currentStatus || currentStatus.error) {
69
+ return false;
70
+ }
71
+
72
+ const currentFingerprint = this.getGitFingerprint(currentStatus);
73
+ if (!currentFingerprint) {
74
+ return false;
75
+ }
76
+
77
+ // Check if any aspect of the repository has changed
78
+ // Most importantly, check if HEAD commit has changed (e.g., after pull)
79
+ return (
80
+ this.initialGitState.localBranch !== currentFingerprint.localBranch ||
81
+ this.initialGitState.remoteBranch !== currentFingerprint.remoteBranch ||
82
+ this.initialGitState.headCommit !== currentFingerprint.headCommit ||
83
+ this.initialGitState.behind !== currentFingerprint.behind ||
84
+ this.initialGitState.ahead !== currentFingerprint.ahead ||
85
+ this.initialGitState.uncommitted !== currentFingerprint.uncommitted
86
+ );
87
+ }
88
+
33
89
  /**
34
90
  * Get the current git status and remote information
35
91
  */
@@ -51,6 +107,16 @@ class GitConflictChecker {
51
107
  return { error: "Could not determine current branch" };
52
108
  }
53
109
 
110
+ // Get the HEAD commit hash for tracking changes
111
+ const headCommit = await execAsync("git", containerPath, [
112
+ "rev-parse",
113
+ "HEAD",
114
+ ]);
115
+
116
+ if (!headCommit || !headCommit.message) {
117
+ return { error: "Could not determine HEAD commit" };
118
+ }
119
+
54
120
  // Fetch latest remote info
55
121
  const fetchResult = await execAsync("git", containerPath, [
56
122
  "fetch",
@@ -141,6 +207,7 @@ class GitConflictChecker {
141
207
  return {
142
208
  localBranch: currentBranch.message.trim(),
143
209
  remoteBranch: remoteRef,
210
+ headCommit: headCommit.message.trim(),
144
211
  behind: parseInt(behind.message.trim()) || 0,
145
212
  ahead: parseInt(ahead.message.trim()) || 0,
146
213
  uncommitted: status.message
@@ -175,26 +242,49 @@ class GitConflictChecker {
175
242
 
176
243
  /**
177
244
  * Determine if there's a risk of conflicts
245
+ * Returns an object with risk level and details
178
246
  */
179
247
  hasConflictRisk(status) {
180
248
  if (!status) {
181
- return false;
249
+ return { hasRisk: false, type: null };
250
+ }
251
+
252
+ // Check if repository has changed externally (e.g., pull in another terminal)
253
+ if (this.hasRepositoryChanged(status)) {
254
+ return { hasRisk: true, type: "external_change", allowBypass: false };
182
255
  }
183
256
 
184
257
  // If there's an error, we should warn the user
185
258
  if (status.error) {
186
- return true;
259
+ return { hasRisk: true, type: "error", allowBypass: true };
187
260
  }
188
261
 
189
262
  // Risk if local is behind remote (remote has new commits that haven't been pulled)
190
263
  // This means any local changes will conflict with remote changes
191
- return status.behind > 0;
264
+ if (status.behind > 0) {
265
+ return { hasRisk: true, type: "behind_remote", allowBypass: true };
266
+ }
267
+
268
+ return { hasRisk: false, type: null };
192
269
  }
193
270
 
194
271
  /**
195
272
  * Get a user-friendly warning message
196
273
  */
197
- getWarningMessage(status = {}) {
274
+ getWarningMessage(status = {}, riskInfo = {}) {
275
+ // Check for external repository changes first (highest priority)
276
+ if (riskInfo.type === "external_change") {
277
+ return `🚫 Repository State Changed Externally!
278
+
279
+ The git repository state has changed since you entered your account.
280
+ This likely means a 'git pull' or other git operation was performed in another terminal.
281
+
282
+ 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.`;
286
+ }
287
+
198
288
  if (status.error) {
199
289
  return `⚠️ Git Status Check Failed!
200
290
 
@@ -224,6 +314,7 @@ Consider quitting Secrez and running in the container:
224
314
  resetCache() {
225
315
  this.isGitRepo = null;
226
316
  this.remoteStatus = null;
317
+ this.initialGitState = null;
227
318
  this.lastCheck = null;
228
319
  }
229
320
  }
package/src/InternalFs.js CHANGED
@@ -27,6 +27,9 @@ class InternalFs {
27
27
  // eslint-disable-next-line require-atomic-updates
28
28
  await this.tree.load();
29
29
  await this.trashToBeDeleted(0);
30
+
31
+ // Capture initial git state when entering the account
32
+ await this.gitConflictChecker.captureInitialState();
30
33
  }
31
34
 
32
35
  getFullPath(entry) {
@@ -462,21 +465,31 @@ class InternalFs {
462
465
  }
463
466
 
464
467
  async checkGitSyncStatus() {
465
- const status = await this.gitConflictChecker.checkForRemoteChanges();
466
-
467
- if (this.gitConflictChecker.hasConflictRisk(status)) {
468
- const warningMessage = this.gitConflictChecker.getWarningMessage(status);
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();
471
+ const riskInfo = this.gitConflictChecker.hasConflictRisk(currentStatus);
472
+
473
+ if (riskInfo.hasRisk) {
474
+ const warningMessage = this.gitConflictChecker.getWarningMessage(
475
+ currentStatus,
476
+ riskInfo
477
+ );
469
478
  return {
470
479
  hasRisk: true,
480
+ riskType: riskInfo.type,
481
+ allowBypass: riskInfo.allowBypass,
471
482
  message: warningMessage,
472
- status: status,
483
+ status: currentStatus,
473
484
  };
474
485
  }
475
486
 
476
487
  return {
477
488
  hasRisk: false,
489
+ riskType: null,
490
+ allowBypass: true,
478
491
  message: null,
479
- status: status,
492
+ status: currentStatus,
480
493
  };
481
494
  }
482
495
  }