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,140 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
const openPath = vi.fn(async () => '')
|
||||
vi.mock('electron', () => ({
|
||||
shell: { openPath },
|
||||
app: { getPath: (name: string) => `C:\\Users\\test\\${name}` }
|
||||
}))
|
||||
|
||||
const writeFileSyncMock = vi.fn()
|
||||
const existsSyncMock = vi.fn(() => false)
|
||||
const mkdirSyncMock = vi.fn()
|
||||
const statSyncMock = vi.fn(() => ({ isDirectory: () => false }))
|
||||
vi.mock('fs', () => ({
|
||||
writeFileSync: writeFileSyncMock,
|
||||
existsSync: existsSyncMock,
|
||||
mkdirSync: mkdirSyncMock,
|
||||
statSync: statSyncMock
|
||||
}))
|
||||
|
||||
const execFileMock = vi.fn((_cmd: string, _args: string[], cb: (err: Error | null) => void) =>
|
||||
cb(null)
|
||||
)
|
||||
vi.mock('child_process', () => ({ execFile: execFileMock }))
|
||||
|
||||
const findFileByName = vi.fn(async (name: string) =>
|
||||
name.includes('introuvable') ? null : `C:\\Users\\test\\desktop\\${name}.txt`
|
||||
)
|
||||
vi.mock('../../src/main/skills/windows/lib/fileSearch', () => ({ findFileByName }))
|
||||
|
||||
const { createFile } = await import('../../src/main/skills/windows/createFile')
|
||||
const { createFolder } = await import('../../src/main/skills/windows/createFolder')
|
||||
const { deleteFileOrFolder } = await import('../../src/main/skills/windows/deleteFileOrFolder')
|
||||
const { printFile } = await import('../../src/main/skills/windows/printFile')
|
||||
const { searchFile } = await import('../../src/main/skills/windows/searchFile')
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
existsSyncMock.mockReturnValue(false)
|
||||
statSyncMock.mockReturnValue({ isDirectory: () => false })
|
||||
findFileByName.mockImplementation(async (name: string) =>
|
||||
name.includes('introuvable') ? null : `C:\\Users\\test\\desktop\\${name}.txt`
|
||||
)
|
||||
})
|
||||
|
||||
describe('create_file', () => {
|
||||
it('should refuse an empty name', async () => {
|
||||
await expect(createFile.execute({ name: ' ' })).rejects.toThrow(/nom manquant/)
|
||||
})
|
||||
|
||||
it('should sanitize illegal characters, write the file and open it', async () => {
|
||||
const result = await createFile.execute({ name: 'note<test>', content: 'hello' })
|
||||
expect(result).toMatch(/Fichier cree et ouvert/)
|
||||
expect(writeFileSyncMock).toHaveBeenCalled()
|
||||
expect(openPath).toHaveBeenCalled()
|
||||
expect(String(writeFileSyncMock.mock.calls[0]?.[0])).not.toMatch(/[<>]/)
|
||||
})
|
||||
|
||||
it('should append .txt when the name has no extension', async () => {
|
||||
await createFile.execute({ name: 'sansextension' })
|
||||
expect(String(writeFileSyncMock.mock.calls[0]?.[0])).toMatch(/sansextension\.txt$/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('create_folder', () => {
|
||||
it('should refuse an empty name', async () => {
|
||||
await expect(createFolder.execute({ name: '' })).rejects.toThrow(/nom manquant/)
|
||||
})
|
||||
|
||||
it('should report when the folder already exists without creating it again', async () => {
|
||||
existsSyncMock.mockReturnValue(true)
|
||||
const result = await createFolder.execute({ name: 'existant' })
|
||||
expect(result).toMatch(/existe deja/)
|
||||
expect(mkdirSyncMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should create and open a new folder', async () => {
|
||||
const result = await createFolder.execute({ name: 'nouveau' })
|
||||
expect(result).toMatch(/Dossier cree et ouvert/)
|
||||
expect(mkdirSyncMock).toHaveBeenCalled()
|
||||
expect(openPath).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('delete_file', () => {
|
||||
it('should refuse an empty name', async () => {
|
||||
await expect(deleteFileOrFolder.execute({ name: '' })).rejects.toThrow(/nom manquant/)
|
||||
})
|
||||
|
||||
it('should report when nothing is found', async () => {
|
||||
const result = await deleteFileOrFolder.execute({ name: 'introuvable' })
|
||||
expect(result).toMatch(/Aucun fichier ou dossier/)
|
||||
})
|
||||
|
||||
it('should refuse to delete a protected location (drive root)', async () => {
|
||||
findFileByName.mockResolvedValue('C:\\')
|
||||
const result = await deleteFileOrFolder.execute({ name: 'quelquechose' })
|
||||
expect(result).toMatch(/protege/)
|
||||
expect(execFileMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should send a found file to the recycle bin', async () => {
|
||||
const result = await deleteFileOrFolder.execute({ name: 'document' })
|
||||
expect(result).toMatch(/corbeille/)
|
||||
expect(execFileMock).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('print_file', () => {
|
||||
it('should refuse an empty name', async () => {
|
||||
await expect(printFile.execute({ name: '' })).rejects.toThrow(/nom manquant/)
|
||||
})
|
||||
|
||||
it('should report when no file is found', async () => {
|
||||
const result = await printFile.execute({ name: 'introuvable' })
|
||||
expect(result).toMatch(/Aucun fichier/)
|
||||
})
|
||||
|
||||
it('should launch printing for a found file', async () => {
|
||||
const result = await printFile.execute({ name: 'rapport' })
|
||||
expect(result).toMatch(/Impression lancee/)
|
||||
expect(execFileMock).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('search_file', () => {
|
||||
it('should refuse an empty name', async () => {
|
||||
await expect(searchFile.execute({ name: '' })).rejects.toThrow(/nom manquant/)
|
||||
})
|
||||
|
||||
it('should report when nothing is found', async () => {
|
||||
const result = await searchFile.execute({ name: 'introuvable' })
|
||||
expect(result).toMatch(/Aucun fichier ou dossier/)
|
||||
})
|
||||
|
||||
it('should find and open a matching file', async () => {
|
||||
const result = await searchFile.execute({ name: 'photo' })
|
||||
expect(result).toMatch(/Trouve et ouvert/)
|
||||
expect(openPath).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user