From 2221113329772d4ea8c6b5b8dd199a275aadbf56 Mon Sep 17 00:00:00 2001 From: altair823 Date: Sun, 10 May 2026 22:04:46 +0900 Subject: [PATCH] =?UTF-8?q?fix(v033):=20sync=20configure-sync=20=E2=80=94?= =?UTF-8?q?=20git=20init=20=EC=A0=84=20syncDir=20mkdir(recursive)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit settings:configure-sync IPC 핸들러가 `git -C init` 호출 전에 syncDir 디렉토리를 생성하지 않아, sync 첫 설정 시 git 이 chdir 단계에서 `fatal: cannot change to '/sync': No such file or directory` 로 실패하던 문제. SyncService.runSync() 의 동일 패턴 (mkdir recursive) 을 핸들러에도 추가. 연쇄 증상: SyncSection 의 "연결 테스트" 버튼 disabled 조건이 저장된 url state 기반이라, 저장 실패로 url 영영 비어 있어 버튼 활성화 불가 (닭/달걀). mkdir fix 로 자동 해소. 회귀: sync-ipc.test.ts 에 mkdir 호출 순서 검증 1건 추가 (18 pass). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/main/ipc/settingsApi.ts | 6 ++++++ tests/unit/sync-ipc.test.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/ipc/settingsApi.ts b/src/main/ipc/settingsApi.ts index 1214ef5..063194b 100644 --- a/src/main/ipc/settingsApi.ts +++ b/src/main/ipc/settingsApi.ts @@ -1,6 +1,7 @@ import electron from 'electron'; import type { BrowserWindow } from 'electron'; import { platform, release, EOL } from 'node:os'; +import { mkdir } from 'node:fs/promises'; const { ipcMain, app, dialog, Notification, shell, clipboard } = electron; import { logger } from '../logger.js'; import type { BackupService } from '../services/BackupService.js'; @@ -324,6 +325,11 @@ export function registerSettingsApi(deps?: SettingsIpcDeps): void { // git init + remote add origin const syncDir = deps.syncSvc.getSyncDir(); + try { + await mkdir(syncDir, { recursive: true }); + } catch (e) { + return { ok: false as const, reason: `mkdir failed: ${(e as Error).message}` }; + } const git = new GitClient(syncDir); if (!(await git.isRepo())) { diff --git a/tests/unit/sync-ipc.test.ts b/tests/unit/sync-ipc.test.ts index 866991a..6a0f9a0 100644 --- a/tests/unit/sync-ipc.test.ts +++ b/tests/unit/sync-ipc.test.ts @@ -2,8 +2,10 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; vi.mock('electron', () => ({ default: { ipcMain: { handle: vi.fn() }, dialog: {}, shell: {} } })); vi.mock('../../src/main/services/GitClient.js'); +vi.mock('node:fs/promises', () => ({ mkdir: vi.fn(async () => undefined) })); import electron from 'electron'; +import { mkdir } from 'node:fs/promises'; import { GitClient } from '../../src/main/services/GitClient.js'; import { registerSettingsApi } from '../../src/main/ipc/settingsApi.js'; import type { SettingsIpcDeps } from '../../src/main/ipc/settingsApi.js'; @@ -105,6 +107,25 @@ describe('sync IPC channels', () => { expect(r).toEqual({ ok: true }); }); + // Regression: syncDir 미생성 상태에서 `git -C init` 호출 시 + // git 이 chdir 실패로 죽음 → mkdir(recursive) 가 init 보다 먼저 호출되어야 함. + // (runSync 의 line 135 패턴과 동일.) + it('mkdir(syncDir, recursive) 가 git init 전에 호출됨', async () => { + const { deps, gitInstance } = makeDeps(); + gitInstance.isRepo.mockResolvedValue(false); + const callOrder: string[] = []; + (mkdir as unknown as ReturnType).mockImplementationOnce(async () => { callOrder.push('mkdir'); }); + (gitInstance.run as unknown as ReturnType).mockImplementation(async (args: string[]) => { + callOrder.push(`git:${args[0]}`); + return { stdout: '', stderr: '', exitCode: 0 }; + }); + registerSettingsApi(deps as SettingsIpcDeps); + const h = getHandler('settings:configure-sync'); + await h({}, 'git@github.com:user/repo.git'); + expect(mkdir).toHaveBeenCalledWith('/tmp/sync', { recursive: true }); + expect(callOrder.indexOf('mkdir')).toBeLessThan(callOrder.indexOf('git:init')); + }); + it('valid URL → isRepo=true, hasRemote=true → remote set-url', async () => { const { deps, gitInstance } = makeDeps(); gitInstance.isRepo.mockResolvedValue(true);