diff --git a/install.cmd b/install.cmd index 32b4ebb..669fb9c 100644 --- a/install.cmd +++ b/install.cmd @@ -59,8 +59,8 @@ goto :setup :download_zip echo [2/4] Downloading archive (git not available or clone failed)... rem PowerShell does the work: no curl/tar dependency on older Windows. -rem Проверяем, что скачался именно архив: сервер, требующий входа, отдаёт -rem HTML-страницу логина с кодом 200, и распаковка падала бы невнятно. +rem Make sure we actually got an archive: a server that requires signing in +rem answers with an HTML login page, and unpacking would fail confusingly. powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$ErrorActionPreference='Stop';" ^ "$url='%REPO_WEB%/archive/%BRANCH%.zip';" ^ @@ -139,26 +139,32 @@ set OLLAMA_ADDR= set /p OLLAMA_ADDR="Ollama URL [http://localhost:11434]: " if "%OLLAMA_ADDR%"=="" set OLLAMA_ADDR=http://localhost:11434 -rem Локальный конфиг делаем из образца: рядом с адресом Ollama человек увидит -rem и остальные настройки с пояснениями, а не одну голую строку. -if exist ".env" ( - echo .env already exists - left as is. Edit it by hand if needed. -) else ( - rem -Encoding UTF8 обязателен: без него PowerShell 5.1 читает файл в - rem системной кодировке, и русские пояснения превращаются в кракозябры. - powershell -NoProfile -Command ^ - "$src = if (Test-Path '.env.example') { Get-Content '.env.example' -Encoding UTF8 } else { @('OLLAMA_HOST=') };" ^ - "$out = $src -replace '^\s*#?\s*OLLAMA_HOST=.*', 'OLLAMA_HOST=%OLLAMA_ADDR%';" ^ - "if (-not ($out -match '^OLLAMA_HOST=')) { $out += 'OLLAMA_HOST=%OLLAMA_ADDR%' }" ^ - "Set-Content -Path '.env' -Value $out -Encoding UTF8" - if errorlevel 1 ( - > .env echo OLLAMA_HOST=%OLLAMA_ADDR% - ) - echo Saved to .env ^(OLLAMA_HOST=%OLLAMA_ADDR%^) -) +rem Build the local config from the example file, so the user sees the other +rem settings with explanations next to the Ollama address. +rem +rem Done with labels, not an if/else block: cmd mis-parses a block that holds +rem rem-lines and a caret-continued PowerShell call, and reports only +rem "The syntax of the command is incorrect". +if exist ".env" goto :env_exists + +rem -Encoding UTF8 is required: without it PowerShell 5.1 reads the file in the +rem system codepage and the Russian comments turn into mojibake. +powershell -NoProfile -Command ^ + "$src = if (Test-Path '.env.example') { Get-Content '.env.example' -Encoding UTF8 } else { @('OLLAMA_HOST=') };" ^ + "$out = $src -replace '^\s*#?\s*OLLAMA_HOST=.*', 'OLLAMA_HOST=%OLLAMA_ADDR%';" ^ + "if (-not ($out -match '^OLLAMA_HOST=')) { $out += 'OLLAMA_HOST=%OLLAMA_ADDR%' }" ^ + "Set-Content -Path '.env' -Value $out -Encoding UTF8" +if not exist ".env" echo OLLAMA_HOST=%OLLAMA_ADDR%>.env +echo Saved to .env: OLLAMA_HOST=%OLLAMA_ADDR% +goto :env_done + +:env_exists +echo .env already exists - left as is. Edit it by hand if needed. + +:env_done rem Check whether Ollama actually answers, and report in plain language. -venv\Scripts\python.exe -c "from hlamingo import ollama, config; ok=ollama.check(); print((' Ollama ' + config.OLLAMA_HOST + (' отвечает.' if ok else ' НЕ отвечает — приложение будет работать, но без разбора фраз и поиска по смыслу.')))" +venv\Scripts\python.exe -c "from hlamingo import ollama, config; print(' Ollama ' + config.OLLAMA_HOST + (' otvechaet.' if ollama.check() else ' NE otvechaet - prilozhenie zapustitsya, no bez razbora fraz.'))" echo. echo ======================================== @@ -181,8 +187,10 @@ echo. set RUNNOW= set /p RUNNOW="Start it now? [Y/n]: " if /i "%RUNNOW%"=="n" goto :end +rem Full path, not a bare name: depending on the shell that launched the +rem installer, a relative .cmd name may not resolve. pushd "%TARGET%" -call start.cmd +call "%CD%\start.cmd" popd :end diff --git a/tests/test_all.py b/tests/test_all.py index ac8872c..758548d 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -177,6 +177,20 @@ config.DB_FILE.write_text("{ битый json", encoding="utf-8") r.check("битая база не роняет", c.get("/api/tree").status_code == 200) r.check("пустой ввод не роняет", "reply" in j("POST", "/api/say", text=" ")) +print("\n== Батники: только ASCII ==") +# cmd.exe читает .cmd в системной кодировке. Кириллица внутри — даже +# в комментарии rem — превращается в мусор, и cmd пытается выполнить обрывки +# как команды. На этом уже дважды ломался инсталлятор. +import pathlib # noqa: E402 +root = pathlib.Path(__file__).resolve().parent.parent +for cmd_file in sorted(root.rglob("*.cmd")): + if "venv" in cmd_file.parts: + continue + lines = cmd_file.read_text(encoding="utf-8").splitlines() + bad = [(n, l) for n, l in enumerate(lines, 1) if any(ord(ch) > 127 for ch in l)] + r.check("%s без не-ASCII" % cmd_file.relative_to(root), not bad, + bad[0] if bad else "") + print("\n== Настройки из браузера ==") d = c.get("/api/config").get_json() r.check("отдаёт текущие", d.get("ollama_host") and d.get("chat_model"), d)