fix(storage): protect Yomitan profiles across Electron runtime changes (#211)

This commit is contained in:
sudacode authored and GitHub committed 2026-10-01 21:44:53 -07:00
1 parent 15cb9fe918
commit a5d0b63792
22 files changed
+934 -21

No files matched your search

+113
View File
@@ -640,3 +640,116 @@ test('configureEarlyAppPaths creates a fresh macOS config directory before Elect
fs.rmSync(homeDir, { recursive: true, force: true });
}
});
test('configureEarlyAppPaths isolates development runs from the production profile', () => {
const calls: string[] = [];
const xdgConfigHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-entry-dev-profile-'));
const devProfileDir = path.posix.join(xdgConfigHome, 'SubMiner-dev');
try {
const userDataPath = configureEarlyAppPaths(
{
setName: (name) => calls.push(`name:${name}`),
setPath: (key, value) => calls.push(`path:${key}:${value}`),
},
{
platform: 'linux',
homeDir: xdgConfigHome,
xdgConfigHome,
existsSync: () => false,
argv: ['electron', '.', '--start', '--dev'],
env: {},
},
);
assert.equal(userDataPath, devProfileDir);
assert.deepEqual(calls, ['name:SubMiner', `path:userData:${devProfileDir}`]);
} finally {
fs.rmSync(xdgConfigHome, { recursive: true, force: true });
}
});
test('configureEarlyAppPaths ignores development flags forwarded to mpv', () => {
const xdgConfigHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-entry-mpv-flags-'));
const configDir = path.posix.join(xdgConfigHome, 'SubMiner');
try {
for (const forwardedFlag of ['--dev', '--debug']) {
let selectedPath = '';
const userDataPath = configureEarlyAppPaths(
{
setName: () => {},
setPath: (_key, value) => {
selectedPath = value;
},
},
{
platform: 'linux',
homeDir: xdgConfigHome,
xdgConfigHome,
existsSync: () => false,
argv: ['electron', '.', '--launch-mpv', forwardedFlag],
env: {},
},
);
assert.equal(userDataPath, configDir);
assert.equal(selectedPath, configDir);
}
} finally {
fs.rmSync(xdgConfigHome, { recursive: true, force: true });
}
});
test('configureEarlyAppPaths uses the supplied environment for config discovery', () => {
const paths: string[] = [];
const xdgConfigHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-entry-injected-env-'));
const configDir = path.posix.join(xdgConfigHome, 'SubMiner');
try {
const userDataPath = configureEarlyAppPaths(
{
setName: () => {},
setPath: (_key, value) => paths.push(value),
},
{
platform: 'linux',
homeDir: path.posix.join(xdgConfigHome, 'home'),
existsSync: () => false,
argv: ['electron', '.', '--start'],
env: { XDG_CONFIG_HOME: xdgConfigHome },
},
);
assert.equal(userDataPath, configDir);
assert.deepEqual(paths, [configDir]);
} finally {
fs.rmSync(xdgConfigHome, { recursive: true, force: true });
}
});
test('configureEarlyAppPaths allows an explicit production-profile development run', () => {
const paths: string[] = [];
const configBaseDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-entry-prod-profile-'));
// Use the host platform so the selected directory is a real path mkdirSync can create.
const configDir = path.join(configBaseDir, 'SubMiner');
try {
const userDataPath = configureEarlyAppPaths(
{
setName: () => {},
setPath: (_key, value) => paths.push(value),
},
{
platform: process.platform,
appDataDir: configBaseDir,
xdgConfigHome: configBaseDir,
homeDir: configBaseDir,
existsSync: () => false,
argv: ['electron', '.', '--debug'],
env: { SUBMINER_USE_PRODUCTION_PROFILE: '1' },
},
);
assert.equal(userDataPath, configDir);
assert.deepEqual(paths, [configDir]);
} finally {
fs.rmSync(configBaseDir, { recursive: true, force: true });
}
});