|
| 1 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
| 2 | +import { execFileSync } from 'node:child_process'; |
| 3 | +import fs from 'node:fs'; |
| 4 | +import os from 'node:os'; |
| 5 | +import path from 'node:path'; |
| 6 | +import { fileURLToPath } from 'node:url'; |
| 7 | +import YAML from 'yaml'; |
| 8 | + |
| 9 | +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..'); |
| 10 | +const CLI = path.join(ROOT, 'dist/index.js'); |
| 11 | +const REPO_URL = 'https://dev.azure.com/teamai-repro/My%20Project/_git/teamai-oe'; |
| 12 | + |
| 13 | +describe('generic Git clone paths without a .git suffix (#1169)', () => { |
| 14 | + let sandbox: string; |
| 15 | + let home: string; |
| 16 | + let workspace: string; |
| 17 | + let seed: string; |
| 18 | + let remote: string; |
| 19 | + let env: NodeJS.ProcessEnv; |
| 20 | + |
| 21 | + function git(args: string[], cwd = sandbox): string { |
| 22 | + return execFileSync('git', args, { cwd, env, encoding: 'utf8', timeout: 30_000 }).trim(); |
| 23 | + } |
| 24 | + |
| 25 | + function cli(args: string[]): string { |
| 26 | + return execFileSync(process.execPath, [CLI, ...args], { |
| 27 | + cwd: workspace, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], |
| 28 | + timeout: 30_000, windowsHide: true, |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + beforeEach(() => { |
| 33 | + sandbox = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'teamai-git-suffixless-'))); |
| 34 | + home = path.join(sandbox, 'home'); |
| 35 | + workspace = path.join(sandbox, 'workspace'); |
| 36 | + seed = path.join(sandbox, 'seed'); |
| 37 | + remote = path.join(sandbox, 'remotes', 'teamai-oe'); |
| 38 | + for (const dir of [home, workspace, path.dirname(remote), path.join(seed, 'manifest')]) { |
| 39 | + fs.mkdirSync(dir, { recursive: true }); |
| 40 | + } |
| 41 | + env = { |
| 42 | + ...process.env, |
| 43 | + HOME: home, |
| 44 | + USERPROFILE: home, |
| 45 | + GIT_CONFIG_GLOBAL: path.join(home, '.gitconfig'), |
| 46 | + GIT_CONFIG_NOSYSTEM: '1', |
| 47 | + GIT_AUTHOR_NAME: 'TeamAI CI', |
| 48 | + GIT_AUTHOR_EMAIL: 'ci@teamai.test', |
| 49 | + GIT_COMMITTER_NAME: 'TeamAI CI', |
| 50 | + GIT_COMMITTER_EMAIL: 'ci@teamai.test', |
| 51 | + GIT_TERMINAL_PROMPT: '0', |
| 52 | + TEAMAI_NONINTERACTIVE: '1', |
| 53 | + FORCE_COLOR: '0', |
| 54 | + }; |
| 55 | + fs.writeFileSync(path.join(seed, 'teamai.yaml'), YAML.stringify({ |
| 56 | + team: 'suffixless-e2e', repo: REPO_URL, provider: 'git', reviewers: [], |
| 57 | + })); |
| 58 | + fs.writeFileSync(path.join(seed, 'manifest', 'roles.yaml'), YAML.stringify({ |
| 59 | + version: 1, |
| 60 | + roles: [{ id: 'dev', resources: { knowledge: [], skills: ['common'] } }], |
| 61 | + })); |
| 62 | + const skill = path.join(seed, 'skills', 'common', 'suffixless-demo'); |
| 63 | + fs.mkdirSync(skill, { recursive: true }); |
| 64 | + fs.writeFileSync(path.join(skill, 'SKILL.md'), |
| 65 | + '---\nname: suffixless-demo\ndescription: Suffixless Git fixture\n---\n\n# Original\n'); |
| 66 | + git(['init', '-q', '-b', 'main'], seed); |
| 67 | + git(['add', '-A'], seed); |
| 68 | + git(['commit', '-q', '-m', 'seed'], seed); |
| 69 | + git(['clone', '-q', '--bare', seed, remote]); |
| 70 | + // Rewrite only the prefix: an added .git must point at a missing repository. |
| 71 | + git(['config', '--global', `url.${path.dirname(remote).replace(/\\/g, '/')}/.insteadOf`, |
| 72 | + 'https://dev.azure.com/teamai-repro/My%20Project/_git/']); |
| 73 | + }); |
| 74 | + |
| 75 | + afterEach(() => { |
| 76 | + if (sandbox) fs.rmSync(sandbox, { recursive: true, force: true }); |
| 77 | + }); |
| 78 | + |
| 79 | + it('initializes, preserves the saved remote, and pulls a later skill update', () => { |
| 80 | + // Establish that the original URL is cloneable before exercising TeamAI. |
| 81 | + git(['clone', '-q', REPO_URL, path.join(sandbox, 'direct-clone')]); |
| 82 | + cli(['init', REPO_URL, '--provider', 'git', '--scope', 'workspace', |
| 83 | + '--role', 'dev', '--agent', 'claude', '--force']); |
| 84 | + const config = YAML.parse(fs.readFileSync(path.join(workspace, '.teamai', 'config.yaml'), 'utf8')) as { |
| 85 | + repo: { remote: string; localPath: string }; |
| 86 | + }; |
| 87 | + expect(config.repo.remote).toBe(REPO_URL); |
| 88 | + expect(git(['config', '--get', 'remote.origin.url'], config.repo.localPath)).toBe(REPO_URL); |
| 89 | + cli(['pull']); |
| 90 | + const delivered = path.join(workspace, '.claude', 'skills', 'suffixless-demo', 'SKILL.md'); |
| 91 | + expect(fs.readFileSync(delivered, 'utf8')).toContain('# Original'); |
| 92 | + |
| 93 | + const skill = path.join(seed, 'skills', 'common', 'suffixless-demo', 'SKILL.md'); |
| 94 | + fs.appendFileSync(skill, '\nUpdated through the suffixless remote.\n'); |
| 95 | + git(['add', '-A'], seed); |
| 96 | + git(['commit', '-q', '-m', 'update skill'], seed); |
| 97 | + git(['push', '-q', remote, 'HEAD:main'], seed); |
| 98 | + cli(['pull']); |
| 99 | + expect(fs.readFileSync(delivered, 'utf8')).toContain('Updated through the suffixless remote.'); |
| 100 | + }); |
| 101 | +}); |
0 commit comments