diff --git a/TODO.md b/TODO.md index 668b4c9..8ad2dbb 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ # TODO — Local CI/CD System - + > Documento unico di lavoro: roadmap, audit trail dei task completati, e backlog post-v1.0 > con priorità e razionale. Le voci aperte sono raggruppate per area e marcate **P0..P3**: @@ -33,16 +33,16 @@ _Last updated: 2026-05-10 (post Sprint 6 perf: §3.1/§3.6 done)_ | §2 Affidabilità & resilienza | 7 | 0 | tutto done | | §3 Performance & throughput | 2 | 4 | 3.1/3.6 done; 3.2 (7-Zip, dipende §6.6), 3.3/3.4/3.5 backlog | | §4 Osservabilità & manutenzione | 3 | 2 | 4.1/4.3/4.4 done; 4.2/4.5 backlog | -| §5 Qualità codice & test | 3 | 2 | 5.2/5.3/5.4 done; 5.1 (Pester) e 5.5 (type hints) backlog | +| §5 Qualità codice & test | 4 | 1 | 5.1/5.2/5.3/5.4 done; 5.5 (type hints) backlog | | §6 Scalabilità & estensioni | 0 | 6 | Linux VM, composite action, toolchain Tier-1 | | §7 Refactor Deploy ↔ Setup | 4 | 1 | 7.1/7.2/7.3/7.4 done; 7.5 (rinomina) opzionale | | In-VM Git Clone (§3.3) | 0 | 4 | dipende da §6.6 (Git+7-Zip nel template) | | Linux Build VM (§6.1) | 0 | 4 | bozza in `docs/LINUX-TEMPLATE-SETUP.md` | **Prossimi passi consigliati** (vedi anche "Suggerimento di sequencing" in fondo): -1. §5.1 — Pester smoke tests (safety net prima di refactor più profondi). -2. §1.2 — Audit TrustedHosts (1 comando, manuale). -3. §1.6 — Threat model doc in BEST-PRACTICES.md. +1. §1.2 — Audit TrustedHosts (1 comando, manuale — 5 min). +2. §1.6 — Threat model doc in BEST-PRACTICES.md (P2 ma importante). +3. §4.2 — Prometheus textfile metrics (esporre phase durations da benchmark.jsonl). 4. §1.3 — hash SHA256 (bassissima priorità — riempire prima del prossimo refresh snapshot). --- @@ -484,19 +484,16 @@ file:// — utile per debug a colpo d'occhio senza aprire Gitea UI. ## 5. Qualità codice & test -### 5.1 [P1] [ ] Pester smoke tests sugli script -File: nuovo `tests/` directory. +### 5.1 [P1] [x] Pester smoke tests sugli script — COMPLETATO 2026-05-10 +File: [tests/_Common.Tests.ps1](tests/_Common.Tests.ps1), [tests/New-BuildVM.Tests.ps1](tests/New-BuildVM.Tests.ps1), [tests/Remove-BuildVM.Tests.ps1](tests/Remove-BuildVM.Tests.ps1), [tests/Wait-VMReady.Tests.ps1](tests/Wait-VMReady.Tests.ps1). -**Motivazione**: manca un livello di test sotto l'e2e. +Test con fake vmrun `.cmd` (exit code via `%FAKE_VMRUN_EXIT%` env var — nessuna VM reale): +- `_Common.psm1`: `New-CISessionOption` TLS flags, `Resolve-VmrunPath` throw/return, `Invoke-Vmrun` ExitCode/Output/ThrowOnError +- `New-BuildVM.ps1`: throw su template mancante, throw + cleanup su clone fail, formato nome Clone_{JobId}_{timestamp} +- `Remove-BuildVM.ps1`: no-op su VMX mancante, cleanup dir parziale, -WhatIf non distrugge, destroy rimuove dir +- `Wait-VMReady.ps1`: throw su vmrun mancante, throw su timeout, ValidatePattern IP (accetta/rifiuta) -Pester può coprire: -- `New-BuildVM` con vmrun mockato — verifica che il VMX path costruito sia ben formato - per JobId con caratteri speciali. -- `Wait-VMReady` con `Test-WSMan` mockato — verifica timeout, fasi, ritorni. -- `Remove-BuildVM` con `vmrun list` mockato — verifica retry deleteVM. -- Validazione IP regex (§1.4) — table tests. - -Eseguire in CI tramite il runner stesso (workflow `lint.yml` esiste già — espandere). +Eseguire: `Invoke-Pester tests\ -Output Detailed` ### 5.2 [P2] [x] Modulo PowerShell condiviso `scripts/_Common.psm1` — COMPLETATO 2026-05-10 File: [scripts/_Common.psm1](scripts/_Common.psm1). diff --git a/tests/New-BuildVM.Tests.ps1 b/tests/New-BuildVM.Tests.ps1 new file mode 100644 index 0000000..2055f59 --- /dev/null +++ b/tests/New-BuildVM.Tests.ps1 @@ -0,0 +1,102 @@ +#Requires -Version 5.1 +<# +.SYNOPSIS + Pester v5 tests for scripts/New-BuildVM.ps1 +#> + +BeforeAll { + $script:ScriptPath = Join-Path $PSScriptRoot '..\scripts\New-BuildVM.ps1' + $script:CloneBaseDir = Join-Path $env:TEMP "CI-Tests-CloneBase-$PID" + New-Item -ItemType Directory -Path $script:CloneBaseDir -Force | Out-Null + + # Fake vmrun.cmd — exits with %FAKE_VMRUN_EXIT% (default 0) + # On success it also creates the destination VMX so the post-clone Test-Path passes. + $script:FakeVmrun = Join-Path $env:TEMP "fake-vmrun-$PID.cmd" + Set-Content $script:FakeVmrun -Value @' +@echo off +if "%FAKE_VMRUN_EXIT%"=="" ( set _exit=0 ) else ( set _exit=%FAKE_VMRUN_EXIT% ) +if "%_exit%"=="0" ( + REM Create the destination VMX file so the caller's Test-Path check passes. + REM The destination path is the 4th positional arg (after -T ws clone