From 6f6e829ad52b32a786db2438d57fea2ddceccf99 Mon Sep 17 00:00:00 2001 From: jeanotx32 Date: Tue, 11 Aug 2026 17:25:28 +0200 Subject: [PATCH] Fix : windows verify crash 1 --- .gitea/workflows/release.yml | 14 ++++++++++---- deploy/install-agent.ps1 | 5 ++++- packages/agent/src/config.ts | 5 ++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 5236a11..f222519 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -164,8 +164,11 @@ jobs: # Le script d'installation Windows n'est exécutable que sur Windows : # ce contrôle de syntaxe est la seule barrière avant qu'il n'atterrisse # sur une VM de production. + # shell: powershell (Windows PowerShell 5.1) et non pwsh : PowerShell 7 + # n'est pas garanti sur un runner Windows, alors que 5.1 est toujours là. + # C'est aussi la version que les VM d'enregistrement exécuteront. - name: Valider la syntaxe du script d'installation - shell: pwsh + shell: powershell run: | $errors = $null [System.Management.Automation.Language.Parser]::ParseFile( @@ -177,17 +180,20 @@ jobs: Write-Host 'install-agent.ps1 : syntaxe valide.' - name: Récupérer le bundle publié - shell: pwsh + shell: powershell run: | $ErrorActionPreference = 'Stop' + # PowerShell 5.1 ne négocie pas TLS 1.2 par défaut sur toutes les éditions. + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $url = "$env:GITHUB_SERVER_URL/api/packages/${{ github.repository_owner }}/generic/$env:PACKAGE_NAME/${{ needs.build.outputs.version }}/agent.cjs" $pair = "${{ github.repository_owner }}:${{ secrets.REGISTERYKEY }}" $auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair)) - Invoke-WebRequest -Uri $url -Headers @{ Authorization = "Basic $auth" } -OutFile agent.cjs + Invoke-WebRequest -Uri $url -Headers @{ Authorization = "Basic $auth" } ` + -OutFile agent.cjs -UseBasicParsing Write-Host "Bundle récupéré : $((Get-Item agent.cjs).Length) octets" - name: Exécuter le diagnostic - shell: pwsh + shell: powershell env: AGENT_TOKEN: ci-smoke-test SERVER_URL: ws://127.0.0.1:1/ws/agent diff --git a/deploy/install-agent.ps1 b/deploy/install-agent.ps1 index 7098a34..35e42e7 100644 --- a/deploy/install-agent.ps1 +++ b/deploy/install-agent.ps1 @@ -114,7 +114,10 @@ if ($isUpgrade) { name = $Name obs = [ordered]@{ host = $ObsHost; port = $ObsPort; password = $ObsPassword } } - $config | ConvertTo-Json -Depth 5 | Set-Content -Path $configFile -Encoding UTF8 + # Surtout pas Set-Content -Encoding UTF8 : sous PowerShell 5.1 il préfixe un + # BOM, et JSON.parse côté Node refuse le fichier. + $json = $config | ConvertTo-Json -Depth 5 + [System.IO.File]::WriteAllText($configFile, $json, (New-Object System.Text.UTF8Encoding($false))) Info "Configuration écrite dans $configFile" } diff --git a/packages/agent/src/config.ts b/packages/agent/src/config.ts index 46a5f70..5e4394e 100644 --- a/packages/agent/src/config.ts +++ b/packages/agent/src/config.ts @@ -26,7 +26,10 @@ const CONFIG_PATH = path.resolve( function readFile(): Partial { if (!fs.existsSync(CONFIG_PATH)) return {}; try { - return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')) as Partial; + // Les éditeurs Windows (et Set-Content -Encoding UTF8) préfixent un BOM que + // JSON.parse rejette. + const raw = fs.readFileSync(CONFIG_PATH, 'utf8').replace(/^\uFEFF/, ''); + return JSON.parse(raw) as Partial; } catch (err) { console.error(`Configuration illisible (${CONFIG_PATH}) :`, err); return {};