Files
ForgeBase/Max Avatar/tests/unit/courseBuildStepper.test.ts
T
williamandClaude Sonnet 5 1c2f002eb3 refactor: move app code into Max Avatar/ subfolder (monorepo prep for backend)
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>
2026-10-31 12:15:30 +01:00

109 lines
4.5 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
const sendToRenderer = vi.fn()
vi.mock('../../src/main/windowBridge', () => ({ sendToRenderer }))
const { recordCourseBuildTool, clearCourseBuild } =
await import('../../src/main/coach/courseBuildStepper')
interface Payload {
subject: string
steps: { key: string; status: string; detail?: string }[]
}
function lastPayload(): Payload {
const call = sendToRenderer.mock.calls.at(-1) as [string, Payload] | undefined
if (!call) throw new Error('sendToRenderer was never called')
return call[1]
}
describe('courseBuildStepper', () => {
beforeEach(() => {
sendToRenderer.mockClear()
})
it('should ignore a tool call with no subject', () => {
recordCourseBuildTool('research_topic', {})
expect(sendToRenderer).not.toHaveBeenCalled()
})
it('should ignore an unrecognized tool name', () => {
recordCourseBuildTool('unknown_tool', { subject: 'algebre' })
expect(sendToRenderer).not.toHaveBeenCalled()
})
it('should mark recherche done and plan active after research_topic, with source count', () => {
recordCourseBuildTool('research_topic', { subject: 'algebre', sources: [{}, {}, {}] })
const payload = lastPayload()
expect(payload.subject).toBe('algebre')
const recherche = payload.steps.find((s) => s.key === 'recherche')
const plan = payload.steps.find((s) => s.key === 'plan')
expect(recherche?.status).toBe('done')
expect(recherche?.detail).toBe('3 source(s)')
expect(plan?.status).toBe('active')
})
it('should mark plan done and redaction active after generate_course_plan with modules', () => {
recordCourseBuildTool('generate_course_plan', {
subject: 'algebre',
modules: [{ name: 'A' }, { name: 'B' }]
})
const payload = lastPayload()
const plan = payload.steps.find((s) => s.key === 'plan')
const redaction = payload.steps.find((s) => s.key === 'redaction')
expect(plan?.status).toBe('done')
expect(redaction?.status).toBe('active')
expect(redaction?.detail).toBe('0/2')
})
it('should mark redaction done and evaluation_initiale active once every module is written', () => {
recordCourseBuildTool('write_module_content', { subject: 'algebre' })
let payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'redaction')?.detail).toBe('1/2')
expect(payload.steps.find((s) => s.key === 'redaction')?.status).toBe('active')
recordCourseBuildTool('write_module_content', { subject: 'algebre' })
payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'redaction')?.status).toBe('done')
expect(payload.steps.find((s) => s.key === 'evaluation_initiale')?.status).toBe('active')
})
it('should mark evaluation_initiale done and niveau active on an initial assessment', () => {
recordCourseBuildTool('ask_written_exercise', { subject: 'algebre', kind: 'initial' })
const payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'evaluation_initiale')?.status).toBe('done')
expect(payload.steps.find((s) => s.key === 'niveau')?.status).toBe('active')
})
it('should not progress the "niveau" step on a non-initial assessment', () => {
recordCourseBuildTool('ask_written_exercise', { subject: 'algebre', kind: 'module' })
const payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'niveau')?.status).toBe('active')
})
it('should mark niveau done after record_subject_level', () => {
recordCourseBuildTool('record_subject_level', { subject: 'algebre' })
const payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'niveau')?.status).toBe('done')
})
it('should mark revision done on a second generate_course_plan call after the level is recorded', () => {
recordCourseBuildTool('generate_course_plan', { subject: 'algebre', modules: [{ name: 'A' }] })
const payload = lastPayload()
expect(payload.steps.find((s) => s.key === 'revision')?.status).toBe('done')
})
it('should reset the stepper state when a different subject starts', () => {
recordCourseBuildTool('research_topic', { subject: 'geometrie', sources: [] })
const payload = lastPayload()
expect(payload.subject).toBe('geometrie')
expect(payload.steps.find((s) => s.key === 'niveau')?.status).toBe('pending')
})
it('should clear the stepper state and notify the renderer with null', () => {
sendToRenderer.mockClear()
clearCourseBuild()
expect(sendToRenderer).toHaveBeenCalledWith('course-build-step', null)
})
})