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
+79
View File
@@ -0,0 +1,79 @@
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()
})
})