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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
60e2fb26af
commit
1c2f002eb3
@@ -0,0 +1,129 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
const readText = vi.fn(async () => '')
|
||||
const writeText = vi.fn(async () => {})
|
||||
const openExternal = vi.fn(async () => {})
|
||||
const NotificationShow = vi.fn()
|
||||
class NotificationMock {
|
||||
show = NotificationShow
|
||||
}
|
||||
vi.mock('electron', () => ({
|
||||
clipboard: { readText, writeText },
|
||||
shell: { openExternal },
|
||||
Notification: NotificationMock
|
||||
}))
|
||||
|
||||
const writeFileSyncMock = vi.fn()
|
||||
const mkdtempSyncMock = vi.fn(() => 'C:\\temp\\forge-avatar-xyz')
|
||||
vi.mock('fs', () => ({ writeFileSync: writeFileSyncMock, mkdtempSync: mkdtempSyncMock }))
|
||||
|
||||
const execFileMock = vi.fn(() => new EventEmitter())
|
||||
vi.mock('child_process', () => ({ execFile: execFileMock }))
|
||||
|
||||
const synthesizeSpeech = vi.fn(async () => new Uint8Array([1, 2, 3]).buffer as unknown as Buffer)
|
||||
vi.mock('../../src/main/ai/elevenlabs', () => ({ synthesizeSpeech }))
|
||||
const sendToRenderer = vi.fn()
|
||||
vi.mock('../../src/main/windowBridge', () => ({ sendToRenderer }))
|
||||
|
||||
const { clipboardSkill } = await import('../../src/main/skills/windows/clipboard')
|
||||
const { showNotification } = await import('../../src/main/skills/windows/showNotification')
|
||||
const { playMusic } = await import('../../src/main/skills/windows/playMusic')
|
||||
const { reminder } = await import('../../src/main/skills/windows/reminder')
|
||||
const { openNotepad } = await import('../../src/main/skills/windows/openNotepad')
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('clipboard', () => {
|
||||
it('should refuse an invalid action', async () => {
|
||||
await expect(clipboardSkill.execute({ action: 'danser' })).rejects.toThrow(/action invalide/)
|
||||
})
|
||||
|
||||
it('should report an empty clipboard', async () => {
|
||||
readText.mockResolvedValue('')
|
||||
const result = await clipboardSkill.execute({ action: 'lire' })
|
||||
expect(result).toMatch(/vide/)
|
||||
})
|
||||
|
||||
it('should read non-empty clipboard content', async () => {
|
||||
readText.mockResolvedValue('Bonjour')
|
||||
const result = await clipboardSkill.execute({ action: 'lire' })
|
||||
expect(result).toMatch(/Bonjour/)
|
||||
})
|
||||
|
||||
it('should refuse to copy an empty text', async () => {
|
||||
await expect(clipboardSkill.execute({ action: 'copier', text: '' })).rejects.toThrow(
|
||||
/texte manquant/
|
||||
)
|
||||
})
|
||||
|
||||
it('should copy a given text to the clipboard', async () => {
|
||||
const result = await clipboardSkill.execute({ action: 'copier', text: 'Salut' })
|
||||
expect(result).toMatch(/copie/)
|
||||
expect(writeText).toHaveBeenCalledWith('Salut')
|
||||
})
|
||||
})
|
||||
|
||||
describe('show_notification', () => {
|
||||
it('should refuse an empty message', async () => {
|
||||
await expect(showNotification.execute({ message: '' })).rejects.toThrow(/message manquant/)
|
||||
})
|
||||
|
||||
it('should show a notification with the given title and message', async () => {
|
||||
const result = await showNotification.execute({ title: 'Alerte', message: 'Ca a marche' })
|
||||
expect(result).toMatch(/affichee/)
|
||||
expect(NotificationShow).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('play_music', () => {
|
||||
it('should refuse an empty query', async () => {
|
||||
await expect(playMusic.execute({ query: '' })).rejects.toThrow(/requete manquante/)
|
||||
})
|
||||
|
||||
it('should open Spotify with the encoded search query', async () => {
|
||||
const result = await playMusic.execute({ query: 'Daft Punk' })
|
||||
expect(result).toMatch(/Spotify ouvert/)
|
||||
expect(openExternal).toHaveBeenCalledWith('spotify:search:Daft%20Punk')
|
||||
})
|
||||
|
||||
it('should fall back to the web player when the Spotify URI fails', async () => {
|
||||
openExternal.mockRejectedValueOnce(new Error('no spotify'))
|
||||
const result = await playMusic.execute({ query: 'Daft Punk' })
|
||||
expect(result).toMatch(/web ouvert/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('set_reminder', () => {
|
||||
it('should refuse an invalid delay', async () => {
|
||||
await expect(reminder.execute({ minutes: 0, message: 'test' })).rejects.toThrow(
|
||||
/minutes invalide/
|
||||
)
|
||||
})
|
||||
|
||||
it('should refuse an empty message', async () => {
|
||||
await expect(reminder.execute({ minutes: 5, message: '' })).rejects.toThrow(/message manquant/)
|
||||
})
|
||||
|
||||
it('should confirm the reminder is scheduled', async () => {
|
||||
const result = await reminder.execute({ minutes: 10, message: 'Pause cafe' })
|
||||
expect(result).toMatch(/Rappel programme dans 10 minute/)
|
||||
expect(result).toMatch(/Pause cafe/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('open_notepad', () => {
|
||||
it('should open an empty notepad when no text is given', async () => {
|
||||
const result = await openNotepad.execute({})
|
||||
expect(result).toBe('Bloc-notes ouvert.')
|
||||
expect(writeFileSyncMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should pre-fill a temp file and open it when text is given', async () => {
|
||||
const result = await openNotepad.execute({ text: 'Mon brouillon' })
|
||||
expect(result).toMatch(/texte demande/)
|
||||
expect(writeFileSyncMock).toHaveBeenCalledWith(expect.any(String), 'Mon brouillon', 'utf-8')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user