feat: add CI/CD, code quality, testing and security hardening
CI / quality (push) Failing after 6m22s

Implements Max_Code_Quality_CICD_Production.md: TypeScript strict mode,
ESLint flat config with type-checking and security plugin, Prettier,
Husky + lint-staged, Vitest with 80%+ coverage (473 tests), Playwright
e2e, Electron security hardening (contextIsolation, CSP, IPC validation),
electron-builder + electron-updater, Dockerfile, Gitea Actions CI/release
workflows, and SonarQube docker-compose setup. Also fixes two real bugs
found while writing tests: unawaited clipboard promises and a mermaid
container ref timing issue in CoachDrawingView.

Fixes lint-staged on Windows/Node 24 by invoking eslint/prettier via
`node <bin>.js` instead of their .cmd shims, which Node's child_process
now refuses to spawn without shell:true.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-10-29 09:05:21 +01:00
co-authored by Claude Sonnet 5
parent 1959ddb41a
commit e9690a49f9
230 changed files with 22781 additions and 448 deletions
+129
View File
@@ -0,0 +1,129 @@
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')
})
})