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,182 @@
|
||||
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-misc-test-'))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => tempDir }
|
||||
}))
|
||||
|
||||
const openCoachProgressWindow = vi.fn()
|
||||
vi.mock('../../src/main/coach/progressWindow', () => ({ openCoachProgressWindow }))
|
||||
|
||||
const {
|
||||
setResearchSummary,
|
||||
createModules,
|
||||
setModuleTheory,
|
||||
saveAssessment,
|
||||
unlockNextModule,
|
||||
upsertConceptStatus,
|
||||
getModuleOrderIndex
|
||||
} = await import('../../src/main/coach/coachStore')
|
||||
const { recordSubjectLevel } = await import('../../src/main/skills/coach/recordSubjectLevel')
|
||||
const { trackConceptMastery } = await import('../../src/main/skills/coach/trackConceptMastery')
|
||||
const { completeSubject } = await import('../../src/main/skills/coach/completeSubject')
|
||||
const { openModuleForUser } = await import('../../src/main/skills/coach/openModuleForUser')
|
||||
const { getCoursePlan } = await import('../../src/main/skills/coach/getCoursePlan')
|
||||
|
||||
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('record_subject_level', () => {
|
||||
const subject = 'chimie-test'
|
||||
|
||||
it('should refuse when no assessment exists yet for the subject', async () => {
|
||||
await expect(recordSubjectLevel.execute({ subject, level: 'debutant' })).rejects.toThrow(
|
||||
/Aucune evaluation/
|
||||
)
|
||||
})
|
||||
|
||||
it('should record the level once an assessment exists', async () => {
|
||||
saveAssessment(subject, null, 'Q ?', 'free_text', null, 'R', 'initial', false, null, null, null)
|
||||
const result = await recordSubjectLevel.execute({ subject, level: 'debutant' })
|
||||
expect(result).toMatch(/debutant/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('track_concept_mastery', () => {
|
||||
const subject = 'physique-test'
|
||||
const concept = 'Loi d-ohm'
|
||||
|
||||
it('should allow a progress-only status without any assessment', async () => {
|
||||
const result = await trackConceptMastery.execute({ subject, concept, status: 'in_progress' })
|
||||
expect(result).toMatch(/in_progress/)
|
||||
})
|
||||
|
||||
it('should refuse an evaluative status ("acquired") without a prior assessment', async () => {
|
||||
await expect(
|
||||
trackConceptMastery.execute({ subject, concept, status: 'acquired' })
|
||||
).rejects.toThrow(/Aucune evaluation/)
|
||||
})
|
||||
|
||||
it('should accept an evaluative status once an assessment exists for that concept', async () => {
|
||||
saveAssessment(
|
||||
subject,
|
||||
concept,
|
||||
'Q ?',
|
||||
'free_text',
|
||||
null,
|
||||
'R',
|
||||
'module',
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
const result = await trackConceptMastery.execute({ subject, concept, status: 'acquired' })
|
||||
expect(result).toMatch(/acquired/)
|
||||
})
|
||||
|
||||
it('should reject an invalid status value', async () => {
|
||||
await expect(
|
||||
trackConceptMastery.execute({ subject, concept, status: 'invalide' })
|
||||
).rejects.toThrow(/status invalide/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('open_module_for_user', () => {
|
||||
const subject = 'histoire-test'
|
||||
|
||||
it('should throw when the module does not exist', async () => {
|
||||
await expect(openModuleForUser.execute({ subject, module: 'Module fantome' })).rejects.toThrow(
|
||||
/introuvable/
|
||||
)
|
||||
})
|
||||
|
||||
it('should refuse to open a locked module', async () => {
|
||||
createModules(subject, [{ name: 'Module 1' }, { name: 'Module 2' }])
|
||||
await expect(openModuleForUser.execute({ subject, module: 'Module 2' })).rejects.toThrow(
|
||||
/verrouille/
|
||||
)
|
||||
})
|
||||
|
||||
it('should refuse to open a module whose content was never written', async () => {
|
||||
await expect(openModuleForUser.execute({ subject, module: 'Module 1' })).rejects.toThrow(
|
||||
/pas encore ecrit/
|
||||
)
|
||||
})
|
||||
|
||||
it('should open an unlocked module with written content', async () => {
|
||||
setModuleTheory(subject, 'Module 1', VALID_CONTENT)
|
||||
openCoachProgressWindow.mockClear()
|
||||
const result = await openModuleForUser.execute({ subject, module: 'Module 1' })
|
||||
expect(result).toMatch(/ouvert/)
|
||||
expect(openCoachProgressWindow).toHaveBeenCalledWith({ subject, module: 'Module 1' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('complete_subject', () => {
|
||||
const subject = 'biologie-test'
|
||||
|
||||
it('should refuse when modules are not all acquired yet', async () => {
|
||||
createModules(subject, [{ name: 'Seul module' }])
|
||||
await expect(completeSubject.execute({ subject })).rejects.toThrow(/pas encore valides/)
|
||||
})
|
||||
|
||||
it('should refuse when all modules are acquired but no final assessment exists', async () => {
|
||||
const orderIndex = getModuleOrderIndex(subject, 'Seul module')
|
||||
upsertConceptStatus(subject, 'Seul module', 'acquired')
|
||||
if (orderIndex !== null) unlockNextModule(subject, orderIndex)
|
||||
await expect(completeSubject.execute({ subject })).rejects.toThrow(/evaluation finale/)
|
||||
})
|
||||
|
||||
it('should mark the subject as mastered once modules are acquired and a final assessment exists', async () => {
|
||||
saveAssessment(
|
||||
subject,
|
||||
null,
|
||||
'Q finale ?',
|
||||
'free_text',
|
||||
null,
|
||||
'R',
|
||||
'final',
|
||||
false,
|
||||
'difficile',
|
||||
null,
|
||||
null
|
||||
)
|
||||
const result = await completeSubject.execute({ subject })
|
||||
expect(result).toMatch(/maitrise/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('get_course_plan', () => {
|
||||
it('should report no existing plan for a brand new subject', async () => {
|
||||
const result = await getCoursePlan.execute({ subject: 'sujet-jamais-vu-xyz' })
|
||||
expect(result).toMatch(/Aucun plan de cours/)
|
||||
})
|
||||
|
||||
it('should summarize research/module state for a subject already in progress', async () => {
|
||||
const subject = 'plan-existant-test'
|
||||
setResearchSummary(subject, JSON.stringify({ sources: [] }))
|
||||
createModules(subject, [{ name: 'Module unique' }])
|
||||
const result = await getCoursePlan.execute({ subject })
|
||||
expect(result).toMatch(/Recherche deja effectuee/)
|
||||
expect(result).toMatch(/Module unique/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user