From c9bf58bc352aa1c38742405184f15464a5b59464 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 26 Aug 2025 08:19:33 +0200 Subject: [PATCH] chore(release): v0.1.2 + tests WASM (Windows), script runner, doc --- CHANGELOG.md | 9 +++++ Cargo.toml | 2 +- docs/TESTING.md | 27 ++++++++++---- scripts/run-wasm-tests.ps1 | 72 +++++++++++++++++++++++++++++++------- 4 files changed, 90 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cca5a5..1be58f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,15 @@ et ce projet adhère au [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Guide de contribution et code de conduite - Scripts de maintenance et nettoyage automatique +## [0.1.2] - 2025-08-26 + +### Changed +- Testing: renforcement de la procédure WASM (Windows) dans `docs/TESTING.md` (LLVM/Clang, variables d’environnement, runner wasm-bindgen, script `scripts/run-wasm-tests.ps1`). +- Build: version `sdk_client` bump à 0.1.2. + +### Fixed +- Stabilisation de l’exécution `wasm-pack test` via script (gestion cache `.wasm-pack`, téléchargement runner, fallback Node). + ### Changed - Documentation `sdk_client` alignée au code: API, Architecture, Usage, Testing, Security Audit, README, INDEX - Réorganisation complète de la structure des tests diff --git a/Cargo.toml b/Cargo.toml index 5157ab1..9a6eee0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sdk_client" -version = "0.1.1" +version = "0.1.2" edition = "2021" [lib] diff --git a/docs/TESTING.md b/docs/TESTING.md index 20abd65..a735bab 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -23,14 +23,27 @@ Répertoires fournis: Exécution standard: unité, intégration, puis front WASM. Les seuils et critères sont définis ci‑dessous. -### Prérequis tests WASM (headless) +### Prérequis tests WASM (Windows) -- Outil: `wasm-pack` installé (via `cargo install wasm-pack`). -- Navigateurs: Chrome et/ou Firefox installés en local (mode headless supporté). -- Windows: installer LLVM/Clang et définir le compilateur C pour la cible WASM: - - Installer LLVM (ex. via `winget install -e --id LLVM.LLVM --accept-package-agreements --accept-source-agreements --silent`). - - Définir le compilateur dans la session: `CC="C:\\Program Files\\LLVM\\bin\\clang.exe"` et `CC_wasm32_unknown_unknown` identique. - - Lancer ensuite: `wasm-pack test --headless --chrome` et/ou `--firefox`. +- Outils: `wasm-pack` et LLVM/Clang installés. + - LLVM via `winget install -e --id LLVM.LLVM --accept-package-agreements --accept-source-agreements --silent`. + - Variables d’environnement (utilisateur) à définir une seule fois, puis ouvrir un nouveau PowerShell: + - `CC = C:\\Program Files\\LLVM\\bin\\clang.exe` + - `TARGET_CC = C:\\Program Files\\LLVM\\bin\\clang.exe` + - `CC_wasm32-unknown-unknown = C:\\Program Files\\LLVM\\bin\\clang.exe` + - `AR_wasm32-unknown-unknown = C:\\Program Files\\LLVM\\bin\\llvm-ar.exe` + - `NM_wasm32-unknown-unknown = C:\\Program Files\\LLVM\\bin\\llvm-nm.exe` + +- Runner wasm-bindgen: + - Le script `scripts/run-wasm-tests.ps1` télécharge automatiquement `wasm-bindgen` (0.2.100) si absent et exporte `WASM_BINDGEN_TEST_RUNNER`. + - En cas d’échec de téléchargement automatique, placer manuellement le binaire `wasm-bindgen-test-runner.exe` dans `C:\\Users\\\\AppData\\Local\\.wasm-pack\\wasm-bindgen-\\`. + +### Exécution des tests WASM + +- Automatisé: `./scripts/run-wasm-tests.ps1` + - Tente Node en priorité, puis navigateurs si nécessaire. + - Purge/recale le cache `.wasm-pack` si requis. +- Manuel: `wasm-pack test --node` (ou `--headless --chrome`, `--headless --firefox`). Options disponibles : - `--verbose` : Mode verbose avec affichage détaillé diff --git a/scripts/run-wasm-tests.ps1 b/scripts/run-wasm-tests.ps1 index 70fc07c..5420c58 100644 --- a/scripts/run-wasm-tests.ps1 +++ b/scripts/run-wasm-tests.ps1 @@ -42,17 +42,65 @@ function Invoke-WasmPackTests { $runnerSet = $false function Ensure-WasmBindgenRunner { param() - $runner = Join-Path "$env:USERPROFILE\.cargo\bin" "wasm-bindgen-test-runner.exe" - if (-not (Test-Path $runner)) { - Write-Host "Installing wasm-bindgen-test-cli..." -ForegroundColor Yellow - cargo install wasm-bindgen-test-cli --locked --force | Out-Null + # Cherche un runner dans le cache wasm-pack + $localWp = Join-Path $env:LOCALAPPDATA ".wasm-pack" + $cachedRunner = $null + if (Test-Path $localWp) { + $candidates = Get-ChildItem -Path $localWp -Recurse -Filter "wasm-bindgen-test-runner.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($candidates) { $cachedRunner = $candidates.FullName } } - if (Test-Path $runner) { + + if (-not $cachedRunner) { + Write-Host "Aucun runner trouvé. Téléchargement de l’archive officielle (tar.gz) pour Windows..." -ForegroundColor Yellow + $wbgVersion = "0.2.100" + $arch = "x86_64-pc-windows-msvc" + $tarName = "wasm-bindgen-$wbgVersion-$arch.tar.gz" + $downloadUrl = "https://github.com/rustwasm/wasm-bindgen/releases/download/$wbgVersion/$tarName" + $destParent = $localWp + $tarPath = Join-Path $env:TEMP $tarName + try { + if (-not (Test-Path $destParent)) { New-Item -ItemType Directory -Force -Path $destParent | Out-Null } + Invoke-WebRequest -Uri $downloadUrl -OutFile $tarPath -UseBasicParsing -ErrorAction Stop + Push-Location $destParent + tar -xzf $tarPath + Pop-Location + } catch { + Write-Warning "Échec du téléchargement/extraction du runner: $($_.Exception.Message)" + } finally { + if (Test-Path $tarPath) { Remove-Item -Force $tarPath } + } + # Recherche récursive du binaire extrait + $found = Get-ChildItem -Path (Join-Path $destParent "wasm-bindgen-$wbgVersion-$arch") -Recurse -Filter "wasm-bindgen-test-runner.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($found) { $cachedRunner = $found.FullName } + } + + if ($cachedRunner -and (Test-Path $cachedRunner)) { $script:runnerSet = $true - $env:WASM_BINDGEN_TEST_RUNNER = $runner - } else { - Write-Warning "wasm-bindgen-test-runner introuvable après installation. PATH: $env:PATH" + $env:WASM_BINDGEN_TEST_RUNNER = $cachedRunner + $runnerDir = Split-Path $cachedRunner -Parent + if ($env:PATH -notlike "*$runnerDir*") { $env:PATH = "$runnerDir;$env:PATH" } + # Force cargo/wasm-pack à utiliser ce runner pour wasm32-unknown-unknown + [System.Environment]::SetEnvironmentVariable('CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER', $cachedRunner, 'Process') + # Copie de secours dans les dossiers cache wasm-pack attendus (hashés) + try { + $wpDirs = Get-ChildItem -Path $localWp -Directory -Filter "wasm-bindgen-*" -ErrorAction SilentlyContinue + foreach ($d in $wpDirs) { + $destRunner = Join-Path $d.FullName "wasm-bindgen-test-runner.exe" + if (-not (Test-Path $destRunner)) { + Copy-Item -Force $cachedRunner $destRunner -ErrorAction SilentlyContinue + } + $wbExeSrc = Join-Path $runnerDir "wasm-bindgen.exe" + $wbExeDst = Join-Path $d.FullName "wasm-bindgen.exe" + if ((Test-Path $wbExeSrc) -and -not (Test-Path $wbExeDst)) { + Copy-Item -Force $wbExeSrc $wbExeDst -ErrorAction SilentlyContinue + } + } + } catch {} + Write-Host "WASM_BINDGEN_TEST_RUNNER défini vers: $cachedRunner" -ForegroundColor Green + return } + + Write-Warning "wasm-bindgen-test-runner introuvable. wasm-pack tentera de le télécharger lors de l'exécution des tests." } $scriptsDir = Split-Path -Parent $MyInvocation.MyCommand.Path @@ -61,12 +109,12 @@ Push-Location $repoRoot try { Set-WasmToolchainEnv Ensure-WasmBindgenRunner - cargo clean --target wasm32-unknown-unknown | Out-Null try { - Invoke-WasmPackTests -Chrome -Firefox - } catch { - Write-Warning "Tests headless navigateur échoués, tentative avec Node." + # D'abord Node (plus robuste sur Windows) Invoke-WasmPackTests -Node + } catch { + Write-Warning "Tests Node échoués, tentative avec navigateurs headless." + Invoke-WasmPackTests -Chrome -Firefox } } finally { Pop-Location