@@ -156,6 +156,7 @@ type TestClaudeCapabilities = {
156156 readonly email : string | undefined ;
157157 readonly subscriptionType : string | undefined ;
158158 readonly tokenSource : string | undefined ;
159+ readonly apiKeySource : string | undefined ;
159160 readonly apiProvider : string | undefined ;
160161 readonly slashCommands : ReadonlyArray < ServerProviderSlashCommand > ;
161162} ;
@@ -166,6 +167,7 @@ function claudeCapabilities(overrides: Partial<TestClaudeCapabilities> = {}) {
166167 email : undefined ,
167168 subscriptionType : undefined ,
168169 tokenSource : undefined ,
170+ apiKeySource : undefined ,
169171 apiProvider : undefined ,
170172 slashCommands : [ ] ,
171173 ...overrides ,
@@ -2972,6 +2974,96 @@ it.layer(Layer.mergeAll(TestNodeServices, ServerSettingsModule.layerTest(), Test
29722974 ) ,
29732975 ) ;
29742976
2977+ it . effect ( "reports a logged-out CLI as unauthenticated" , ( ) =>
2978+ Effect . gen ( function * ( ) {
2979+ // The capability probe resolves for a logged-out CLI, so `tokenSource:
2980+ // "none"` is the only thing separating it from an authenticated one.
2981+ const status = yield * checkClaudeProviderStatus (
2982+ defaultClaudeSettings ,
2983+ claudeCapabilities ( { tokenSource : "none" , apiProvider : "firstParty" } ) ,
2984+ ) ;
2985+ assert . strictEqual ( status . status , "error" ) ;
2986+ assert . strictEqual ( status . auth . status , "unauthenticated" ) ;
2987+ } ) . pipe (
2988+ Effect . provide (
2989+ mockSpawnerLayer ( ( args ) => {
2990+ const joined = args . join ( " " ) ;
2991+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
2992+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
2993+ } ) ,
2994+ ) ,
2995+ ) ,
2996+ ) ;
2997+
2998+ it . effect ( "keeps an API key install authenticated when it reports no token source" , ( ) =>
2999+ Effect . gen ( function * ( ) {
3000+ // `ANTHROPIC_API_KEY` never populates `tokenSource`, so reading that
3001+ // field alone would log the install out.
3002+ const status = yield * checkClaudeProviderStatus (
3003+ defaultClaudeSettings ,
3004+ claudeCapabilities ( {
3005+ tokenSource : "none" ,
3006+ apiKeySource : "ANTHROPIC_API_KEY" ,
3007+ apiProvider : "firstParty" ,
3008+ } ) ,
3009+ ) ;
3010+ assert . strictEqual ( status . status , "ready" ) ;
3011+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3012+ } ) . pipe (
3013+ Effect . provide (
3014+ mockSpawnerLayer ( ( args ) => {
3015+ const joined = args . join ( " " ) ;
3016+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3017+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3018+ } ) ,
3019+ ) ,
3020+ ) ,
3021+ ) ;
3022+
3023+ it . effect ( "keeps a third-party backend authenticated without any token source" , ( ) =>
3024+ Effect . gen ( function * ( ) {
3025+ // Bedrock and Vertex authenticate outside the CLI, so the account
3026+ // payload is empty by design rather than because nobody logged in.
3027+ const status = yield * checkClaudeProviderStatus (
3028+ defaultClaudeSettings ,
3029+ claudeCapabilities ( { tokenSource : "none" , apiProvider : "bedrock" } ) ,
3030+ ) ;
3031+ assert . strictEqual ( status . status , "ready" ) ;
3032+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3033+ } ) . pipe (
3034+ Effect . provide (
3035+ mockSpawnerLayer ( ( args ) => {
3036+ const joined = args . join ( " " ) ;
3037+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3038+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3039+ } ) ,
3040+ ) ,
3041+ ) ,
3042+ ) ;
3043+
3044+ it . effect ( "keeps a CLI that says nothing about its account authenticated" , ( ) =>
3045+ Effect . gen ( function * ( ) {
3046+ // Profile-authenticated installs report no token source at all, and a
3047+ // CLI too old to send an account payload reports nothing whatsoever.
3048+ // Only `tokenSource: "none"` disproves authentication; saying nothing
3049+ // is not the same as saying no.
3050+ const status = yield * checkClaudeProviderStatus (
3051+ defaultClaudeSettings ,
3052+ claudeCapabilities ( ) ,
3053+ ) ;
3054+ assert . strictEqual ( status . status , "ready" ) ;
3055+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
3056+ } ) . pipe (
3057+ Effect . provide (
3058+ mockSpawnerLayer ( ( args ) => {
3059+ const joined = args . join ( " " ) ;
3060+ if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
3061+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
3062+ } ) ,
3063+ ) ,
3064+ ) ,
3065+ ) ;
3066+
29753067 it . effect ( "returns a display label for claude subscription types" , ( ) =>
29763068 Effect . gen ( function * ( ) {
29773069 const status = yield * checkClaudeProviderStatus (
@@ -3009,6 +3101,7 @@ it.layer(Layer.mergeAll(TestNodeServices, ServerSettingsModule.layerTest(), Test
30093101 email : undefined ,
30103102 subscriptionType : undefined ,
30113103 tokenSource : undefined ,
3104+ apiKeySource : undefined ,
30123105 apiProvider : undefined ,
30133106 slashCommands : [ ] ,
30143107 usage : { rate_limits_available : true , rate_limits : { } } ,
0 commit comments