Files
kompas3d-mcp/tools/tests/Launcher.Tests.ps1
T

36 lines
2.2 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
BeforeAll {
$script:Launcher = Join-Path $PSScriptRoot '..' '..' 'plugin' 'scripts' 'launch-kompas-mcp.ps1'
}
Describe 'launch-kompas-mcp.ps1' {
It 'не сорит в stdout: наружу идёт только вывод сервера' {
$env:KOMPAS_MCP_EXE = $env:ComSpec
try {
$out = & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $script:Launcher /c echo PONG
($out | Where-Object { $_.Trim().Length -gt 0 }) -join "`n" | Should -Be 'PONG'
} finally { Remove-Item Env:\KOMPAS_MCP_EXE -ErrorAction SilentlyContinue }
}
It 'пробрасывает код возврата сервера' {
$env:KOMPAS_MCP_EXE = $env:ComSpec
try {
& powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $script:Launcher /c exit 42 | Out-Null
$LASTEXITCODE | Should -Be 42
} finally { Remove-Item Env:\KOMPAS_MCP_EXE -ErrorAction SilentlyContinue }
}
It 'падает с кодом 1 и сообщением в stderr, когда путь из KOMPAS_MCP_EXE не существует' {
$env:KOMPAS_MCP_EXE = 'C:\нет\такого\kompas-mcp.exe'
try {
# Примечание: "2>&1 1>$null" — стандартная идиома для изоляции stderr у cmdlet'ов,
# но для внешнего процесса (powershell.exe) PowerShell разрешает "1>$null" раньше
# слияния "2>&1", и объединённый поток тоже уходит в NUL (проверено эмпирически:
# $stderr.Count == 0 при обеих раскладках операторов). В этом сценарии скрипт падает
# до вызова сервера и ничего не пишет в stdout, поэтому достаточно "2>&1" без null-редиректа.
$stderr = & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $script:Launcher 2>&1
$LASTEXITCODE | Should -Be 1
($stderr | Out-String) | Should -Match 'kompas-mcp launcher'
} finally { Remove-Item Env:\KOMPAS_MCP_EXE -ErrorAction SilentlyContinue }
}
}