Files
genoffice/apps/docs/tests/external-change.test.ts
T
merrick-2002andGenOffice 8f523289d6 Sync snapshot (2026-08-04) (#19)
- Docs: paragraph writing direction (LTR/RTL) toggle with auto-detection
- Docs: hardened file lifecycle, docx fidelity, and editor performance
- PDF: Export as Word via cloud conversion, non-destructive Save As, and an in-progress export dialog
- Slides: treat full-page background shapes as the page background
- Sheets: faster recalculation with a session-resident engine; better xlsx compatibility (builtin number formats, auto-fit row heights, sheet-name resolution)
- AI: surface stream and gateway errors instead of finishing empty turns; parse non-SSE JSON gateway replies; stall watchdogs
- Fixes from alpha feedback batches 3 and 4 (TOC levels, Windows menus, honest AI applies, login flow diagnostics, credits-exhausted notice)
- CI: sheets save round-trip E2E and xlsx compatibility corpus gate
- Start the 0.5 release train (v0.5.0/v0.5.1)

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-04 21:26:02 +08:00

50 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { isExternallyModified, type DiskFileState } from '../src/main/external-change'
const recorded: DiskFileState = { mtimeMs: 1000, size: 42, hash: 'aaa' }
describe('isExternallyModified', () => {
it('is false when mtime and size still match (no hash read)', async () => {
const readHash = vi.fn(() => 'zzz')
await expect(
isExternallyModified(recorded, { mtimeMs: 1000, size: 42 }, readHash),
).resolves.toBe(false)
expect(readHash).not.toHaveBeenCalled()
})
it('is false when the stamp moved but the content hash is unchanged (e.g. touch)', async () => {
await expect(
isExternallyModified(recorded, { mtimeMs: 2000, size: 42 }, () => 'aaa'),
).resolves.toBe(false)
})
// the regression: another program's write must be detected before autosave overwrites it
it('is true when the content on disk changed', async () => {
await expect(
isExternallyModified(recorded, { mtimeMs: 2000, size: 43 }, () => 'bbb'),
).resolves.toBe(true)
})
it('supports an async hash reader', async () => {
await expect(
isExternallyModified(recorded, { mtimeMs: 2000, size: 43 }, async () => 'bbb'),
).resolves.toBe(true)
})
it('is false without a recorded state (path never tracked)', async () => {
await expect(
isExternallyModified(undefined, { mtimeMs: 2000, size: 43 }, () => 'bbb'),
).resolves.toBe(false)
})
it('is false when the file was deleted (save recreates it)', async () => {
await expect(isExternallyModified(recorded, null, () => null)).resolves.toBe(false)
})
it('is false when the changed file cannot be read back for hashing', async () => {
await expect(
isExternallyModified(recorded, { mtimeMs: 2000, size: 43 }, () => null),
).resolves.toBe(false)
})
})