mirror of
https://github.com/aaif-goose/goose.git
synced 2026-06-02 06:14:27 +02:00
Apply ruff and add to CI (#40)
This commit is contained in:
@@ -9,14 +9,19 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install UV
|
- name: Install UV
|
||||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
|
||||||
- name: Source Cargo Environment
|
- name: Source Cargo Environment
|
||||||
run: source $HOME/.cargo/env
|
run: source $HOME/.cargo/env
|
||||||
|
|
||||||
- name: Run tests
|
- name: Ruff
|
||||||
run: |
|
run: |
|
||||||
uv run pytest tests -m 'not integration'
|
uvx ruff check
|
||||||
|
uvx ruff format --check
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
uv run pytest tests -m 'not integration'
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import sys
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
@@ -12,10 +11,12 @@ from goose.cli.session import Session
|
|||||||
from goose.utils import load_plugins
|
from goose.utils import load_plugins
|
||||||
from goose.utils.session_file import list_sorted_session_files
|
from goose.utils.session_file import list_sorted_session_files
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def goose_cli() -> None:
|
def goose_cli() -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@goose_cli.command()
|
@goose_cli.command()
|
||||||
def version() -> None:
|
def version() -> None:
|
||||||
"""Lists the version of goose and any plugins"""
|
"""Lists the version of goose and any plugins"""
|
||||||
@@ -100,14 +101,17 @@ def session_clear(keep: int) -> None:
|
|||||||
def get_session_files() -> Dict[str, Path]:
|
def get_session_files() -> Dict[str, Path]:
|
||||||
return list_sorted_session_files(SESSIONS_PATH)
|
return list_sorted_session_files(SESSIONS_PATH)
|
||||||
|
|
||||||
|
|
||||||
@click.group(
|
@click.group(
|
||||||
invoke_without_command=True,
|
invoke_without_command=True,
|
||||||
name="goose",
|
name="goose",
|
||||||
help="AI-powered tool to assist in solving programming and operational tasks",)
|
help="AI-powered tool to assist in solving programming and operational tasks",
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(_: click.Context, **kwargs: Dict) -> None:
|
def cli(_: click.Context, **kwargs: Dict) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
all_cli_group_options = load_plugins("goose.cli.group_option")
|
all_cli_group_options = load_plugins("goose.cli.group_option")
|
||||||
for option in all_cli_group_options.values():
|
for option in all_cli_group_options.values():
|
||||||
cli = option()(cli)
|
cli = option()(cli)
|
||||||
|
|||||||
@@ -85,36 +85,41 @@ def test_session_clear_command(mock_session_files_path, create_session_file):
|
|||||||
def test_combined_group_option():
|
def test_combined_group_option():
|
||||||
with patch("goose.utils.load_plugins") as mock_load_plugin:
|
with patch("goose.utils.load_plugins") as mock_load_plugin:
|
||||||
group_option_name = "--describe-commands"
|
group_option_name = "--describe-commands"
|
||||||
|
|
||||||
def option_callback(ctx, *_):
|
def option_callback(ctx, *_):
|
||||||
click.echo("Option callback")
|
click.echo("Option callback")
|
||||||
ctx.exit()
|
ctx.exit()
|
||||||
|
|
||||||
mock_group_options = {
|
mock_group_options = {
|
||||||
'option1': lambda: click.option(
|
"option1": lambda: click.option(
|
||||||
group_option_name,
|
group_option_name,
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
callback=option_callback,
|
callback=option_callback,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def side_effect_func(param):
|
def side_effect_func(param):
|
||||||
if param == "goose.cli.group_option":
|
if param == "goose.cli.group_option":
|
||||||
return mock_group_options
|
return mock_group_options
|
||||||
elif param == "goose.cli.group":
|
elif param == "goose.cli.group":
|
||||||
return { }
|
return {}
|
||||||
|
|
||||||
mock_load_plugin.side_effect = side_effect_func
|
mock_load_plugin.side_effect = side_effect_func
|
||||||
|
|
||||||
# reload cli after mocking
|
# reload cli after mocking
|
||||||
importlib.reload(importlib.import_module('goose.cli.main'))
|
importlib.reload(importlib.import_module("goose.cli.main"))
|
||||||
import goose.cli.main
|
import goose.cli.main
|
||||||
|
|
||||||
cli = goose.cli.main.cli
|
cli = goose.cli.main.cli
|
||||||
|
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
result = runner.invoke(cli, [group_option_name])
|
result = runner.invoke(cli, [group_option_name])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
def test_combined_group_commands(mock_session):
|
def test_combined_group_commands(mock_session):
|
||||||
mock_session_class, mock_session_instance = mock_session
|
mock_session_class, mock_session_instance = mock_session
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"])
|
runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"])
|
||||||
mock_session_class.assert_called_once_with(name="session1", profile="default")
|
mock_session_class.assert_called_once_with(name="session1", profile="default")
|
||||||
mock_session_instance.run.assert_called_once()
|
mock_session_instance.run.assert_called_once()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user