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>
195 lines
6.5 KiB
TypeScript
195 lines
6.5 KiB
TypeScript
import { describe, it, expect, vi, beforeAll } from 'vitest'
|
|
import { mkdtempSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
|
|
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-coach-test-'))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: { getPath: () => tempDir }
|
|
}))
|
|
|
|
// Importe apres le mock : getDb() lit app.getPath('userData') au premier appel et cree le fichier
|
|
// sqlite dans un dossier temporaire dedie a ce fichier de test (jamais la vraie base utilisateur).
|
|
const {
|
|
setSubjectObjective,
|
|
getSubjectObjective,
|
|
setSubjectLevel,
|
|
getSubjectLevel,
|
|
createModules,
|
|
listModules,
|
|
allModulesHaveContent,
|
|
modulesMissingContent,
|
|
setModuleTheory,
|
|
canWriteModuleContent,
|
|
saveAssessment,
|
|
hasAssessment,
|
|
hasMultipleDifficulties,
|
|
moduleDontKnowRatio,
|
|
upsertConceptStatus,
|
|
getProgress,
|
|
getCourseComplianceReport,
|
|
getResearchSummary
|
|
} = await import('../../src/main/coach/coachStore')
|
|
|
|
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('coachStore — objective', () => {
|
|
it('should return null for a subject objective that was never set', () => {
|
|
expect(getSubjectObjective('sujet-sans-objectif')).toBeNull()
|
|
})
|
|
|
|
it('should return null when the subject exists but its objective/research were never set', () => {
|
|
createModules('sujet-existant-sans-objectif', [{ name: 'Module unique' }])
|
|
expect(getSubjectObjective('sujet-existant-sans-objectif')).toBeNull()
|
|
expect(getResearchSummary('sujet-existant-sans-objectif')).toBeNull()
|
|
})
|
|
|
|
it('should persist and retrieve a subject objective', () => {
|
|
setSubjectObjective(
|
|
'algebre-test',
|
|
'Tu seras capable de resoudre une equation du premier degre'
|
|
)
|
|
expect(getSubjectObjective('algebre-test')).toBe(
|
|
'Tu seras capable de resoudre une equation du premier degre'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('coachStore — modules et verrouillage sequentiel', () => {
|
|
const subject = 'fractions-test'
|
|
|
|
it('should create modules with only the first one unlocked', () => {
|
|
createModules(subject, [{ name: 'Module A' }, { name: 'Module B' }])
|
|
const modules = listModules(subject)
|
|
expect(modules.map((m) => m.name)).toEqual(['Module A', 'Module B'])
|
|
expect(modules[0]?.locked).toBe(false)
|
|
expect(modules[1]?.locked).toBe(true)
|
|
})
|
|
|
|
it('should report missing content for every module before any is written', () => {
|
|
expect(allModulesHaveContent(subject)).toBe(false)
|
|
expect(modulesMissingContent(subject)).toEqual(['Module A', 'Module B'])
|
|
})
|
|
|
|
it('should allow writing module content before a subject level is recorded', () => {
|
|
expect(canWriteModuleContent(subject, 'Module A')).toEqual({ ok: true, blockedBy: null })
|
|
expect(canWriteModuleContent(subject, 'Module B')).toEqual({ ok: true, blockedBy: null })
|
|
})
|
|
|
|
it('should accept well-structured content and reflect it as no-longer-missing', () => {
|
|
expect(setModuleTheory(subject, 'Module A', VALID_CONTENT)).toBe(true)
|
|
expect(modulesMissingContent(subject)).toEqual(['Module B'])
|
|
})
|
|
|
|
it('should block writing a later module once a subject level is recorded and an earlier module is unfinished', () => {
|
|
setSubjectLevel(subject, 'debutant')
|
|
expect(getSubjectLevel(subject)).toBe('debutant')
|
|
const result = canWriteModuleContent(subject, 'Module B')
|
|
expect(result.ok).toBe(false)
|
|
expect(result.blockedBy).toBe('Module A')
|
|
})
|
|
})
|
|
|
|
describe("coachStore — evaluations et validation d'un module", () => {
|
|
const subject = 'geometrie-test'
|
|
const module = 'Module unique'
|
|
|
|
beforeAll(() => {
|
|
createModules(subject, [{ name: module }])
|
|
})
|
|
|
|
it('should report no assessment and a 100% "dont know" ratio before any is saved', () => {
|
|
expect(hasAssessment(subject, module, 'module')).toBe(false)
|
|
expect(moduleDontKnowRatio(subject, module)).toBe(1)
|
|
expect(hasMultipleDifficulties(subject, module)).toBe(false)
|
|
})
|
|
|
|
it('should track multiple distinct difficulties and a correct dont-know ratio after saving assessments', () => {
|
|
saveAssessment(
|
|
subject,
|
|
module,
|
|
'Question facile',
|
|
'short_answer',
|
|
null,
|
|
'reponse',
|
|
'module',
|
|
false,
|
|
'facile',
|
|
'prediction',
|
|
null
|
|
)
|
|
saveAssessment(
|
|
subject,
|
|
module,
|
|
'Question moyenne',
|
|
'short_answer',
|
|
null,
|
|
'je ne sais pas',
|
|
'module',
|
|
true,
|
|
'moyen',
|
|
'debogage',
|
|
'erreur de signe'
|
|
)
|
|
|
|
expect(hasAssessment(subject, module, 'module')).toBe(true)
|
|
expect(hasMultipleDifficulties(subject, module)).toBe(true)
|
|
expect(moduleDontKnowRatio(subject, module)).toBeCloseTo(0.5)
|
|
})
|
|
|
|
it('should default to false/1 (blocking) for a subject that does not exist at all', () => {
|
|
expect(hasMultipleDifficulties('sujet-totalement-inconnu', module)).toBe(false)
|
|
expect(moduleDontKnowRatio('sujet-totalement-inconnu', module)).toBe(1)
|
|
})
|
|
|
|
it('should persist multiple-choice options as JSON on the assessment', () => {
|
|
saveAssessment(
|
|
subject,
|
|
module,
|
|
'QCM',
|
|
'multiple_choice',
|
|
['A', 'B', 'C'],
|
|
'A',
|
|
'module',
|
|
false,
|
|
'difficile',
|
|
'qcm_cible',
|
|
null
|
|
)
|
|
expect(hasAssessment(subject, module, 'module')).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('coachStore — progression et conformite', () => {
|
|
it('should return an empty list when no subject exists yet', () => {
|
|
expect(getProgress('sujet-totalement-inconnu')).toEqual([])
|
|
})
|
|
|
|
it('should return null compliance for an unknown subject', () => {
|
|
expect(getCourseComplianceReport('sujet-totalement-inconnu')).toBeNull()
|
|
})
|
|
|
|
it('should include the source-documentation check in the compliance report for a known subject', () => {
|
|
upsertConceptStatus('conformite-test', 'Un concept', 'not_started')
|
|
const report = getCourseComplianceReport('conformite-test')
|
|
expect(report).not.toBeNull()
|
|
expect(report?.checks.some((c) => c.key === 'sources')).toBe(true)
|
|
})
|
|
})
|