Files
openchamber/packages/ui/src/components/views/fileStatChange.test.ts
T
Ibrahim KhanandBohdan Triapitsyn 7ea24e3c50 fix(files): stop file viewer reload loop from sub-ms mtime jitter (#1489) (#2297)
* fix(files): guard file polling races

- Ignore sub-millisecond mtime jitter on a same-size file so an unchanged
  open file no longer loops through reload and flickers.
- Swap externally changed text content into the open editor in place
  instead of clearing the loaded path and showing the load spinner.
- Read content only after metadata changed, confirm it with a second
  read, and skip the swap when the file is unchanged, the buffer is
  dirty, or a newer local write landed.
- Keep the stat baseline unchanged when a poll cannot observe content so
  a failed read is retried rather than treated as unchanged.
- Fall back to a full reload for images, PDFs, binaries, and files above
  the content-poll byte limit, and when a poll returns binary content.
- Serialize polls and dispose the poller on unmount, file switch, and
  directory change.
- Add a `fresh` file read option that bypasses the content cache and the
  HTTP cache.

* fix(files): invalidate stale polls after diagram saves

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-09-05 18:31:35 +03:00

18 lines
666 B
TypeScript

import { describe, expect, test } from 'bun:test';
import { hasFileStatChanged } from './fileStatChange';
describe('hasFileStatChanged', () => {
test('ignores sub-millisecond mtime jitter on an unchanged file (issue #1489)', () => {
expect(hasFileStatChanged(
{ size: 100, mtimeMs: 1700000000123.456 },
{ size: 100, mtimeMs: 1700000000123.4561 },
)).toBe(false);
});
test('detects size changes and meaningful mtime changes', () => {
expect(hasFileStatChanged({ size: 100, mtimeMs: 1 }, { size: 101, mtimeMs: 1 })).toBe(true);
expect(hasFileStatChanged({ size: 100, mtimeMs: 1 }, { size: 100, mtimeMs: 2 })).toBe(true);
});
});