feat: add CI/CD, code quality, testing and security hardening
CI / quality (push) Failing after 6m22s
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:
co-authored by
Claude Sonnet 5
parent
1959ddb41a
commit
e9690a49f9
@@ -0,0 +1,105 @@
|
||||
import { BrowserWindow, ipcMain, type IpcMainEvent } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import type { ExerciseFormAnswer, ExerciseFormItem } from '../../shared/coach'
|
||||
import { SECURE_WEB_PREFERENCES, blockExternalNavigation } from '../utils/windowSecurity'
|
||||
|
||||
let win: BrowserWindow | null = null
|
||||
|
||||
// Delai avant fermeture automatique de la fenetre une fois le formulaire soumis (demande
|
||||
// utilisateur explicite : la fenetre ne doit pas rester ouverte indefiniment apres soumission).
|
||||
const AUTO_CLOSE_DELAY_MS = 2000
|
||||
|
||||
// Fenetre normale et independante de l'avatar et de la courbe d'apprentissage, meme pattern
|
||||
// singleton que progressWindow.ts.
|
||||
function ensureWindow(): BrowserWindow {
|
||||
if (win && !win.isDestroyed()) return win
|
||||
|
||||
win = new BrowserWindow({
|
||||
width: 520,
|
||||
height: 480,
|
||||
title: 'Max — exercice',
|
||||
alwaysOnTop: true,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
...SECURE_WEB_PREFERENCES
|
||||
}
|
||||
})
|
||||
blockExternalNavigation(win)
|
||||
// Niveau en dessous de l'avatar ('screen-saver') mais au-dessus de tout le reste, y compris une
|
||||
// appli en plein ecran : sans ca, la fenetre pouvait s'ouvrir derriere le premier plan actuel et
|
||||
// l'utilisateur devait la retrouver via la barre des taches (constate en test reel).
|
||||
win.setAlwaysOnTop(true, 'floating')
|
||||
win.maximize()
|
||||
win.on('closed', () => {
|
||||
win = null
|
||||
})
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
void win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}#coach-exercise`)
|
||||
} else {
|
||||
void win.loadFile(join(__dirname, '../renderer/index.html'), { hash: 'coach-exercise' })
|
||||
}
|
||||
return win
|
||||
}
|
||||
|
||||
export interface QuestionInput {
|
||||
question: string
|
||||
type: ExerciseFormItem['type']
|
||||
options: string[] | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Ouvre la fenetre d'exercice, pose TOUTES les questions en une seule fois (formulaire groupe, pas
|
||||
* une par une : demande utilisateur explicite) et attend la soumission de l'utilisateur. Renvoie un
|
||||
* tableau de reponses (meme ordre que `questions`), `null` par entree si la fenetre est fermee sans
|
||||
* soumission ou si le delai est depasse. La fenetre se ferme automatiquement 2 secondes apres
|
||||
* soumission.
|
||||
*/
|
||||
export function requestWrittenAnswers(
|
||||
questions: QuestionInput[],
|
||||
timeoutMs = 30 * 60 * 1000
|
||||
): Promise<(string | null)[]> {
|
||||
return new Promise((resolve) => {
|
||||
const window = ensureWindow()
|
||||
window.show()
|
||||
window.moveTop()
|
||||
window.focus()
|
||||
const requestId = Math.random().toString(36).slice(2)
|
||||
const items: ExerciseFormItem[] = questions.map((q, index) => ({
|
||||
id: String(index),
|
||||
question: q.question,
|
||||
type: q.type,
|
||||
options: q.options
|
||||
}))
|
||||
|
||||
let settled = false
|
||||
const finish = (answers: (string | null)[]): void => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
clearTimeout(timeout)
|
||||
ipcMain.removeListener('written-form-result', handler)
|
||||
resolve(answers)
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => finish(items.map(() => null)), timeoutMs)
|
||||
|
||||
function handler(_event: IpcMainEvent, id: string, answers: ExerciseFormAnswer[]): void {
|
||||
if (id !== requestId) return
|
||||
const byId = new Map(answers.map((a) => [a.id, a.answer]))
|
||||
finish(items.map((item) => byId.get(item.id) ?? null))
|
||||
setTimeout(() => {
|
||||
if (win && !win.isDestroyed()) win.close()
|
||||
}, AUTO_CLOSE_DELAY_MS)
|
||||
}
|
||||
ipcMain.on('written-form-result', handler)
|
||||
window.once('closed', () => finish(items.map(() => null)))
|
||||
|
||||
const send = (): void => window.webContents.send('ask-written-form', { requestId, items })
|
||||
if (window.webContents.isLoading()) {
|
||||
window.webContents.once('did-finish-load', send)
|
||||
} else {
|
||||
send()
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user