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>
97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { renderHook } from '@testing-library/react'
|
|
|
|
let onToggleCallback: ((transcribing: boolean) => void) | undefined
|
|
const sendMeetingAudioChunk = vi.fn()
|
|
const sendMeetingRecordingStopped = vi.fn()
|
|
const onToggleMeetingTranscription = vi.fn((cb: (transcribing: boolean) => void) => {
|
|
onToggleCallback = cb
|
|
return () => {}
|
|
})
|
|
|
|
function fakeStream(): MediaStream {
|
|
const stop = vi.fn()
|
|
return { getTracks: () => [{ stop }] } as unknown as MediaStream
|
|
}
|
|
|
|
const getUserMedia = vi.fn(async () => fakeStream())
|
|
const enumerateDevices = vi.fn(async () => [])
|
|
|
|
class FakeMediaRecorder {
|
|
static instances: FakeMediaRecorder[] = []
|
|
state: 'recording' | 'inactive' = 'recording'
|
|
ondataavailable: ((event: { data: Blob }) => void) | null = null
|
|
onstop: (() => void) | null = null
|
|
constructor(
|
|
public stream: MediaStream,
|
|
public options: { mimeType: string }
|
|
) {
|
|
FakeMediaRecorder.instances.push(this)
|
|
}
|
|
start(): void {
|
|
this.state = 'recording'
|
|
}
|
|
stop(): void {
|
|
this.state = 'inactive'
|
|
this.ondataavailable?.({ data: new Blob(['chunk'], { type: 'audio/webm' }) })
|
|
this.onstop?.()
|
|
}
|
|
}
|
|
|
|
const { useMeetingRecorder } = await import('../../../src/renderer/src/voice/useMeetingRecorder')
|
|
|
|
describe('useMeetingRecorder()', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
FakeMediaRecorder.instances = []
|
|
;(window as unknown as { api: Record<string, unknown> }).api = {
|
|
onToggleMeetingTranscription,
|
|
sendMeetingAudioChunk,
|
|
sendMeetingRecordingStopped
|
|
}
|
|
Object.defineProperty(navigator, 'mediaDevices', {
|
|
value: { getUserMedia, enumerateDevices },
|
|
configurable: true
|
|
})
|
|
vi.stubGlobal('MediaRecorder', FakeMediaRecorder)
|
|
})
|
|
|
|
it('should start recording the microphone when transcription is toggled on', async () => {
|
|
renderHook(() => useMeetingRecorder())
|
|
onToggleCallback?.(true)
|
|
await vi.waitFor(() => expect(FakeMediaRecorder.instances.length).toBe(1))
|
|
expect(getUserMedia).toHaveBeenCalledWith({ audio: true })
|
|
})
|
|
|
|
it('should give up quietly when the microphone is unavailable, without ever starting a recorder', async () => {
|
|
getUserMedia.mockRejectedValueOnce(new Error('no mic'))
|
|
renderHook(() => useMeetingRecorder())
|
|
onToggleCallback?.(true)
|
|
await vi.waitFor(() => expect(getUserMedia).toHaveBeenCalled())
|
|
// Rien n'a jamais demarre : stopper ensuite ne doit ni planter ni envoyer de notification pour
|
|
// une session qui n'a jamais existe.
|
|
expect(() => onToggleCallback?.(false)).not.toThrow()
|
|
expect(FakeMediaRecorder.instances.length).toBe(0)
|
|
})
|
|
|
|
it('should send the recorded chunk and notify the main process when stopped', async () => {
|
|
renderHook(() => useMeetingRecorder())
|
|
onToggleCallback?.(true)
|
|
await vi.waitFor(() => expect(FakeMediaRecorder.instances.length).toBe(1))
|
|
|
|
onToggleCallback?.(false)
|
|
await vi.waitFor(() => expect(sendMeetingAudioChunk).toHaveBeenCalled())
|
|
expect(sendMeetingRecordingStopped).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should start a new segment automatically instead of stopping when not asked to stop', async () => {
|
|
renderHook(() => useMeetingRecorder())
|
|
onToggleCallback?.(true)
|
|
await vi.waitFor(() => expect(FakeMediaRecorder.instances.length).toBe(1))
|
|
|
|
FakeMediaRecorder.instances[0]?.stop()
|
|
await vi.waitFor(() => expect(FakeMediaRecorder.instances.length).toBe(2))
|
|
expect(sendMeetingRecordingStopped).not.toHaveBeenCalled()
|
|
})
|
|
})
|