Fix Windows mpv logging and add log export (#88)

This commit is contained in:
2026-05-26 00:31:38 -07:00
committed by GitHub
parent 43ebc7d371
commit 11c196821d
150 changed files with 2748 additions and 582 deletions
+65 -8
View File
@@ -3,7 +3,14 @@ import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { appendLogLine, pruneLogFiles, resolveDefaultLogFilePath } from './log-files';
import {
applyLogFileTogglesToEnv,
appendLogLine,
isLogFileEnabled,
pruneLogDirectoryForPath,
pruneLogFiles,
resolveDefaultLogFilePath,
} from './log-files';
test('resolveDefaultLogFilePath uses app prefix by default', () => {
const now = new Date('2026-03-22T12:00:00.000Z');
@@ -15,16 +22,47 @@ test('resolveDefaultLogFilePath uses app prefix by default', () => {
assert.equal(
resolved,
path.join(
'/home/tester',
'.config',
'SubMiner',
'logs',
`app-${now.toISOString().slice(0, 10)}.log`,
),
path.join('/home/tester', '.config', 'SubMiner', 'logs', 'app-2026-03-22.log'),
);
});
test('resolveDefaultLogFilePath uses daily filenames for mpv logs', () => {
const now = new Date('2026-03-22T12:00:00.000Z');
const resolved = resolveDefaultLogFilePath('mpv', {
platform: 'linux',
homeDir: '/home/tester',
now,
});
assert.equal(
resolved,
path.join('/home/tester', '.config', 'SubMiner', 'logs', 'mpv-2026-03-22.log'),
);
});
test('log file toggles keep app and launcher enabled while mpv defaults off', () => {
assert.equal(isLogFileEnabled('app', {}), true);
assert.equal(isLogFileEnabled('launcher', {}), true);
assert.equal(isLogFileEnabled('mpv', {}), false);
assert.equal(isLogFileEnabled('mpv', { SUBMINER_MPV_LOG: '/tmp/mpv.log' }), true);
assert.equal(
isLogFileEnabled('mpv', {
SUBMINER_MPV_LOG: '/tmp/mpv.log',
SUBMINER_MPV_LOG_ENABLED: 'false',
}),
false,
);
});
test('applyLogFileTogglesToEnv writes log enable env flags', () => {
const env: NodeJS.ProcessEnv = {};
applyLogFileTogglesToEnv({ app: false, launcher: true, mpv: true }, env);
assert.equal(env.SUBMINER_APP_LOG_ENABLED, 'false');
assert.equal(env.SUBMINER_LAUNCHER_LOG_ENABLED, 'true');
assert.equal(env.SUBMINER_MPV_LOG_ENABLED, 'true');
});
test('pruneLogFiles removes logs older than retention window', () => {
const logsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-log-prune-'));
const stalePath = path.join(logsDir, 'app-old.log');
@@ -69,3 +107,22 @@ test('appendLogLine trims oversized logs to newest bytes', () => {
fs.rmSync(logsDir, { recursive: true, force: true });
}
});
test('empty log path operations are no-ops', () => {
const cwd = process.cwd();
const logsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-empty-log-path-'));
const candidate = path.join(logsDir, 'cwd.log');
try {
process.chdir(logsDir);
fs.writeFileSync(candidate, 'keep\n', 'utf8');
pruneLogDirectoryForPath('', 1);
appendLogLine('', 'ignored', { retentionDays: 1 });
assert.equal(fs.readFileSync(candidate, 'utf8'), 'keep\n');
} finally {
process.chdir(cwd);
fs.rmSync(logsDir, { recursive: true, force: true });
}
});