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
25 changes: 22 additions & 3 deletions src/lib/version-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const SUPPRESSED_ARGS = new Set([
"token",
]);

/**
* CLI management subcommands that should not trigger version checks.
* Matched only when preceded by "cli" to avoid false positives
* (e.g., `--project setup` should not suppress notifications).
*/
const SUPPRESSED_CLI_SUBCOMMANDS = new Set(["setup", "fix"]);

/** AbortController for pending version check fetch */
let pendingAbortController: AbortController | null = null;

Expand Down Expand Up @@ -63,7 +70,14 @@ function shouldCheckForUpdate(): boolean {
* Check if update notifications should be suppressed for these args.
*/
export function shouldSuppressNotification(args: string[]): boolean {
return args.some((arg) => SUPPRESSED_ARGS.has(arg));
if (args.some((arg) => SUPPRESSED_ARGS.has(arg))) {
return true;
}
// Suppress for "cli <subcommand>" management commands (setup, fix)
if (args[0] === "cli" && SUPPRESSED_CLI_SUBCOMMANDS.has(args[1] ?? "")) {
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -107,9 +121,14 @@ function checkForUpdateInBackgroundImpl(): void {
setVersionCheckInfo(latestVersion);
span.setStatus({ code: 1 }); // OK
} catch (error) {
// Don't report abort errors - they're expected when process exits
// Don't report abort errors - they're expected when process exits.
// Record other errors (network failures, JSON parse errors) as span
// attributes rather than captureException — these are transient
// infrastructure issues (GitHub rate limits, CDN errors), not CLI bugs.
// They remain queryable in Discover without cluttering the Issues feed.
if (error instanceof Error && error.name !== "AbortError") {
Sentry.captureException(error);
span.setAttribute("version_check.error", error.message);
span.setAttribute("version_check.error_type", error.constructor.name);
}
span.setStatus({ code: 2 }); // Error
} finally {
Expand Down
27 changes: 27 additions & 0 deletions test/lib/version-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ describe("shouldSuppressNotification", () => {
expect(shouldSuppressNotification(["upgrade", "--check"])).toBe(true);
});

test("suppresses for cli management commands", () => {
expect(shouldSuppressNotification(["cli", "setup"])).toBe(true);
expect(shouldSuppressNotification(["cli", "fix"])).toBe(true);
expect(
shouldSuppressNotification([
"cli",
"setup",
"--install",
"--method",
"curl",
])
).toBe(true);
});

test("does not suppress for cli feedback", () => {
expect(shouldSuppressNotification(["cli", "feedback"])).toBe(false);
});

test("does not suppress when setup/fix appear as non-cli args", () => {
expect(
shouldSuppressNotification(["issue", "list", "--project", "setup"])
).toBe(false);
expect(
shouldSuppressNotification(["issue", "list", "--query", "fix"])
).toBe(false);
});

test("suppresses for --version flag", () => {
expect(shouldSuppressNotification(["--version"])).toBe(true);
expect(shouldSuppressNotification(["-V"])).toBe(true);
Expand Down
Loading