Skip to content

ref(cli): Parse alert rule positionals before the command runs - #1745

Merged
BYK merged 3 commits into
mainfrom
byk/cli-alert-rule-positionals
Oct 30, 2026
Merged

BYK merged 3 commits into
mainfrom
byk/cli-alert-rule-positionals

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1564

Moves the nine allow-listed alert commands off in-func target parsing. Their positionals are now parsed before the command runs.

Rule commands (alert issues view/delete/edit, alert metrics view/delete/edit): these use issueRuleParameter / metricRuleParameter. Both wrap the new alertRuleParameter (src/commands/alert/arguments.ts), which is a boundPositional over the existing parseIssueRuleArg / parseMetricRuleArg splitters. func takes an AlertRuleArgument and reads { ref, target } from await rule.resolved. Rule lookup by ID or name is unchanged. No API calls or endpoints changed.

I didn't add an ID_KINDS entry. Rule names are free text and can contain spaces, while the ID grammar splits IDs at spaces. The rule part also comes after a 1- or 2-segment target, which isn't the [<org>/[<project>/]]<id> shape. The splitters already handle this syntax, so I kept them.

Target-only commands:

  • alert issues create uses orgProjectTarget with its resolver, which still requires exactly one project.
  • alert metrics create uses orgProjectTarget with resolveOrgOnlyTarget.
  • alert metrics list uses listTarget(ORG_PROJECT_TARGET). It keeps its own brief ("project ignored").

Lint and docs:

  • Removed the nine alert entries from UNBOUND_TARGET_PARSING_ALLOWED, then the list itself (see below).
  • Added AlertRuleArgument to BOUND_TARGET_TYPES so require-target-resolution covers it.
  • Added a short "Alert rule positionals" note to packages/cli/AGENTS.md.

Tests:

  • argument-conventions.test.ts checks that each rule command parses 42, my-org/web/High error rate and my-org/High error rate the same way.
  • It also checks invalid forms (my-org/web for issue rules, my-org/, a/b/c, blank) and target parsing for the create and list commands.
  • A pasted URL's server is applied on resolve, not on parse.
  • Command tests now set commandPrefix, like Stricli does, and metrics delete spies on resolveOrgOnlyTarget.

Behavior changes

  • An invalid rule argument (for example alert metrics view a/b/c, or alert issues view my-org/web without a rule) now fails in Stricli's argument scanner. Before, it failed inside func. The message gets the usual Failed to parse "<input>" for <placeholder>: … prefix and the exit code changes from 21 to 252. The error text is otherwise the same. It also fails before the auth guard now, like other migrated commands.
  • A pasted Sentry URL in the target part now has its server applied when the target resolves (after the auth guard), not during parsing.

Lint allow-lists

Drops the last allow-list, per review on #1747; closes out #1564's ratchet. Once #1746 landed, UNBOUND_TARGET_PARSING_ALLOWED held only these nine alert commands. This PR deletes it, along with ratchetedNames and allowedFollowUp. require-target-resolution now uses bannedNames, so it reports every banned reference in command files and has no exemption path. The allow-list and ratchet lint-rule test cases are removed, and packages/cli/AGENTS.md now says neither positional rule has an allow-list.

Not in scope: alert rule URLs (/alerts/rules/..., /monitors/...) were not accepted before and still aren't. sentry-url-parser has no alert-rule paths. That could be a follow-up.

Verification: tsc, pnpm run lint, lint-rule tests (scripts/cli-lint-rules.test.mjs, 69/69 after the cleanup) and the alert and argument-conventions tests pass. Before the merge, the full CLI unit suite had 12593 passing tests and only 6 failures, all known root-permission sandbox tests (EACCES/readonly).

via BYK.

--

View Junior Session in Sentry

Move the nine allow-listed alert commands off in-func target parsing:

- alert issues view/delete/edit and alert metrics view/delete/edit take
  their rule argument through issueRuleParameter/metricRuleParameter, a
  boundPositional over the existing parseIssueRuleArg/parseMetricRuleArg
  splitters. Rule names may contain spaces, so they keep their own syntax
  rather than an ID_KINDS entry.
- alert issues create and alert metrics create use orgProjectTarget with
  their existing resolvers; alert metrics list uses listTarget.

A pasted URL's server is applied on resolve, after the auth guard. Drop
the commands from UNBOUND_TARGET_PARSING_ALLOWED, register
AlertRuleArgument with require-target-resolution, and cover the commands
in argument-conventions.test.ts.

Part of #1564

Co-Authored-By: BYK <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-local Error Error Oct 29, 2026 11:55pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 29, 2026
@BYK
BYK enabled auto-merge (squash) October 29, 2026 22:46
sentry-junior Bot added a commit that referenced this pull request Oct 29, 2026
#1747 emptied AD_HOC_ID_PARSING_ALLOWED, so no-ad-hoc-id-arguments now
reports every hand-parsed ID reference in a command directly, with no
exemption path. The target-parsing allow-list keeps only the alert
commands until #1745 lands.

Part of #1564

Co-Authored-By: BYK <burak.kaya@sentry.io>
sentry-junior Bot and others added 2 commits October 29, 2026 23:53
Resolve conflicts with #1746: UNBOUND_TARGET_PARSING_ALLOWED is now empty, so drop its allow-list and ratchet test cases (they pointed at alert/metrics/view.ts); keep both sides' argument-conventions tests.

Co-Authored-By: BYK <burak.kaya@sentry.io>
UNBOUND_TARGET_PARSING_ALLOWED is empty now that every command parses
its positionals before run. Delete it with ratchetedNames and
allowedFollowUp, and have require-target-resolution report every banned
reference in command files through bannedNames. Update AGENTS.md: neither
positional rule has an allow-list.

Part of #1564

Co-Authored-By: BYK <burak.kaya@sentry.io>
@BYK
BYK merged commit c277e4d into main Oct 30, 2026
32 checks passed
@BYK
BYK deleted the byk/cli-alert-rule-positionals branch October 30, 2026 00:09

This branch was previously deployed

1 inactive deployment
Preview — bc0e3294 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant