feat: add CI/CD, code quality, testing and security hardening
CI / quality (push) Failing after 6m22s
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
1959ddb41a
commit
e9690a49f9
@@ -0,0 +1,131 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, act } from '@testing-library/react'
|
||||
|
||||
const drawShape = vi.fn()
|
||||
vi.mock('../../../src/renderer/src/components/drawRoughShapes', () => ({ drawShape }))
|
||||
|
||||
const roughCanvas = vi.fn(() => ({}))
|
||||
vi.mock('roughjs', () => ({ default: { canvas: roughCanvas } }))
|
||||
|
||||
const mermaidRender = vi.fn(async () => ({ svg: '<svg></svg>' }))
|
||||
const mermaidInitialize = vi.fn()
|
||||
vi.mock('mermaid', () => ({
|
||||
default: { initialize: mermaidInitialize, render: mermaidRender }
|
||||
}))
|
||||
|
||||
interface InitDrawingPayload {
|
||||
title: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
interface RevealShapePayload {
|
||||
requestId: string
|
||||
shape: { type: string }
|
||||
audio: ArrayBuffer | null
|
||||
}
|
||||
interface RenderMermaidPayload {
|
||||
requestId: string
|
||||
title: string
|
||||
mermaidCode: string
|
||||
}
|
||||
interface PlayCaptionPayload {
|
||||
requestId: string
|
||||
audio: ArrayBuffer
|
||||
}
|
||||
|
||||
const listeners: {
|
||||
onInitDrawing?: (payload: InitDrawingPayload) => void
|
||||
onRevealShape?: (payload: RevealShapePayload) => void
|
||||
onRenderMermaid?: (payload: RenderMermaidPayload) => void
|
||||
onPlayCaption?: (payload: PlayCaptionPayload) => void
|
||||
} = {}
|
||||
|
||||
function setupWindowApi(): void {
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
onInitDrawing: vi.fn((cb: (payload: InitDrawingPayload) => void) => {
|
||||
listeners.onInitDrawing = cb
|
||||
return () => {}
|
||||
}),
|
||||
onRevealShape: vi.fn((cb: (payload: RevealShapePayload) => void) => {
|
||||
listeners.onRevealShape = cb
|
||||
return () => {}
|
||||
}),
|
||||
onRenderMermaid: vi.fn((cb: (payload: RenderMermaidPayload) => void) => {
|
||||
listeners.onRenderMermaid = cb
|
||||
return () => {}
|
||||
}),
|
||||
onPlayCaption: vi.fn((cb: (payload: PlayCaptionPayload) => void) => {
|
||||
listeners.onPlayCaption = cb
|
||||
return () => {}
|
||||
}),
|
||||
acknowledgeShapeReveal: vi.fn(),
|
||||
acknowledgeMermaidRendered: vi.fn(),
|
||||
acknowledgeCaptionDone: vi.fn()
|
||||
}
|
||||
}
|
||||
|
||||
const { default: CoachDrawingView } =
|
||||
await import('../../../src/renderer/src/components/CoachDrawingView')
|
||||
|
||||
describe('<CoachDrawingView />', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
setupWindowApi()
|
||||
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(
|
||||
{} as CanvasRenderingContext2D
|
||||
)
|
||||
})
|
||||
|
||||
it('should show a waiting message before any drawing is initialized', () => {
|
||||
render(<CoachDrawingView />)
|
||||
expect(screen.getByText(/En attente/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should display the title once a drawing is initialized', () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() => listeners.onInitDrawing?.({ title: 'Mon dessin', width: 700, height: 500 }))
|
||||
expect(screen.getByText('Mon dessin')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should draw a revealed shape and acknowledge it when there is no audio', () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() => listeners.onInitDrawing?.({ title: 'Mon dessin', width: 700, height: 500 }))
|
||||
const api = (window as unknown as { api: { acknowledgeShapeReveal: ReturnType<typeof vi.fn> } })
|
||||
.api
|
||||
act(() =>
|
||||
listeners.onRevealShape?.({ requestId: 'r1', shape: { type: 'circle' }, audio: null })
|
||||
)
|
||||
expect(drawShape).toHaveBeenCalled()
|
||||
expect(api.acknowledgeShapeReveal).toHaveBeenCalledWith('r1')
|
||||
})
|
||||
|
||||
it('should switch to mermaid mode and render the diagram on success, waiting for the container to mount', async () => {
|
||||
render(<CoachDrawingView />)
|
||||
act(() =>
|
||||
listeners.onRenderMermaid?.({
|
||||
requestId: 'r2',
|
||||
title: 'Cycle de l-eau',
|
||||
mermaidCode: 'graph LR; A --> B'
|
||||
})
|
||||
)
|
||||
expect(screen.getByText('Cycle de l-eau')).toBeInTheDocument()
|
||||
const api = (
|
||||
window as unknown as { api: { acknowledgeMermaidRendered: ReturnType<typeof vi.fn> } }
|
||||
).api
|
||||
await waitFor(() => expect(api.acknowledgeMermaidRendered).toHaveBeenCalledWith('r2', true))
|
||||
})
|
||||
|
||||
it('should report a mermaid render failure', async () => {
|
||||
mermaidRender.mockRejectedValueOnce(new Error('syntaxe invalide'))
|
||||
render(<CoachDrawingView />)
|
||||
act(() =>
|
||||
listeners.onRenderMermaid?.({ requestId: 'r3', title: 'Echec', mermaidCode: 'invalide' })
|
||||
)
|
||||
const api = (
|
||||
window as unknown as { api: { acknowledgeMermaidRendered: ReturnType<typeof vi.fn> } }
|
||||
).api
|
||||
await waitFor(() =>
|
||||
expect(api.acknowledgeMermaidRendered).toHaveBeenCalledWith('r3', false, 'syntaxe invalide')
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user