fix(cli): prevent Termux relaunch and resize remount loops (#27110)

Co-authored-by: Spencer <spencertang@google.com>
This commit is contained in:
Syed Ayman Quadri
2026-05-22 00:33:52 -06:00
committed by GitHub
parent 6afb109953
commit ba04e99bea
6 changed files with 26 additions and 58 deletions
+21
View File
@@ -46,6 +46,14 @@ import { relaunchAppInChildProcess, relaunchOnExitCode } from './relaunch.js';
describe('relaunchOnExitCode', () => {
let processExitSpy: MockInstance;
let stdinResumeSpy: MockInstance;
const originalPlatform = process.platform;
const setPlatform = (platform: NodeJS.Platform) => {
Object.defineProperty(process, 'platform', {
value: platform,
configurable: true,
});
};
beforeEach(() => {
processExitSpy = vi.spyOn(process, 'exit').mockImplementation(() => {
@@ -60,6 +68,7 @@ describe('relaunchOnExitCode', () => {
afterEach(() => {
vi.unstubAllEnvs();
setPlatform(originalPlatform);
processExitSpy.mockRestore();
stdinResumeSpy.mockRestore();
});
@@ -92,6 +101,18 @@ describe('relaunchOnExitCode', () => {
expect(processExitSpy).toHaveBeenCalledWith(0);
});
it('should not relaunch on Android when RELAUNCH_EXIT_CODE is returned', async () => {
setPlatform('android');
const runner = vi.fn().mockResolvedValue(RELAUNCH_EXIT_CODE);
await expect(relaunchOnExitCode(runner)).rejects.toThrow(
'PROCESS_EXIT_CALLED',
);
expect(runner).toHaveBeenCalledTimes(1);
expect(processExitSpy).toHaveBeenCalledWith(RELAUNCH_EXIT_CODE);
});
it('should handle runner errors', async () => {
const error = new Error('Runner failed');
const runner = vi.fn().mockRejectedValue(error);
+1 -1
View File
@@ -20,7 +20,7 @@ export async function relaunchOnExitCode(runner: () => Promise<number>) {
try {
const exitCode = await runner();
if (exitCode !== RELAUNCH_EXIT_CODE) {
if (process.platform === 'android' || exitCode !== RELAUNCH_EXIT_CODE) {
process.exit(exitCode);
}
} catch (error) {