Skip to content

Commit

Permalink
Apply ruff and add to CI (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
baxen authored Sep 4, 2024
1 parent 466ce23 commit bb8966b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh

- name: Source Cargo Environment
run: source $HOME/.cargo/env
- name: Source Cargo Environment
run: source $HOME/.cargo/env

- name: Run tests
run: |
uv run pytest tests -m 'not integration'
- name: Ruff
run: |
uvx ruff check
uvx ruff format --check
- name: Run tests
run: |
uv run pytest tests -m 'not integration'
12 changes: 8 additions & 4 deletions src/goose/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from datetime import datetime
from pathlib import Path
from typing import Dict, Optional
Expand All @@ -12,10 +11,12 @@
from goose.utils import load_plugins
from goose.utils.session_file import list_sorted_session_files


@click.group()
def goose_cli() -> None:
pass


@goose_cli.command()
def version() -> None:
"""Lists the version of goose and any plugins"""
Expand Down Expand Up @@ -100,14 +101,17 @@ def session_clear(keep: int) -> None:
def get_session_files() -> Dict[str, Path]:
return list_sorted_session_files(SESSIONS_PATH)


@click.group(
invoke_without_command=True,
name="goose",
help="AI-powered tool to assist in solving programming and operational tasks",)
invoke_without_command=True,
name="goose",
help="AI-powered tool to assist in solving programming and operational tasks",
)
@click.pass_context
def cli(_: click.Context, **kwargs: Dict) -> None:
pass


all_cli_group_options = load_plugins("goose.cli.group_option")
for option in all_cli_group_options.values():
cli = option()(cli)
Expand Down
13 changes: 9 additions & 4 deletions tests/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,41 @@ def test_session_clear_command(mock_session_files_path, create_session_file):
def test_combined_group_option():
with patch("goose.utils.load_plugins") as mock_load_plugin:
group_option_name = "--describe-commands"

def option_callback(ctx, *_):
click.echo("Option callback")
ctx.exit()

mock_group_options = {
'option1': lambda: click.option(
"option1": lambda: click.option(
group_option_name,
is_flag=True,
callback=option_callback,
),
}

def side_effect_func(param):
if param == "goose.cli.group_option":
return mock_group_options
elif param == "goose.cli.group":
return { }
return {}

mock_load_plugin.side_effect = side_effect_func

# reload cli after mocking
importlib.reload(importlib.import_module('goose.cli.main'))
importlib.reload(importlib.import_module("goose.cli.main"))
import goose.cli.main

cli = goose.cli.main.cli

runner = CliRunner()
result = runner.invoke(cli, [group_option_name])
assert result.exit_code == 0


def test_combined_group_commands(mock_session):
mock_session_class, mock_session_instance = mock_session
runner = CliRunner()
runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"])
mock_session_class.assert_called_once_with(name="session1", profile="default")
mock_session_instance.run.assert_called_once()

0 comments on commit bb8966b

Please sign in to comment.