Skip to content

Commit 24264d7

Browse files
committed
chore: remove redundant trigger normalization in session handler
1 parent f83c5e6 commit 24264d7

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';
@@ -53,7 +52,6 @@ const IOS_APPSTATE_SESSION_REQUIRED_MESSAGE =
5352
const BATCH_PARENT_FLAG_KEYS: Array<keyof CommandFlags> = ['platform', 'target', 'device', 'udid', 'serial', 'verbose', 'out'];
5453
const REPLAY_PARENT_FLAG_KEYS: Array<keyof CommandFlags> = ['platform', 'target', 'device', 'udid', 'serial', 'verbose', 'out'];
5554
const LOG_ACTIONS = ['path', 'start', 'stop', 'doctor', 'mark', 'clear'] as const;
56-
const TRIGGER_COMMANDS = new Set(['trigger-app-event']);
5755
const LOG_ACTIONS_MESSAGE = `logs requires ${LOG_ACTIONS.slice(0, -1).join(', ')}, or ${LOG_ACTIONS.at(-1)}`;
5856
const PERF_UNAVAILABLE_REASON = 'Not implemented for this platform in this release.';
5957
const STARTUP_SAMPLE_METHOD = 'open-command-roundtrip';
@@ -550,9 +548,7 @@ export async function handleSessionCommands(params: {
550548
const ensureReady = ensureReadyOverride ?? ensureDeviceReady;
551549
const resolveDevice = resolveTargetDeviceOverride ?? resolveTargetDevice;
552550
const stopIosRunner = stopIosRunnerOverride ?? stopIosRunnerSession;
553-
const normalizedTrigger = normalizeTriggerAliasCommand(req.command, req.positionals ?? []);
554-
const command = normalizedTrigger.command;
555-
const triggerPositionals = normalizedTrigger.positionals;
551+
const command = req.command;
556552

557553
if (command === 'session_list') {
558554
const data = {
@@ -783,7 +779,7 @@ export async function handleSessionCommands(params: {
783779
});
784780
}
785781

786-
if (TRIGGER_COMMANDS.has(command)) {
782+
if (command === 'trigger-app-event') {
787783
return await runSessionOrSelectorDispatch({
788784
req,
789785
sessionName,
@@ -793,7 +789,7 @@ export async function handleSessionCommands(params: {
793789
resolveDevice,
794790
dispatch,
795791
command: 'trigger-app-event',
796-
positionals: triggerPositionals,
792+
positionals: req.positionals ?? [],
797793
deriveNextSession: async (session, result) => {
798794
const eventUrl = typeof result?.eventUrl === 'string' ? result.eventUrl : undefined;
799795
const nextAppBundleId = eventUrl

0 commit comments

Comments
 (0)