@@ -4,7 +4,7 @@ import * as FileSystem from "@effect/platform/FileSystem"
44import * as Path from "@effect/platform/Path"
55import { NodeContext } from "@effect/platform-node"
66import { describe , expect , it } from "@effect/vitest"
7- import { Effect } from "effect"
7+ import { Effect , Logger } from "effect"
88import * as Inspectable from "effect/Inspectable"
99import * as Sink from "effect/Sink"
1010import * as Stream from "effect/Stream"
@@ -13,8 +13,7 @@ import { authClaudeLogin } from "../../src/usecases/auth-claude.js"
1313
1414const encode = ( value : string ) : Uint8Array => new TextEncoder ( ) . encode ( value )
1515
16- const oauthTokenPrefix = [ "sk" , "ant" , "" ] . join ( "-" )
17- const oauthToken = `${ oauthTokenPrefix } oat01-EXAMPLE0123456789abcdef`
16+ const oauthToken = "TEST_CLAUDE_OAUTH_TOKEN_EXAMPLE"
1817
1918// Mirrors the real `claude setup-token` output that the OAuth parser scans for.
2019const setupTokenOutput = ( token : string ) : string =>
@@ -130,10 +129,18 @@ const withPatchedEnv = <A, E, R>(
130129const runLoginAndReadToken = (
131130 root : string ,
132131 pingExitCode : number
133- ) : Effect . Effect < string , unknown , FileSystem . FileSystem | Path . Path > =>
132+ ) : Effect . Effect <
133+ { readonly logs : ReadonlyArray < string > ; readonly tokenText : string } ,
134+ unknown ,
135+ FileSystem . FileSystem | Path . Path
136+ > =>
134137 Effect . gen ( function * ( _ ) {
135138 const fs = yield * _ ( FileSystem . FileSystem )
136139 const path = yield * _ ( Path . Path )
140+ const logs : Array < string > = [ ]
141+ const logger = Logger . make ( ( { message } ) => {
142+ logs . push ( String ( message ) )
143+ } )
137144 const claudeAuthPath = path . join ( root , ".docker-git/.orch/auth/claude" )
138145
139146 yield * _ (
@@ -142,11 +149,13 @@ const runLoginAndReadToken = (
142149 label : null ,
143150 claudeAuthPath
144151 } ) . pipe (
145- Effect . provideService ( CommandExecutor . CommandExecutor , makeFakeExecutor ( oauthToken , pingExitCode ) )
152+ Effect . provideService ( CommandExecutor . CommandExecutor , makeFakeExecutor ( oauthToken , pingExitCode ) ) ,
153+ Effect . provide ( Logger . replace ( Logger . defaultLogger , logger ) )
146154 )
147155 )
148156
149- return yield * _ ( fs . readFileString ( path . join ( claudeAuthPath , "default" , ".oauth-token" ) ) )
157+ const tokenText = yield * _ ( fs . readFileString ( path . join ( claudeAuthPath , "default" , ".oauth-token" ) ) )
158+ return { logs, tokenText }
150159 } )
151160
152161const runLoginWithoutCapturedToken = (
@@ -184,8 +193,9 @@ describe("authClaudeLogin", () => {
184193 withPatchedEnv (
185194 { HOME : root , DOCKER_GIT_STATE_AUTO_SYNC : "0" , DOCKER_GIT_PROJECTS_ROOT : undefined } ,
186195 Effect . gen ( function * ( _ ) {
187- const persisted = yield * _ ( runLoginAndReadToken ( root , 7 ) )
188- expect ( persisted . trim ( ) ) . toBe ( oauthToken )
196+ const { logs, tokenText } = yield * _ ( runLoginAndReadToken ( root , 7 ) )
197+ expect ( tokenText . trim ( ) ) . toBe ( oauthToken )
198+ expect ( logs . some ( ( message ) => message . includes ( "claude -p ping failed with exit=7" ) ) ) . toBe ( true )
189199 } )
190200 )
191201 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
@@ -195,8 +205,8 @@ describe("authClaudeLogin", () => {
195205 withPatchedEnv (
196206 { HOME : root , DOCKER_GIT_STATE_AUTO_SYNC : "0" , DOCKER_GIT_PROJECTS_ROOT : undefined } ,
197207 Effect . gen ( function * ( _ ) {
198- const persisted = yield * _ ( runLoginAndReadToken ( root , 0 ) )
199- expect ( persisted . trim ( ) ) . toBe ( oauthToken )
208+ const { tokenText } = yield * _ ( runLoginAndReadToken ( root , 0 ) )
209+ expect ( tokenText . trim ( ) ) . toBe ( oauthToken )
200210 } )
201211 )
202212 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
0 commit comments