Skip to content

Commit bef3f0d

Browse files
committed
fix: .bat files had Unix-style /dev/null; add CI lint
The previous .bat rewrite accidentally contained '>/dev/null' which cmd.exe treats as a literal file path ('dev\null'), so start.bat would create bogus files instead of suppressing output — it was still broken on Windows. - Rewrite start.bat/stop.bat with '1>/dev/null 2>&1' + CRLF line endings. - Add a Windows CI lint step that rejects any .bat containing non-ASCII bytes, LF-only line endings, or '/dev/null'. - Add an end-to-end 'Run start.bat' CI step so future bat regressions fail in CI instead of on a real Windows box.
1 parent 6e778bd commit bef3f0d

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

.github/workflows/windows-smoke.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ jobs:
2626
shell: pwsh
2727
run: npm ci
2828

29+
- name: Lint .bat launchers
30+
shell: pwsh
31+
run: |
32+
$ErrorActionPreference = "Stop"
33+
$bats = @("start.bat", "stop.bat")
34+
$failed = $false
35+
foreach ($bat in $bats) {
36+
$bytes = [System.IO.File]::ReadAllBytes($bat)
37+
$text = [System.Text.Encoding]::ASCII.GetString($bytes)
38+
39+
# 1. Pure ASCII (no UTF-8 multi-byte sequences that would
40+
# be misread under Chinese Windows code page 936).
41+
foreach ($b in $bytes) {
42+
if ($b -gt 0x7f) {
43+
Write-Error "$bat contains non-ASCII byte 0x$("{0:X2}" -f $b) — cmd.exe on zh-CN will fail to parse it"
44+
$failed = $true
45+
break
46+
}
47+
}
48+
49+
# 2. CRLF line endings — LF-only .bat files misbehave on some
50+
# cmd.exe versions.
51+
if ($text -notmatch "`r`n") {
52+
Write-Error "$bat has no CRLF line endings"
53+
$failed = $true
54+
}
55+
56+
# 3. No Unix-style /dev/null redirection — cmd.exe would create
57+
# an actual file named 'null' under a 'dev' directory.
58+
if ($text -match "/dev/null") {
59+
Write-Error "$bat contains Unix-style '/dev/null' — use 'NUL' instead"
60+
$failed = $true
61+
}
62+
}
63+
if ($failed) { exit 1 }
64+
Write-Host "All .bat files passed ASCII / CRLF / NUL lint."
65+
66+
- name: Run start.bat end-to-end
67+
shell: cmd
68+
run: |
69+
start.bat
70+
71+
- name: Stop agent started by start.bat
72+
shell: pwsh
73+
run: |
74+
$pidFile = "runtime/agent/agent.pid"
75+
if (Test-Path $pidFile) {
76+
$agentPid = (Get-Content $pidFile -Raw).Trim()
77+
try {
78+
Stop-Process -Id $agentPid -Force -ErrorAction Stop
79+
Write-Host "Stopped start.bat agent PID $agentPid"
80+
} catch {
81+
Write-Host "start.bat agent PID $agentPid already gone"
82+
}
83+
Remove-Item -Force -ErrorAction SilentlyContinue $pidFile, "runtime/agent/agent.port"
84+
}
85+
2986
- name: Start agent via start-local-agent.ps1 (foreground)
3087
shell: pwsh
3188
run: |

start.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
cd /d "%~dp0"
66

7-
where pwsh >/dev/null 2>&1
7+
where pwsh 1>NUL 2>&1
88
if %errorlevel% equ 0 (
99
pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\dev\start-local-agent.ps1"
1010
) else (
@@ -14,5 +14,5 @@ if %errorlevel% equ 0 (
1414
if %errorlevel% neq 0 (
1515
echo.
1616
echo Something went wrong. Press any key to close...
17-
pause >/dev/null
17+
pause 1>NUL
1818
)

stop.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
cd /d "%~dp0"
55

6-
where pwsh >/dev/null 2>&1
6+
where pwsh 1>NUL 2>&1
77
if %errorlevel% equ 0 (
88
pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\dev\stop-local-agent.ps1"
99
) else (
@@ -13,5 +13,5 @@ if %errorlevel% equ 0 (
1313
if %errorlevel% neq 0 (
1414
echo.
1515
echo Press any key to close...
16-
pause >/dev/null
16+
pause 1>NUL
1717
)

0 commit comments

Comments
 (0)