fix(tgit): run gf auth commands from a neutral cwd - #312
Merged
Conversation
`gf auth whoami` / `gf auth login` inspect the current git repository's `origin` remote and scope the authentication check to that remote's host. When `teamai` runs inside a repo whose origin is not git.woa.com (e.g. a GitHub mirror), gf reports "not logged in" even though a valid git.woa.com token exists — so `teamai init` wrongly re-triggers interactive login and fails with "gf auth login failed" in the very repo teamai itself lives in. Run the three auth calls (gfIsAuthenticated / gfAuthWhoami / gfAuthLogin) from os.tmpdir(), which is not a git repo, so the host-scoped credential is found reliably regardless of where teamai was invoked. Verified end-to-end: `teamai init` now authenticates and completes inside a repo whose origin is github.com (previously reproduced the failure). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
teamai initfails withgf auth login failedwhen run inside a git repository whoseoriginremote is notgit.woa.com(e.g. a GitHub mirror — including this very repo).Root cause:
gf auth whoami/gf auth logininspect the current git repository'soriginremote and scope the authentication check to that remote's host. When teamai runs from a repo whose origin isgithub.com, gf reports "还未登录" (not logged in) even though a valid git.woa.com OAuth token exists.ensureAuthenticated()takes that at face value, re-triggers interactive login, and fails.The token itself is valid — the check is just being run from the wrong place. Reproduced deterministically:
gf auth whoamiorigin = git.woa.com/...origin = github.com/.../tmp)Fix
Run the three
gf authcalls (gfIsAuthenticated,gfAuthWhoami,gfAuthLogin) from a neutral working directory (os.tmpdir(), which is not a git repo). Authentication is host-scoped (git.woa.com), so it must not depend on the cwd's local git remote.Test Plan
npm run build— successnpx vitest run src/__tests__/gf-cli.test.ts— 13 passed (added 3 tests asserting each auth call spawns withcwd = os.tmpdir())npx tsc --noEmiton changed files — no errorsteamai initfrom a temp repo whoseorigin = github.com/Tencent/teamai-cli(the failing condition) →✔ Authenticated as jeffyxu, no interactive login triggered, clone + config + hooks all completed.🤖 Generated with Claude Code