Skip to content

fix(tgit): run gf auth commands from a neutral cwd - #312

Merged
jeff-r2026 merged 1 commit into
mainfrom
fix/gf-auth-cwd-independent
Aug 24, 2026
Merged

fix(tgit): run gf auth commands from a neutral cwd#312
jeff-r2026 merged 1 commit into
mainfrom
fix/gf-auth-cwd-independent

Conversation

@jeff-r2026

Copy link
Copy Markdown
Collaborator

Problem

teamai init fails with gf auth login failed when run inside a git repository whose origin remote is not git.woa.com (e.g. a GitHub mirror — including this very repo).

Root cause: 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 from a repo whose origin is github.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:

cwd gf auth whoami
a repo with origin = git.woa.com/... ✅ 当前登录用户
a repo with origin = github.com/... ❌ 还未登录
a non-git dir (/tmp) ✅ 当前登录用户

Fix

Run the three gf auth calls (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 — success
  • npx vitest run src/__tests__/gf-cli.test.ts — 13 passed (added 3 tests asserting each auth call spawns with cwd = os.tmpdir())
  • npx tsc --noEmit on changed files — no errors
  • End-to-end: ran the built CLI's teamai init from a temp repo whose origin = github.com/Tencent/teamai-cli (the failing condition) → ✔ Authenticated as jeffyxu, no interactive login triggered, clone + config + hooks all completed.

Note: 9 pre-existing failures in iwiki-dual / iwiki-review-apply / import-repo-incremental are unrelated (local vitest version drift) and reproduce on a pristine main checkout without this change.

🤖 Generated with Claude Code

`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>
@jeff-r2026
jeff-r2026 merged commit 7368979 into main Aug 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant