feat(a2a): Introduce restore command for a2a server (#13015)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
This commit is contained in:
Coco Sheng
2025-12-09 10:08:23 -05:00
committed by GitHub
parent afd4829f10
commit 1f813f6a06
23 changed files with 1173 additions and 148 deletions
@@ -32,6 +32,7 @@ const hoistedMockInit = vi.hoisted(() => vi.fn());
const hoistedMockRaw = vi.hoisted(() => vi.fn());
const hoistedMockAdd = vi.hoisted(() => vi.fn());
const hoistedMockCommit = vi.hoisted(() => vi.fn());
const hoistedMockStatus = vi.hoisted(() => vi.fn());
vi.mock('simple-git', () => ({
simpleGit: hoistedMockSimpleGit.mockImplementation(() => ({
checkIsRepo: hoistedMockCheckIsRepo,
@@ -39,6 +40,7 @@ vi.mock('simple-git', () => ({
raw: hoistedMockRaw,
add: hoistedMockAdd,
commit: hoistedMockCommit,
status: hoistedMockStatus,
env: hoistedMockEnv,
})),
CheckRepoActions: { IS_REPO_ROOT: 'is-repo-root' },
@@ -89,6 +91,7 @@ describe('GitService', () => {
raw: hoistedMockRaw,
add: hoistedMockAdd,
commit: hoistedMockCommit,
status: hoistedMockStatus,
}));
hoistedMockSimpleGit.mockImplementation(() => ({
checkIsRepo: hoistedMockCheckIsRepo,
@@ -96,6 +99,7 @@ describe('GitService', () => {
raw: hoistedMockRaw,
add: hoistedMockAdd,
commit: hoistedMockCommit,
status: hoistedMockStatus,
env: hoistedMockEnv,
}));
hoistedMockCheckIsRepo.mockResolvedValue(false);
@@ -248,6 +252,7 @@ describe('GitService', () => {
describe('createFileSnapshot', () => {
it('should commit with --no-verify flag', async () => {
hoistedMockStatus.mockResolvedValue({ isClean: () => false });
const service = new GitService(projectRoot, storage);
await service.initialize();
await service.createFileSnapshot('test commit');
@@ -255,5 +260,30 @@ describe('GitService', () => {
'--no-verify': null,
});
});
it('should create a new commit if there are staged changes', async () => {
hoistedMockStatus.mockResolvedValue({ isClean: () => false });
hoistedMockCommit.mockResolvedValue({ commit: 'new-commit-hash' });
const service = new GitService(projectRoot, storage);
const commitHash = await service.createFileSnapshot('test message');
expect(hoistedMockAdd).toHaveBeenCalledWith('.');
expect(hoistedMockStatus).toHaveBeenCalled();
expect(hoistedMockCommit).toHaveBeenCalledWith('test message', {
'--no-verify': null,
});
expect(commitHash).toBe('new-commit-hash');
});
it('should return the current HEAD commit hash if there are no staged changes', async () => {
hoistedMockStatus.mockResolvedValue({ isClean: () => true });
hoistedMockRaw.mockResolvedValue('current-head-hash');
const service = new GitService(projectRoot, storage);
const commitHash = await service.createFileSnapshot('test message');
expect(hoistedMockAdd).toHaveBeenCalledWith('.');
expect(hoistedMockStatus).toHaveBeenCalled();
expect(hoistedMockCommit).not.toHaveBeenCalled();
expect(hoistedMockRaw).toHaveBeenCalledWith('rev-parse', 'HEAD');
expect(commitHash).toBe('current-head-hash');
});
});
});