import { describe, it, expect, vi } from 'vitest' import { readFileSync } from 'fs' import { resolve } from 'path' import { APP_NAME, APP_USER_MODEL_ID, applyAppIdentity } from '../../src/main/app-identity' const DESKTOP_ROOT = resolve(__dirname, '../..') function readBuilderAppId(): string { const yml = readFileSync(resolve(DESKTOP_ROOT, 'electron-builder.yml'), 'utf-8') const match = /^appId:\s*["']?([^"'\s#]+)["']?/m.exec(yml) if (!match) throw new Error('electron-builder.yml에 top-level appId가 없다') return match[1] } describe('app identity (AUMID SSOT)', () => { it('런타임 AUMID가 electron-builder appId(설치본 바로가기 AUMID)와 같다', () => { expect(APP_USER_MODEL_ID).toBe(readBuilderAppId()) }) it('applyAppIdentity는 앱 이름과 SSOT AUMID를 선언한다', () => { const target = { setName: vi.fn(), setAppUserModelId: vi.fn() } applyAppIdentity(target) expect(target.setName).toHaveBeenCalledWith(APP_NAME) expect(target.setAppUserModelId).toHaveBeenCalledWith(readBuilderAppId()) }) it('main 진입점은 AUMID 문자열을 하드코딩하지 않고 applyAppIdentity를 쓴다', () => { const entry = readFileSync(resolve(DESKTOP_ROOT, 'src/main/index.ts'), 'utf-8') expect(entry).toContain('applyAppIdentity(app)') expect(entry).not.toMatch(/setAppUserModelId\(\s*['"`]/) }) })