Files
ForgeBase/Max Avatar/tests/unit/skills.windowsSystemInfo.test.ts
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

119 lines
4.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
const execFileMock = vi.fn(
(
_cmd: string,
_args: string[],
_opts: unknown,
cb?: (err: Error | null, result: unknown) => void
) => {
const callback = typeof _opts === 'function' ? (_opts as typeof cb) : cb
callback?.(null, { stdout: '{}', stderr: '' })
}
)
vi.mock('child_process', () => ({ execFile: execFileMock }))
const { systemStatus } = await import('../../src/main/skills/windows/systemStatus')
const { systemStorage } = await import('../../src/main/skills/windows/systemStorage')
const { checkInternet } = await import('../../src/main/skills/windows/checkInternet')
const { lockScreen } = await import('../../src/main/skills/windows/lockScreen')
const { emptyRecycleBin } = await import('../../src/main/skills/windows/emptyRecycleBin')
function mockStdout(json: unknown): void {
execFileMock.mockImplementation(
(
_cmd: string,
_args: string[],
optsOrCb: unknown,
cb?: (err: Error | null, result: unknown) => void
) => {
const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb
callback?.(null, { stdout: JSON.stringify(json), stderr: '' })
}
)
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('check_battery_and_cpu', () => {
it('should report no battery for a desktop computer', async () => {
mockStdout({ BatteryPercent: null, Charging: null, CpuPercent: 42 })
const result = await systemStatus.execute({})
expect(result).toMatch(/Pas de batterie detectee/)
expect(result).toMatch(/42%/)
})
it('should report battery level and charging state for a laptop', async () => {
mockStdout({ BatteryPercent: 80, Charging: true, CpuPercent: 10 })
const result = await systemStatus.execute({})
expect(result).toMatch(/Batterie a 80%/)
expect(result).toMatch(/en charge/)
})
})
describe('check_storage', () => {
it('should report usage for a single drive', async () => {
mockStdout({ DriveLetter: 'C', SizeGB: 500, FreeGB: 100 })
const result = await systemStorage.execute({})
expect(result).toMatch(/Disque C : 400\.0 Go utilises sur 500 Go \(100 Go libres\)/)
})
it('should report usage for multiple drives', async () => {
mockStdout([
{ DriveLetter: 'C', SizeGB: 500, FreeGB: 100 },
{ DriveLetter: 'D', SizeGB: 1000, FreeGB: 900 }
])
const result = await systemStorage.execute({})
expect(result).toMatch(/Disque C/)
expect(result).toMatch(/Disque D/)
})
})
describe('check_internet_connection', () => {
it('should report a working connection with its local IP', async () => {
mockStdout({ Connected: true, Ip: '192.168.1.10' })
const result = await checkInternet.execute({})
expect(result).toMatch(/Internet fonctionne/)
expect(result).toMatch(/192\.168\.1\.10/)
})
it('should report no connection', async () => {
mockStdout({ Connected: false, Ip: null })
const result = await checkInternet.execute({})
expect(result).toMatch(/Pas de connexion internet/)
})
})
describe('lock_screen', () => {
it('should invoke the lock command and confirm immediately', async () => {
const result = await lockScreen.execute({})
expect(result).toBe('Ecran verrouille.')
})
})
describe('empty_recycle_bin', () => {
it('should confirm the recycle bin was emptied', async () => {
mockStdout({})
const result = await emptyRecycleBin.execute({})
expect(result).toBe('Corbeille videe.')
})
it('should still confirm even if the underlying command fails (bin already empty)', async () => {
execFileMock.mockImplementation(
(
_cmd: string,
_args: string[],
optsOrCb: unknown,
cb?: (err: Error | null, result: unknown) => void
) => {
const callback = typeof optsOrCb === 'function' ? (optsOrCb as typeof cb) : cb
callback?.(new Error('already empty'), null)
}
)
const result = await emptyRecycleBin.execute({})
expect(result).toBe('Corbeille videe.')
})
})