import { describe, expect, it } from 'vitest'; import { mkdtempSync, utimesSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { installChanged, readInstallStamp } from '../src/main/upgrade-watch'; describe('upgrade-watch', () => { it('lit une empreinte de fichier, et rien pour un chemin absent', () => { const file = join(mkdtempSync(join(tmpdir(), 'arb-stamp-')), 'bin'); writeFileSync(file, 'v1', 'utf8'); const stamp = readInstallStamp(file); expect(stamp?.size).toBe(2); expect(readInstallStamp(join(file, 'nulle-part'))).toBeNull(); }); it('détecte le remplacement du binaire (mtime/taille)', () => { const file = join(mkdtempSync(join(tmpdir(), 'arb-stamp-')), 'bin'); writeFileSync(file, 'v1', 'utf8'); const boot = readInstallStamp(file); expect(installChanged(boot, readInstallStamp(file))).toBe(false); writeFileSync(file, 'version deux', 'utf8'); utimesSync(file, new Date(), new Date(Date.now() + 5_000)); // dpkg pose un mtime plus récent expect(installChanged(boot, readInstallStamp(file))).toBe(true); }); it('une empreinte illisible ne conclut jamais à une mise à jour', () => { const stamp = { ino: 1, mtimeMs: 2, size: 3 }; expect(installChanged(null, stamp)).toBe(false); expect(installChanged(stamp, null)).toBe(false); expect(installChanged(null, null)).toBe(false); }); });