Skip to content

Commit 5d4071f

Browse files
Prithvi-Webclaude
andcommitted
the duplicates measurement skipped the commonest roots, and survived into a cloud scan
Two more from adversarial verification of the shipped duplicates work. THE FREE-SPACE CHECK REFUSED THE COMMONEST SCANS. /api/system measures the home folder's volume, so the question the gate is asking is "is the scanned tree on that volume?" — but it tested only `root.startsWith(home)`, which answers a narrower one. A scan of /, /Users or C:\ is on the home volume and failed it, so every one of those got the unmeasurable branch no matter what the trash actually did. Containment either way now. THE MEASURED LINE SURVIVED INTO A CLOUD SCAN. The duplicates view is disabled for cloud scans and its mount() returns early after writing "Not available for cloud scans" — without reaching updateDupToolbar, and without unmount() having run, because switchView only unmounts when the view actually changes. So a cloud scan finishing while the user sat on the Duplicates tab left the previous local scan's "Moved 3 copies to the Trash" standing underneath a panel saying the feature is unavailable. The outcome belongs to the scan that produced it and is cleared there. Checked and deliberately NOT changed: on Windows SendToRecycleBin is best-effort, and a file too large for the Recycle Bin is deleted outright with the confirmation suppressed — so "the Trash is still holding them" would be false, and would tell someone a destroyed file is recoverable. The 1 MB gate already sorts this correctly: a file big enough to be refused by the Recycle Bin frees at least a megabyte when it is destroyed, so that case takes the measured branch and never claims recoverability. Left as it is, with the reasoning recorded rather than assumed. Two mutants, two caught. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 63008bb commit 5d4071f

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎public/index.html‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6604,6 +6604,12 @@ <h3 id="portableTitle"><span data-icon="disc"></span>Portable session</h3>
66046604
$('ndBody').innerHTML = msg;
66056605
$('dupSummary').textContent = 'Not available for cloud scans.';
66066606
$('ndSummary').textContent = 'Not available for cloud scans.';
6607+
// This branch paints nothing else and never reaches updateDupToolbar,
6608+
// and unmount() has not run — switchView only unmounts when the view
6609+
// actually changes. Without this the previous local scan's measured
6610+
// trash line stands under "Not available for cloud scans."
6611+
dupTrashOutcome = null;
6612+
renderDupNote();
66076613
return;
66086614
}
66096615
if (state.dupMode === 'near') loadNearDupes(); else loadDuplicates();
@@ -28355,7 +28361,12 @@ <h4>${icon('cart', 16)}Staged — deleted only when you say so</h4>
2835528361
*/
2835628362
async function freeSpaceNow() {
2835728363
const home = (state.system || {}).homeDir;
28358-
if (!home || !state.root || !state.root.path.startsWith(home)) return null;
28364+
const root = state.root && state.root.path;
28365+
// Containment EITHER WAY. /api/system measures the home folder's volume, so
28366+
// the question is whether the scanned tree is on that volume — and a scan of
28367+
// /, /Users or C:\ is, while failing a one-directional startsWith(home).
28368+
// Those are among the commonest roots anyone scans.
28369+
if (!home || !root || !(root.startsWith(home) || home.startsWith(root))) return null;
2835928370
try { return (await api('/api/system')).freeDisk; } catch { return null; }
2836028371
}
2836128372

‎src/ui/app/020-view-registry.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ const VIEWS = [
175175
$('ndBody').innerHTML = msg;
176176
$('dupSummary').textContent = 'Not available for cloud scans.';
177177
$('ndSummary').textContent = 'Not available for cloud scans.';
178+
// This branch paints nothing else and never reaches updateDupToolbar,
179+
// and unmount() has not run — switchView only unmounts when the view
180+
// actually changes. Without this the previous local scan's measured
181+
// trash line stands under "Not available for cloud scans."
182+
dupTrashOutcome = null;
183+
renderDupNote();
178184
return;
179185
}
180186
if (state.dupMode === 'near') loadNearDupes(); else loadDuplicates();

‎src/ui/app/200-duplicates-view.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ let dupNotePainted = '';
309309
*/
310310
async function freeSpaceNow() {
311311
const home = (state.system || {}).homeDir;
312-
if (!home || !state.root || !state.root.path.startsWith(home)) return null;
312+
const root = state.root && state.root.path;
313+
// Containment EITHER WAY. /api/system measures the home folder's volume, so
314+
// the question is whether the scanned tree is on that volume — and a scan of
315+
// /, /Users or C:\ is, while failing a one-directional startsWith(home).
316+
// Those are among the commonest roots anyone scans.
317+
if (!home || !root || !(root.startsWith(home) || home.startsWith(root))) return null;
313318
try { return (await api('/api/system')).freeDisk; } catch { return null; }
314319
}
315320

‎tests/duplicatesHonesty.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,29 @@ test('the trash toast no longer claims bytes were recovered', () => {
123123
'the bytes are in the Trash until it is emptied');
124124
assert.match(INDEX, /to Trash — \$\{formatBytes\(recovered\)\}/, 'the size itself still gets said');
125125
});
126+
127+
test('the free-space check covers a scan of a folder that CONTAINS home, not just one inside it', () => {
128+
// /api/system measures the home folder's volume, so the question is "is the
129+
// scanned tree on that volume?". Testing only `root.startsWith(home)` answers
130+
// a narrower one and says no for /, /Users and C:\ — roots that are on the
131+
// home volume and are among the commonest things anyone scans.
132+
const start = INDEX.indexOf('async function freeSpaceNow()');
133+
assert.notEqual(start, -1);
134+
const fn = INDEX.slice(start, INDEX.indexOf('\n}', start));
135+
assert.match(fn, /home\.startsWith\(/,
136+
'a root that contains the home folder is on the home volume too');
137+
assert.match(fn, /startsWith\(home\)/, 'and so is a root inside it');
138+
});
139+
140+
test('a cloud scan does not inherit the previous local scan’s trash line', () => {
141+
// The duplicates view is disabled for cloud scans and its mount() returns
142+
// early — without unmount() running, because switchView only unmounts when
143+
// the view actually changes. The note would otherwise stand under "Not
144+
// available for cloud scans."
145+
const start = INDEX.indexOf("id: 'duplicates'");
146+
assert.notEqual(start, -1);
147+
const mount = INDEX.slice(start, INDEX.indexOf("id: 'trends'", start));
148+
const cloud = mount.slice(mount.indexOf('if (isCloudScan())'), mount.indexOf('state.dupMode'));
149+
assert.match(cloud, /dupTrashOutcome = null/, 'the measured line belongs to the scan that produced it');
150+
assert.match(cloud, /renderDupNote\(\)/, 'and the panel is repainted so it actually goes');
151+
});

0 commit comments

Comments
 (0)