Skip to content

fix(init): verify cached clone remote before reuse - #329

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
jeff-r2026:fix-init-remote-mismatch
Aug 26, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
jeff-r2026:fix-init-remote-mismatch

Conversation

@jeff-r2026

Copy link
Copy Markdown
Collaborator

Problem

teamai init reused an existing .teamai/team-repo clone whenever the path was a git repo, without checking that its origin matched the requested --repo. A leftover clone from a different team repo was served silently, surfacing the wrong roles/skills manifest.

Concretely: a .teamai/team-repo cloned earlier from repo A, then teamai init --repo <repoB>, would print "Repo already exists, using existing clone" and then list repo A's roles — repo B was never cloned, and if repo B has no roles the user sees a stale role list from an unrelated repo.

Fix

Before reusing an existing clone, compare its origin remote against the requested repo, ignoring differences that don't change the target: embedded credentials, http/https/ssh, scp-vs-URL form, a trailing .git, port, and case.

On mismatch:

  • --force → replace with a fresh clone
  • interactive → prompt to remove & re-clone
  • otherwise → abort and keep the clone (never silently deleted); the message tells the user to remove it manually or pass --force

Embedded credentials are redacted from the warning so tokens in the cached origin URL are never printed.

Changes

  • src/utils/git.ts: new pure helpers normalizeRepoUrlForCompare, remotesMatch, redactGitCredentials
  • src/init.ts: remote check in the clone-reuse branch of init()
  • src/__tests__/git.test.ts: 16 cases covering URL-form normalization, matching, and redaction (incl. the exact bug scenario)

Test Plan

  • npx tsc --noEmit clean
  • npx vitest run — 163 files / 2199 tests pass
  • Real CLI e2e (built dist, local bare repos):
    • remote matches → reuses existing clone
    • mismatch, no --force, non-interactive → aborts, clone preserved
    • mismatch, --force → replaces clone
    • token in cached origin, mismatch → token redacted in warning (leak count 0)
    • token in cached origin, same repo → still matches & reuses

teamai init reused an existing .teamai/team-repo clone whenever the path
was a git repo, without checking that its origin matched the requested
--repo. A leftover clone from a different team repo was served silently,
surfacing the wrong roles/skills manifest.

Compare the existing clone's origin against the requested repo (ignoring
credentials, protocol, scp-vs-URL form, .git suffix, port, and case). On
mismatch: --force replaces it, interactive prompts, otherwise abort and
keep the clone. Embedded credentials are redacted from the warning.
@jeff-r2026
jeff-r2026 requested a review from m0Nst3r873 August 26, 2026 04:01
@jeff-r2026
jeff-r2026 merged commit b7d0022 into Tencent:main Aug 26, 2026
7 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
teamai init reused an existing .teamai/team-repo clone whenever the path
was a git repo, without checking that its origin matched the requested
--repo. A leftover clone from a different team repo was served silently,
surfacing the wrong roles/skills manifest.

Compare the existing clone's origin against the requested repo (ignoring
credentials, protocol, scp-vs-URL form, .git suffix, port, and case). On
mismatch: --force replaces it, interactive prompts, otherwise abort and
keep the clone. Embedded credentials are redacted from the warning.
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