diff --git a/apps/host/server/timeskip.mjs b/apps/host/server/timeskip.mjs index f21dc82c..959a402b 100644 --- a/apps/host/server/timeskip.mjs +++ b/apps/host/server/timeskip.mjs @@ -118,6 +118,16 @@ function readText(path) { } catch { return { missing: true }; } } +/** Whether two files hold the same bytes (a big file that did not change must not be listed as changed). Files over 64 MB are treated as changed. */ +function sameBytes(a, b) { + try { + const sa = statSync(a), sb = statSync(b); + if (sa.size !== sb.size) return false; + if (sa.size > 64 * 1024 * 1024) return false; + return readFileSync(a).equals(readFileSync(b)); + } catch { return false; } +} + /** What the assistant is told for one revision attempt. It works on a copy, so it is told to stay in it and to say what it did. */ export function timeskipRevisionMessage(request) { return [ @@ -235,6 +245,8 @@ export function diffRun(record) { const status = a.missing ? 'added' : b.missing ? 'removed' : null; const same = !status && a.text !== undefined && a.text === b.text; if (same) continue; + // A file too big to read as text is the same file when its bytes are the same: it must not show up as a change. + if (!status && (a.big || b.big) && sameBytes(join(baseRoot, path), join(updatedRoot, path))) continue; if (imageTypeOf(path)) { // A picture is compared as bytes and shown from the file itself, never read as text. let differs = true; diff --git a/apps/host/tests/timeskip-compare-server.test.mjs b/apps/host/tests/timeskip-compare-server.test.mjs index 17afecd8..63ef0c11 100644 --- a/apps/host/tests/timeskip-compare-server.test.mjs +++ b/apps/host/tests/timeskip-compare-server.test.mjs @@ -65,3 +65,17 @@ test('the page that was made comes first; a browser profile and other housekeepi assert.deepEqual(onlyNoise.files, [], 'when only housekeeping changed nothing is shown as changed'); assert.equal(onlyNoise.housekeeping, 12); } finally { rmSync(dir, { recursive: true, force: true }); } }); + +test('a big file that did not change is not listed as changed; one that did is', () => { + const dir = mkdtempSync(join(tmpdir(), 'strata-ts-big-')); + try { + const base = join(dir, 'base'), cand = join(dir, 'cand'); mkdirSync(base); mkdirSync(cand); + const big = Buffer.alloc(400 * 1024, 7); + writeFileSync(join(base, 'archive.bin'), big); writeFileSync(join(cand, 'archive.bin'), big); + writeFileSync(join(base, 'data.json'), Buffer.alloc(300 * 1024, 65)); writeFileSync(join(cand, 'data.json'), Buffer.alloc(300 * 1024, 66)); + writeFileSync(join(cand, 'page.html'), '

x

'); + const found = diffRun({ checkpoints: [{ id: 'cp1-baseline', label: 'baseline', path: base }], selected_checkpoint: 'cp1-baseline', attempts: [{ index: 1, path: cand }] }); + assert.deepEqual(found.files.map(f => f.path), ['page.html', 'data.json'], 'the untouched big file is gone from the list; the changed one is last (too big to show)'); + assert.equal(found.files[1].unreadable, true); + } finally { rmSync(dir, { recursive: true, force: true }); } +});