@@ -182,6 +182,51 @@ function mockSpawnerLayer(
182182 ) ;
183183}
184184
185+ function mockClaudeAuthStatusLayer ( status : "authenticated" | "unauthenticated" ) {
186+ const loggedIn = status === "authenticated" ;
187+ return mockSpawnerLayer ( ( args ) => {
188+ const joined = args . join ( " " ) ;
189+ if ( joined === "--version" ) return { stdout : "2.1.41\n" , stderr : "" , code : 0 } ;
190+ if ( joined === "auth status" ) {
191+ return {
192+ stdout : `${ JSON . stringify ( {
193+ loggedIn,
194+ authMethod : loggedIn ? "claude.ai" : "none" ,
195+ } ) } \n`,
196+ stderr : "" ,
197+ code : loggedIn ? 0 : 1 ,
198+ } ;
199+ }
200+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
201+ } ) ;
202+ }
203+
204+ function failingClaudeAuthStatusLayer ( description : string ) {
205+ return Layer . succeed (
206+ ChildProcessSpawner . ChildProcessSpawner ,
207+ ChildProcessSpawner . make ( ( command ) => {
208+ const cmd = command as unknown as { args : ReadonlyArray < string > } ;
209+ if ( cmd . args . join ( " " ) === "--version" ) {
210+ return Effect . succeed (
211+ mockHandle ( {
212+ stdout : "2.1.41\n" ,
213+ stderr : "" ,
214+ code : 0 ,
215+ } ) ,
216+ ) ;
217+ }
218+ return Effect . fail (
219+ PlatformError . systemError ( {
220+ _tag : "Unknown" ,
221+ module : "ChildProcess" ,
222+ method : "spawn" ,
223+ description,
224+ } ) ,
225+ ) ;
226+ } ) ,
227+ ) ;
228+ }
229+
185230function recordingMockSpawnerLayer (
186231 handler : ( args : ReadonlyArray < string > ) => {
187232 stdout : string ;
@@ -1783,7 +1828,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
17831828 Effect . provide (
17841829 mockSpawnerLayer ( ( args ) => {
17851830 const joined = args . join ( " " ) ;
1786- if ( joined === "--version" ) return { stdout : "1.0.0 \n" , stderr : "" , code : 0 } ;
1831+ if ( joined === "--version" ) return { stdout : "2.1.41 \n" , stderr : "" , code : 0 } ;
17871832 if ( joined === "auth status" )
17881833 return {
17891834 stdout : '{"loggedIn":true,"authMethod":"claude.ai"}\n' ,
@@ -1796,6 +1841,136 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
17961841 ) ,
17971842 ) ;
17981843
1844+ it . effect (
1845+ "returns unauthenticated when initialization has no account and the CLI reports logged out" ,
1846+ ( ) =>
1847+ Effect . gen ( function * ( ) {
1848+ const status = yield * checkClaudeProviderStatus (
1849+ defaultClaudeSettings ,
1850+ claudeCapabilities ( ) ,
1851+ ) ;
1852+ assert . strictEqual ( status . status , "error" ) ;
1853+ assert . strictEqual ( status . installed , true ) ;
1854+ assert . strictEqual ( status . auth . status , "unauthenticated" ) ;
1855+ assert . strictEqual (
1856+ status . message ,
1857+ "Claude is not authenticated. Run `claude auth login` and try again." ,
1858+ ) ;
1859+ } ) . pipe ( Effect . provide ( mockClaudeAuthStatusLayer ( "unauthenticated" ) ) ) ,
1860+ ) ;
1861+
1862+ it . effect (
1863+ "prefers the CLI logged-out result over stale initialization account metadata" ,
1864+ ( ) =>
1865+ Effect . gen ( function * ( ) {
1866+ const status = yield * checkClaudeProviderStatus (
1867+ defaultClaudeSettings ,
1868+ claudeCapabilities ( {
1869+ 1870+ subscriptionType : "team" ,
1871+ apiProvider : "firstParty" ,
1872+ } ) ,
1873+ ) ;
1874+ assert . strictEqual ( status . status , "error" ) ;
1875+ assert . strictEqual ( status . auth . status , "unauthenticated" ) ;
1876+ } ) . pipe ( Effect . provide ( mockClaudeAuthStatusLayer ( "unauthenticated" ) ) ) ,
1877+ ) ;
1878+
1879+ it . effect ( "uses loggedIn=false even when the auth command exits successfully" , ( ) =>
1880+ Effect . gen ( function * ( ) {
1881+ const status = yield * checkClaudeProviderStatus (
1882+ defaultClaudeSettings ,
1883+ claudeCapabilities ( {
1884+ 1885+ subscriptionType : "team" ,
1886+ apiProvider : "firstParty" ,
1887+ } ) ,
1888+ ) ;
1889+ assert . strictEqual ( status . status , "error" ) ;
1890+ assert . strictEqual ( status . auth . status , "unauthenticated" ) ;
1891+ } ) . pipe (
1892+ Effect . provide (
1893+ mockSpawnerLayer ( ( args ) => {
1894+ const joined = args . join ( " " ) ;
1895+ if ( joined === "--version" ) {
1896+ return { stdout : "2.1.41\n" , stderr : "" , code : 0 } ;
1897+ }
1898+ if ( joined === "auth status" ) {
1899+ return {
1900+ stdout : '{"loggedIn":false,"authMethod":"none"}\n' ,
1901+ stderr : "" ,
1902+ code : 0 ,
1903+ } ;
1904+ }
1905+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
1906+ } ) ,
1907+ ) ,
1908+ ) ,
1909+ ) ;
1910+
1911+ it . effect ( "preserves initialization auth on Claude versions without auth status" , ( ) =>
1912+ Effect . gen ( function * ( ) {
1913+ const status = yield * checkClaudeProviderStatus (
1914+ defaultClaudeSettings ,
1915+ claudeCapabilities ( {
1916+ 1917+ subscriptionType : "team" ,
1918+ apiProvider : "firstParty" ,
1919+ } ) ,
1920+ ) ;
1921+ assert . strictEqual ( status . status , "ready" ) ;
1922+ assert . strictEqual ( status . auth . status , "authenticated" ) ;
1923+ } ) . pipe (
1924+ Effect . provide (
1925+ mockSpawnerLayer ( ( args ) => {
1926+ if ( args . join ( " " ) === "--version" ) {
1927+ return { stdout : "2.1.40\n" , stderr : "" , code : 0 } ;
1928+ }
1929+ throw new Error ( `Unexpected args: ${ args . join ( " " ) } ` ) ;
1930+ } ) ,
1931+ ) ,
1932+ ) ,
1933+ ) ;
1934+
1935+ it . effect ( "returns unknown when the auth command exits unexpectedly" , ( ) =>
1936+ Effect . gen ( function * ( ) {
1937+ const status = yield * checkClaudeProviderStatus (
1938+ defaultClaudeSettings ,
1939+ claudeCapabilities ( ) ,
1940+ ) ;
1941+ assert . strictEqual ( status . status , "warning" ) ;
1942+ assert . strictEqual ( status . installed , true ) ;
1943+ assert . strictEqual ( status . auth . status , "unknown" ) ;
1944+ assert . strictEqual ( status . message , "Could not verify Claude authentication status." ) ;
1945+ } ) . pipe (
1946+ Effect . provide (
1947+ mockSpawnerLayer ( ( args ) => {
1948+ const joined = args . join ( " " ) ;
1949+ if ( joined === "--version" ) {
1950+ return { stdout : "2.1.41\n" , stderr : "" , code : 0 } ;
1951+ }
1952+ if ( joined === "auth status" ) {
1953+ return { stdout : "" , stderr : "unexpected failure" , code : 2 } ;
1954+ }
1955+ throw new Error ( `Unexpected args: ${ joined } ` ) ;
1956+ } ) ,
1957+ ) ,
1958+ ) ,
1959+ ) ;
1960+
1961+ it . effect ( "returns unknown when the auth command cannot be started" , ( ) =>
1962+ Effect . gen ( function * ( ) {
1963+ const status = yield * checkClaudeProviderStatus (
1964+ defaultClaudeSettings ,
1965+ claudeCapabilities ( ) ,
1966+ ) ;
1967+ assert . strictEqual ( status . status , "warning" ) ;
1968+ assert . strictEqual ( status . installed , true ) ;
1969+ assert . strictEqual ( status . auth . status , "unknown" ) ;
1970+ assert . strictEqual ( status . message , "Could not verify Claude authentication status." ) ;
1971+ } ) . pipe ( Effect . provide ( failingClaudeAuthStatusLayer ( "spawn auth status failed" ) ) ) ,
1972+ ) ;
1973+
17991974 it . effect ( "returns ready and labels Bedrock-backed Claude as authenticated" , ( ) =>
18001975 Effect . gen ( function * ( ) {
18011976 // Bedrock authenticates via external AWS credentials, so the SDK init
@@ -2044,15 +2219,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
20442219 assert . strictEqual ( status . auth . status , "authenticated" ) ;
20452220 assert . strictEqual ( status . auth . type , "Claude Max Subscription" ) ;
20462221 assert . strictEqual ( status . auth . label , "Claude Max Subscription" ) ;
2047- } ) . pipe (
2048- Effect . provide (
2049- mockSpawnerLayer ( ( args ) => {
2050- const joined = args . join ( " " ) ;
2051- if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
2052- throw new Error ( `Unexpected args: ${ joined } ` ) ;
2053- } ) ,
2054- ) ,
2055- ) ,
2222+ } ) . pipe ( Effect . provide ( mockClaudeAuthStatusLayer ( "authenticated" ) ) ) ,
20562223 ) ;
20572224
20582225 it . effect ( "does not duplicate Claude in provider-prefixed subscription names" , ( ) =>
@@ -2066,15 +2233,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
20662233 assert . strictEqual ( status . auth . status , "authenticated" ) ;
20672234 assert . strictEqual ( status . auth . type , "Claude Max" ) ;
20682235 assert . strictEqual ( status . auth . label , "Claude Max Subscription" ) ;
2069- } ) . pipe (
2070- Effect . provide (
2071- mockSpawnerLayer ( ( args ) => {
2072- const joined = args . join ( " " ) ;
2073- if ( joined === "--version" ) return { stdout : "1.0.0\n" , stderr : "" , code : 0 } ;
2074- throw new Error ( `Unexpected args: ${ joined } ` ) ;
2075- } ) ,
2076- ) ,
2077- ) ,
2236+ } ) . pipe ( Effect . provide ( mockClaudeAuthStatusLayer ( "authenticated" ) ) ) ,
20782237 ) ;
20792238
20802239 it . effect ( "returns claude auth email from initialization result" , ( ) =>
@@ -2107,7 +2266,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
21072266 const claudeConfigDir = "/tmp/t3code-claude-home" ;
21082267 const recorded = recordingMockSpawnerLayer ( ( args ) => {
21092268 const joined = args . join ( " " ) ;
2110- if ( joined === "--version" ) return { stdout : "1.0.0 \n" , stderr : "" , code : 0 } ;
2269+ if ( joined === "--version" ) return { stdout : "2.1.41 \n" , stderr : "" , code : 0 } ;
21112270 if ( joined === "auth status" )
21122271 return {
21132272 stdout : '{"loggedIn":true,"authMethod":"claude.ai"}\n' ,
@@ -2127,8 +2286,14 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
21272286 ) ;
21282287 assert . strictEqual ( status . status , "ready" ) ;
21292288 assert . deepStrictEqual (
2130- recorded . commands . map ( ( command ) => command . env ?. CLAUDE_CONFIG_DIR ) ,
2131- [ claudeConfigDir ] ,
2289+ recorded . commands . map ( ( command ) => ( {
2290+ args : command . args ,
2291+ claudeConfigDir : command . env ?. CLAUDE_CONFIG_DIR ,
2292+ } ) ) ,
2293+ [
2294+ { args : [ "--version" ] , claudeConfigDir } ,
2295+ { args : [ "auth" , "status" ] , claudeConfigDir } ,
2296+ ] ,
21322297 ) ;
21332298 } ) . pipe ( Effect . provide ( recorded . layer ) ) ;
21342299 } ) ;
0 commit comments