Files
ForgeBase/Max Avatar/tests/unit/skills.index.test.ts
T
williamandClaude Sonnet 5 1c2f002eb3 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>
2026-10-31 12:15:30 +01:00

80 lines
2.8 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import { mkdtempSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-skillsindex-test-'))
vi.mock('electron', () => ({
app: { getPath: () => tempDir },
shell: { openPath: vi.fn(), openExternal: vi.fn() },
clipboard: { readText: vi.fn(), writeText: vi.fn() },
Notification: class {
show = vi.fn()
},
desktopCapturer: { getSources: vi.fn(async () => []) },
screen: { getPrimaryDisplay: () => ({ size: { width: 0, height: 0 } }) },
BrowserWindow: class {
static getAllWindows(): unknown[] {
return []
}
on = vi.fn()
webContents = { on: vi.fn(), send: vi.fn(), isLoading: () => false, once: vi.fn() }
loadURL = vi.fn()
loadFile = vi.fn()
setAlwaysOnTop = vi.fn()
maximize = vi.fn()
},
ipcMain: { on: vi.fn(), handle: vi.fn() },
session: { defaultSession: { webRequest: { onHeadersReceived: vi.fn() } } }
}))
// @electron-toolkit/utils fait lui-meme `require('electron')` en interne : hors runtime Electron,
// le vrai paquet 'electron' exporte juste une chaine (chemin du binaire), ce qui casse l'interop
// ESM/CJS pour tout import nomme ulterieur de 'electron' dans le graphe de modules. On le mocke
// directement pour ne jamais toucher le vrai paquet.
vi.mock('@electron-toolkit/utils', () => ({
is: { dev: false },
electronApp: { setAppUserModelId: vi.fn() },
optimizer: { watchWindowShortcuts: vi.fn() }
}))
const { loadSkills, getSkillsForMode, findSkill } = await import('../../src/main/skills')
describe('loadSkills()', () => {
it('should load a non-empty list of skills without throwing', () => {
const skills = loadSkills()
expect(skills.length).toBeGreaterThan(20)
})
it('should not register the same skill name twice', () => {
const names = loadSkills().map((s) => s.name)
expect(new Set(names).size).toBe(names.length)
})
})
describe('getSkillsForMode()', () => {
it('should include a coach-only skill in coach mode but not in basic mode', () => {
const coachSkills = getSkillsForMode('coach').map((s) => s.name)
const basicSkills = getSkillsForMode('basic').map((s) => s.name)
expect(coachSkills).toContain('draw_schema')
expect(basicSkills).not.toContain('draw_schema')
})
it('should include a transversal skill in every mode', () => {
for (const mode of ['basic', 'coach', 'assistant'] as const) {
expect(getSkillsForMode(mode).map((s) => s.name)).toContain('search_web')
}
})
})
describe('findSkill()', () => {
it('should find a registered skill by name', () => {
expect(findSkill('search_web')?.name).toBe('search_web')
})
it('should return undefined for an unknown skill name', () => {
expect(findSkill('inexistant')).toBeUndefined()
})
})