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>
138 lines
4.7 KiB
TypeScript
138 lines
4.7 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-drawing-test-'))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: { getPath: () => tempDir }
|
|
}))
|
|
|
|
const openDrawingWindow = vi.fn(async () => {})
|
|
const revealShape = vi.fn(async () => {})
|
|
const renderMermaid = vi.fn(async () => {})
|
|
const playCaption = vi.fn(async () => {})
|
|
vi.mock('../../src/main/coach/drawingWindow', () => ({
|
|
openDrawingWindow,
|
|
revealShape,
|
|
renderMermaid,
|
|
playCaption
|
|
}))
|
|
|
|
const synthesizeSpeech = vi.fn(async () => Buffer.from('audio'))
|
|
vi.mock('../../src/main/ai/elevenlabs', () => ({ synthesizeSpeech }))
|
|
|
|
const { getModuleDetail, createModules } = await import('../../src/main/coach/coachStore')
|
|
const { drawSchema } = await import('../../src/main/skills/coach/drawSchema')
|
|
const { drawFlowDiagram } = await import('../../src/main/skills/coach/drawFlowDiagram')
|
|
|
|
describe('draw_schema', () => {
|
|
it('should refuse when no valid shape is given', async () => {
|
|
await expect(drawSchema.execute({ title: 'Test', shapes: [] })).rejects.toThrow(
|
|
/Aucune forme valide/
|
|
)
|
|
})
|
|
|
|
it('should refuse when no shape has a caption', async () => {
|
|
await expect(
|
|
drawSchema.execute({
|
|
title: 'Test',
|
|
shapes: [{ type: 'circle', x: 10, y: 10, radius: 5 }]
|
|
})
|
|
).rejects.toThrow(/Aucune caption/)
|
|
})
|
|
|
|
it('should refuse an unknown preset name', async () => {
|
|
await expect(
|
|
drawSchema.execute({
|
|
title: 'Test',
|
|
shapes: [{ type: 'preset', preset: 'inexistant', caption: 'voila' }]
|
|
})
|
|
).rejects.toThrow(/Preset inconnu/)
|
|
})
|
|
|
|
it('should draw a manual shape with a caption, calling the drawing window and speech synthesis', async () => {
|
|
openDrawingWindow.mockClear()
|
|
revealShape.mockClear()
|
|
synthesizeSpeech.mockClear()
|
|
const result = await drawSchema.execute({
|
|
title: 'Mon dessin',
|
|
shapes: [{ type: 'circle', x: 10, y: 10, radius: 5, caption: 'Voici un cercle' }]
|
|
})
|
|
expect(result).toMatch(/termine/)
|
|
expect(openDrawingWindow).toHaveBeenCalledWith('Mon dessin', 700, 500)
|
|
expect(synthesizeSpeech).toHaveBeenCalledWith('Voici un cercle')
|
|
expect(revealShape).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should expand a geometry preset into real shapes', async () => {
|
|
const result = await drawSchema.execute({
|
|
title: 'Triangle',
|
|
shapes: [
|
|
{
|
|
type: 'preset',
|
|
preset: 'right_triangle',
|
|
presetParams: { adjacentCaption: 'Le cote vertical' }
|
|
}
|
|
]
|
|
})
|
|
expect(result).toMatch(/termine/)
|
|
})
|
|
|
|
it('should persist the drawing to the module when subject and module are both given', async () => {
|
|
createModules('dessin-subject-test', [{ name: 'Module dessin' }])
|
|
await drawSchema.execute({
|
|
title: 'Sauvegarde',
|
|
subject: 'dessin-subject-test',
|
|
module: 'Module dessin',
|
|
shapes: [{ type: 'circle', x: 1, y: 1, radius: 1, caption: 'un cercle' }]
|
|
})
|
|
const detail = getModuleDetail('dessin-subject-test', 'Module dessin')
|
|
expect(detail?.diagrams).toHaveLength(1)
|
|
})
|
|
})
|
|
|
|
describe('draw_flow_diagram', () => {
|
|
it('should refuse missing mermaid code', async () => {
|
|
await expect(
|
|
drawFlowDiagram.execute({ title: 'Cycle', mermaid: '', captions: ['une etape'] })
|
|
).rejects.toThrow(/mermaid manquant/)
|
|
})
|
|
|
|
it('should refuse when no caption is provided', async () => {
|
|
await expect(
|
|
drawFlowDiagram.execute({ title: 'Cycle', mermaid: 'graph LR; A --> B', captions: [] })
|
|
).rejects.toThrow(/Aucune caption/)
|
|
})
|
|
|
|
it('should render the diagram and narrate each caption in sequence', async () => {
|
|
renderMermaid.mockClear()
|
|
playCaption.mockClear()
|
|
const result = await drawFlowDiagram.execute({
|
|
title: 'Cycle de l-eau',
|
|
mermaid: 'graph LR; Evaporation --> Condensation',
|
|
captions: ['Premiere etape', 'Deuxieme etape']
|
|
})
|
|
expect(result).toMatch(/affiche/)
|
|
expect(renderMermaid).toHaveBeenCalledWith(
|
|
'Cycle de l-eau',
|
|
'graph LR; Evaporation --> Condensation'
|
|
)
|
|
expect(playCaption).toHaveBeenCalledTimes(2)
|
|
})
|
|
|
|
it('should persist the diagram to the module when subject and module are both given', async () => {
|
|
createModules('diagramme-subject-test', [{ name: 'Module diagramme' }])
|
|
await drawFlowDiagram.execute({
|
|
title: 'Sauvegarde',
|
|
subject: 'diagramme-subject-test',
|
|
module: 'Module diagramme',
|
|
mermaid: 'graph LR; A --> B',
|
|
captions: ['une etape']
|
|
})
|
|
const detail = getModuleDetail('diagramme-subject-test', 'Module diagramme')
|
|
expect(detail?.diagrams).toHaveLength(1)
|
|
})
|
|
})
|