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,130 @@
|
||||
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-skills-test-'))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => tempDir }
|
||||
}))
|
||||
|
||||
vi.mock('../../src/main/coach/exerciseWindow', () => ({
|
||||
requestWrittenAnswers: vi.fn(async (items: { question: string }[]) =>
|
||||
items.map(() => 'une reponse')
|
||||
)
|
||||
}))
|
||||
|
||||
const { setResearchSummary } = await import('../../src/main/coach/coachStore')
|
||||
const { generateCoursePlan } = await import('../../src/main/skills/coach/generateCoursePlan')
|
||||
const { writeModuleContent } = await import('../../src/main/skills/coach/writeModuleContent')
|
||||
const { completeModule } = await import('../../src/main/skills/coach/completeModule')
|
||||
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')
|
||||
|
||||
const SUBJECT = 'trigonometrie-pipeline-test'
|
||||
|
||||
describe('generate_course_plan', () => {
|
||||
it('should refuse when no research exists yet for the subject', async () => {
|
||||
await expect(
|
||||
generateCoursePlan.execute({
|
||||
subject: 'sujet-jamais-recherche',
|
||||
objective: 'Tu seras capable de calculer un sinus dans un triangle rectangle',
|
||||
modules: [{ name: 'Module 1' }]
|
||||
})
|
||||
).rejects.toThrow(/Aucune recherche/)
|
||||
})
|
||||
|
||||
it('should refuse when the objective is missing', async () => {
|
||||
setResearchSummary(SUBJECT, JSON.stringify({ sources: [] }))
|
||||
await expect(
|
||||
generateCoursePlan.execute({ subject: SUBJECT, objective: '', modules: [{ name: 'A' }] })
|
||||
).rejects.toThrow(/objective manquant/)
|
||||
})
|
||||
|
||||
it('should create the course plan once research and objective are present', async () => {
|
||||
const result = await generateCoursePlan.execute({
|
||||
subject: SUBJECT,
|
||||
objective: 'Tu seras capable de calculer un sinus dans un triangle rectangle',
|
||||
modules: [{ name: 'Module A' }, { name: 'Module B' }]
|
||||
})
|
||||
expect(result).toMatch(/Module A/)
|
||||
expect(result).toMatch(/Module B/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('write_module_content', () => {
|
||||
it('should reject content missing required sections', async () => {
|
||||
await expect(
|
||||
writeModuleContent.execute({ subject: SUBJECT, module: 'Module A', content: 'Trop court.' })
|
||||
).rejects.toThrow(/Contenu invalide/)
|
||||
})
|
||||
|
||||
it('should accept well-structured content for the first (unlocked) module', async () => {
|
||||
const result = await writeModuleContent.execute({
|
||||
subject: SUBJECT,
|
||||
module: 'Module A',
|
||||
content: VALID_CONTENT
|
||||
})
|
||||
expect(result).toMatch(/enregistre/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('complete_module', () => {
|
||||
it('should refuse when no assessment exists yet for the module', async () => {
|
||||
await expect(completeModule.execute({ subject: SUBJECT, module: 'Module A' })).rejects.toThrow(
|
||||
/Aucune evaluation/
|
||||
)
|
||||
})
|
||||
|
||||
it('should refuse when only a single difficulty level was used', async () => {
|
||||
await askWrittenExercise.execute({
|
||||
subject: SUBJECT,
|
||||
kind: 'module',
|
||||
questions: [
|
||||
{
|
||||
question: 'Question facile ?',
|
||||
type: 'free_text',
|
||||
concept: 'Module A',
|
||||
difficulty: 'facile'
|
||||
}
|
||||
]
|
||||
})
|
||||
await expect(completeModule.execute({ subject: SUBJECT, module: 'Module A' })).rejects.toThrow(
|
||||
/niveau de difficulte/
|
||||
)
|
||||
})
|
||||
|
||||
it('should validate the module once at least two difficulty levels were used and answers were correct', async () => {
|
||||
await askWrittenExercise.execute({
|
||||
subject: SUBJECT,
|
||||
kind: 'module',
|
||||
questions: [
|
||||
{
|
||||
question: 'Question difficile ?',
|
||||
type: 'free_text',
|
||||
concept: 'Module A',
|
||||
difficulty: 'difficile'
|
||||
}
|
||||
]
|
||||
})
|
||||
const result = await completeModule.execute({ subject: SUBJECT, module: 'Module A' })
|
||||
expect(result).toMatch(/valide/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user