Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/__tests__/cli-grammar.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test } from 'vitest';
import assert from 'node:assert/strict';
import { readInputFromCli } from '../commands/cli-grammar.ts';
import type { CommandName } from '../commands/command-metadata.ts';
import type { CliFlags } from '../commands/cli-grammar/flag-types.ts';

const BASE_FLAGS: CliFlags = {
Expand Down Expand Up @@ -138,6 +139,38 @@ test('find and is grammar decodes command action positionals', () => {
assert.equal(isOptions.value, 'Welcome');
});

// --no-record is accepted on every command (COMMON_COMMAND_SUPPORTED_FLAG_KEYS),
// but it only reaches the daemon if the reader forwards it, so a reader that
// never names it accepts the flag and silently ignores it. Cover every command
// whose actions are recorded into a session script.
test('readers forward --no-record instead of silently dropping it', () => {
const recordable: Array<[CommandName, string[]]> = [
['press', ['@e5']],
['click', ['@e5']],
['fill', ['id=email', 'qa@example.com']],
['longpress', ['@e5']],
['swipe', ['up']],
['focus', ['10', '20']],
['type', ['hello']],
['scroll', ['down']],
['get', ['attrs', '@e5']],
['is', ['visible', 'id=title']],
['find', ['label', 'Continue', 'exists']],
['snapshot', []],
['wait', ['Continue']],
];

for (const [command, positionals] of recordable) {
const options = readInputFromCli(command, positionals, { ...BASE_FLAGS, noRecord: true });
assert.equal(options.noRecord, true, `${command} dropped --no-record`);
}
});

test('readers omit noRecord entirely when the flag is absent', () => {
const options = readInputFromCli('press', ['@e5'], BASE_FLAGS);
assert.equal(Object.hasOwn(options, 'noRecord'), false);
});

test('is grammar accepts the selector-first form with a trailing predicate', () => {
// `visible` is both a selector boolean key and a predicate; the trailing bare token
// must be reserved as the predicate instead of being swallowed by the selector.
Expand Down
7 changes: 6 additions & 1 deletion src/commands/capture/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { PUBLIC_COMMANDS } from '../../command-catalog.ts';
import { SNAPSHOT_FLAGS } from '../cli-grammar/flag-groups.ts';
import { booleanField, integerField, stringField } from '../command-input.ts';
import { defineExecutableCommand } from '../command-contract.ts';
import { commonInputFromFlags, direct } from '../cli-grammar/common.ts';
import {
commonInputFromFlags,
direct,
recordControlInputFromFlags,
} from '../cli-grammar/common.ts';
import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
import { defineCommandFacet } from '../family/types.ts';
import { defineFieldCommandMetadata } from '../field-command-contract.ts';
Expand Down Expand Up @@ -41,6 +45,7 @@ const snapshotCliSchema = {

export const snapshotCliReader: CliReader = (_positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
interactiveOnly: flags.snapshotInteractiveOnly,
depth: flags.snapshotDepth,
scope: flags.snapshotScope,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/capture/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { defineExecutableCommand } from '../command-contract.ts';
import {
direct,
optionalNumber,
recordControlInputFromFlags,
selectionOptionsFromFlags,
selectorSnapshotOptionsFromFlags,
} from '../cli-grammar/common.ts';
Expand Down Expand Up @@ -92,6 +93,7 @@ function readWaitOptionsFromPositionals(
const base = {
...selectionOptionsFromFlags(flags),
...selectorSnapshotOptionsFromFlags(flags),
...recordControlInputFromFlags(flags),
};
if (parsed.kind === 'sleep') return { ...base, durationMs: parsed.durationMs };
if (parsed.kind === 'text') {
Expand Down
10 changes: 10 additions & 0 deletions src/commands/cli-grammar/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export function commonInputFromFlags(flags: CliFlags): Record<string, unknown> {
});
}

// --no-record is a common flag, but it only takes effect if the reader forwards
// it: command-flags.ts maps options.noRecord onto the daemon request, and
// recordActionEntry reads it from there. A reader that never names it accepts
// the flag and silently drops it.
export function recordControlInputFromFlags(flags: CliFlags): Record<string, unknown> {
return compactRecord({
noRecord: flags.noRecord,
});
}

export function selectionOptionsFromFlags(flags: CliFlags): SelectionOptions {
return {
platform: flags.platform,
Expand Down
10 changes: 10 additions & 0 deletions src/commands/interaction/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
optionalNumber,
readElementTargetFromPositionals,
readGetFormat,
recordControlInputFromFlags,
request,
requiredDaemonString,
repeatedInputFromFlags,
Expand All @@ -35,6 +36,7 @@ import type { CliReader, DaemonWriter } from '../cli-grammar/types.ts';
export const interactionCliReaders = {
click: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...selectorSnapshotInputFromFlags(flags),
...repeatedInputFromFlags(flags),
...settleInputFromFlags(flags),
Expand All @@ -44,6 +46,7 @@ export const interactionCliReaders = {
}),
press: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...selectorSnapshotInputFromFlags(flags),
...repeatedInputFromFlags(flags),
...settleInputFromFlags(flags),
Expand All @@ -54,6 +57,7 @@ export const interactionCliReaders = {
const decoded = readLongPressTargetFromPositionals(positionals);
return {
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...selectorSnapshotInputFromFlags(flags),
...settleInputFromFlags(flags),
target: targetInputFromClientTarget(decoded),
Expand All @@ -62,6 +66,7 @@ export const interactionCliReaders = {
},
swipe: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...swipePayloadFromPositionals(positionals, {
count: flags.count,
pauseMs: flags.pauseMs,
Expand All @@ -70,18 +75,21 @@ export const interactionCliReaders = {
}),
focus: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
x: Number(positionals[0]),
y: Number(positionals[1]),
}),
type: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
text: positionals.join(' '),
delayMs: flags.delayMs,
}),
fill: (positionals, flags) => {
const decoded = readFillTargetFromPositionals(positionals);
return {
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...selectorSnapshotInputFromFlags(flags),
...settleInputFromFlags(flags),
target: targetInputFromClientTarget(decoded.target),
Expand All @@ -92,13 +100,15 @@ export const interactionCliReaders = {
},
scroll: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
direction: readScrollDirection(positionals[0]),
amount: optionalCliNumber(positionals[1]),
pixels: flags.pixels,
durationMs: flags.durationMs,
}),
get: (positionals, flags) => ({
...commonInputFromFlags(flags),
...recordControlInputFromFlags(flags),
...selectorSnapshotInputFromFlags(flags),
format: readGetFormat(positionals[0]),
target: targetInputFromClientTarget(readElementTargetFromPositionals(positionals.slice(1))),
Expand Down
3 changes: 3 additions & 0 deletions src/commands/interaction/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
direct,
optionalCliNumber,
optionalNumber,
recordControlInputFromFlags,
request,
selectionOptionsFromFlags,
selectorSnapshotOptionsFromFlags,
Expand Down Expand Up @@ -64,6 +65,7 @@ function readFindOptionsFromPositionals(positionals: string[], flags: CliFlags):
const base = {
...findSnapshotOptionsFromFlags(flags),
...selectionOptionsFromFlags(flags),
...recordControlInputFromFlags(flags),
first: flags.findFirst,
last: flags.findLast,
};
Expand Down Expand Up @@ -111,6 +113,7 @@ function readIsOptionsFromPositionals(positionals: string[], flags: CliFlags): I
const base = {
...selectorSnapshotOptionsFromFlags(flags),
...selectionOptionsFromFlags(flags),
...recordControlInputFromFlags(flags),
};
const normalized = normalizeIsPositionals(positionals);
const predicate = normalized[0];
Expand Down
Loading