Commit Graph
8 Commits
Author SHA1 Message Date
haelyra 4674f91097 test(dev-command): cover manager-specific option arity across both dev hooks
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.
2026-11-16 21:15:56 -05:00
Nguyen Thanh Dat 9826c934ff fix(dev-command): resolve the script by the manager's own grammar
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, ...).
2026-08-24 14:21:11 +07:00
Nguyen Thanh Dat e2d742b86d fix(dev-command): the script is the token after run, not any token
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.
2026-08-24 11:53:55 +07:00
Nguyen Thanh Dat e3c1437317 fix(dev-command): an unknown option must not swallow the script name
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.
2026-08-24 11:17:21 +07:00
Nguyen Thanh Dat ddfdfffffc fix(dev-server-block): decide the script name from tokens, not raw text
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.
2026-08-24 10:46:01 +07:00
bymleandbymle 7883da658b fix(dev-server-block): stop blocking dev-<suffix> scripts (#2179)
`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>
2026-06-07 13:25:39 +08:00
375d750b4c fix: integrate recent hook and docs PRs (#1905)
Integrates useful changes from #1882, #1884, #1889, #1893, #1898, #1899, and #1903:
- fix rule install docs to preserve language directories
- correct Ruby security command examples
- harden dev-server hook command-substitution parsing
- add Prisma patterns skill and catalog/package surfaces
- allow first-time protected config creation while blocking existing configs
- read cost metrics from Stop hook transcripts
- emit suggest-compact additionalContext on stdout

Co-authored-by: Jamkris <dltmdgus1412@gmail.com>
Co-authored-by: Levi-Evan <levishantz@gmail.com>
Co-authored-by: gaurav0107 <gauravdubey0107@gmail.com>
Co-authored-by: richm-spp <richard.millar@salarypackagingplus.com.au>
Co-authored-by: zomia <zomians@outlook.jp>
Co-authored-by: donghyeun02 <donghyeun02@gmail.com>
2026-05-14 21:37:28 -04:00
Affaan Mustafa b6595974c2 feat: add C++ language support and hook tests (#539)
- agents: cpp-build-resolver, cpp-reviewer
- commands: cpp-build, cpp-review, cpp-test
- rules: cpp/ (coding-style, hooks, patterns, security, testing)
- tests: 9 new hook test files with comprehensive coverage

Cherry-picked from PR #436.
2026-03-16 14:31:49 -07:00