mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-10-02 01:29:32 +05:30
VersionHistory snapshots the previous content on every explicit save — an unsaved buffer is still lost on crash. AutosaveBuffer fills that gap. - src/main/AutosaveBuffer.js — pure module mirroring VersionHistory's injectable-IO pattern; one blob per doc path under <userData>/autosave/by-path/<sha1>/recovery.md + meta.json. No history (VersionHistory owns that) — just the latest dirty buffer. - src/main.js — IPC channels autosave:write/read/clear/list; real paths go through validatePath, synthetic 'untitled-tab-<id>' keys skip it. - src/preload.js — added the four channels to ALLOWED_SEND_CHANNELS. - src/renderer/autosave-client.js — debounced (2s) flush per tab + periodic safety net (10s max age) + dirty-write retry on failure. - src/renderer.js — register on tab create, unregister on close, notifyChange piggybacks on performAutoSave's existing dirty-check, clearForDocPath after a successful save, showAutosaveRecoveryBanner on startup listing pending recoveries with Restore/Dismiss. Tests (39 new): - tests/main/AutosaveBuffer.test.js (19): round-trip, overwrite, isolation, unicode/emoji, empty content, null coercion, ENOENT vs corrupt meta, list ordering, corrupt-sibling skip, input validation, sha1 storage. - tests/autosave-client.test.js (11): debounce, flushNow bypass, no-path skip, clearForDocPath, list proxy, IPC error fallback, unregister tear-down, failure-retry, periodic flush, idempotency. Full suite: 692 tests pass, 63 suites, lint+format clean. Amit Haridas
115 lines
4.1 KiB
JavaScript
115 lines
4.1 KiB
JavaScript
/**
|
|
* Tests for bundled external tools
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
describe('Bundled Pandoc binary', () => {
|
|
const rootDir = path.resolve(__dirname, '..');
|
|
const platform = process.platform;
|
|
const binaryPath = path.join(rootDir, 'bin', platform, 'pandoc');
|
|
const windowsBinaryPath = path.join(rootDir, 'bin', platform, 'pandoc.exe');
|
|
|
|
test('Pandoc binary exists for current platform', () => {
|
|
const exists = fs.existsSync(binaryPath) || fs.existsSync(windowsBinaryPath);
|
|
expect(exists).toBe(true);
|
|
});
|
|
|
|
test('Pandoc binary is executable', () => {
|
|
if (platform === 'win32') {
|
|
expect(fs.existsSync(windowsBinaryPath)).toBe(true);
|
|
} else {
|
|
expect(fs.existsSync(binaryPath)).toBe(true);
|
|
const stats = fs.statSync(binaryPath);
|
|
expect(stats.mode & 0o111).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Bundled MarkItDown binary (optional)', () => {
|
|
const rootDir = path.resolve(__dirname, '..');
|
|
const platform = process.platform;
|
|
const binaryPath = path.join(rootDir, 'bin', platform, 'markitdown');
|
|
const windowsBinaryPath = path.join(rootDir, 'bin', platform, 'markitdown.exe');
|
|
|
|
// The binary is built on demand (npm run bundle:markitdown), so CI machines
|
|
// that haven't built it yet skip these — but when present it must be valid.
|
|
const hasBinary = fs.existsSync(binaryPath) || fs.existsSync(windowsBinaryPath);
|
|
const which = platform === 'win32' ? windowsBinaryPath : binaryPath;
|
|
|
|
(hasBinary ? describe : describe.skip)('binary present', () => {
|
|
test('is executable', () => {
|
|
const stats = fs.statSync(which);
|
|
expect(stats.mode & 0o111).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('answers --version', (done) => {
|
|
const { execFile } = require('child_process');
|
|
execFile(which, ['--version'], { timeout: 30000 }, (error, stdout) => {
|
|
expect(error).toBeNull();
|
|
expect(stdout.toLowerCase()).toContain('markitdown');
|
|
done();
|
|
});
|
|
}, 60000);
|
|
});
|
|
});
|
|
|
|
describe('Legal compliance artifacts', () => {
|
|
const rootDir = path.resolve(__dirname, '..');
|
|
|
|
test('THIRD-PARTY-NOTICES.md and SOURCES.md ship at the repo root', () => {
|
|
expect(fs.existsSync(path.join(rootDir, 'THIRD-PARTY-NOTICES.md'))).toBe(true);
|
|
expect(fs.existsSync(path.join(rootDir, 'SOURCES.md'))).toBe(true);
|
|
});
|
|
|
|
test('canonical copyleft license texts are present', () => {
|
|
for (const file of [
|
|
'GPL-2.0.txt',
|
|
'LGPL-2.1.txt',
|
|
'MPL-2.0.txt',
|
|
'Apache-2.0.txt',
|
|
'OFL-1.1.txt',
|
|
]) {
|
|
expect(fs.existsSync(path.join(rootDir, 'third-party-licenses', file))).toBe(true);
|
|
}
|
|
});
|
|
|
|
test('notices mention every bundled external binary', () => {
|
|
const notices = fs.readFileSync(path.join(rootDir, 'THIRD-PARTY-NOTICES.md'), 'utf-8');
|
|
for (const component of [
|
|
'Pandoc',
|
|
'FFmpeg',
|
|
'MarkItDown',
|
|
'libvips',
|
|
'KaTeX',
|
|
'JetBrains Mono',
|
|
]) {
|
|
expect(notices).toContain(component);
|
|
}
|
|
// GPL source offer must reference the sources document
|
|
expect(notices).toContain('SOURCES.md');
|
|
});
|
|
|
|
test('SOURCES.md covers every GPL-licensed binary with a source link', () => {
|
|
const sources = fs.readFileSync(path.join(rootDir, 'SOURCES.md'), 'utf-8');
|
|
for (const section of ['Pandoc', 'FFmpeg', 'PyInstaller', 'libvips']) {
|
|
expect(sources).toContain(section);
|
|
}
|
|
expect(sources).toMatch(/https:\/\/github\.com\/jgm\/pandoc/);
|
|
expect(sources).toMatch(/https:\/\/ffmpeg\.org\/releases\//);
|
|
});
|
|
|
|
test('packaging includes the legal documents in build files', () => {
|
|
// The build config lives in electron-builder.config.js (dynamic — it
|
|
// conditionally bundles the markitdown binary per platform)
|
|
const configSrc = fs.readFileSync(path.join(rootDir, 'electron-builder.config.js'), 'utf-8');
|
|
expect(configSrc).toContain("'THIRD-PARTY-NOTICES.md'");
|
|
expect(configSrc).toContain("'SOURCES.md'");
|
|
expect(configSrc).toContain('third-party-licenses');
|
|
// And package.json must not carry a stale static build section anymore
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf-8'));
|
|
expect(pkg.build).toBeUndefined();
|
|
});
|
|
});
|