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>
160 lines
6.3 KiB
TypeScript
160 lines
6.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { mkdtempSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
|
|
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-vision-meeting-test-'))
|
|
|
|
const getSources = vi.fn(async () => [{ thumbnail: { toPNG: () => Buffer.from([1, 2, 3]) } }])
|
|
const requestCameraFrame = vi.fn(async () => 'data:image/png;base64,abc')
|
|
vi.mock('electron', () => ({
|
|
app: { getPath: () => tempDir },
|
|
desktopCapturer: { getSources },
|
|
screen: { getPrimaryDisplay: () => ({ size: { width: 1920, height: 1080 } }) }
|
|
}))
|
|
vi.mock('../../src/main/windowBridge', () => ({ requestCameraFrame, sendToRenderer: vi.fn() }))
|
|
|
|
// pdf-parse/index.js execute du code de demo au chargement quand `module.parent` est absent (cas du
|
|
// loader de Vitest), ce qui tente de lire un fichier de test inexistant : on le mocke entierement
|
|
// plutot que de changer le point d'entree importe par le code de production pour contourner ce bug
|
|
// tiers.
|
|
vi.mock('pdf-parse', () => ({ default: vi.fn(async () => ({ text: 'Texte extrait du PDF' })) }))
|
|
vi.mock('mammoth', () => ({
|
|
default: { extractRawText: vi.fn(async () => ({ value: 'Texte extrait du docx' })) }
|
|
}))
|
|
|
|
const analyzeImage = vi.fn(async (_dataUrl: string, question: string) => `Reponse a: ${question}`)
|
|
vi.mock('../../src/main/ai/vision', () => ({ analyzeImage }))
|
|
|
|
const { analyzeScreen } = await import('../../src/main/skills/vision/analyzeScreen')
|
|
const { watchCamera } = await import('../../src/main/skills/vision/watchCamera')
|
|
const { searchWeb } = await import('../../src/main/skills/web/searchWeb')
|
|
const { getLastMeetingSummarySkill } =
|
|
await import('../../src/main/skills/meeting/getLastMeetingSummary')
|
|
const { saveMeeting } = await import('../../src/main/meeting/meetingStore')
|
|
const { extractText } = await import('../../src/main/skills/documents/extractText')
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
getSources.mockResolvedValue([{ thumbnail: { toPNG: () => Buffer.from([1, 2, 3]) } }])
|
|
requestCameraFrame.mockResolvedValue('data:image/png;base64,abc')
|
|
analyzeImage.mockImplementation(
|
|
async (_dataUrl: string, question: string) => `Reponse a: ${question}`
|
|
)
|
|
})
|
|
|
|
describe('analyze_screen', () => {
|
|
it('should capture the screen and ask the vision model with a default question', async () => {
|
|
const result = await analyzeScreen.execute({})
|
|
expect(result).toMatch(/Decris ce que tu vois a l'ecran/)
|
|
})
|
|
|
|
it('should throw when no screen source is detected', async () => {
|
|
getSources.mockResolvedValueOnce([])
|
|
await expect(analyzeScreen.execute({ question: 'test' })).rejects.toThrow(/Aucun ecran/)
|
|
})
|
|
})
|
|
|
|
describe('watch_camera', () => {
|
|
it('should request a camera frame and ask the vision model', async () => {
|
|
const result = await watchCamera.execute({ question: "Qu'est-ce que c'est ?" })
|
|
expect(result).toMatch(/Qu'est-ce que c'est/)
|
|
expect(requestCameraFrame).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should use a default question when none is given', async () => {
|
|
const result = await watchCamera.execute({})
|
|
expect(result).toMatch(/Decris ce que tu vois/)
|
|
})
|
|
})
|
|
|
|
describe('search_web', () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal('fetch', vi.fn())
|
|
})
|
|
|
|
it('should refuse an empty query', async () => {
|
|
await expect(searchWeb.execute({ query: '' })).rejects.toThrow(/query manquante/)
|
|
})
|
|
|
|
it('should parse DuckDuckGo HTML results into a readable list', async () => {
|
|
const html = `
|
|
<div class="result web-result">
|
|
<div class="result__body">
|
|
<a class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com">Titre du resultat</a>
|
|
<a class="result__title"><span>Titre du resultat</span></a>
|
|
<div class="result__snippet">Un extrait pertinent.</div>
|
|
</div>
|
|
</div>
|
|
`
|
|
vi.mocked(fetch).mockResolvedValue({ ok: true, text: () => Promise.resolve(html) } as Response)
|
|
const result = await searchWeb.execute({ query: 'test' })
|
|
expect(result).toMatch(/example\.com/)
|
|
})
|
|
|
|
it('should report no results when nothing matches', async () => {
|
|
vi.mocked(fetch).mockResolvedValue({
|
|
ok: true,
|
|
text: () => Promise.resolve('<html></html>')
|
|
} as Response)
|
|
const result = await searchWeb.execute({ query: 'test' })
|
|
expect(result).toMatch(/Aucun resultat/)
|
|
})
|
|
|
|
it('should throw when the request fails', async () => {
|
|
vi.mocked(fetch).mockResolvedValue({ ok: false, status: 503 } as Response)
|
|
await expect(searchWeb.execute({ query: 'test' })).rejects.toThrow(/echouee/)
|
|
})
|
|
})
|
|
|
|
describe('get_last_meeting_summary', () => {
|
|
it('should report no session recorded yet', async () => {
|
|
const result = await getLastMeetingSummarySkill.execute({})
|
|
expect(result).toMatch(/Aucune session/)
|
|
})
|
|
|
|
it('should return the last saved meeting summary', async () => {
|
|
saveMeeting('transcript complet', 'resume de la reunion')
|
|
const result = await getLastMeetingSummarySkill.execute({})
|
|
expect(result).toMatch(/resume de la reunion/)
|
|
})
|
|
})
|
|
|
|
describe('extractText()', () => {
|
|
it('should read a plain text file as-is', async () => {
|
|
const filePath = join(tempDir, 'note.txt')
|
|
writeFileSync(filePath, 'Contenu simple')
|
|
const doc = await extractText(filePath)
|
|
expect(doc.text).toBe('Contenu simple')
|
|
expect(doc.truncated).toBe(false)
|
|
})
|
|
|
|
it('should truncate content longer than the max length', async () => {
|
|
const filePath = join(tempDir, 'long.txt')
|
|
writeFileSync(filePath, 'a'.repeat(20000))
|
|
const doc = await extractText(filePath)
|
|
expect(doc.truncated).toBe(true)
|
|
expect(doc.text.length).toBe(12000)
|
|
})
|
|
|
|
it('should throw for an unsupported file extension', async () => {
|
|
const filePath = join(tempDir, 'image.png')
|
|
writeFileSync(filePath, 'binaire')
|
|
await expect(extractText(filePath)).rejects.toThrow(/non supporte/)
|
|
})
|
|
|
|
it('should extract text from a .pdf file via pdf-parse', async () => {
|
|
const filePath = join(tempDir, 'document.pdf')
|
|
writeFileSync(filePath, 'contenu-binaire-simule')
|
|
const doc = await extractText(filePath)
|
|
expect(doc.text).toBe('Texte extrait du PDF')
|
|
})
|
|
|
|
it('should extract text from a .docx file via mammoth', async () => {
|
|
const filePath = join(tempDir, 'document.docx')
|
|
writeFileSync(filePath, 'contenu-binaire-simule')
|
|
const doc = await extractText(filePath)
|
|
expect(doc.text).toBe('Texte extrait du docx')
|
|
})
|
|
})
|