Skip to content

Commit 016ce8d

Browse files
authored
feat: accept tap as an alias of press (#1053)
* feat: accept tap as an alias of press * test: restore #1036 ordering regression coverage, assert tap dispatches press Making tap a real alias deleted the only tests covering unknown-command-before-flag-validation ordering (they used tap as the unknown command). Restore them with a genuinely unknown command, and strengthen the alias test to assert the dispatched call records press with positionals preserved instead of merely not-erroring. * test: cover tap alias composing with the bare-ref hint Adopted from #1052 (credit: @vku2018): tap e3 must normalize to press and then surface the @e3 suggestion, proving the alias and the bare-ref hint compose instead of masking each other.
1 parent 0453826 commit 016ce8d

4 files changed

Lines changed: 51 additions & 12 deletions

File tree

‎src/__tests__/cli-help.test.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,38 @@ test('help rejects multiple positional commands and skips daemon dispatch', asyn
150150
assert.match(result.stderr, /Error \(INVALID_ARGS\): help accepts at most one command/);
151151
});
152152

153-
test('unknown command with flags reports unknown command before flag validation', async () => {
153+
test('tap dispatches as press with positionals and flags preserved', async () => {
154+
const result = await runCliCapture(['tap', '@e3', '--json']);
155+
assert.doesNotMatch(result.stderr, /Unknown command/);
156+
// Canonicalization: the daemon call must record press, never tap.
157+
assert.equal(result.calls.length, 1);
158+
assert.equal(result.calls[0]?.command, 'press');
159+
assert.deepEqual(result.calls[0]?.positionals, ['@e3']);
160+
});
161+
162+
// From #1052 (credit: @vku2018): the alias must compose with the bare-ref
163+
// hint — `tap e3` normalizes to press, then gets the @e3 suggestion.
164+
test('tap with a bare ref gets the @ref hint, not an unknown-command error', async () => {
154165
const result = await runCliCapture(['tap', 'e3', '--session', 'foo']);
155166
assert.equal(result.code, 1);
156167
assert.equal(result.calls.length, 0);
157-
assert.match(result.stderr, /Error \(INVALID_ARGS\): Unknown command: tap/);
158-
assert.match(result.stderr, /Did you mean press or click/);
168+
assert.match(result.stderr, /Did you mean "@e3"\?/);
169+
assert.doesNotMatch(result.stderr, /Unknown command: tap/);
170+
});
171+
172+
// Regression coverage for #1036 (moved off `tap` when it became an alias):
173+
// unknown commands must be reported before per-command flag validation.
174+
test('unknown command with flags reports unknown command before flag validation', async () => {
175+
const result = await runCliCapture(['bogus-cmd', 'e3', '--session', 'foo']);
176+
assert.equal(result.code, 1);
177+
assert.equal(result.calls.length, 0);
178+
assert.match(result.stderr, /Error \(INVALID_ARGS\): Unknown command: bogus-cmd/);
179+
assert.doesNotMatch(result.stderr, /not supported for command/);
159180
});
160181

161-
test('unknown command without flags reports unknown command with alias suggestion', async () => {
162-
const result = await runCliCapture(['tap', 'e3']);
182+
test('unknown command without flags reports unknown command', async () => {
183+
const result = await runCliCapture(['bogus-cmd', 'e3']);
163184
assert.equal(result.code, 1);
164185
assert.equal(result.calls.length, 0);
165-
assert.match(result.stderr, /Error \(INVALID_ARGS\): Unknown command: tap/);
166-
assert.match(result.stderr, /Did you mean press or click/);
186+
assert.match(result.stderr, /Error \(INVALID_ARGS\): Unknown command: bogus-cmd/);
167187
});

‎src/cli/parser/args.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,7 @@ function isCommandKnown(command: string): boolean {
357357
return (listCliCommandNames() as readonly string[]).includes(command);
358358
}
359359

360-
const COMMAND_ALIAS_SUGGESTIONS: Record<string, string> = {
361-
tap: 'press or click',
362-
};
360+
const COMMAND_ALIAS_SUGGESTIONS: Record<string, string> = {};
363361

364362
function getCommandAliasSuggestion(command: string): string | undefined {
365363
return COMMAND_ALIAS_SUGGESTIONS[command];
@@ -387,5 +385,6 @@ export function usageForCommand(command: string): string | null {
387385
function normalizeCommandAlias(command: string): string {
388386
if (command === 'long-press') return 'longpress';
389387
if (command === 'metrics') return 'perf';
388+
if (command === 'tap') return 'press';
390389
return command;
391390
}

‎src/cli/parser/cli-help.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const AGENT_QUICKSTART_LINES = [
7777
'Implicit default sessions are scoped to the current worktree; if a prompt names a Session, include --session <name> on every command in that flow.',
7878
'Run mutating commands serially within one session; parallelize only read-only commands or separate sessions/devices.',
7979
'Clipboard limits: iOS Allow Paste cannot be automated through XCUITest; prefill with clipboard write. Android non-ASCII should use fill/type, not raw adb input.',
80-
'After mutation: refs are stale. If the next target is known, use its selector directly; otherwise refresh with snapshot -i, scoped with -s when a stable container is known. Do not use tap; use press or click.',
80+
'After mutation: refs are stale. If the next target is known, use its selector directly; otherwise refresh with snapshot -i, scoped with -s when a stable container is known. Use press/click for taps.',
8181
'Raw coordinates are fallback-only: use snapshot -i --json rects when iOS refs no-op or child refs are missing, then verify the action with diff snapshot -i or snapshot --diff.',
8282
'Sparse or AX-unavailable snapshot: use screenshot for visual truth, press the visible coordinate to leave the bad screen, then retry AX with snapshot -i.',
8383
'macOS context menus use click <ref> --button secondary, then snapshot -i. Longpress is for mobile hold gestures, not macOS secondary-click menus.',
@@ -145,7 +145,7 @@ Command shape:
145145
Snapshot refs look like @e12. After snapshot -i, use the exact @eN ref from that output.
146146
If the exact ref is not known yet, first output snapshot -i, then use a concrete example shape like press @e12 in the next command; do not write @<ref>, @ref, @Label_Name, or @eN placeholders.
147147
Close means agent-device close. App-owned back means back; system back means back --system.
148-
Taps are press or click; tap is not a command. Gestures use swipe, longpress, or gesture <pan|fling|swipe|pinch|rotate|transform>. Use gesture swipe left|right for reliable in-page horizontal swipes, and gesture swipe right-edge for left-edge navigation/back gestures. Android swipe, pinch, rotate, and transform use provider-native touch injection when available, then the bundled touch helper. iOS simulator transform uses private XCTest synthesis for a continuous two-finger pan/scale/rotation path; otherwise it reports UNSUPPORTED_OPERATION.
148+
Taps are press or click; tap is an alias for press. Gestures use swipe, longpress, or gesture <pan|fling|swipe|pinch|rotate|transform>. Use gesture swipe left|right for reliable in-page horizontal swipes, and gesture swipe right-edge for left-edge navigation/back gestures. Android swipe, pinch, rotate, and transform use provider-native touch injection when available, then the bundled touch helper. iOS simulator transform uses private XCTest synthesis for a continuous two-finger pan/scale/rotation path; otherwise it reports UNSUPPORTED_OPERATION.
149149
150150
Bootstrap:
151151
agent-device devices --platform ios

‎src/utils/__tests__/args.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,19 @@ test('parseArgs supports metrics alias for perf', () => {
11671167
assert.deepEqual(parsed.positionals, []);
11681168
});
11691169

1170+
test('parseArgs supports tap alias for press', () => {
1171+
const parsed = parseArgs(['tap', '@e3'], { strictFlags: true });
1172+
assert.equal(parsed.command, 'press');
1173+
assert.deepEqual(parsed.positionals, ['@e3']);
1174+
});
1175+
1176+
test('parseArgs preserves flags when tap is aliased to press', () => {
1177+
const parsed = parseArgs(['tap', '@e3', '--json'], { strictFlags: true });
1178+
assert.equal(parsed.command, 'press');
1179+
assert.deepEqual(parsed.positionals, ['@e3']);
1180+
assert.equal(parsed.flags.json, true);
1181+
});
1182+
11701183
test('parseArgs supports trigger-app-event payload argument', () => {
11711184
const parsed = parseArgs(['trigger-app-event', 'screenshot_taken', '{"source":"qa"}'], {
11721185
strictFlags: true,
@@ -1194,6 +1207,13 @@ test('usageForCommand supports legacy long-press alias', () => {
11941207
assert.doesNotMatch(help ?? '', /agent-device long-press/);
11951208
});
11961209

1210+
test('usageForCommand supports tap alias for press', () => {
1211+
const help = usageForCommand('tap');
1212+
assert.equal(help === null, false);
1213+
assert.match(help ?? '', /agent-device press/);
1214+
assert.doesNotMatch(help ?? '', /agent-device tap/);
1215+
});
1216+
11971217
test('usageForCommand documents keyboard dismissal flow', () => {
11981218
const help = usageForCommand('keyboard');
11991219
assert.equal(help === null, false);

0 commit comments

Comments
 (0)