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>
106 lines
3.8 KiB
TypeScript
106 lines
3.8 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-research-test-'))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: { getPath: () => tempDir }
|
|
}))
|
|
|
|
const { getResearchSummary } = await import('../../src/main/coach/coachStore')
|
|
const { researchTopic } = await import('../../src/main/skills/coach/researchTopic')
|
|
|
|
function buildSources(count: number, level = 1): { title: string; url: string; level: number }[] {
|
|
return Array.from({ length: count }, (_, i) => ({
|
|
title: `Source ${i + 1}`,
|
|
url: `https://example.edu/source-${i + 1}`,
|
|
level
|
|
}))
|
|
}
|
|
|
|
const BASE_ARGS = {
|
|
subject: 'trigonometrie-recherche-test',
|
|
subjectDomain: 'math_science',
|
|
definition: 'La trigonometrie etudie les relations entre angles et longueurs.',
|
|
usageToday: 'Utilisee en architecture, navigation, physique.',
|
|
whyUsedToday: 'Permet de calculer des distances inaccessibles directement.',
|
|
practicalCases: 'Calcul de la hauteur d-un batiment via son ombre.',
|
|
application: 'Mesurer un angle puis appliquer sinus/cosinus/tangente.',
|
|
prerequisites: 'Connaitre le theoreme de Pythagore et les triangles rectangles.',
|
|
keyConcepts: ['sinus', 'cosinus', 'tangente', 'hypotenuse', 'angle'],
|
|
commonErrors: [
|
|
'confondre sinus et cosinus',
|
|
'oublier de convertir en radians',
|
|
'mauvais triangle de reference'
|
|
],
|
|
feynmanExplanation:
|
|
'Imagine une echelle contre un mur : la trigonometrie dit comment l-angle change la hauteur atteinte.'
|
|
}
|
|
|
|
describe('research_topic', () => {
|
|
it('should reject an invalid subjectDomain', async () => {
|
|
await expect(
|
|
researchTopic.execute({
|
|
...BASE_ARGS,
|
|
subjectDomain: 'domaine-inconnu',
|
|
sources: buildSources(5)
|
|
})
|
|
).rejects.toThrow(/subjectDomain invalide/)
|
|
})
|
|
|
|
it('should reject a source with an invalid URL', async () => {
|
|
await expect(
|
|
researchTopic.execute({
|
|
...BASE_ARGS,
|
|
sources: [{ title: 'Source', url: 'pas-une-url', level: 1 }]
|
|
})
|
|
).rejects.toThrow(/URL valide/)
|
|
})
|
|
|
|
it('should reject when fewer sources than the domain minimum are provided', async () => {
|
|
await expect(researchTopic.execute({ ...BASE_ARGS, sources: buildSources(3) })).rejects.toThrow(
|
|
/Au moins 5 sources/
|
|
)
|
|
})
|
|
|
|
it('should reject when every source is level 4 only', async () => {
|
|
await expect(
|
|
researchTopic.execute({ ...BASE_ARGS, sources: buildSources(5, 4) })
|
|
).rejects.toThrow(/niveau 1, 2 ou 3/)
|
|
})
|
|
|
|
it('should reject fewer than 5 key concepts', async () => {
|
|
await expect(
|
|
researchTopic.execute({ ...BASE_ARGS, sources: buildSources(5), keyConcepts: ['a', 'b'] })
|
|
).rejects.toThrow(/keyConcepts/)
|
|
})
|
|
|
|
it('should reject fewer than 3 common errors', async () => {
|
|
await expect(
|
|
researchTopic.execute({ ...BASE_ARGS, sources: buildSources(5), commonErrors: ['a'] })
|
|
).rejects.toThrow(/commonErrors/)
|
|
})
|
|
|
|
it('should require a higher minimum source count for medicine_law_finance', async () => {
|
|
await expect(
|
|
researchTopic.execute({
|
|
...BASE_ARGS,
|
|
subjectDomain: 'medicine_law_finance',
|
|
sources: buildSources(5)
|
|
})
|
|
).rejects.toThrow(/Au moins 10 sources/)
|
|
})
|
|
|
|
it('should accept a fully valid research payload and persist it', async () => {
|
|
const result = await researchTopic.execute({ ...BASE_ARGS, sources: buildSources(5) })
|
|
expect(result).toMatch(/enregistree/)
|
|
const stored = getResearchSummary(BASE_ARGS.subject)
|
|
expect(stored).not.toBeNull()
|
|
const parsed = JSON.parse(stored ?? '{}') as { sources: unknown[]; subjectDomain: string }
|
|
expect(parsed.sources).toHaveLength(5)
|
|
expect(parsed.subjectDomain).toBe('math_science')
|
|
})
|
|
})
|