Compare commits

...
6 changed files with 59 additions and 2 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'eas-cli': patch
---
Keep simulator credentials when the stop response does not confirm that the allocated session stopped.
@@ -3495,6 +3495,31 @@ describe(Simulator, () => {
);
});
it.each([
{ id: 'session-123', status: DeviceRunSessionStatus.InProgress },
{ id: 'another-session', status: DeviceRunSessionStatus.Stopped },
])(
'keeps local credentials when the stop response does not confirm this session: %j',
async response => {
mockByIdAsync
.mockResolvedValueOnce(makeDeviceRunSession())
.mockImplementationOnce(async () => {
process.emit('SIGINT');
return makeDeviceRunSession();
});
mockEnsureDeviceRunSessionStoppedAsync.mockResolvedValueOnce(response);
const { command } = createCommand(['--platform', 'ios']);
await command.runAsync();
expect(mockEnsureDeviceRunSessionStoppedAsync).toHaveBeenCalledWith(
graphqlClient,
'session-123'
);
expect(mockResetSimulatorEnvAsync).not.toHaveBeenCalled();
}
);
it('stops the session when interrupted while it is running', async () => {
mockByIdAsync.mockResolvedValueOnce(makeDeviceRunSession()).mockImplementationOnce(async () => {
process.emit('SIGINT');
@@ -135,6 +135,20 @@ describe(SimulatorStop, () => {
}
});
it.each([{ status: DeviceRunSessionStatus.InProgress }, { id: 'another-session' }])(
'preserves credentials when the stop is unconfirmed: %j',
async response => {
mockEnsureDeviceRunSessionStoppedAsync.mockResolvedValueOnce(
makeStoppedDeviceRunSession(response)
);
const { command } = createCommand(['--id', 'session-123', '--json']);
await expect(command.runAsync()).rejects.toThrow('could not confirm');
expect(mockResetSimulatorEnvAsync).not.toHaveBeenCalled();
expect(mockPrintJsonOnlyOutput).not.toHaveBeenCalled();
}
);
it('throws a helpful error when no simulator session ID is available', async () => {
const previousDeviceRunSessionId = process.env[EAS_SIMULATOR_SESSION_ID];
delete process.env[EAS_SIMULATOR_SESSION_ID];
@@ -77,6 +77,7 @@ import {
getLocalEgressConfig,
getPreviewApiAccess,
getRemoteSessionEnvironmentVariables,
isSimulatorStopConfirmed,
sanitizeRemoteConfigForJson,
} from '../../simulator/utils';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
@@ -1119,11 +1120,11 @@ async function ensureDeviceRunSessionStoppedSafelyAsync(
deviceRunSessionId: string
): Promise<boolean> {
try {
await DeviceRunSessionMutation.ensureDeviceRunSessionStoppedAsync(
const stopped = await DeviceRunSessionMutation.ensureDeviceRunSessionStoppedAsync(
graphqlClient,
deviceRunSessionId
);
return true;
return isSimulatorStopConfirmed(stopped, deviceRunSessionId);
} catch (err) {
// Cleanup is best-effort; surface the failure but don't mask the original error.
Log.warn(
@@ -13,6 +13,7 @@ import {
loadSimulatorEnvAsync,
resetSimulatorEnvAsync,
} from '../../simulator/env';
import { isSimulatorStopConfirmed } from '../../simulator/utils';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
import {
getSimulatorCommandAliases,
@@ -67,6 +68,9 @@ export default class SimulatorStop extends EasCommand {
graphqlClient,
flagId
);
if (!isSimulatorStopConfirmed(session, flagId)) {
throw new Error(`EAS could not confirm that simulator session ${flagId} stopped.`);
}
stopSpinner.succeed(`🎉 Simulator session ${session.id} is ${session.status.toLowerCase()}`);
} catch (err) {
stopSpinner.fail(`Failed to stop simulator session ${flagId}`);
+8
View File
@@ -6,6 +6,7 @@ import {
AppPlatform,
DeviceRunSessionByIdQuery,
DeviceRunSessionResourceClass,
DeviceRunSessionStatus,
DeviceRunSessionType,
} from '../graphql/generated';
import { link } from '../log';
@@ -21,6 +22,13 @@ import {
type DeviceRunSessionByIdResult = DeviceRunSessionByIdQuery['deviceRunSessions']['byId'];
export type DeviceRunSessionRemoteConfig = NonNullable<DeviceRunSessionByIdResult['remoteConfig']>;
export function isSimulatorStopConfirmed(
session: Pick<DeviceRunSessionByIdResult, 'id' | 'status'>,
requestedId: string
): boolean {
return session.id === requestedId && session.status === DeviceRunSessionStatus.Stopped;
}
/**
* Message shown when EAS Simulator is not enabled for the account. Shared by every
* command that can hit the gate so users always get the same upgrade pointer. The gate