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
5 changes: 5 additions & 0 deletions .changeset/cli-strict-integer-flags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'e2e': patch
---

The numeric flags of `e2e run`, `e2e mcp`, and `e2e explore` take decimal digits only. An empty value, such as `--retries "$RETRIES"` with the variable unset, used to read as 0 and turn retries off without a word; it is now a usage error, exit 2, as an empty `--tag` is. `0x1` and `1e3` are refused the same way.
5 changes: 4 additions & 1 deletion docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,10 @@ anything starts, as the config value would. `--target`, `--tag`,
`--exclude-tag`, and `--agent` take each name once. An empty value (`--tag ''`,
or `--tag "$TAGS"` with the variable unset) is a usage error, exit 2, never a
wider selection. An empty `--reporter` is the same usage error, never a run
with no reporters.
with no reporters. A numeric flag (`--retries`, `--workers`,
`--max-failures`, a timeout) takes decimal digits only: an empty value
(`--retries "$RETRIES"` with the variable unset), `0x1`, or `1e3` is the same
usage error, never read as some other number.
Comment on lines +864 to +867

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 · Non-blocking · The decimal-digits rule is documented for e2e run only

Optional. This does not block the merge.

The new sentence is in the e2e run section, but the changeset says that the e2e mcp and e2e explore numeric flags changed too. These pages describe the affected flags and still give only their ranges:

  • docs/reference/mcp.mdx:69 (--max-sessions): --max-sessions 0x2 now exits 2 instead of starting with 2 sessions.
  • The e2e explore option table, docs/reference/cli.mdx:1253-1254 (--max-steps, --timeout): --timeout 6e5 now exits 2.
  • skills/e2e/references/running.md:44-47 says that an empty --target or --tag exits 2 and gives --retries guidance, but does not say that an empty --retries "$RETRIES" now exits 2.

AGENTS.md requires the matching docs page and skills/e2e/ to change with the behavior. Non-blocking.


Filters only narrow, and each applies after the one before: positionals, then
`.only`, `--tag`, `--exclude-tag`, `--grep`, `--grep-invert`, `--last-failed`,
Expand Down
15 changes: 12 additions & 3 deletions packages/e2e/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ import { telemetry as telemetryCommand, TELEMETRY_ACTIONS, type TelemetryAction
import { parseUpgradeTarget, type UpgradeTarget } from './upgrade-target.ts';
import { wordmarkBanner } from './wordmark.ts';

/**
* The decimal digits of a flag value as a number, else NaN. `Number` alone
* reads `''` and `' '` as 0 and takes `0x10` and `1e3`, so an unset
* `--retries "$RETRIES"` would turn retries off instead of failing.
*/
function integerOf(value: string): number {
return /^\d+$/u.test(value) ? Number(value) : Number.NaN;
}

/** An integer of at least one, for `--max-failures` and `--repeat-each`. */
function parsePositiveInt(value: string): number {
const parsed = Number(value);
const parsed = integerOf(value);
if (!Number.isSafeInteger(parsed) || parsed < 1) throw new InvalidArgumentError('must be a positive integer');
return parsed;
}
Expand All @@ -65,7 +74,7 @@ function parseDevice(value: string): string {

/** Shape check only; the config resolver applies each flag's bounds. */
function parseNonNegativeInt(value: string): number {
const parsed = Number(value);
const parsed = integerOf(value);
if (!Number.isSafeInteger(parsed) || parsed < 0) {
throw new InvalidArgumentError('must be a nonnegative integer');
}
Expand Down Expand Up @@ -99,7 +108,7 @@ function parseShard(value: string): Shard {
/** An integer inside a closed range, for the explore budgets, `--max-duration`, and the timeout overrides. */
function parseBoundedInt(bounds: { readonly min: number; readonly max: number }): (value: string) => number {
return (value) => {
const parsed = Number(value);
const parsed = integerOf(value);
if (!Number.isSafeInteger(parsed) || parsed < bounds.min || parsed > bounds.max) {
throw new InvalidArgumentError(`must be an integer from ${bounds.min} through ${bounds.max}`);
}
Expand Down
18 changes: 10 additions & 8 deletions packages/e2e/tests/unit/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('e2e run argument parsing', () => {
await invoke('run', '--max-failures', '3');
expect(lastRunOptions().maxFailures).toBe(3);
runMock.mockClear();
for (const value of ['0', '-1', '2.5', 'many']) {
for (const value of ['0', '-1', '2.5', 'many', '', '1e1']) {
stderrSpy.mockClear();
process.exitCode = undefined;
await invoke('run', '--max-failures', value);
Expand All @@ -230,7 +230,7 @@ describe('e2e run argument parsing', () => {
await invoke('run', '--max-duration', '2147483647');
expect(lastRunOptions().maxDuration).toBe(2_147_483_647);
runMock.mockClear();
for (const value of ['0', '-1', '2.5', '15m', '2147483648']) {
for (const value of ['0', '-1', '2.5', '15m', '2147483648', '', '0x10']) {
stderrSpy.mockClear();
process.exitCode = undefined;
await invoke('run', '--max-duration', value);
Expand Down Expand Up @@ -467,12 +467,14 @@ describe('e2e run argument parsing', () => {
});

it('rejects negative and non-integer numeric flags with exit code 2', async () => {
for (const value of ['-1', '1.5', 'abc']) {
runMock.mockClear();
process.exitCode = undefined;
await invoke('run', '--retries', value);
expect(runMock).not.toHaveBeenCalled();
expect(process.exitCode).toBe(2);
for (const flag of ['--retries', '--workers']) {
for (const value of ['-1', '1.5', 'abc', '', ' ', '0x1', '1e1']) {
runMock.mockClear();
process.exitCode = undefined;
await invoke('run', flag, value);
expect(runMock, `${flag} '${value}'`).not.toHaveBeenCalled();
expect(process.exitCode, `${flag} '${value}'`).toBe(2);
}
}
});

Expand Down
Loading