Step 1 of adding a backend proxy server (API keys held server-side instead of shipped in the installer). Moves everything app-specific into "Max Avatar/" via git mv (preserves history): src/, tests/, scripts/, assets/, build/, resources/, package.json/-lock.json, electron-builder.yml, electron.vite.config.ts, eslint.config.mjs, playwright.config.ts, vitest.config.mts, sonar-project.properties, tsconfig*.json, Dockerfile, .editorconfig/.env*/.gitignore/.prettier*. CLAUDE.md, README.md, docs/, .claude/, .gitea/, .husky/, .vscode/, and the docker-compose files stay at the repo root, since they'll apply to both the app and the future backend. No application code needed changes (all its internal paths are relative to its own tree). Adjusted what referenced the old root from outside: - .husky/pre-commit: cd into "Max Avatar" before lint-staged - .gitea/workflows/*.yml: working-directory + cache-dependency-path + artifact paths + SonarQube projectBaseDir - docker-compose.yml: build context -> ./Max Avatar - Max Avatar/Dockerfile: node:20-alpine -> node:24-alpine (same node:sqlite issue already fixed elsewhere, never applied here before) - .vscode/launch.json, README.md: updated paths/instructions Verified from Max Avatar/ after the move: npm ci, typecheck, lint, test:coverage (473/473, same coverage numbers), build, and dev all work unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
183 lines
6.4 KiB
TypeScript
183 lines
6.4 KiB
TypeScript
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/)
|
|
})
|
|
})
|