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,246 @@
|
||||
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-askexercise-test-'))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => tempDir }
|
||||
}))
|
||||
|
||||
const requestWrittenAnswers = vi.fn(
|
||||
async (items: { question: string }[]): Promise<(string | null)[]> =>
|
||||
items.map(() => 'une reponse')
|
||||
)
|
||||
vi.mock('../../src/main/coach/exerciseWindow', () => ({ requestWrittenAnswers }))
|
||||
|
||||
const {
|
||||
setResearchSummary,
|
||||
createModules,
|
||||
setModuleTheory,
|
||||
setSubjectLevel,
|
||||
upsertConceptStatus,
|
||||
getModuleOrderIndex,
|
||||
unlockNextModule
|
||||
} = await import('../../src/main/coach/coachStore')
|
||||
const { askWrittenExercise } = await import('../../src/main/skills/coach/askWrittenExercise')
|
||||
|
||||
const VALID_CONTENT = [
|
||||
'Accroche',
|
||||
'Un vendeur doit calculer rapidement combien de tissu acheter pour un mur triangulaire. '.repeat(
|
||||
16
|
||||
),
|
||||
'Developpement theorique',
|
||||
'Idee centrale, analogie, definition formelle, exemple resolu et contre-exemple. '.repeat(35),
|
||||
'Phase guidee',
|
||||
'ETAPE 1 : identifier les donnees. ETAPE 2 : appliquer la formule. ETAPE 3 : verifier.',
|
||||
'Exercices progressifs',
|
||||
'EXERCICE 1 facile. EXERCICE 2 facile. EXERCICE 3 moyen. EXERCICE 4 moyen. EXERCICE 5 difficile. EXERCICE 6 difficile.',
|
||||
'Exercice de debogage',
|
||||
"Trouve l'erreur dans ce calcul errone et corrige-la.",
|
||||
'Synthese',
|
||||
'Resume final avec question de meta-cognition et test Feynman. '.repeat(15)
|
||||
].join('\n\n')
|
||||
|
||||
describe('ask_written_exercise — kind="initial"', () => {
|
||||
const subject = 'geographie-initial-test'
|
||||
|
||||
it('should refuse missing questions array', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({ subject, kind: 'initial', questions: [] })
|
||||
).rejects.toThrow(/questions manquantes/)
|
||||
})
|
||||
|
||||
it('should refuse when no course plan exists yet', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [{ question: 'Q ?', type: 'free_text', concept: 'Module A' }]
|
||||
})
|
||||
).rejects.toThrow(/Aucun plan de cours ecrit/)
|
||||
})
|
||||
|
||||
it('should refuse when module content is missing', async () => {
|
||||
setResearchSummary(subject, JSON.stringify({ sources: [] }))
|
||||
createModules(subject, [{ name: 'Module A' }, { name: 'Module B' }])
|
||||
const { setSubjectObjective } = await import('../../src/main/coach/coachStore')
|
||||
setSubjectObjective(subject, 'Tu seras capable de situer un pays sur une carte')
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [
|
||||
{ question: 'Q A ?', type: 'free_text', concept: 'Module A' },
|
||||
{ question: 'Q B ?', type: 'free_text', concept: 'Module B' }
|
||||
]
|
||||
})
|
||||
).rejects.toThrow(/contenu de certains modules/)
|
||||
})
|
||||
|
||||
it('should refuse when question coverage does not exactly match the modules', async () => {
|
||||
setModuleTheory(subject, 'Module A', VALID_CONTENT)
|
||||
setModuleTheory(subject, 'Module B', VALID_CONTENT)
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [{ question: 'Q A ?', type: 'free_text', concept: 'Module A' }]
|
||||
})
|
||||
).rejects.toThrow(/Modules non couverts/)
|
||||
})
|
||||
|
||||
it('should refuse a concept not matching any real module', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [
|
||||
{ question: 'Q ?', type: 'free_text', concept: 'Module A' },
|
||||
{ question: 'Q2 ?', type: 'free_text', concept: 'Module Fantome' }
|
||||
]
|
||||
})
|
||||
).rejects.toThrow(/Concepts invalides/)
|
||||
})
|
||||
|
||||
it('should accept exactly one question per module and save the assessments', async () => {
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [
|
||||
{ question: 'Q A ?', type: 'free_text', concept: 'Module A' },
|
||||
{ question: 'Q B ?', type: 'free_text', concept: 'Module B' }
|
||||
]
|
||||
})
|
||||
expect(result).toMatch(/Formulaire soumis/)
|
||||
})
|
||||
|
||||
it('should refuse a second initial evaluation once the level is already recorded', async () => {
|
||||
setSubjectLevel(subject, 'debutant')
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'initial',
|
||||
questions: [{ question: 'Q ?', type: 'free_text', concept: 'Module A' }]
|
||||
})
|
||||
).rejects.toThrow(/deja enregistre/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ask_written_exercise — kind="final"', () => {
|
||||
const subject = 'final-test'
|
||||
|
||||
it('should refuse when not all modules are acquired yet', async () => {
|
||||
createModules(subject, [{ name: 'Seul module' }])
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'final',
|
||||
questions: [{ question: 'Q finale ?', type: 'free_text', difficulty: 'difficile' }]
|
||||
})
|
||||
).rejects.toThrow(/ne sont pas encore valides/)
|
||||
})
|
||||
|
||||
it('should refuse a final evaluation with no demanding question', async () => {
|
||||
const orderIndex = getModuleOrderIndex(subject, 'Seul module')
|
||||
upsertConceptStatus(subject, 'Seul module', 'acquired')
|
||||
if (orderIndex !== null) unlockNextModule(subject, orderIndex)
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'final',
|
||||
questions: [{ question: 'Q facile ?', type: 'free_text', difficulty: 'facile' }]
|
||||
})
|
||||
).rejects.toThrow(/exigeante/)
|
||||
})
|
||||
|
||||
it('should accept a final evaluation with at least one demanding question', async () => {
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'final',
|
||||
questions: [{ question: 'Q difficile ?', type: 'free_text', difficulty: 'difficile' }]
|
||||
})
|
||||
expect(result).toMatch(/Formulaire soumis/)
|
||||
})
|
||||
|
||||
it('should also accept a demanding exerciseStyle without difficulty="difficile"', async () => {
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject,
|
||||
kind: 'final',
|
||||
questions: [{ question: 'Projet ?', type: 'free_text', exerciseStyle: 'projet' }]
|
||||
})
|
||||
expect(result).toMatch(/Formulaire soumis/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ask_written_exercise — validation generale', () => {
|
||||
it('should refuse an invalid kind', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'invalide',
|
||||
questions: [{ question: 'Q ?', type: 'free_text' }]
|
||||
})
|
||||
).rejects.toThrow(/kind invalide/)
|
||||
})
|
||||
|
||||
it('should refuse a multiple_choice question without enough options', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'multiple_choice', options: ['A'] }]
|
||||
})
|
||||
).rejects.toThrow(/options manquantes/)
|
||||
})
|
||||
|
||||
it('should refuse an invalid difficulty value', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'free_text', difficulty: 'impossible' }]
|
||||
})
|
||||
).rejects.toThrow(/difficulty invalide/)
|
||||
})
|
||||
|
||||
it('should refuse an invalid exerciseStyle value', async () => {
|
||||
await expect(
|
||||
askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'free_text', exerciseStyle: 'inexistant' }]
|
||||
})
|
||||
).rejects.toThrow(/exerciseStyle invalide/)
|
||||
})
|
||||
|
||||
it('should normalize an accented exerciseStyle value', async () => {
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'free_text', exerciseStyle: 'problème_ouvert' }]
|
||||
})
|
||||
expect(result).toMatch(/Formulaire soumis/)
|
||||
})
|
||||
|
||||
it('should record a "dont know" answer distinctly from a real answer', async () => {
|
||||
requestWrittenAnswers.mockResolvedValueOnce(['Je ne sais pas'])
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'free_text' }]
|
||||
})
|
||||
expect(result).toMatch(/lacune enregistree/)
|
||||
})
|
||||
|
||||
it('should report a missing answer when the window closes without one', async () => {
|
||||
requestWrittenAnswers.mockResolvedValueOnce([null])
|
||||
const result = await askWrittenExercise.execute({
|
||||
subject: 'autre-sujet',
|
||||
kind: 'module',
|
||||
questions: [{ question: 'Q ?', type: 'free_text' }]
|
||||
})
|
||||
expect(result).toMatch(/pas de reponse/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user