@@ -164,6 +164,7 @@ type TestClaudeCapabilities = {
164164 readonly email : string | undefined ;
165165 readonly subscriptionType : string | undefined ;
166166 readonly tokenSource : string | undefined ;
167+ readonly apiKeySource : string | undefined ;
167168 readonly apiProvider : string | undefined ;
168169 readonly slashCommands : ReadonlyArray < ServerProviderSlashCommand > ;
169170} ;
@@ -174,6 +175,7 @@ function claudeCapabilities(overrides: Partial<TestClaudeCapabilities> = {}) {
174175 email : undefined ,
175176 subscriptionType : undefined ,
176177 tokenSource : undefined ,
178+ apiKeySource : undefined ,
177179 apiProvider : undefined ,
178180 slashCommands : [ ] ,
179181 ...overrides ,
@@ -3167,6 +3169,100 @@ it.layer(
31673169 ) ,
31683170 ) ;
31693171
3172+ it . effect ( "reports a logged-out CLI as unauthenticated" , ( ) =>
3173+ Effect . gen ( function * ( ) {
3174+ // The capability probe resolves for a logged-out CLI, so `tokenSource:
3175+ // "none"` is the only thing separating it from an authenticated one.
3176+ const status = yield * checkClaudeProviderStatus (
3177+ defaultClaudeSettings ,
3178+ claudeCapabilities ( {
3179+ tokenSource : "none" ,
3180+ apiKeySource : "none" ,
3181+ apiProvider : "firstParty" ,
3182+ } ) ,
3183+ ) ;
3184+ assert . strictEqual ( status . status , "error" ) ;
3185+ assert . strictEqual ( status . auth . status , "unauthenticated" ) ;
3186+ } ) . pipe (
3187+ Effect . provide (
3188+ layerMockSpawner ( ( args ) => {
3189+ const joined = args . join ( " " ) ;
3190+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3191+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3192+ } ) ,
3193+ ) ,
3194+ ) ,
3195+ ) ;
3196+
3197+ it . effect ( "keeps an API key install authenticated when it reports no token source" , ( ) =>
3198+ Effect . gen ( function * ( ) {
3199+ // `ANTHROPIC_API_KEY` never populates `tokenSource`, so reading that
3200+ // field alone would log the install out.
3201+ const status = yield * checkClaudeProviderStatus (
3202+ defaultClaudeSettings ,
3203+ claudeCapabilities ( {
3204+ tokenSource : "none" ,
3205+ apiKeySource : "ANTHROPIC_API_KEY" ,
3206+ apiProvider : "firstParty" ,
3207+ } ) ,
3208+ ) ;
3209+ assert . strictEqual ( status . status , "ready" ) ;
3210+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3211+ } ) . pipe (
3212+ Effect . provide (
3213+ layerMockSpawner ( ( args ) => {
3214+ const joined = args . join ( " " ) ;
3215+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3216+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3217+ } ) ,
3218+ ) ,
3219+ ) ,
3220+ ) ;
3221+
3222+ it . effect ( "keeps a third-party backend authenticated without any token source" , ( ) =>
3223+ Effect . gen ( function * ( ) {
3224+ // Bedrock and Vertex authenticate outside the CLI, so the account
3225+ // payload is empty by design rather than because nobody logged in.
3226+ const status = yield * checkClaudeProviderStatus (
3227+ defaultClaudeSettings ,
3228+ claudeCapabilities ( { tokenSource : "none" , apiProvider : "bedrock" } ) ,
3229+ ) ;
3230+ assert . strictEqual ( status . status , "ready" ) ;
3231+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3232+ } ) . pipe (
3233+ Effect . provide (
3234+ layerMockSpawner ( ( args ) => {
3235+ const joined = args . join ( " " ) ;
3236+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3237+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3238+ } ) ,
3239+ ) ,
3240+ ) ,
3241+ ) ;
3242+
3243+ it . effect ( "keeps a CLI that says nothing about its account authenticated" , ( ) =>
3244+ Effect . gen ( function * ( ) {
3245+ // Profile-authenticated installs report no token source at all, and a
3246+ // CLI too old to send an account payload reports nothing whatsoever.
3247+ // Only `tokenSource: "none"` disproves authentication; saying nothing
3248+ // is not the same as saying no.
3249+ const status = yield * checkClaudeProviderStatus (
3250+ defaultClaudeSettings ,
3251+ claudeCapabilities ( ) ,
3252+ ) ;
3253+ assert . strictEqual ( status . status , "ready" ) ;
3254+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3255+ } ) . pipe (
3256+ Effect . provide (
3257+ layerMockSpawner ( ( args ) => {
3258+ const joined = args . join ( " " ) ;
3259+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3260+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3261+ } ) ,
3262+ ) ,
3263+ ) ,
3264+ ) ;
3265+
31703266 it . effect ( "returns a display label for claude subscription types" , ( ) =>
31713267 Effect . gen ( function * ( ) {
31723268 const status = yield * checkClaudeProviderStatus (
@@ -3204,6 +3300,7 @@ it.layer(
32043300 email : undefined ,
32053301 subscriptionType : undefined ,
32063302 tokenSource : undefined ,
3303+ apiKeySource : undefined ,
32073304 apiProvider : undefined ,
32083305 slashCommands : [ ] ,
32093306 usage : { rate_limits_available : true , rate_limits : { } } ,
0 commit comments