import { describe, it, expect, vi } from 'vitest' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-skillsindex-test-')) vi.mock('electron', () => ({ app: { getPath: () => tempDir }, shell: { openPath: vi.fn(), openExternal: vi.fn() }, clipboard: { readText: vi.fn(), writeText: vi.fn() }, Notification: class { show = vi.fn() }, desktopCapturer: { getSources: vi.fn(async () => []) }, screen: { getPrimaryDisplay: () => ({ size: { width: 0, height: 0 } }) }, BrowserWindow: class { static getAllWindows(): unknown[] { return [] } on = vi.fn() webContents = { on: vi.fn(), send: vi.fn(), isLoading: () => false, once: vi.fn() } loadURL = vi.fn() loadFile = vi.fn() setAlwaysOnTop = vi.fn() maximize = vi.fn() }, ipcMain: { on: vi.fn(), handle: vi.fn() }, session: { defaultSession: { webRequest: { onHeadersReceived: vi.fn() } } } })) // @electron-toolkit/utils fait lui-meme `require('electron')` en interne : hors runtime Electron, // le vrai paquet 'electron' exporte juste une chaine (chemin du binaire), ce qui casse l'interop // ESM/CJS pour tout import nomme ulterieur de 'electron' dans le graphe de modules. On le mocke // directement pour ne jamais toucher le vrai paquet. vi.mock('@electron-toolkit/utils', () => ({ is: { dev: false }, electronApp: { setAppUserModelId: vi.fn() }, optimizer: { watchWindowShortcuts: vi.fn() } })) const { loadSkills, getSkillsForMode, findSkill } = await import('../../src/main/skills') describe('loadSkills()', () => { it('should load a non-empty list of skills without throwing', () => { const skills = loadSkills() expect(skills.length).toBeGreaterThan(20) }) it('should not register the same skill name twice', () => { const names = loadSkills().map((s) => s.name) expect(new Set(names).size).toBe(names.length) }) }) describe('getSkillsForMode()', () => { it('should include a coach-only skill in coach mode but not in basic mode', () => { const coachSkills = getSkillsForMode('coach').map((s) => s.name) const basicSkills = getSkillsForMode('basic').map((s) => s.name) expect(coachSkills).toContain('draw_schema') expect(basicSkills).not.toContain('draw_schema') }) it('should include a transversal skill in every mode', () => { for (const mode of ['basic', 'coach', 'assistant'] as const) { expect(getSkillsForMode(mode).map((s) => s.name)).toContain('search_web') } }) }) describe('findSkill()', () => { it('should find a registered skill by name', () => { expect(findSkill('search_web')?.name).toBe('search_web') }) it('should return undefined for an unknown skill name', () => { expect(findSkill('inexistant')).toBeUndefined() }) })