GitNexus/gitnexus/test/unit/skip-git-cli.test.ts
Shunsuke Hayashi 09e3609376 fix(analyze): address review — rename --no-git to --skip-git, fix stale cache
Addresses all review items from @magyargergo and Copilot:

1. **Rename --no-git to --skip-git**: Commander.js treats --no-X flags
   as negation of --X (stores as options.git = false, not options.noGit).
   --skip-git maps correctly to options.skipGit.

2. **Fix false " Already up to date\ on non-git folders**: When
 currentCommit is empty string, skip the cache check — we cannot
 detect changes without git, so always rebuild.

3. **Replace isGitRepo() with hasGitDir()**: Use filesystem check
 (statSync on .git) instead of shelling out to git CLI. Consistent,
 faster, and works when git is not installed.

4. **Fix misleading warning**: Message now only fires when .git
 directory is actually absent (not when git CLI fails).

5. **Add CLI integration tests**: Verify Commander maps --skip-git
 correctly and that non-git folders are rejected without the flag.
2026-03-22 17:40:02 +09:00

38 lines
1.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { execSync } from 'child_process';
import path from 'path';
import os from 'os';
import fs from 'fs';
describe('--skip-git CLI flag', () => {
it('Commander maps --skip-git to options.skipGit (not --no-git inversion)', () => {
// Verify the CLI defines --skip-git, not --no-git
const helpOutput = execSync('node dist/cli/index.js analyze --help', {
cwd: path.resolve(__dirname, '../..'),
encoding: 'utf8',
timeout: 10000,
});
expect(helpOutput).toContain('--skip-git');
expect(helpOutput).not.toContain('--no-git');
});
it('rejects non-git folder without --skip-git', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-no-git-'));
fs.writeFileSync(path.join(tmpDir, 'test.ts'), 'export const x = 1;');
try {
execSync(`node dist/cli/index.js analyze "${tmpDir}"`, {
cwd: path.resolve(__dirname, '../..'),
encoding: 'utf8',
timeout: 10000,
});
// Should not reach here
expect.unreachable('Should have exited with non-zero');
} catch (err: any) {
expect(err.stdout || err.stderr || '').toContain('--skip-git');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
});