feat(auth): mid-flight 401 만료 세션 투명 재인증 (withReauthRetry, #210)#211
Merged
Conversation
- TossApiError에 isGeoBlocked(4010), isExpiredSession 게터 추가 - withReauthRetry<T> 헬퍼: 읽기 전용 명령에서 만료 세션 감지 시 저장된 파일 크리덴셜로 headless 재인증 후 1회 재실행 - 재인증 carve-out: AITCC_SESSION env, 환경변수 크리덴셜, geo-block은 제외 - 읽기 명령 전체 적용: whoami, app ls/show/status/bundles, workspace ls/show/partner/terms/segments, members ls, notices ls/show/categories, me terms show, keys ls, app init - 변이 명령은 의도적으로 제외(이중 제출 방지) - withReauthRetry 단위 테스트(7 케이스) + isExpiredSession/isGeoBlocked 테스트 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요약
이 PR은 #210 을 닫습니다. 의존: #209 (headless 재인증 인프라) 가 main에 머지된 뒤 base를 main으로 재타겟해야 합니다.
문제 (mid-flight 401 갭)
세션 파일이 있어도 쿠키가 만료된 경우, live API 호출이
TossApiError(401)을 던지면 기존 코드는 "Session is no longer valid. Runaitcc loginagain." 을 출력하고 종료했습니다. 크리덴셜이 저장돼 있어도 자동 재인증이 없었습니다.해결책
Part 1 —
TossApiError게터 추가 (src/api/http.ts):isGeoBlocked:errorCode === '4010'— 지역 차단은 재인증해도 소용없음isExpiredSession:isAuthError && !isGeoBlocked— 진짜 만료된 세션만Part 2 —
withReauthRetry<T>헬퍼 (src/commands/_shared.ts):isExpiredSession에러 시 파일 크리덴셜로 headless 재인증 후 1회 재실행AITCC_SESSIONenv, env 크리덴셜(kind: 'env'), geo-block(4010) → 재인증 없이 rethrowAcquireSessionDepsinjection seam으로 단위 테스트 가능Part 3 — 읽기 명령 전체 적용:
whoami,app ls/show/status/bundles ls/bundles deployedworkspace ls/use/show/partner/terms show/segments lsmembers ls,notices ls/show/categoriesme terms show,keys ls,app init(워크스페이스 목록 fetch)Part 4 — 변이 명령은 의도적으로 제외:
app deploy/register,keys create/revoke,members invite/removeworkspace terms agree,me terms agree보안 제약 (유지 확인)
AITCC_SESSIONenv 활성 시 자동 재인증 없음AITCC_EMAIL/PASSWORD) → 재인증 없음headlessLoginFromCredentials사용)테스트
src/commands/_shared.reauth-retry.test.ts:withReauthRetry7 케이스 (a~g)src/api/http.test.ts:isGeoBlocked,isExpiredSession게터 3 케이스 추가pnpm typecheck && pnpm lint && pnpm test && pnpm build— 728 tests passedCloses #210