Skip to content

Commit 16f269c

Browse files
committed
fix(profile): simplify explicit target resolution and add disambiguation example
- Explicit org/project targets now use parsed values directly instead of routing through resolveOrgAndProject (consistent with view.ts) - Add disambiguationExample to resolveProjectBySlug call in list.ts so users see an actionable command when a project exists in multiple orgs
1 parent 47e63fd commit 16f269c

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/commands/profile/list.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,15 @@ async function resolveListTarget(
7070
"Usage: sentry profile list <org>/<project>"
7171
);
7272

73-
case "explicit": {
74-
const resolved = await resolveOrgAndProject({
75-
org: parsed.org,
76-
project: parsed.project,
77-
cwd,
78-
usageHint: USAGE_HINT,
79-
});
80-
if (!resolved) {
81-
throw new ContextError("Organization and project", USAGE_HINT);
82-
}
83-
return resolved;
84-
}
73+
case "explicit":
74+
return { org: parsed.org, project: parsed.project };
8575

8676
case "project-search":
87-
return await resolveProjectBySlug(parsed.projectSlug, USAGE_HINT);
77+
return await resolveProjectBySlug(
78+
parsed.projectSlug,
79+
USAGE_HINT,
80+
`sentry profile list <org>/${parsed.projectSlug}`
81+
);
8882

8983
case "auto-detect": {
9084
const resolved = await resolveOrgAndProject({

test/commands/profile/list.test.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,21 @@ describe("listCommand.func", () => {
143143
await expect(func.call(ctx, defaultFlags)).rejects.toThrow(ContextError);
144144
});
145145

146-
test("resolves explicit org/project target", async () => {
146+
test("resolves explicit org/project target directly", async () => {
147147
const ctx = createMockContext();
148-
setupResolvedTarget();
148+
getProjectSpy.mockResolvedValue({
149+
id: "12345",
150+
slug: "backend",
151+
name: "Backend",
152+
});
149153
listProfiledTransactionsSpy.mockResolvedValue({ data: [] });
150154
const func = await loadListFunc();
151155

152156
await func.call(ctx, defaultFlags, "my-org/backend");
153157

154-
expect(resolveOrgAndProjectSpy).toHaveBeenCalledWith(
155-
expect.objectContaining({ org: "my-org", project: "backend" })
156-
);
158+
// Explicit targets skip resolveOrgAndProject and use parsed values directly
159+
expect(resolveOrgAndProjectSpy).not.toHaveBeenCalled();
160+
expect(ctx.setContext).toHaveBeenCalledWith(["my-org"], ["backend"]);
157161
});
158162

159163
test("resolves project-only target via findProjectsBySlug", async () => {
@@ -357,23 +361,28 @@ describe("listCommand.func", () => {
357361
);
358362
});
359363

360-
test("shows detectedFrom hint when present", async () => {
364+
test("shows detectedFrom hint when auto-detected", async () => {
361365
const ctx = createMockContext();
362366
setupResolvedTarget({ detectedFrom: ".env file" });
363367
listProfiledTransactionsSpy.mockResolvedValue({
364368
data: [{ transaction: "/api/users", "count_unique(timestamp)": 10 }],
365369
});
366370
const func = await loadListFunc();
367371

368-
await func.call(ctx, defaultFlags, "my-org/backend");
372+
// No target arg → auto-detect path, which returns detectedFrom
373+
await func.call(ctx, defaultFlags);
369374

370375
const output = getOutput(ctx);
371376
expect(output).toContain("Detected from .env file");
372377
});
373378

374-
test("does not show detectedFrom when absent", async () => {
379+
test("does not show detectedFrom for explicit target", async () => {
375380
const ctx = createMockContext();
376-
setupResolvedTarget();
381+
getProjectSpy.mockResolvedValue({
382+
id: "12345",
383+
slug: "backend",
384+
name: "Backend",
385+
});
377386
listProfiledTransactionsSpy.mockResolvedValue({
378387
data: [{ transaction: "/api/users", "count_unique(timestamp)": 10 }],
379388
});

0 commit comments

Comments
 (0)