mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-24 10:32:45 +00:00
test(cli): cover CLI Apps on Windows CI
This commit is contained in:
parent
e2d00ffc8f
commit
c0d4f012c8
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: ${{ github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]') || fromJSON('["ubuntu-latest","windows-latest"]') }}
|
os: ${{ fromJSON('["ubuntu-latest","windows-latest"]') }}
|
||||||
# CI concentrates on newer runtimes (3.11/3.12 still supported per pyproject requires-python).
|
# CI concentrates on newer runtimes (3.11/3.12 still supported per pyproject requires-python).
|
||||||
python-version: ${{ fromJSON('["3.13","3.14"]') }}
|
python-version: ${{ fromJSON('["3.13","3.14"]') }}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import stat
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@ -341,17 +339,22 @@ def test_run_installed_cli_uses_argv_without_shell(
|
|||||||
) -> None:
|
) -> None:
|
||||||
manager = _manager(tmp_path)
|
manager = _manager(tmp_path)
|
||||||
_seed_catalog(manager)
|
_seed_catalog(manager)
|
||||||
bin_dir = tmp_path / "bin"
|
resolved = str(tmp_path / "bin" / "cli-anything-gimp")
|
||||||
bin_dir.mkdir()
|
monkeypatch.setattr(
|
||||||
cli = bin_dir / "cli-anything-gimp"
|
"nanobot.cli_apps.service.shutil.which",
|
||||||
cli.write_text(
|
lambda entry: resolved if entry == "cli-anything-gimp" else None,
|
||||||
"#!/usr/bin/env python3\n"
|
|
||||||
"import sys\n"
|
|
||||||
"print('ARGS=' + repr(sys.argv[1:]))\n",
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
)
|
||||||
cli.chmod(cli.stat().st_mode | stat.S_IEXEC)
|
|
||||||
monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ.get('PATH', '')}")
|
def fake_run(argv: list[str], **kwargs: object) -> subprocess.CompletedProcess[str]:
|
||||||
|
assert "shell" not in kwargs or kwargs["shell"] is False
|
||||||
|
return subprocess.CompletedProcess(
|
||||||
|
argv,
|
||||||
|
0,
|
||||||
|
stdout="ARGS=" + repr(argv[1:]),
|
||||||
|
stderr="",
|
||||||
|
)
|
||||||
|
|
||||||
|
monkeypatch.setattr("nanobot.cli_apps.service.subprocess.run", fake_run)
|
||||||
manager._save_installed(
|
manager._save_installed(
|
||||||
{
|
{
|
||||||
"gimp": {
|
"gimp": {
|
||||||
|
|||||||
@ -2,8 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import subprocess
|
||||||
import stat
|
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -45,17 +44,22 @@ def test_run_cli_app_uses_installed_registry_app(
|
|||||||
CliAppManager(workspace=workspace, data_dir=data_dir)._save_installed(
|
CliAppManager(workspace=workspace, data_dir=data_dir)._save_installed(
|
||||||
{"gimp": {"entry_point": "cli-anything-gimp"}}
|
{"gimp": {"entry_point": "cli-anything-gimp"}}
|
||||||
)
|
)
|
||||||
bin_dir = tmp_path / "bin"
|
resolved = str(tmp_path / "bin" / "cli-anything-gimp")
|
||||||
bin_dir.mkdir()
|
monkeypatch.setattr(
|
||||||
cli = bin_dir / "cli-anything-gimp"
|
"nanobot.cli_apps.service.shutil.which",
|
||||||
cli.write_text(
|
lambda entry: resolved if entry == "cli-anything-gimp" else None,
|
||||||
"#!/usr/bin/env python3\n"
|
|
||||||
"import sys\n"
|
|
||||||
"print('tool:' + ' '.join(sys.argv[1:]))\n",
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
)
|
||||||
cli.chmod(cli.stat().st_mode | stat.S_IEXEC)
|
|
||||||
monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ.get('PATH', '')}")
|
def fake_run(argv: list[str], **kwargs: object) -> subprocess.CompletedProcess[str]:
|
||||||
|
assert "shell" not in kwargs or kwargs["shell"] is False
|
||||||
|
return subprocess.CompletedProcess(
|
||||||
|
argv,
|
||||||
|
0,
|
||||||
|
stdout="tool:" + " ".join(argv[1:]),
|
||||||
|
stderr="",
|
||||||
|
)
|
||||||
|
|
||||||
|
monkeypatch.setattr("nanobot.cli_apps.service.subprocess.run", fake_run)
|
||||||
monkeypatch.setattr("nanobot.cli_apps.service.get_runtime_subdir", lambda _name: data_dir)
|
monkeypatch.setattr("nanobot.cli_apps.service.get_runtime_subdir", lambda _name: data_dir)
|
||||||
|
|
||||||
tool = CliAppsTool(
|
tool = CliAppsTool(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user