chore(cleanup): remove basic-only utility skills

Removes the system-action skills that were only ever available in the now
-retired Basic/Assistant modes (play_music, open/close_app, open_notepad,
create_document, create_powerpoint, control_volume, control_media_playback,
take_screenshot, clipboard, search_file, set_reminder, lock_screen,
empty_recycle_bin, show_notification, print_file, create_folder,
create_file, delete_file, fill_browser_field) along with their
windows/lib helpers (appRegistry, fileSearch, locations, sendVirtualKey)
and the fillField browser-window helper. Keeps the read-only, side-effect
-free transversal skills (search_web, navigate_browser and friends,
check_system_memory/storage/battery/internet). Drops the now-unused
docx/pptxgenjs dependencies and the stale coachStore/meetingStore entries
from the coverage exclude list.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-10-31 19:33:04 +01:00
parent 83043b5819
commit b8aec9ed6b
45 changed files with 7 additions and 1891 deletions
@@ -73,13 +73,11 @@ const {
goBack,
readPageText,
clickElementByText,
fillField,
collectTranslatableElements,
applyTranslations,
highlightText,
dismissCookieBannerInPage,
clickByTextInPage,
fillFieldInPage,
collectInPage,
applyInPage,
highlightInPage
@@ -216,47 +214,6 @@ describe('page interaction functions (require an open window)', () => {
expect(await clickElementByText('Envoyer')).toBe(true)
})
it('fillField() should fill a matching input by its name/placeholder/label', async () => {
document.body.innerHTML = '<input name="email" placeholder="Votre email" />'
const result = await fillField('email', 'test@example.com', false)
expect(result).toBe(true)
expect((document.querySelector('input') as HTMLInputElement).value).toBe('test@example.com')
})
it('fillField() should return false when no matching field is found', async () => {
document.body.innerHTML = '<input name="phone" />'
expect(await fillField('adresse', 'x', false)).toBe(false)
})
it('fillField() should match a field by its associated <label>', async () => {
document.body.innerHTML = '<label for="champ1">Numero de telephone</label><input id="champ1" />'
expect(await fillField('telephone', '0600000000', false)).toBe(true)
})
it('fillField() should fill a textarea too', async () => {
document.body.innerHTML = '<textarea name="message"></textarea>'
expect(await fillField('message', 'Bonjour', false)).toBe(true)
expect((document.querySelector('textarea') as HTMLTextAreaElement).value).toBe('Bonjour')
})
it('fillField() should submit the enclosing form when submit is requested', async () => {
document.body.innerHTML = '<form><input name="q" /></form>'
const form = document.querySelector('form') as HTMLFormElement
const requestSubmit = vi.fn()
form.requestSubmit = requestSubmit
await fillField('q', 'recherche', true)
expect(requestSubmit).toHaveBeenCalled()
})
it('fillField() should dispatch an Enter keydown when submitting a field with no form', async () => {
document.body.innerHTML = '<input name="q" />'
const input = document.querySelector('input')!
const keydown = vi.fn()
input.addEventListener('keydown', keydown)
await fillField('q', 'recherche', true)
expect(keydown).toHaveBeenCalled()
})
it('collectTranslatableElements() should collect visible leaf text nodes', async () => {
document.body.innerHTML = '<p>Un paragraphe</p><div><span>Imbrique</span></div>'
const elements = await collectTranslatableElements()
@@ -344,36 +301,6 @@ describe('clickByTextInPage()', () => {
})
})
describe('fillFieldInPage()', () => {
beforeEach(() => {
document.body.innerHTML = ''
})
it('should return false when there are no input/textarea elements at all', () => {
expect(fillFieldInPage('email', 'x', false)).toBe(false)
})
it('should match by aria-label', () => {
document.body.innerHTML = '<input aria-label="Code postal" />'
expect(fillFieldInPage('code postal', '75000', false)).toBe(true)
})
it('should match by id', () => {
document.body.innerHTML = '<input id="search-box" />'
expect(fillFieldInPage('search', 'chaussures', false)).toBe(true)
})
it('should fall back to form.submit() when requestSubmit is unavailable', () => {
document.body.innerHTML = '<form><input name="q" /></form>'
const form = document.querySelector('form') as HTMLFormElement
;(form as unknown as { requestSubmit: unknown }).requestSubmit = undefined
const submit = vi.fn()
form.submit = submit
fillFieldInPage('q', 'recherche', true)
expect(submit).toHaveBeenCalled()
})
})
describe('collectInPage()', () => {
beforeEach(() => {
document.body.innerHTML = ''
@@ -1,64 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
vi.mock('electron', () => ({ app: { getPath: (name: string) => `C:\\Users\\test\\${name}` } }))
const execFileMock = vi.fn(
(
_cmd: string,
_args: string[],
_opts: unknown,
cb?: (err: Error | null, result: { stdout: string; stderr: string }) => void
) => {
const callback = typeof _opts === 'function' ? (_opts as typeof cb) : cb
callback?.(null, { stdout: '', stderr: '' })
}
)
vi.mock('child_process', () => ({ execFile: execFileMock }))
const { findFileByName } = await import('../../src/main/skills/windows/lib/fileSearch')
function mockStdout(stdout: string): void {
execFileMock.mockImplementation(
(
_cmd: string,
_args: string[],
optsOrCb: unknown,
cb?: (err: Error | null, result: { stdout: string; stderr: string }) => void
) => {
const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb
callback?.(null, { stdout, stderr: '' })
}
)
}
describe('findFileByName()', () => {
beforeEach(() => vi.clearAllMocks())
it('should return null when the name has no significant word', async () => {
expect(await findFileByName(' ')).toBeNull()
expect(execFileMock).not.toHaveBeenCalled()
})
it('should return null when nothing is found', async () => {
mockStdout('')
expect(await findFileByName('fichier introuvable')).toBeNull()
})
it('should return the found path, trimmed', async () => {
mockStdout('C:\\Users\\test\\desktop\\rapport.docx\r\n')
expect(await findFileByName('rapport')).toBe('C:\\Users\\test\\desktop\\rapport.docx')
})
it('should pick the longest word as the primary search term', async () => {
mockStdout('C:\\found.txt')
await findFileByName("le rapport d'activite")
const script = execFileMock.mock.calls[0]?.[1]?.[2] as string
expect(script).toContain("'*activite*'")
})
it('should ignore French stopwords when building significant words', async () => {
mockStdout('')
await findFileByName('le')
expect(execFileMock).not.toHaveBeenCalled()
})
})
@@ -1,29 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
const execFileMock = vi.fn((_cmd: string, _args: string[], cb: (err: Error | null) => void) =>
cb(null)
)
vi.mock('child_process', () => ({ execFile: execFileMock }))
const { pressVirtualKey } = await import('../../src/main/skills/windows/lib/sendVirtualKey')
describe('pressVirtualKey()', () => {
beforeEach(() => vi.clearAllMocks())
it('should invoke the PowerShell script once by default', async () => {
await pressVirtualKey(0xaf)
expect(execFileMock).toHaveBeenCalledTimes(1)
const script = execFileMock.mock.calls[0]?.[1]?.[2] as string
expect(script).toContain('175')
expect(script).toContain('$i -lt 1')
})
it('should bake the requested repeat count into the script', async () => {
await pressVirtualKey(0xae, 5)
const script = execFileMock.mock.calls[0]?.[1]?.[2] as string
expect(script).toContain('$i -lt 5')
})
})
import { describe, it, expect, vi, afterEach } from 'vitest'
describe('systemPaths', () => {
const originalSystemRoot = process.env.SystemRoot
@@ -1,7 +1,6 @@
import { describe, it, expect, vi } from 'vitest'
const clickElementByText = vi.fn(async (text: string) => text !== 'introuvable')
const fillField = vi.fn(async (field: string) => field !== 'introuvable')
const goBack = vi.fn(async () => true)
const highlightText = vi.fn(async (text: string) => text !== 'introuvable')
const navigateTo = vi.fn(async () => 'Titre de la page')
@@ -9,7 +8,6 @@ const readPageText = vi.fn(async () => 'Contenu de la page')
vi.mock('../../src/main/browser/browserWindow', () => ({
clickElementByText,
fillField,
goBack,
highlightText,
navigateTo,
@@ -17,7 +15,6 @@ vi.mock('../../src/main/browser/browserWindow', () => ({
}))
const { clickBrowserElement } = await import('../../src/main/skills/browser/clickBrowserElement')
const { fillBrowserField } = await import('../../src/main/skills/browser/fillBrowserField')
const { goBackBrowser } = await import('../../src/main/skills/browser/goBackBrowser')
const { highlightBrowserText } = await import('../../src/main/skills/browser/highlightBrowserText')
const { navigateBrowser } = await import('../../src/main/skills/browser/navigateBrowser')
@@ -39,28 +36,6 @@ describe('click_browser_element', () => {
})
})
describe('fill_browser_field', () => {
it('should refuse an empty field name', async () => {
await expect(fillBrowserField.execute({ field: '', value: 'x' })).rejects.toThrow(
/field manquant/
)
})
it('should report success and mention submission when requested', async () => {
const result = await fillBrowserField.execute({
field: 'email',
value: 'a@b.com',
submit: true
})
expect(result).toMatch(/rempli et formulaire valide/)
})
it('should report failure when no matching field is found', async () => {
const result = await fillBrowserField.execute({ field: 'introuvable', value: 'x' })
expect(result).toMatch(/Echec/)
})
})
describe('go_back_browser', () => {
it('should report success when going back worked', async () => {
const result = await goBackBrowser.execute({})
@@ -1,33 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
const execFileMock = vi.fn((_cmd: string, _args: string[], cb: (err: Error | null) => void) =>
cb(null)
)
vi.mock('child_process', () => ({ execFile: execFileMock }))
const { closeApp } = await import('../../src/main/skills/windows/closeApp')
describe('close_app', () => {
it('should refuse to close an unrecognized application', async () => {
const result = await closeApp.execute({ application: 'application-inexistante-xyz' })
expect(result).toMatch(/non reconnue/)
})
it('should refuse to close the Windows shell (explorer)', async () => {
const result = await closeApp.execute({ application: 'explorateur de fichiers' })
expect(result).toMatch(/pas autorise/)
})
it('should close a recognized application by killing its process', async () => {
const result = await closeApp.execute({ application: 'bloc-notes' })
expect(result).toMatch(/ferme/)
expect(execFileMock).toHaveBeenCalled()
})
it('should try each override candidate for an app with multiple possible process names', async () => {
execFileMock.mockClear()
const result = await closeApp.execute({ application: 'calculatrice' })
expect(result).toMatch(/ferme/)
expect(execFileMock.mock.calls[0]?.[1]).toContain('CalculatorApp.exe')
})
})
@@ -1,65 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
import { mkdtempSync, existsSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-documents-test-'))
const openPath = vi.fn(async () => '')
vi.mock('electron', () => ({
app: { getPath: () => tempDir },
shell: { openPath }
}))
const { writeWordDocument } = await import('../../src/main/skills/windows/writeWordDocument')
const { createPowerpoint } = await import('../../src/main/skills/windows/createPowerpoint')
describe('create_document', () => {
it('should refuse empty content', async () => {
await expect(writeWordDocument.execute({ title: 'Rapport', content: '' })).rejects.toThrow(
/contenu manquant/
)
})
it('should write both a real .docx and .pdf file by default and open one of them', async () => {
openPath.mockClear()
const result = await writeWordDocument.execute({
title: 'Rapport de test',
content: 'Premiere ligne.\nDeuxieme ligne.'
})
expect(result).toMatch(/cree, enregistre et ouvert/)
expect(existsSync(join(tempDir, 'Rapport de test.docx'))).toBe(true)
expect(existsSync(join(tempDir, 'Rapport de test.pdf'))).toBe(true)
expect(openPath).toHaveBeenCalled()
})
it('should only write the requested format', async () => {
const result = await writeWordDocument.execute({
title: 'Uniquement PDF',
content: 'Contenu',
format: 'pdf'
})
expect(result).toMatch(/\.pdf/)
expect(existsSync(join(tempDir, 'Uniquement PDF.docx'))).toBe(false)
expect(existsSync(join(tempDir, 'Uniquement PDF.pdf'))).toBe(true)
})
})
describe('create_powerpoint', () => {
it('should refuse an empty slide list', async () => {
await expect(createPowerpoint.execute({ title: 'Presentation', slides: [] })).rejects.toThrow(
/diapositives manquantes/
)
})
it('should generate a real .pptx file from the given slides', async () => {
openPath.mockClear()
const result = await createPowerpoint.execute({
title: 'Ma presentation',
slides: [{ title: 'Introduction', content: 'Bienvenue' }, { title: 'Conclusion' }]
})
expect(result).toMatch(/creee, enregistree et ouverte/)
expect(existsSync(join(tempDir, 'Ma presentation.pptx'))).toBe(true)
expect(openPath).toHaveBeenCalled()
})
})
+1 -1
View File
@@ -44,7 +44,7 @@ const { loadSkills, 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)
expect(skills.length).toBeGreaterThan(5)
})
it('should not register the same skill name twice', () => {
@@ -1,25 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
const pressVirtualKey = vi.fn(async () => {})
vi.mock('../../src/main/skills/windows/lib/sendVirtualKey', () => ({ pressVirtualKey }))
const { mediaControl } = await import('../../src/main/skills/windows/mediaControl')
describe('control_media_playback', () => {
it('should send the play/pause media key', async () => {
pressVirtualKey.mockClear()
const result = await mediaControl.execute({ action: 'lecture_pause' })
expect(result).toMatch(/lecture_pause/)
expect(pressVirtualKey).toHaveBeenCalledWith(0xb3, 1)
})
it('should send the next-track media key', async () => {
pressVirtualKey.mockClear()
await mediaControl.execute({ action: 'suivant' })
expect(pressVirtualKey).toHaveBeenCalledWith(0xb0, 1)
})
it('should throw on an invalid action', async () => {
await expect(mediaControl.execute({ action: 'inconnue' })).rejects.toThrow(/action invalide/)
})
})
@@ -1,29 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
const execMock = vi.fn((_cmd: string, cb: (err: Error | null) => void) => cb(null))
vi.mock('child_process', () => ({ exec: execMock }))
const { openApp } = await import('../../src/main/skills/windows/openApp')
describe('open_app', () => {
it('should report an unrecognized application without running any command', async () => {
execMock.mockClear()
const result = await openApp.execute({ application: 'application-inexistante-xyz' })
expect(result).toMatch(/non reconnue/)
expect(execMock).not.toHaveBeenCalled()
})
it('should open a recognized application by its registered executable', async () => {
execMock.mockClear()
const result = await openApp.execute({ application: 'bloc-notes' })
expect(result).toMatch(/ouvert/)
expect(execMock.mock.calls[0]?.[0]).toContain('notepad.exe')
})
it('should be case- and whitespace-insensitive when matching the application name', async () => {
execMock.mockClear()
const result = await openApp.execute({ application: ' CALCULATRICE ' })
expect(result).toMatch(/ouvert/)
expect(execMock.mock.calls[0]?.[0]).toContain('calc.exe')
})
})
@@ -1,31 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
const pressVirtualKey = vi.fn(async () => {})
vi.mock('../../src/main/skills/windows/lib/sendVirtualKey', () => ({ pressVirtualKey }))
const { systemVolume } = await import('../../src/main/skills/windows/systemVolume')
describe('control_volume', () => {
it('should mute with a single key press regardless of steps', async () => {
pressVirtualKey.mockClear()
const result = await systemVolume.execute({ action: 'couper', steps: 10 })
expect(result).toMatch(/coupe/)
expect(pressVirtualKey).toHaveBeenCalledWith(0xad, 1)
})
it('should increase volume using the default 5 steps when none is given', async () => {
pressVirtualKey.mockClear()
await systemVolume.execute({ action: 'augmenter' })
expect(pressVirtualKey).toHaveBeenCalledWith(0xaf, 5)
})
it('should decrease volume using the given number of steps, capped at 25', async () => {
pressVirtualKey.mockClear()
await systemVolume.execute({ action: 'baisser', steps: 999 })
expect(pressVirtualKey).toHaveBeenCalledWith(0xae, 25)
})
it('should throw on an invalid action', async () => {
await expect(systemVolume.execute({ action: 'danser' })).rejects.toThrow(/action invalide/)
})
})
@@ -1,30 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
import { mkdtempSync, existsSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-screenshot-test-'))
const getSources = vi.fn(async () => [{ thumbnail: { toPNG: () => Buffer.from([1, 2, 3]) } }])
vi.mock('electron', () => ({
app: { getPath: () => tempDir },
desktopCapturer: { getSources },
screen: { getPrimaryDisplay: () => ({ size: { width: 1920, height: 1080 } }) }
}))
const { takeScreenshot } = await import('../../src/main/skills/windows/takeScreenshot')
describe('take_screenshot', () => {
it('should capture the primary screen and save it as a real PNG file', async () => {
const result = await takeScreenshot.execute({})
expect(result).toMatch(/Capture d'ecran enregistree/)
expect(result).toMatch(/\.png/)
const match = /: (.+\.png)\./.exec(result)
expect(match?.[1] ? existsSync(match[1]) : false).toBe(true)
})
it('should throw when no screen source is detected', async () => {
getSources.mockResolvedValueOnce([])
await expect(takeScreenshot.execute({})).rejects.toThrow(/Aucun ecran detecte/)
})
})
@@ -1,140 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
const openPath = vi.fn(async () => '')
vi.mock('electron', () => ({
shell: { openPath },
app: { getPath: (name: string) => `C:\\Users\\test\\${name}` }
}))
const writeFileSyncMock = vi.fn()
const existsSyncMock = vi.fn(() => false)
const mkdirSyncMock = vi.fn()
const statSyncMock = vi.fn(() => ({ isDirectory: () => false }))
vi.mock('fs', () => ({
writeFileSync: writeFileSyncMock,
existsSync: existsSyncMock,
mkdirSync: mkdirSyncMock,
statSync: statSyncMock
}))
const execFileMock = vi.fn((_cmd: string, _args: string[], cb: (err: Error | null) => void) =>
cb(null)
)
vi.mock('child_process', () => ({ execFile: execFileMock }))
const findFileByName = vi.fn(async (name: string) =>
name.includes('introuvable') ? null : `C:\\Users\\test\\desktop\\${name}.txt`
)
vi.mock('../../src/main/skills/windows/lib/fileSearch', () => ({ findFileByName }))
const { createFile } = await import('../../src/main/skills/windows/createFile')
const { createFolder } = await import('../../src/main/skills/windows/createFolder')
const { deleteFileOrFolder } = await import('../../src/main/skills/windows/deleteFileOrFolder')
const { printFile } = await import('../../src/main/skills/windows/printFile')
const { searchFile } = await import('../../src/main/skills/windows/searchFile')
beforeEach(() => {
vi.clearAllMocks()
existsSyncMock.mockReturnValue(false)
statSyncMock.mockReturnValue({ isDirectory: () => false })
findFileByName.mockImplementation(async (name: string) =>
name.includes('introuvable') ? null : `C:\\Users\\test\\desktop\\${name}.txt`
)
})
describe('create_file', () => {
it('should refuse an empty name', async () => {
await expect(createFile.execute({ name: ' ' })).rejects.toThrow(/nom manquant/)
})
it('should sanitize illegal characters, write the file and open it', async () => {
const result = await createFile.execute({ name: 'note<test>', content: 'hello' })
expect(result).toMatch(/Fichier cree et ouvert/)
expect(writeFileSyncMock).toHaveBeenCalled()
expect(openPath).toHaveBeenCalled()
expect(String(writeFileSyncMock.mock.calls[0]?.[0])).not.toMatch(/[<>]/)
})
it('should append .txt when the name has no extension', async () => {
await createFile.execute({ name: 'sansextension' })
expect(String(writeFileSyncMock.mock.calls[0]?.[0])).toMatch(/sansextension\.txt$/)
})
})
describe('create_folder', () => {
it('should refuse an empty name', async () => {
await expect(createFolder.execute({ name: '' })).rejects.toThrow(/nom manquant/)
})
it('should report when the folder already exists without creating it again', async () => {
existsSyncMock.mockReturnValue(true)
const result = await createFolder.execute({ name: 'existant' })
expect(result).toMatch(/existe deja/)
expect(mkdirSyncMock).not.toHaveBeenCalled()
})
it('should create and open a new folder', async () => {
const result = await createFolder.execute({ name: 'nouveau' })
expect(result).toMatch(/Dossier cree et ouvert/)
expect(mkdirSyncMock).toHaveBeenCalled()
expect(openPath).toHaveBeenCalled()
})
})
describe('delete_file', () => {
it('should refuse an empty name', async () => {
await expect(deleteFileOrFolder.execute({ name: '' })).rejects.toThrow(/nom manquant/)
})
it('should report when nothing is found', async () => {
const result = await deleteFileOrFolder.execute({ name: 'introuvable' })
expect(result).toMatch(/Aucun fichier ou dossier/)
})
it('should refuse to delete a protected location (drive root)', async () => {
findFileByName.mockResolvedValue('C:\\')
const result = await deleteFileOrFolder.execute({ name: 'quelquechose' })
expect(result).toMatch(/protege/)
expect(execFileMock).not.toHaveBeenCalled()
})
it('should send a found file to the recycle bin', async () => {
const result = await deleteFileOrFolder.execute({ name: 'document' })
expect(result).toMatch(/corbeille/)
expect(execFileMock).toHaveBeenCalled()
})
})
describe('print_file', () => {
it('should refuse an empty name', async () => {
await expect(printFile.execute({ name: '' })).rejects.toThrow(/nom manquant/)
})
it('should report when no file is found', async () => {
const result = await printFile.execute({ name: 'introuvable' })
expect(result).toMatch(/Aucun fichier/)
})
it('should launch printing for a found file', async () => {
const result = await printFile.execute({ name: 'rapport' })
expect(result).toMatch(/Impression lancee/)
expect(execFileMock).toHaveBeenCalled()
})
})
describe('search_file', () => {
it('should refuse an empty name', async () => {
await expect(searchFile.execute({ name: '' })).rejects.toThrow(/nom manquant/)
})
it('should report when nothing is found', async () => {
const result = await searchFile.execute({ name: 'introuvable' })
expect(result).toMatch(/Aucun fichier ou dossier/)
})
it('should find and open a matching file', async () => {
const result = await searchFile.execute({ name: 'photo' })
expect(result).toMatch(/Trouve et ouvert/)
expect(openPath).toHaveBeenCalled()
})
})
@@ -1,129 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { EventEmitter } from 'node:events'
const readText = vi.fn(async () => '')
const writeText = vi.fn(async () => {})
const openExternal = vi.fn(async () => {})
const NotificationShow = vi.fn()
class NotificationMock {
show = NotificationShow
}
vi.mock('electron', () => ({
clipboard: { readText, writeText },
shell: { openExternal },
Notification: NotificationMock
}))
const writeFileSyncMock = vi.fn()
const mkdtempSyncMock = vi.fn(() => 'C:\\temp\\forge-avatar-xyz')
vi.mock('fs', () => ({ writeFileSync: writeFileSyncMock, mkdtempSync: mkdtempSyncMock }))
const execFileMock = vi.fn(() => new EventEmitter())
vi.mock('child_process', () => ({ execFile: execFileMock }))
const synthesizeSpeech = vi.fn(async () => new Uint8Array([1, 2, 3]).buffer as unknown as Buffer)
vi.mock('../../src/main/ai/elevenlabs', () => ({ synthesizeSpeech }))
const sendToRenderer = vi.fn()
vi.mock('../../src/main/windowBridge', () => ({ sendToRenderer }))
const { clipboardSkill } = await import('../../src/main/skills/windows/clipboard')
const { showNotification } = await import('../../src/main/skills/windows/showNotification')
const { playMusic } = await import('../../src/main/skills/windows/playMusic')
const { reminder } = await import('../../src/main/skills/windows/reminder')
const { openNotepad } = await import('../../src/main/skills/windows/openNotepad')
beforeEach(() => {
vi.clearAllMocks()
})
describe('clipboard', () => {
it('should refuse an invalid action', async () => {
await expect(clipboardSkill.execute({ action: 'danser' })).rejects.toThrow(/action invalide/)
})
it('should report an empty clipboard', async () => {
readText.mockResolvedValue('')
const result = await clipboardSkill.execute({ action: 'lire' })
expect(result).toMatch(/vide/)
})
it('should read non-empty clipboard content', async () => {
readText.mockResolvedValue('Bonjour')
const result = await clipboardSkill.execute({ action: 'lire' })
expect(result).toMatch(/Bonjour/)
})
it('should refuse to copy an empty text', async () => {
await expect(clipboardSkill.execute({ action: 'copier', text: '' })).rejects.toThrow(
/texte manquant/
)
})
it('should copy a given text to the clipboard', async () => {
const result = await clipboardSkill.execute({ action: 'copier', text: 'Salut' })
expect(result).toMatch(/copie/)
expect(writeText).toHaveBeenCalledWith('Salut')
})
})
describe('show_notification', () => {
it('should refuse an empty message', async () => {
await expect(showNotification.execute({ message: '' })).rejects.toThrow(/message manquant/)
})
it('should show a notification with the given title and message', async () => {
const result = await showNotification.execute({ title: 'Alerte', message: 'Ca a marche' })
expect(result).toMatch(/affichee/)
expect(NotificationShow).toHaveBeenCalled()
})
})
describe('play_music', () => {
it('should refuse an empty query', async () => {
await expect(playMusic.execute({ query: '' })).rejects.toThrow(/requete manquante/)
})
it('should open Spotify with the encoded search query', async () => {
const result = await playMusic.execute({ query: 'Daft Punk' })
expect(result).toMatch(/Spotify ouvert/)
expect(openExternal).toHaveBeenCalledWith('spotify:search:Daft%20Punk')
})
it('should fall back to the web player when the Spotify URI fails', async () => {
openExternal.mockRejectedValueOnce(new Error('no spotify'))
const result = await playMusic.execute({ query: 'Daft Punk' })
expect(result).toMatch(/web ouvert/)
})
})
describe('set_reminder', () => {
it('should refuse an invalid delay', async () => {
await expect(reminder.execute({ minutes: 0, message: 'test' })).rejects.toThrow(
/minutes invalide/
)
})
it('should refuse an empty message', async () => {
await expect(reminder.execute({ minutes: 5, message: '' })).rejects.toThrow(/message manquant/)
})
it('should confirm the reminder is scheduled', async () => {
const result = await reminder.execute({ minutes: 10, message: 'Pause cafe' })
expect(result).toMatch(/Rappel programme dans 10 minute/)
expect(result).toMatch(/Pause cafe/)
})
})
describe('open_notepad', () => {
it('should open an empty notepad when no text is given', async () => {
const result = await openNotepad.execute({})
expect(result).toBe('Bloc-notes ouvert.')
expect(writeFileSyncMock).not.toHaveBeenCalled()
})
it('should pre-fill a temp file and open it when text is given', async () => {
const result = await openNotepad.execute({ text: 'Mon brouillon' })
expect(result).toMatch(/texte demande/)
expect(writeFileSyncMock).toHaveBeenCalledWith(expect.any(String), 'Mon brouillon', 'utf-8')
})
})
@@ -16,8 +16,6 @@ vi.mock('child_process', () => ({ execFile: execFileMock }))
const { systemStatus } = await import('../../src/main/skills/windows/systemStatus')
const { systemStorage } = await import('../../src/main/skills/windows/systemStorage')
const { checkInternet } = await import('../../src/main/skills/windows/checkInternet')
const { lockScreen } = await import('../../src/main/skills/windows/lockScreen')
const { emptyRecycleBin } = await import('../../src/main/skills/windows/emptyRecycleBin')
function mockStdout(json: unknown): void {
execFileMock.mockImplementation(
@@ -85,34 +83,3 @@ describe('check_internet_connection', () => {
expect(result).toMatch(/Pas de connexion internet/)
})
})
describe('lock_screen', () => {
it('should invoke the lock command and confirm immediately', async () => {
const result = await lockScreen.execute({})
expect(result).toBe('Ecran verrouille.')
})
})
describe('empty_recycle_bin', () => {
it('should confirm the recycle bin was emptied', async () => {
mockStdout({})
const result = await emptyRecycleBin.execute({})
expect(result).toBe('Corbeille videe.')
})
it('should still confirm even if the underlying command fails (bin already empty)', async () => {
execFileMock.mockImplementation(
(
_cmd: string,
_args: string[],
optsOrCb: unknown,
cb?: (err: Error | null, result: unknown) => void
) => {
const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb
callback?.(new Error('already empty'), null)
}
)
const result = await emptyRecycleBin.execute({})
expect(result).toBe('Corbeille videe.')
})
})