@@ -79,6 +79,7 @@ mock.module("../../../src/lib/logger.js", () => ({
7979// Dynamic import: must run AFTER mock.module() so login.ts picks up fakeLog.
8080const { loginCommand } = await import ( "../../../src/commands/auth/login.js" ) ;
8181
82+ import { rcTokenHint } from "../../../src/commands/auth/login.js" ;
8283// biome-ignore lint/performance/noNamespaceImport: needed for spyOn mocking
8384import * as apiClient from "../../../src/lib/api-client.js" ;
8485// biome-ignore lint/performance/noNamespaceImport: needed for spyOn mocking
@@ -88,6 +89,7 @@ import * as dbUser from "../../../src/lib/db/user.js";
8889import { AuthError } from "../../../src/lib/errors.js" ;
8990// biome-ignore lint/performance/noNamespaceImport: needed for spyOn mocking
9091import * as interactiveLogin from "../../../src/lib/interactive-login.js" ;
92+ import type { SentryCliRcConfig } from "../../../src/lib/sentryclirc.js" ;
9193
9294type LoginFlags = {
9395 readonly token ?: string ;
@@ -780,3 +782,52 @@ describe("applyLoginUrl (trust anchor registration)", () => {
780782 ) . toBe ( false ) ;
781783 } ) ;
782784} ) ;
785+
786+ function makeRcConfig (
787+ token : string | undefined ,
788+ url ?: string
789+ ) : SentryCliRcConfig {
790+ return {
791+ token,
792+ url,
793+ sources : { token : token ? "~/.sentryclirc" : undefined } ,
794+ } ;
795+ }
796+
797+ describe ( "rcTokenHint" , ( ) => {
798+ test ( "no token → no hint" , ( ) => {
799+ expect (
800+ rcTokenHint ( makeRcConfig ( undefined ) , "https://sentry.io" )
801+ ) . toBeUndefined ( ) ;
802+ } ) ;
803+
804+ test ( "SaaS host, no rc URL → hint without --url" , ( ) => {
805+ const hint = rcTokenHint ( makeRcConfig ( "sntrys_abc" ) , "https://sentry.io" ) ;
806+ expect ( hint ) . toContain ( "sentry auth login --token <token>" ) ;
807+ expect ( hint ) . not . toContain ( "--url" ) ;
808+ } ) ;
809+
810+ test ( "self-hosted, rc URL matches → hint includes --url" , ( ) => {
811+ const hint = rcTokenHint (
812+ makeRcConfig ( "sntrys_abc" , "https://self.example.com" ) ,
813+ "https://self.example.com"
814+ ) ;
815+ expect ( hint ) . toContain ( "--url https://self.example.com" ) ;
816+ } ) ;
817+
818+ test ( "self-hosted, rc URL mismatches → no hint (token is for a different instance)" , ( ) => {
819+ const hint = rcTokenHint (
820+ makeRcConfig ( "sntrys_abc" , "https://other.example.com" ) ,
821+ "https://self.example.com"
822+ ) ;
823+ expect ( hint ) . toBeUndefined ( ) ;
824+ } ) ;
825+
826+ test ( "self-hosted, no rc URL → no hint (bare SaaS token shouldn't be suggested for self-hosted)" , ( ) => {
827+ const hint = rcTokenHint (
828+ makeRcConfig ( "sntrys_abc" ) ,
829+ "https://self.example.com"
830+ ) ;
831+ expect ( hint ) . toBeUndefined ( ) ;
832+ } ) ;
833+ } ) ;
0 commit comments