Files
ForgeBase/tests/unit/skills.windowsSystemInfo.test.ts
T
williamandClaude Sonnet 5 e9690a49f9
CI / quality (push) Failing after 6m22s
feat: add CI/CD, code quality, testing and security hardening
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>
2026-10-29 09:05:21 +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.')
})
})