mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-27 16:49:51 -07:00
fix(sync-ui): preserve headless child arguments
This commit is contained in:
@@ -2,7 +2,11 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import type { SyncProgressEvent } from '../../shared/sync/sync-events';
|
||||
import { runSyncLauncher, type SyncLauncherSpawn } from './sync-launcher-client';
|
||||
import {
|
||||
runSyncLauncher,
|
||||
sanitizeSyncLauncherEnv,
|
||||
type SyncLauncherSpawn,
|
||||
} from './sync-launcher-client';
|
||||
|
||||
class FakeChild extends EventEmitter {
|
||||
stdout = new EventEmitter();
|
||||
@@ -214,3 +218,16 @@ test('resolveSyncLauncherCommand self-spawns the app in --sync-cli mode', async
|
||||
});
|
||||
assert.deepEqual(dev, ['/usr/bin/electron', '/home/u/SubMiner', '--sync-cli']);
|
||||
});
|
||||
|
||||
test('sanitizeSyncLauncherEnv removes transported parent startup arguments', () => {
|
||||
const parentEnv = {
|
||||
PATH: '/usr/bin',
|
||||
ELECTRON_RUN_AS_NODE: '1',
|
||||
SUBMINER_APP_ARGC: '2',
|
||||
SUBMINER_APP_ARG_0: '--start',
|
||||
SUBMINER_APP_ARG_1: '--background',
|
||||
};
|
||||
|
||||
assert.deepEqual(sanitizeSyncLauncherEnv(parentEnv), { PATH: '/usr/bin' });
|
||||
assert.equal(parentEnv.SUBMINER_APP_ARGC, '2');
|
||||
});
|
||||
|
||||
@@ -26,6 +26,16 @@ export interface SyncLauncherRunHandle {
|
||||
done: Promise<SyncLauncherRunResult>;
|
||||
}
|
||||
|
||||
export function sanitizeSyncLauncherEnv(baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
||||
const env = { ...baseEnv };
|
||||
delete env.ELECTRON_RUN_AS_NODE;
|
||||
delete env.SUBMINER_APP_ARGC;
|
||||
for (const name of Object.keys(env)) {
|
||||
if (name.startsWith('SUBMINER_APP_ARG_')) delete env[name];
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
// Sync runs in a child copy of this app in headless --sync-cli mode: same
|
||||
// engine and NDJSON protocol as `subminer sync --json`, with no dependency on
|
||||
// bun or an installed command-line launcher. In dev runs process.execPath is
|
||||
@@ -54,8 +64,7 @@ export function runSyncLauncher(options: {
|
||||
((command, args) => {
|
||||
// The child must boot as a full Electron app (its entry handles
|
||||
// --sync-cli); a leaked ELECTRON_RUN_AS_NODE would turn it into node.
|
||||
const env = { ...process.env };
|
||||
delete env.ELECTRON_RUN_AS_NODE;
|
||||
const env = sanitizeSyncLauncherEnv(process.env);
|
||||
return nodeSpawn(command, args, { stdio: 'pipe', env });
|
||||
});
|
||||
const [executable, ...prefixArgs] = options.command;
|
||||
|
||||
Reference in New Issue
Block a user