Files
git-agent-sync/tests/integration/cli.test.ts
7000pctAUTO 30dad27081
Some checks failed
CI / test (push) Has been cancelled
fix: Add missing tests directory and files
2026-02-03 08:11:33 +00:00

49 lines
1.4 KiB
TypeScript

import * as path from 'path';
import * as fs from 'fs-extra';
import * as os from 'os';
import simpleGit from 'simple-git';
import { setupTestRepo, cleanupTestRepo } from './helpers';
describe('Integration Tests', () => {
let testRepo: string;
beforeEach(async () => {
testRepo = await setupTestRepo();
});
afterEach(async () => {
if (testRepo) {
await cleanupTestRepo(testRepo);
}
});
describe('Error Handling', () => {
it('should handle invalid agent names gracefully', async () => {
const { sanitizeAgentName, isValidAgentName } = await import('../../src/utils/file-utils');
expect(isValidAgentName('')).toBe(false);
expect(isValidAgentName('123')).toBe(false);
expect(isValidAgentName('my agent')).toBe(true);
expect(isValidAgentName('my@agent')).toBe(true);
expect(sanitizeAgentName('My Agent')).toBe('my-agent');
});
it('should fail when not in a git repository', async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gas-not-git-'));
try {
const git = simpleGit(tempDir);
let errorThrown = false;
try {
await git.raw('rev-parse', '--is-inside-work-tree');
} catch {
errorThrown = true;
}
expect(errorThrown).toBe(true);
} finally {
fs.removeSync(tempDir);
}
});
});
});