Skip to content

ref(toolkit-core): Share API path template matching between CLI and Code Mode - #1807

Draft
betegon wants to merge 7 commits into
bt/code-mode-httpfrom
bt/code-mode-path-matcher
Draft

betegon wants to merge 7 commits into
bt/code-mode-httpfrom
bt/code-mode-path-matcher

Conversation

@betegon

@betegon betegon commented Nov 2, 2026

Copy link
Copy Markdown
Member

Stacked on #1670.

Code Mode's authorization (access.ts) and the CLI's idempotent-retry check (idempotent-operations.ts) both ask whether a concrete API path matches an OpenAPI template. Code Mode looped over segments, and the CLI compiled a regex per template. Both now call matchApiPathTemplate() from @sentry/toolkit-core/api-path-template.

Each product keeps its own policy on top:

  • Code Mode: decodes segments and rejects encoded separators, picks the most literal template, treats ties as ambiguous, and checks the organization constraint.
  • CLI: filters by method.

Behavior change in Code Mode: a path missing its trailing slash, such as /organizations/acme/issues, failed authorization with a 403. Code Mode now adds the slash (the CLI's retry check already normalized it this way) and sends that canonical path. Templates without a trailing slash, like SCIM, still match as published. Paths that are not in the schema still fail.

sentry schema keeps its own matcher: it also matches template-shaped queries and returns every tie, which a discovery command needs and authorization must not do.

Tests:

  • toolkit-core unit tests for the matcher
  • the existing Code Mode access tests plus a trailing-slash case
  • the routing integration test, which now sends a path without the slash
  • the CLI idempotent-operation tests, unchanged

Generated by Claude Code

…ode Mode

Code Mode's authorization and the CLI's idempotent-retry check both ask the
same question: does this concrete path match this OpenAPI template? Code Mode
looped over segments, and the CLI compiled a regex per template. Both now use
`matchApiPathTemplate()` from toolkit-core, and each keeps its own policy on
top: Code Mode decodes and rejects separators, picks the most literal
template and checks the organization; the CLI filters by method.

Code Mode also adds a missing trailing slash, as the CLI's retry check does,
and sends that canonical path. A request for `/organizations/acme/issues` now
reaches the published route instead of failing authorization.

`sentry schema` keeps its own matcher: it also matches template-shaped
queries and returns every tie for discovery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017M6odW3kt5i65zATxfz9RX
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 2, 2026 8:58pm UTC

Request Review

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants