191 lines
9.9 KiB
PowerShell
191 lines
9.9 KiB
PowerShell
|
|
# =============================================================================
|
|||
|
|
# test_syncVisualStudioCode.ps1 - synchronizacja Kilo Code (Windows).
|
|||
|
|
#
|
|||
|
|
# Kilo rozni sie od OpenCode w dwoch miejscach i oba trzeba udowodnic:
|
|||
|
|
# - "temperature" jest FLAGA mozliwosci, nie wartoscia liczbowa
|
|||
|
|
# - blok indeksowania kodu pojawia sie WYLACZNIE dla kluczy z uprawnieniem
|
|||
|
|
# i zawiera klucz TEGO klienta (nie rejestr wszystkich)
|
|||
|
|
# =============================================================================
|
|||
|
|
. "$PSScriptRoot\..\lib\testHelper.ps1"
|
|||
|
|
|
|||
|
|
Initialize-Sandbox
|
|||
|
|
$sandbox = $script:Sandbox
|
|||
|
|
$syncPath = Join-Path $sandbox 'bundle\syncVisualStudioCode.ps1'
|
|||
|
|
$port = 7892
|
|||
|
|
$key = 'tioxyai_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
|||
|
|
$server = "http://127.0.0.1:$port"
|
|||
|
|
$mockPath = Join-Path $script:TestsRoot 'mocks\mockProxy.py'
|
|||
|
|
$configFile = Join-Path $sandbox 'home\kilo.jsonc'
|
|||
|
|
|
|||
|
|
function Invoke-Sync {
|
|||
|
|
param([switch]$KeepHome)
|
|||
|
|
if (-not $KeepHome) { $null = New-SandboxHome }
|
|||
|
|
$sandboxHome = Join-Path $sandbox 'home'
|
|||
|
|
# INSTALL_KILO=0: test nie instaluje wtyczek w prawdziwym VS Code.
|
|||
|
|
$childEnv = @{ 'USERPROFILE' = $sandboxHome; 'SYNC_ANYWAY' = '1'; 'INSTALL_KILO' = '0' }
|
|||
|
|
$command = "powershell -NoProfile -ExecutionPolicy Bypass -File `"$syncPath`" " +
|
|||
|
|
"-Server `"$server`" -Key `"$key`" -ConfigFile `"$configFile`" -NoInstall"
|
|||
|
|
return Invoke-Child -Command $command -Environment $childEnv
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Zapis konfiguracji Kilo'
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'ok'; ALLOW_EMBED = '1' }
|
|||
|
|
try {
|
|||
|
|
$result = Invoke-Sync
|
|||
|
|
Assert-Equal 10 $result.ExitCode 'kod wyjscia 10 (konfiguracja zmieniona)'
|
|||
|
|
Assert-FileExists $configFile 'plik kilo.jsonc powstal'
|
|||
|
|
Assert-ValidJson $configFile 'zapisany plik jest poprawnym JSON-em'
|
|||
|
|
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.name' 'TioxyAi vLLM' 'provider vLLM'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-llamacpp.name' 'TioxyAi llamacpp' 'provider llamacpp'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].name' 'Qwen3.8-27B' `
|
|||
|
|
'nazwa modelu bez powtorzonego dopisku silnika (niesie go provider)'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].id' 'Qwen3.8-27B' `
|
|||
|
|
'identyfikator modelu pozostaje surowy'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].limit.context' 60127 'kontekst z serwera'
|
|||
|
|
|
|||
|
|
# Kilo ustawia sampling per tryb w interfejsie - liczba w tym polu bylaby bledem.
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].temperature' 'True' `
|
|||
|
|
'temperatura zapisana jako flaga, nie wartosc'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].attachment' 'True' 'obsluga obrazow'
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.models[Qwen3.8-27B].tool_call' 'True' 'wywolywanie narzedzi'
|
|||
|
|
|
|||
|
|
Assert-JsonPath $configFile 'indexing.provider' 'openai' 'blok indeksowania kodu obecny'
|
|||
|
|
Assert-JsonPath $configFile 'indexing.openai.apiKey' 'sk-test-embedding' 'klucz indeksowania z serwera'
|
|||
|
|
|
|||
|
|
# Kilo czyta blok indexing przy starcie - musi stac zaraz za $schema.
|
|||
|
|
$keys = @((ConvertFrom-Jsonc -Text (Get-Content -LiteralPath $configFile -Raw)).PSObject.Properties.Name)
|
|||
|
|
Assert-Equal '$schema' $keys[0] 'pierwszy klucz to $schema'
|
|||
|
|
Assert-Equal 'indexing' $keys[1] 'indeksowanie tuz za $schema'
|
|||
|
|
} finally { Stop-Mock $mock }
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Bez uprawnienia do indeksowania - brak bloku indexing'
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'ok'; ALLOW_EMBED = '0' }
|
|||
|
|
try {
|
|||
|
|
$result = Invoke-Sync
|
|||
|
|
Assert-Equal 10 $result.ExitCode 'konfiguracja zapisana'
|
|||
|
|
Assert-True ($null -eq (Get-JsonPath $configFile 'indexing')) 'bloku indeksowania nie ma'
|
|||
|
|
Assert-Contains $result.All 'brak uprawnienia' 'podsumowanie mowi o braku uprawnienia'
|
|||
|
|
} finally { Stop-Mock $mock }
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Brak modeli - konfiguracja NIE jest ruszana'
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'ok' }
|
|||
|
|
try { $null = Invoke-Sync } finally { Stop-Mock $mock }
|
|||
|
|
$snapshot = Get-Content -LiteralPath $configFile -Raw
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'brak-modeli' }
|
|||
|
|
try {
|
|||
|
|
$result = Invoke-Sync -KeepHome
|
|||
|
|
Assert-Equal 0 $result.ExitCode 'kod wyjscia 0 (bez zmian)'
|
|||
|
|
Assert-Equal $snapshot (Get-Content -LiteralPath $configFile -Raw) 'poprzednia konfiguracja nietknieta'
|
|||
|
|
} finally { Stop-Mock $mock }
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Uszkodzona odpowiedz serwera - konfiguracja NIE jest ruszana'
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'uszkodzone-ustawienia' }
|
|||
|
|
try {
|
|||
|
|
$result = Invoke-Sync -KeepHome
|
|||
|
|
Assert-Equal 1 $result.ExitCode 'kod wyjscia 1 (blad)'
|
|||
|
|
Assert-Equal $snapshot (Get-Content -LiteralPath $configFile -Raw) 'poprzednia konfiguracja nietknieta'
|
|||
|
|
} finally { Stop-Mock $mock }
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Kopia zapasowa i odbudowa od zera'
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'ok' }
|
|||
|
|
try {
|
|||
|
|
# Wpis po nieistniejacym juz silniku - odbudowa od zera musi go usunac.
|
|||
|
|
$stale = ConvertFrom-Jsonc -Text (Get-Content -LiteralPath $configFile -Raw)
|
|||
|
|
$stale | Add-Member NoteProperty 'stary-provider' ([pscustomobject]@{ name = 'Nieistniejacy' }) -Force
|
|||
|
|
Set-Content -LiteralPath $configFile -Value ($stale | ConvertTo-Json -Depth 20) -Encoding UTF8
|
|||
|
|
|
|||
|
|
$result = Invoke-Sync -KeepHome
|
|||
|
|
Assert-Equal 10 $result.ExitCode 'konfiguracja zapisana'
|
|||
|
|
Assert-NotContains (Get-Content -LiteralPath $configFile -Raw) 'stary-provider' `
|
|||
|
|
'wpis po nieistniejacym silniku zniknal'
|
|||
|
|
$backups = @(Get-ChildItem -Path "$configFile.bak.*" -ErrorAction SilentlyContinue)
|
|||
|
|
Assert-True ($backups.Count -ge 1) 'powstala kopia zapasowa'
|
|||
|
|
Assert-True ($backups.Count -le 3) 'stare kopie sa sprzatane'
|
|||
|
|
} finally { Stop-Mock $mock }
|
|||
|
|
|
|||
|
|
# =============================================================================
|
|||
|
|
Start-Test 'Host: zdalny komputer z modelami jako provider i subagent'
|
|||
|
|
|
|||
|
|
# Scenariusz z zycia: na hoscie dziala proxy (serwer na localhost = rola hosta),
|
|||
|
|
# a w sieci stoi drugi komputer z LM Studio (tu udaje go atrapa). Skrypt ma
|
|||
|
|
# dopisac jego model jako provider "mac" i jako subagenta.
|
|||
|
|
$portZdalny = 18236
|
|||
|
|
$mockLmsPath = Join-Path $script:TestsRoot 'mocks\mockLmStudio.py'
|
|||
|
|
$pythonBin = $null
|
|||
|
|
foreach ($kandydat in @('python', 'python3', 'py')) {
|
|||
|
|
$cmd = Get-Command $kandydat -ErrorAction SilentlyContinue
|
|||
|
|
if (-not $cmd) { continue }
|
|||
|
|
$probe = & $cmd.Source -c "print('ok')" 2>$null
|
|||
|
|
if ($probe -eq 'ok') { $pythonBin = $cmd.Source; break }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (-not $pythonBin) {
|
|||
|
|
Assert-True $true 'POMINIETE - brak dzialajacego Pythona do atrapy'
|
|||
|
|
} else {
|
|||
|
|
$env:SCENARIUSZ = 'lmstudio'
|
|||
|
|
$env:PORT = "$portZdalny"
|
|||
|
|
$procLms = Start-Process -FilePath $pythonBin -ArgumentList $mockLmsPath `
|
|||
|
|
-PassThru -WindowStyle Hidden
|
|||
|
|
for ($i = 0; $i -lt 50; $i++) {
|
|||
|
|
try {
|
|||
|
|
Invoke-RestMethod -Uri "http://127.0.0.1:$portZdalny/v1/models" -TimeoutSec 1 | Out-Null
|
|||
|
|
break
|
|||
|
|
} catch { Start-Sleep -Milliseconds 200 }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$mock = Start-Mock -Script $mockPath -Port $port -Environment @{ PORT = $port; KEY = $key; SCENARIO = 'ok' }
|
|||
|
|
try {
|
|||
|
|
$null = New-SandboxHome
|
|||
|
|
$sandboxHome = Join-Path $sandbox 'home'
|
|||
|
|
$childEnv = @{
|
|||
|
|
'USERPROFILE' = $sandboxHome
|
|||
|
|
'SYNC_ANYWAY' = '1'
|
|||
|
|
'INSTALL_KILO' = '0'
|
|||
|
|
# Lista kandydatow: najpierw martwy adres, potem atrapa - jak
|
|||
|
|
# w prawdziwym skanowaniu LAN/VPN.
|
|||
|
|
'REMOTE_LLM_SCAN' = "127.0.0.1:19,127.0.0.1:$portZdalny"
|
|||
|
|
'REMOTE_LLM_NAME' = 'mac'
|
|||
|
|
}
|
|||
|
|
$command = "powershell -NoProfile -ExecutionPolicy Bypass -File `"$syncPath`" " +
|
|||
|
|
"-Server `"$server`" -Key `"$key`" -ConfigFile `"$configFile`" -NoInstall"
|
|||
|
|
$result = Invoke-Child -Command $command -Environment $childEnv
|
|||
|
|
|
|||
|
|
Assert-Equal 10 $result.ExitCode 'kod wyjscia 10 (konfiguracja zmieniona)'
|
|||
|
|
Assert-Contains $result.All 'Zdalny komputer odpowiada' 'skrypt melduje znalezienie komputera'
|
|||
|
|
|
|||
|
|
# Provider zdalny w kilo.jsonc - ze stala nazwa i adresem z wykrycia.
|
|||
|
|
Assert-JsonPath $configFile 'provider.mac.options.baseURL' "http://127.0.0.1:$portZdalny/v1" `
|
|||
|
|
'baseURL providera zdalnego'
|
|||
|
|
Assert-JsonPath $configFile 'provider.mac.models[qwen3.8-27b-instruct].limit.context' 32768 `
|
|||
|
|
'kontekst modelu zdalnego'
|
|||
|
|
# Modele proxy nadal obecne - blok zdalnych niczego nie nadpisal.
|
|||
|
|
Assert-JsonPath $configFile 'provider.tioxyai-vllm.name' 'TioxyAi vLLM' 'providery z proxy zostaly'
|
|||
|
|
|
|||
|
|
# Subagent - plik agenta wskazujacy model zdalny. Katalog globalny to
|
|||
|
|
# ~/.config/kilo/agents (patrz Get-KiloAgentDir), a USERPROFILE w tym
|
|||
|
|
# tescie wskazuje na sandboxHome.
|
|||
|
|
$plikSub = Join-Path $sandboxHome '.config\kilo\agents\tioxyai-sub-mac-qwen3.8-27b-instruct.md'
|
|||
|
|
Assert-FileExists $plikSub 'plik subagenta powstal'
|
|||
|
|
$trescSub = Get-Content -LiteralPath $plikSub -Raw
|
|||
|
|
Assert-Contains $trescSub 'mode: subagent' 'subagent w trybie subagenta'
|
|||
|
|
Assert-Contains $trescSub 'model: mac/qwen3.8-27b-instruct' 'subagent wskazuje model zdalny'
|
|||
|
|
} finally {
|
|||
|
|
Stop-Mock $mock
|
|||
|
|
Stop-Process -Id $procLms.Id -Force -ErrorAction SilentlyContinue
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
exit (Get-SuiteSummary 'test_syncVisualStudioCode')
|