Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/cli/src/commands/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ import {
listSupportedReplayFields,
parseReplayEnvironmentFilter,
} from "../lib/replay-search.js";
import { resolveOrgOptionalFromArg } from "../lib/resolve-target.js";
import { sanitizeQuery } from "../lib/search-query.js";
import {
type OrgOptionalTarget,
orgOptionalTarget,
} from "../lib/target-positional.js";
import {
appendPeriodHint,
PERIOD_BRIEF,
Expand Down Expand Up @@ -697,7 +700,7 @@ export const exploreCommand = buildListCommand("explore", {
placeholder: "target",
brief:
"Target: <org>/<project>, <org>/, or <project>. Auto-detected if omitted.",
parse: String,
parse: orgOptionalTarget,
optional: true as const,
},
],
Expand Down Expand Up @@ -773,13 +776,12 @@ export const exploreCommand = buildListCommand("explore", {
n: "limit",
},
},
async *func(this: SentryContext, flags: ExploreFlags, target?: string) {
const { cwd } = this;
const { org, project } = await resolveOrgOptionalFromArg(
target,
cwd,
"explore",
);
async *func(
this: SentryContext,
flags: ExploreFlags,
target: OrgOptionalTarget,
) {
const { org, project } = await target.resolved;

let dataset = flags.dataset;
const userSuppliedFields = flags.field && flags.field.length > 0;
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/test/commands/explore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function createContext() {
}),
},
cwd: "/tmp/test-explore",
commandPrefix: ["sentry", "explore"],
},
getStdout: () => stdoutChunks.join(""),
};
Expand Down Expand Up @@ -150,8 +151,8 @@ beforeEach(async () => {
nextCursor: undefined,
});

// Default: resolveOrgOptionalFromArg returns org-only (auto-detect)
resolveTargetSpy = vi.spyOn(resolveTarget, "resolveOrgOptionalFromArg");
// Default: resolveOrgOptionalTarget returns org-only (auto-detect)
resolveTargetSpy = vi.spyOn(resolveTarget, "resolveOrgOptionalTarget");
resolveTargetSpy.mockResolvedValue({ org: "test-org" });

resolveCursorSpy = vi.spyOn(paginationDb, "resolveCursor").mockReturnValue({
Expand Down Expand Up @@ -209,7 +210,7 @@ describe("sentry explore", () => {
await func.call(context, DEFAULT_FLAGS, "my-org/");

expect(resolveTargetSpy).toHaveBeenCalledWith(
"my-org/",
{ type: "org-all", org: "my-org" },
"/tmp/test-explore",
"explore",
);
Expand Down Expand Up @@ -257,7 +258,7 @@ describe("sentry explore", () => {
await func.call(context, DEFAULT_FLAGS, "cli");

expect(resolveTargetSpy).toHaveBeenCalledWith(
"cli",
{ type: "project-search", projectSlug: "cli" },
"/tmp/test-explore",
"explore",
);
Expand All @@ -274,7 +275,7 @@ describe("sentry explore", () => {
await func.call(context, DEFAULT_FLAGS);

expect(resolveTargetSpy).toHaveBeenCalledWith(
undefined,
{ type: "auto-detect" },
"/tmp/test-explore",
"explore",
);
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/test/lib/complete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ describe("getCompletions: context detection", () => {
expect(result.some((c) => c.value === "test-org/")).toBe(true);
});

test("returns org/project completions for the top-level explore command", async () => {
await seedOrgs([{ slug: "my-org", name: "My Organization" }]);
const result = getCompletions(["explore"], "");
expect(result.some((c) => c.value === "my-org/")).toBe(true);
});

test("returns org-only completions for team list", async () => {
await seedOrgs([{ slug: "acme", name: "Acme Inc" }]);
const result = getCompletions(["team", "list"], "");
Expand Down
Loading