Add cross-manager fixtures for the same short flag with different meanings
(npm/pnpm -d, pnpm -w, bun -d, bun -c optional value), options before and
after run, -- boundaries, quoted script names and missing values, through
the real pre-bash-dev-server-block entry point and auto-tmux-dev. The new
tests/lib/dev-command.test.js rows for npm and Yarn match real npm 11.6.0
and Yarn 4.9.2 runs of a scratch project whose dev script writes a marker.
Two gaps left by the held-candidate approach:
pnpm dev run build allow -- runs `dev`, passing it `run build`
pnpm --loglevel debug dev allow -- `debug` read as the script name
npm has no implicit script form (`npm dev` is not a command), so for npm a
bare token before `run` is always an option value — which is what keeps
`npm --userconfig /tmp/npmrc run dev` blocked without enumerating npm's config
surface. pnpm/yarn/bun do accept `pnpm dev`, so for them the FIRST bare token
is the script and everything after it, `run` included, is its argument.
Their option sets are finite, so the value-taking list is extended with the
ones that can precede an implicit script (--loglevel, --reporter, --store-dir,
--registry, --network-timeout, --env-file, ...).
Scanning every candidate token fixed the npm-config bypass but blocked valid
commands: `npm run run dev` runs a script called `run` with `dev` as its
argument, and `npm run build dev` passes `dev` to build. Both were refused
outside tmux.
Anchor on the keyword instead. With a `run`, the script is the token right
after it and everything later is that script's argument. Without one
(`pnpm dev`), the first bare token is the script — held rather than returned,
because a `run` further along proves it was an option value, which is what
keeps `npm --userconfig /tmp/npmrc run dev` blocked without needing to know
npm's whole config surface.
npm accepts any config key as `--key value`, so listing the value-taking
options can never be complete. `npm --userconfig /tmp/npmrc run dev` read the
script name as `/tmp/npmrc`, and the dev server started outside tmux.
Collect every candidate token after the manager word instead of only the
first, keeping the known value-taking options (so `--workspace dev` still
means a workspace named dev, not the dev script) and the `--` stop. An unknown
option's value now gets scanned too: that costs a false positive only when a
config value is literally `dev`, and a refusal the user sees beats a guard
that silently did nothing.
The auto-tmux tests now gate on tmux availability like their neighbours —
without tmux the hook passes the command through by design — and assert the
hook's exit code before parsing its stdout.
The hook matched `npm\s+run\s+dev` against the raw command string, which
cannot see through the shell's own quoting. Every one of these reached the
shell as a plain `npm run dev` and was allowed:
npm run "dev" npm --silent run dev
npm run 'dev' yarn --cwd app dev
npm run de"v" pnpm "dev" / yarn run "dev" / bun run "dev"
Read the script name from the tokens instead, reusing the quote-aware
readToken() the file already had: skip options (and the value of one known to
take a value), skip a `run` / `run-script` keyword, stop at `--`, then compare
the first remaining token against /^dev(?::|$)/.
`dev-setup` / `dev-docs` / `dev-build` stay allowed by the same rule the old
lookahead encoded, `npm test -- --grep dev` is allowed because `--` ends the
manager's own arguments, and the tmux launcher exemption is unchanged.
The blocking tests were skipped on Windows, where the hook no-ops, so this
class could only be caught on CI. The new cases force the platform in-process
and therefore run everywhere.
`DEV_PATTERN`'s trailing `\b` treats a hyphen as a word boundary, so
`dev\b` matched the `dev` prefix of distinct npm scripts like
`dev-setup` / `dev-docs` / `dev-build` and blocked them with exit 2.
Replace the trailing `\b` with `(?![\w-])` so the dev server still
matches (`dev`, `dev;`, `dev:ssr`) but `dev-<suffix>` scripts pass.
Adds regression tests for dev-setup/dev-docs/dev-build (allowed) and
dev:ssr (still blocked).
Co-authored-by: bymle <229636660+bymle@users.noreply.github.com>