From 4ee3341dc17a67c0fba6c9c4fa9521c5a15c3e56 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:29:55 +0000 Subject: [PATCH 1/3] fix(mcp): Check events, traces and replays an ID alone names against the session's project A project-scoped `sentry mcp --commands` session still reached other projects through IDs that name no project. `event view ` fell back to the org-wide event ID lookup, `trace view ` reads a trace org-wide, and `replay view ` checked the replay's project only when the call named one. The scope checks in `target-scope.ts` now take what they check (`Issue 123`, `Event abc`), and `assertProjectInScope` covers anything with a project slug: - `getEvent` and `resolveEventInOrg` refuse an event outside the scope, and `event view` no longer swallows that refusal in its fallbacks. - `getDetailedTrace` refuses a trace with no span in the session's project. A trace that has one keeps the spans of the projects it calls into. - `resolveReplay` refuses another organization, and the replay project check also compares the replay with the session's project. A replay without a project is refused in a project scope. Refs #2237 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .../src/content/docs/library-usage.md | 2 +- packages/cli/src/commands/event/view.ts | 8 ++- packages/cli/src/commands/replay/view.ts | 26 ++++++++- packages/cli/src/lib/api/events.ts | 31 ++++++---- packages/cli/src/lib/api/issues.ts | 4 +- packages/cli/src/lib/api/replays.ts | 2 + packages/cli/src/lib/api/traces.ts | 38 +++++++++++++ packages/cli/src/lib/sdk-types.ts | 9 +-- packages/cli/src/lib/target-scope.ts | 56 ++++++++++++------- 9 files changed, 135 insertions(+), 41 deletions(-) diff --git a/apps/cli-docs/src/content/docs/library-usage.md b/apps/cli-docs/src/content/docs/library-usage.md index 63b6bd40f..feb5e5604 100644 --- a/apps/cli-docs/src/content/docs/library-usage.md +++ b/apps/cli-docs/src/content/docs/library-usage.md @@ -171,7 +171,7 @@ const sdk = createSentrySDK({ token: "...", text: true, cwd: "/my/project" }); | `url` | `string` | `sentry.io` | Sentry instance URL for self-hosted | | `org` | `string` | Auto-detected | Organization slug; also a limit while `limitToTarget` is on | | `project` | `string` | Auto-detected | Project slug; also a limit while `limitToTarget` is on | -| `limitToTarget` | `boolean` | `true` | Refuse an issue outside `org` and `project`, even one an ID alone names (`12345`, `@latest`). Set `false` to use `org` and `project` only as defaults | +| `limitToTarget` | `boolean` | `true` | Refuse an issue, event, trace or replay outside `org` and `project`, even one an ID alone names (`12345`, `@latest`, an event ID). Set `false` to use `org` and `project` only as defaults | | `text` | `boolean` | `false` | Return human-readable text instead of parsed JSON (`run()` only) | | `cwd` | `string` | `process.cwd()` | Working directory for DSN auto-detection | | `headers` | `Record` | — | Extra HTTP headers for self-hosted instances behind a reverse proxy (same as [`SENTRY_CUSTOM_HEADERS`](../configuration/#sentry_custom_headers)); ignored for sentry.io | diff --git a/packages/cli/src/commands/event/view.ts b/packages/cli/src/commands/event/view.ts index 26edc8a9a..b2a7a76fb 100644 --- a/packages/cli/src/commands/event/view.ts +++ b/packages/cli/src/commands/event/view.ts @@ -880,8 +880,12 @@ async function tryEventFallbacks( return resolved; } } catch (sameOrgError) { - // Propagate auth errors — they indicate a global problem (expired token) - if (sameOrgError instanceof AuthError) { + // Propagate auth errors (a global problem, such as an expired token) and + // an event outside the invocation's target scope. + if ( + sameOrgError instanceof AuthError || + sameOrgError instanceof ResolutionError + ) { throw sameOrgError; } if (sameOrgError instanceof ApiError && sameOrgError.status === 429) { diff --git a/packages/cli/src/commands/replay/view.ts b/packages/cli/src/commands/replay/view.ts index 0ff15f3d5..207fe88b1 100644 --- a/packages/cli/src/commands/replay/view.ts +++ b/packages/cli/src/commands/replay/view.ts @@ -46,6 +46,10 @@ import { } from "../../lib/resolve-target.js"; import { applySentryUrlContext } from "../../lib/sentry-url-parser.js"; import { buildReplayUrl } from "../../lib/sentry-web-urls.js"; +import { + assertProjectInScope, + getTargetScope, +} from "../../lib/target-scope.js"; import type { ReplayActivityEvent, ReplayDetails, @@ -161,7 +165,8 @@ type ReplayProjectScope = { }; /** - * Reject a replay that is not in the project the user named. + * Reject a replay that is not in the project the user named, or outside the + * invocation's target scope (`limitToTarget`). * * Replays are looked up org-wide, so an explicit `//` target * has to be checked against the replay's own project. @@ -171,6 +176,7 @@ export async function validateReplayProjectScope( ): Promise { const { expectedProjectId, org, project, replay, replayId } = scope; const command = scope.command ?? "view"; + await assertReplayInTargetScope(org, replayId, replay); if (!project) { return; } @@ -203,6 +209,24 @@ export async function validateReplayProjectScope( } } +/** + * Refuse a replay outside the invocation's target scope. A replay without a + * project, such as an archived one, is refused in a project scope. + */ +async function assertReplayInTargetScope( + org: string, + replayId: string, + replay: ReplayDetails, +): Promise { + const scopeProject = getTargetScope()?.project; + let project: string | undefined; + if (scopeProject && replay.project_id) { + const { id } = await getProject(org, scopeProject); + project = String(id) === replay.project_id ? scopeProject : undefined; + } + assertProjectInScope(org, project, `Replay ${replayId}`); +} + async function fetchReplayActivity( org: string, replay: ReplayDetails, diff --git a/packages/cli/src/lib/api/events.ts b/packages/cli/src/lib/api/events.ts index 29af5164c..24eb32631 100644 --- a/packages/cli/src/lib/api/events.ts +++ b/packages/cli/src/lib/api/events.ts @@ -17,6 +17,7 @@ import pLimit from "p-limit"; import type { IssueEvent, SentryEvent } from "../../types/index.js"; import { ApiError, AuthError } from "../errors.js"; +import { assertOrgInScope, assertProjectInScope } from "../target-scope.js"; import { API_MAX_PER_PAGE, @@ -60,12 +61,16 @@ export async function getLatestEvent( /** * Get a specific event by ID. * Uses region-aware routing for multi-region support. + * + * @throws {ResolutionError} When `orgSlug`/`projectSlug` is outside the + * invocation's target scope (`limitToTarget`) */ export async function getEvent( orgSlug: string, projectSlug: string, eventId: string, ): Promise { + assertProjectInScope(orgSlug, projectSlug, `Event ${eventId}`); const config = getOrgSdkConfig(); const result = await getProjectEvent({ @@ -136,11 +141,15 @@ export type ResolvedEvent = { * * Returns the resolved org, project, and full event on success, * or null if the event is not found in the given org. + * + * @throws {ResolutionError} When the org, or the event's project, is outside + * the invocation's target scope (`limitToTarget`) */ export async function resolveEventInOrg( orgSlug: string, eventId: string, ): Promise { + assertOrgInScope(orgSlug, `Event ${eventId}`); const config = getOrgSdkConfig(); const result = await sdkResolveAnEventId({ @@ -148,17 +157,9 @@ export async function resolveEventInOrg( path: { organization_id_or_slug: orgSlug, event_id: eventId }, }); + let data: { organizationSlug: string; projectSlug: string; event: unknown }; try { - const data = unwrapResult<{ - organizationSlug: string; - projectSlug: string; - event: unknown; - }>(result, "Failed to resolve event ID"); - return { - org: data.organizationSlug, - project: data.projectSlug, - event: data.event as SentryEvent, - }; + data = unwrapResult(result, "Failed to resolve event ID"); } catch (error) { // 404 means the event doesn't exist in this org — not an error if (error instanceof ApiError && error.status === 404) { @@ -166,6 +167,16 @@ export async function resolveEventInOrg( } throw error; } + assertProjectInScope( + data.organizationSlug, + data.projectSlug, + `Event ${eventId}`, + ); + return { + org: data.organizationSlug, + project: data.projectSlug, + event: data.event as SentryEvent, + }; } /** Options for {@link findEventAcrossOrgs}. */ diff --git a/packages/cli/src/lib/api/issues.ts b/packages/cli/src/lib/api/issues.ts index 73c811735..2624caed7 100644 --- a/packages/cli/src/lib/api/issues.ts +++ b/packages/cli/src/lib/api/issues.ts @@ -334,7 +334,7 @@ export async function getIssueInOrg( issueId: string, options?: { collapse?: IssueCollapseField[] }, ): Promise { - assertOrgInScope(orgSlug, issueId); + assertOrgInScope(orgSlug, `Issue ${issueId}`); const collapse = toIssueDetailsCollapse(options?.collapse); const result = await getOrganizationIssue({ ...getOrgSdkConfig(), @@ -413,7 +413,7 @@ export async function getIssueByShortId( options?: { collapse?: IssueCollapseField[] }, ): Promise { const normalizedShortId = shortId.toUpperCase(); - assertOrgInScope(orgSlug, normalizedShortId); + assertOrgInScope(orgSlug, `Issue ${normalizedShortId}`); const config = getOrgSdkConfig(); let data: { group?: SentryIssue }; diff --git a/packages/cli/src/lib/api/replays.ts b/packages/cli/src/lib/api/replays.ts index cfd0ae7f5..b9acb364a 100644 --- a/packages/cli/src/lib/api/replays.ts +++ b/packages/cli/src/lib/api/replays.ts @@ -26,6 +26,7 @@ import { import { ApiError } from "../errors.js"; import { logger } from "../logger.js"; import { resolveOrgRegion } from "../region.js"; +import { assertOrgInScope } from "../target-scope.js"; import { API_MAX_PER_PAGE, @@ -305,6 +306,7 @@ export async function resolveReplay( replayOrTraceId: string, options: Pick = {}, ): Promise { + assertOrgInScope(orgSlug, `Replay ${replayOrTraceId}`); try { return await getReplay(orgSlug, replayOrTraceId); } catch (error) { diff --git a/packages/cli/src/lib/api/traces.ts b/packages/cli/src/lib/api/traces.ts index ac93958d4..314c02366 100644 --- a/packages/cli/src/lib/api/traces.ts +++ b/packages/cli/src/lib/api/traces.ts @@ -37,6 +37,11 @@ export type { TraceItemAttribute, TraceItemDetail } from "../../types/index.js"; import { logger } from "../logger.js"; import { resolveOrgRegion } from "../region.js"; import { getSdkClientConfig } from "../sentry-sdk-client.js"; +import { + assertOrgInScope, + assertProjectInScope, + getTargetScope, +} from "../target-scope.js"; import { isAllDigits } from "../utils.js"; import { @@ -158,15 +163,48 @@ async function requestTrace( * - Known event `timestamp` → one query around that instant (no retry). * - Unknown time → `statsPeriod=14d`, then `90d` if the first response is empty. * + * In a project-limited invocation (`limitToTarget`), a trace with no span + * in that project is refused. A trace that has one keeps the spans of every + * project it calls into. + * * @param orgSlug - Organization slug * @param traceId - The trace ID (from event.contexts.trace.trace_id) * @param options - Optional timestamp and additional attributes * @returns Array of root spans with nested children + * @throws {ResolutionError} When the trace is outside the invocation's + * target scope */ export async function getDetailedTrace( orgSlug: string, traceId: string, options: GetDetailedTraceOptions = {}, +): Promise { + assertOrgInScope(orgSlug, `Trace ${traceId}`); + const spans = await fetchDetailedTrace(orgSlug, traceId, options); + const scopeProject = getTargetScope()?.project; + if (scopeProject && spans.length > 0) { + assertProjectInScope( + orgSlug, + hasSpanInProject(spans, scopeProject) ? scopeProject : undefined, + `Trace ${traceId}`, + ); + } + return spans; +} + +/** Whether a span of the tree, at any depth, is in `projectSlug`. */ +function hasSpanInProject(spans: TraceSpan[], projectSlug: string): boolean { + return spans.some( + (span) => + span.project_slug === projectSlug || + hasSpanInProject(span.children ?? [], projectSlug), + ); +} + +async function fetchDetailedTrace( + orgSlug: string, + traceId: string, + options: GetDetailedTraceOptions, ): Promise { const regionUrl = await resolveOrgRegion(orgSlug); const shared = { additionalAttributes: options.additionalAttributes }; diff --git a/packages/cli/src/lib/sdk-types.ts b/packages/cli/src/lib/sdk-types.ts index 1cf8912f5..30a07ba37 100644 --- a/packages/cli/src/lib/sdk-types.ts +++ b/packages/cli/src/lib/sdk-types.ts @@ -39,10 +39,11 @@ export type SentryOptions = { /** * Treat `org` and `project` as a limit, not only as defaults (default - * `true`). A command then refuses an issue outside them, including one - * named by an ID that says nothing about its project (a numeric ID, a - * share link, `@latest`). Has no effect without `org`. Set `false` to use - * `org` and `project` only as defaults. + * `true`). A command then refuses an issue, event, trace or replay + * outside them, including one named by an ID that says nothing about its + * project (a numeric issue ID, an event ID, a share link, `@latest`). Has + * no effect without `org`. Set `false` to use `org` and `project` only as + * defaults. */ limitToTarget?: boolean; diff --git a/packages/cli/src/lib/target-scope.ts b/packages/cli/src/lib/target-scope.ts index 5f971848c..de6e2a9b8 100644 --- a/packages/cli/src/lib/target-scope.ts +++ b/packages/cli/src/lib/target-scope.ts @@ -2,10 +2,11 @@ * The organization and project an SDK invocation is limited to: the `org` * and `project` of `createSentrySDK()`, unless `limitToTarget` is `false`. * - * The caller checks the targets a call names, but not an issue that an ID - * alone names: a numeric ID, a share link, or a selector such as `@latest` - * says nothing about its project. Issue lookups check the issue they find - * with {@link assertIssueInScope} before a command reads or changes it. + * The caller checks the targets a call names, but not what an ID alone + * names: a numeric issue ID, an event, trace or replay ID, a share link, or a + * selector such as `@latest` says nothing about its project. Lookups check + * what they find with {@link assertProjectInScope} (or + * {@link assertIssueInScope}) before a command reads or changes it. */ import type { SentryIssue } from "../types/index.js"; @@ -27,13 +28,13 @@ export function getTargetScope(): TargetScope | undefined { return project ? { org, project } : { org }; } -function outsideScope(issueId: string, scope: TargetScope): ResolutionError { +function outsideScope(subject: string, scope: TargetScope): ResolutionError { const target = scope.project ? `${scope.org}/${scope.project}` : scope.org; return new ResolutionError( - `Issue ${issueId}`, + subject, `is outside this session's scope (${target})`, sentry`issue list ${scope.project ? target : `${target}/`}`, - [`This session can only read or change issues in ${target}.`], + [`This session can only read or change data in ${target}.`], ); } @@ -42,19 +43,40 @@ function outsideScope(issueId: string, scope: TargetScope): ResolutionError { * to it. * * @param org - The organization a lookup asks - * @param issueId - The issue as given, for the error + * @param subject - What is looked up, for the error (`Issue 123`) * @throws {ResolutionError} When `org` is not the limit's organization */ -export function assertOrgInScope(org: string, issueId: string): void { +export function assertOrgInScope(org: string, subject: string): void { const scope = getTargetScope(); if (scope && org !== scope.org) { - throw outsideScope(issueId, scope); + throw outsideScope(subject, scope); } } /** - * Refuse an issue outside the invocation's limit. An issue whose project is - * unknown is refused in a project-limited invocation. + * Refuse something a lookup found outside the invocation's limit. Something + * whose project is unknown is refused in a project-limited invocation. + * + * @param org - The organization it was found in + * @param project - The slug of its project, if known + * @param subject - What was found, for the error (`Event abc`) + * @throws {ResolutionError} When it is in another organization or project + */ +export function assertProjectInScope( + org: string, + project: string | undefined, + subject: string, +): void { + assertOrgInScope(org, subject); + const scope = getTargetScope(); + if (scope?.project && project !== scope.project) { + throw outsideScope(subject, scope); + } +} + +/** + * Refuse an issue outside the invocation's limit, as + * {@link assertProjectInScope} does. * * @param org - The organization the issue was found in * @param issue - The issue a lookup found @@ -65,13 +87,5 @@ export function assertIssueInScope( org: string, issue: Pick, ): void { - const scope = getTargetScope(); - if (!scope) { - return; - } - const issueId = issue.id; - assertOrgInScope(org, issueId); - if (scope.project && issue.project?.slug !== scope.project) { - throw outsideScope(issueId, scope); - } + assertProjectInScope(org, issue.project?.slug, `Issue ${issue.id}`); } From 719d2014c288fadbf7468ce23fcf7952ef3e8584 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:05:27 +0000 Subject: [PATCH 2/3] fix(mcp): Check a replay's project before --web, and suggest the right list `replay view --web` opened the replay before `validateReplayProjectScope` ran, so a project-scoped session could open another project's replay that an ID alone names. The scope check now runs first. A refused event, trace or replay suggested `issue list`. The hint now names the list command of what was refused (`event list acme/web`). Refs #2237 --- packages/cli/src/commands/replay/view.ts | 10 +++--- packages/cli/src/lib/target-scope.ts | 10 +++++- .../cli/test/commands/replay/view.test.ts | 13 ++++++++ packages/cli/test/lib/target-scope.test.ts | 33 ++++++++++++++++++- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/commands/replay/view.ts b/packages/cli/src/commands/replay/view.ts index 207fe88b1..609a23ba9 100644 --- a/packages/cli/src/commands/replay/view.ts +++ b/packages/cli/src/commands/replay/view.ts @@ -421,11 +421,6 @@ export const viewCommand = buildCommand({ throw error; } - if (flags.web) { - await openInBrowser(buildReplayUrl(resolved.org, replay.id), "replay"); - return; - } - await validateReplayProjectScope({ org: resolved.org, project: resolved.project, @@ -434,6 +429,11 @@ export const viewCommand = buildCommand({ replay, }); + if (flags.web) { + await openInBrowser(buildReplayUrl(resolved.org, replay.id), "replay"); + return; + } + const enrichment = await enrichReplayView(resolved.org, replay); const data: ReplayViewData = { org: resolved.org, diff --git a/packages/cli/src/lib/target-scope.ts b/packages/cli/src/lib/target-scope.ts index de6e2a9b8..99ece7aaf 100644 --- a/packages/cli/src/lib/target-scope.ts +++ b/packages/cli/src/lib/target-scope.ts @@ -28,12 +28,20 @@ export function getTargetScope(): TargetScope | undefined { return project ? { org, project } : { org }; } +/** The command group that lists what a refused subject names (`Event abc`). */ +const LIST_GROUPS: Readonly> = { + Event: "event", + Trace: "trace", + Replay: "replay", +}; + function outsideScope(subject: string, scope: TargetScope): ResolutionError { const target = scope.project ? `${scope.org}/${scope.project}` : scope.org; + const group = LIST_GROUPS[subject.split(" ", 1)[0] ?? ""] ?? "issue"; return new ResolutionError( subject, `is outside this session's scope (${target})`, - sentry`issue list ${scope.project ? target : `${target}/`}`, + sentry`${group} list ${scope.project ? target : `${target}/`}`, [`This session can only read or change data in ${target}.`], ); } diff --git a/packages/cli/test/commands/replay/view.test.ts b/packages/cli/test/commands/replay/view.test.ts index b5570ba19..922869c4b 100644 --- a/packages/cli/test/commands/replay/view.test.ts +++ b/packages/cli/test/commands/replay/view.test.ts @@ -394,6 +394,19 @@ describe("viewCommand.func", () => { ).rejects.toThrow(ResolutionError); }); + test("rejects replays outside the explicit project scope with --web", async () => { + resolveTargetSpy.mockResolvedValue({ org: "test-org", project: "cli" }); + resolveReplaySpy.mockResolvedValue(sampleReplay({ project_id: "999" })); + + const { context } = createMockContext(); + const func = await loadCommand(viewCommand); + + await expect( + func.call(context, { json: false, web: true, fresh: false }, REPLAY_ID), + ).rejects.toThrow(ResolutionError); + expect(openInBrowserSpy).not.toHaveBeenCalled(); + }); + test("allows archived replays with no project ID in explicit project scope", async () => { resolveTargetSpy.mockResolvedValue({ org: "test-org", project: "cli" }); resolveReplaySpy.mockResolvedValue( diff --git a/packages/cli/test/lib/target-scope.test.ts b/packages/cli/test/lib/target-scope.test.ts index 3005e024f..b6a04fab5 100644 --- a/packages/cli/test/lib/target-scope.test.ts +++ b/packages/cli/test/lib/target-scope.test.ts @@ -9,7 +9,10 @@ import { withEnv, } from "../../src/lib/env.js"; import { ResolutionError } from "../../src/lib/errors.js"; -import { assertIssueInScope } from "../../src/lib/target-scope.js"; +import { + assertIssueInScope, + assertProjectInScope, +} from "../../src/lib/target-scope.js"; const WEB_ISSUE = { id: "100", @@ -59,3 +62,31 @@ describe("assertIssueInScope", () => { ).not.toThrow(); }); }); + +describe("the error of a refused lookup", () => { + const webScope = { + [SCOPE_ORG_ENV_VAR]: "acme", + [SCOPE_PROJECT_ENV_VAR]: "web", + }; + + function refusal(subject: string): ResolutionError { + try { + withEnv(webScope, () => assertProjectInScope("acme", "api", subject)); + } catch (error) { + if (error instanceof ResolutionError) { + return error; + } + throw error; + } + throw new Error(`${subject} was not refused`); + } + + test.each([ + ["Issue 100", "issue list acme/web"], + ["Event abc", "event list acme/web"], + ["Trace abc", "trace list acme/web"], + ["Replay abc", "replay list acme/web"], + ])("for %s suggests %s", (subject, command) => { + expect(refusal(subject).hint).toContain(command); + }); +}); From 2cded4ff4e023c917769f8208c71d52482d7ba55 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:13:14 +0000 Subject: [PATCH 3/3] fix(mcp): Suggest only list commands that take the session's scope `event list` takes an issue, not a project, and `trace list` needs a project. A refused event now suggests `issue list`, and a refused trace suggests `trace list` only in a project scope. Refs #2237 --- packages/cli/src/lib/target-scope.ts | 26 +++++++++++++++------- packages/cli/test/lib/target-scope.test.ts | 15 ++++++++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/lib/target-scope.ts b/packages/cli/src/lib/target-scope.ts index 99ece7aaf..86cb5bf2c 100644 --- a/packages/cli/src/lib/target-scope.ts +++ b/packages/cli/src/lib/target-scope.ts @@ -28,20 +28,30 @@ export function getTargetScope(): TargetScope | undefined { return project ? { org, project } : { org }; } -/** The command group that lists what a refused subject names (`Event abc`). */ -const LIST_GROUPS: Readonly> = { - Event: "event", - Trace: "trace", - Replay: "replay", -}; +/** + * The command that lists what the scope allows, for a refused subject + * (`Replay abc`): `replay list`, `trace list` in a project scope (traces + * need a project), or `issue list`. `event list` takes an issue, not a + * project, so events get `issue list` too. + */ +function listCommand(subject: string, scope: TargetScope, target: string) { + const kind = subject.split(" ", 1)[0]; + const listTarget = scope.project ? target : `${target}/`; + if (kind === "Replay") { + return sentry`replay list ${listTarget}`; + } + if (kind === "Trace" && scope.project) { + return sentry`trace list ${listTarget}`; + } + return sentry`issue list ${listTarget}`; +} function outsideScope(subject: string, scope: TargetScope): ResolutionError { const target = scope.project ? `${scope.org}/${scope.project}` : scope.org; - const group = LIST_GROUPS[subject.split(" ", 1)[0] ?? ""] ?? "issue"; return new ResolutionError( subject, `is outside this session's scope (${target})`, - sentry`${group} list ${scope.project ? target : `${target}/`}`, + listCommand(subject, scope, target), [`This session can only read or change data in ${target}.`], ); } diff --git a/packages/cli/test/lib/target-scope.test.ts b/packages/cli/test/lib/target-scope.test.ts index b6a04fab5..539acb511 100644 --- a/packages/cli/test/lib/target-scope.test.ts +++ b/packages/cli/test/lib/target-scope.test.ts @@ -11,6 +11,7 @@ import { import { ResolutionError } from "../../src/lib/errors.js"; import { assertIssueInScope, + assertOrgInScope, assertProjectInScope, } from "../../src/lib/target-scope.js"; @@ -83,10 +84,22 @@ describe("the error of a refused lookup", () => { test.each([ ["Issue 100", "issue list acme/web"], - ["Event abc", "event list acme/web"], + ["Event abc", "issue list acme/web"], ["Trace abc", "trace list acme/web"], ["Replay abc", "replay list acme/web"], ])("for %s suggests %s", (subject, command) => { expect(refusal(subject).hint).toContain(command); }); + + test("suggests issue list for a trace in an organization scope", () => { + let hint: string | undefined; + try { + withEnv({ [SCOPE_ORG_ENV_VAR]: "acme" }, () => + assertOrgInScope("other", "Trace abc"), + ); + } catch (error) { + hint = error instanceof ResolutionError ? error.hint : undefined; + } + expect(hint).toContain("issue list acme/"); + }); });