Skip to content

Commit a85f9a8

Browse files
committed
chore: remove redundant trigger normalization in session handler
1 parent 5c0548d commit a85f9a8

2 files changed

Lines changed: 6 additions & 81 deletions

File tree

src/daemon/handlers/__tests__/session-trigger.test.ts

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test('trigger-app-event supports explicit selector without active session', asyn
8888
assert.equal(response.ok, true);
8989
});
9090

91-
test('trigger command records action and refreshes session app bundle context', async () => {
91+
test('trigger-app-event records action and refreshes session app bundle context', async () => {
9292
const sessionStore = makeStore();
9393
const session = makeSession('default', {
9494
platform: 'android',
@@ -103,8 +103,8 @@ test('trigger command records action and refreshes session app bundle context',
103103
req: {
104104
token: 't',
105105
session: 'default',
106-
command: 'trigger-screenshot-notification',
107-
positionals: [],
106+
command: 'trigger-app-event',
107+
positionals: ['screenshot_taken'],
108108
flags: {},
109109
},
110110
sessionName: 'default',
@@ -130,74 +130,3 @@ test('trigger command records action and refreshes session app bundle context',
130130
assert.equal(nextSession?.actions[0]?.command, 'trigger-app-event');
131131
assert.deepEqual(nextSession?.actions[0]?.positionals, ['screenshot_taken']);
132132
});
133-
134-
test('trigger aliases are normalized to trigger-app-event before dispatch', async () => {
135-
const sessionStore = makeStore();
136-
sessionStore.set('default', makeSession('default', {
137-
platform: 'android',
138-
id: 'emulator-5554',
139-
name: 'Pixel',
140-
kind: 'emulator',
141-
booted: true,
142-
}));
143-
144-
let dispatchedCommand = '';
145-
let dispatchedPositionals: string[] = [];
146-
const response = await handleSessionCommands({
147-
req: {
148-
token: 't',
149-
session: 'default',
150-
command: 'trigger-memory-warning',
151-
positionals: [],
152-
flags: {},
153-
},
154-
sessionName: 'default',
155-
logPath: '/tmp/daemon.log',
156-
sessionStore,
157-
invoke,
158-
ensureReady: async () => {},
159-
dispatch: async (_device, command, positionals) => {
160-
dispatchedCommand = command;
161-
dispatchedPositionals = positionals;
162-
return { event: 'memory_warning', eventUrl: 'myapp://agent-device/event?name=memory_warning' };
163-
},
164-
});
165-
166-
assert.ok(response);
167-
assert.equal(response.ok, true);
168-
assert.equal(dispatchedCommand, 'trigger-app-event');
169-
assert.deepEqual(dispatchedPositionals, ['memory_warning']);
170-
});
171-
172-
test('trigger aliases reject unexpected positional arguments', async () => {
173-
const sessionStore = makeStore();
174-
sessionStore.set('default', makeSession('default', {
175-
platform: 'android',
176-
id: 'emulator-5554',
177-
name: 'Pixel',
178-
kind: 'emulator',
179-
booted: true,
180-
}));
181-
182-
await assert.rejects(
183-
() => handleSessionCommands({
184-
req: {
185-
token: 't',
186-
session: 'default',
187-
command: 'trigger-screenshot',
188-
positionals: ['extra'],
189-
flags: {},
190-
},
191-
sessionName: 'default',
192-
logPath: '/tmp/daemon.log',
193-
sessionStore,
194-
invoke,
195-
ensureReady: async () => {},
196-
}),
197-
(error: unknown) =>
198-
error instanceof Error
199-
&& 'code' in error
200-
&& (error as { code?: string }).code === 'INVALID_ARGS'
201-
&& /does not accept positional arguments/i.test(error.message),
202-
);
203-
});

src/daemon/handlers/session.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
validateAndNormalizeBatchSteps,
88
} from '../../core/batch.ts';
99
import { isCommandSupportedOnDevice } from '../../core/capabilities.ts';
10-
import { normalizeTriggerAliasCommand } from '../../core/app-events.ts';
1110
import { isDeepLinkTarget, resolveIosDeviceDeepLinkBundleId } from '../../core/open-target.ts';
1211
import { AppError, asAppError, normalizeError } from '../../utils/errors.ts';
1312
import { normalizePlatformSelector, type DeviceInfo } from '../../utils/device.ts';
@@ -61,7 +60,6 @@ const IOS_APPSTATE_SESSION_REQUIRED_MESSAGE =
6160
const BATCH_PARENT_FLAG_KEYS: Array<keyof CommandFlags> = ['platform', 'target', 'device', 'udid', 'serial', 'verbose', 'out'];
6261
const REPLAY_PARENT_FLAG_KEYS: Array<keyof CommandFlags> = ['platform', 'target', 'device', 'udid', 'serial', 'verbose', 'out'];
6362
const LOG_ACTIONS = ['path', 'start', 'stop', 'doctor', 'mark', 'clear'] as const;
64-
const TRIGGER_COMMANDS = new Set(['trigger-app-event']);
6563
const LOG_ACTIONS_MESSAGE = `logs requires ${LOG_ACTIONS.slice(0, -1).join(', ')}, or ${LOG_ACTIONS.at(-1)}`;
6664
const PERF_UNAVAILABLE_REASON = 'Not implemented for this platform in this release.';
6765
const STARTUP_SAMPLE_METHOD = 'open-command-roundtrip';
@@ -585,9 +583,7 @@ export async function handleSessionCommands(params: {
585583
const ensureReady = ensureReadyOverride ?? ensureDeviceReady;
586584
const resolveDevice = resolveTargetDeviceOverride ?? resolveTargetDevice;
587585
const stopIosRunner = stopIosRunnerOverride ?? stopIosRunnerSession;
588-
const normalizedTrigger = normalizeTriggerAliasCommand(req.command, req.positionals ?? []);
589-
const command = normalizedTrigger.command;
590-
const triggerPositionals = normalizedTrigger.positionals;
586+
const command = req.command;
591587

592588
if (command === 'session_list') {
593589
const data = {
@@ -909,7 +905,7 @@ export async function handleSessionCommands(params: {
909905
});
910906
}
911907

912-
if (TRIGGER_COMMANDS.has(command)) {
908+
if (command === 'trigger-app-event') {
913909
return await runSessionOrSelectorDispatch({
914910
req,
915911
sessionName,
@@ -919,7 +915,7 @@ export async function handleSessionCommands(params: {
919915
resolveDevice,
920916
dispatch,
921917
command: 'trigger-app-event',
922-
positionals: triggerPositionals,
918+
positionals: req.positionals ?? [],
923919
deriveNextSession: async (session, result) => {
924920
const eventUrl = typeof result?.eventUrl === 'string' ? result.eventUrl : undefined;
925921
const nextAppBundleId = eventUrl

0 commit comments

Comments
 (0)