mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-28 04:46:07 -08:00
- kill a tool's whole POSIX process group on cancel (orphaned children held the pipes open, so the run never finished); kill running groups on exit - refuse an in-place rewrite when the subtitle changed on disk mid-sync - pick only a freshly added track for the secondary slot, and reset its delay only after selecting it - pass cancellation to the video-reference alass and ffsubsync runs, and never open a picker for media the user already left - treat a failed media-path baseline read as unknown instead of null - align worker: honor aborts during startup and finish queued calls on the main thread when the worker fails to start - temp dirs: keep failed removals registered, never sweep a dir mpv still plays from, and clean up when writing a cleaned reference fails - an empty cached audio result means no usable audio, as on a fresh decode - compare external track paths case-sensitively on POSIX - decode ffmpeg stderr as a stream; coverage lane for subtitle tests - make the cancellation test wait for the tool to start
52 lines
2.5 KiB
TypeScript
52 lines
2.5 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { cleanupTemporaryFile, pruneRetainedSubsyncTempDirs } from './subsync-files';
|
|
|
|
test('synced embedded-track temp dirs keep only the loaded file and go away once mpv drops it', () => {
|
|
const isolatedTmp = fs.mkdtempSync(path.join(os.tmpdir(), 'subsync-files-test-'));
|
|
try {
|
|
// Left behind by a crashed session two days ago.
|
|
const staleDir = fs.mkdtempSync(path.join(isolatedTmp, 'subminer-subsync-'));
|
|
const twoDaysAgo = (Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000;
|
|
fs.utimesSync(staleDir, twoDaysAgo, twoDaysAgo);
|
|
|
|
// Extraction of an embedded target plus the retimed copy mpv loaded.
|
|
const runDir = fs.mkdtempSync(path.join(isolatedTmp, 'subminer-subsync-'));
|
|
const extractedPath = path.join(runDir, 'track_2.ass');
|
|
const retimedPath = path.join(runDir, 'track_2_retimed.ass');
|
|
fs.writeFileSync(extractedPath, 'original');
|
|
fs.writeFileSync(retimedPath, 'retimed');
|
|
|
|
cleanupTemporaryFile({ path: extractedPath, temporary: true });
|
|
assert.deepEqual(fs.readdirSync(runDir), ['track_2_retimed.ass']);
|
|
|
|
// An old dir whose file mpv still plays survives the sweep.
|
|
const playingDir = fs.mkdtempSync(path.join(isolatedTmp, 'subminer-subsync-'));
|
|
const playingPath = path.join(playingDir, 'track_4_retimed.srt');
|
|
fs.writeFileSync(playingPath, 'still loaded');
|
|
fs.utimesSync(playingDir, twoDaysAgo, twoDaysAgo);
|
|
|
|
pruneRetainedSubsyncTempDirs([retimedPath, playingPath], { tmpRoot: isolatedTmp });
|
|
assert.equal(fs.existsSync(runDir), true, 'mpv still lists the retimed file');
|
|
assert.equal(fs.existsSync(staleDir), false, 'stale dirs from old sessions are swept');
|
|
assert.equal(fs.existsSync(playingDir), true, 'stale but referenced dirs are kept');
|
|
|
|
pruneRetainedSubsyncTempDirs(['/media/ep02.ja.srt'], { tmpRoot: isolatedTmp });
|
|
assert.equal(fs.existsSync(runDir), false, 'dropped once mpv no longer lists it');
|
|
} finally {
|
|
fs.rmSync(isolatedTmp, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('cleanupTemporaryFile removes a reference extraction and its dir entirely', () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-subsync-'));
|
|
const extractedPath = path.join(dir, 'track_3.srt');
|
|
fs.writeFileSync(extractedPath, 'reference');
|
|
|
|
cleanupTemporaryFile({ path: extractedPath, temporary: true });
|
|
assert.equal(fs.existsSync(dir), false);
|
|
});
|