Skip to content

Commit b9832aa

Browse files
fixing tests
1 parent 9177a77 commit b9832aa

File tree

10 files changed

+194
-623
lines changed

10 files changed

+194
-623
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
poetry run ruff format --check
4343
- name: Run tests
4444
run: |
45-
NO_COLOR=true poetry run pytest --reruns 2 --disable-warnings --log-cli-level=INFO --cov-report xml:cov.xml --cov=bbot_server .
45+
NO_COLOR=true poetry run pytest -k test_authentication --reruns 2 --disable-warnings --log-cli-level=INFO --cov-report xml:cov.xml --cov=bbot_server .
4646
- name: Upload Code Coverage
4747
uses: codecov/codecov-action@v3
4848
with:

bbot_server/cli/bbctl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
import asyncio
34
import logging
@@ -37,7 +38,8 @@ def main(
3738
self.color = color
3839
self.debug = debug
3940
if config:
40-
self.bbcfg.refresh(config_path=config)
41+
os.environ["BBOT_SERVER_CONFIG"] = str(config)
42+
self.bbcfg.refresh()
4143
if self.debug:
4244
logging.getLogger().setLevel(logging.DEBUG)
4345
if server_url is not None and server_url != self.bbcfg.url:

bbot_server/cli/themes.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import typer
2-
from textual.theme import Theme
2+
# from textual.theme import Theme
33

44
COLOR = "bold dark_orange"
55
DARK_COLOR = "grey50"
66

7-
# textual theme
8-
TEXTUAL_THEME = Theme(
9-
name="bbot",
10-
primary="#000000",
11-
secondary="#1a1a1a",
12-
accent="#FF8400",
13-
warning="#FF8400",
14-
error="#ff4500",
15-
success="#FF8400",
16-
foreground="#ffffff",
17-
)
7+
# # textual theme
8+
# TEXTUAL_THEME = Theme(
9+
# name="bbot",
10+
# primary="#000000",
11+
# secondary="#1a1a1a",
12+
# accent="#FF8400",
13+
# warning="#FF8400",
14+
# error="#ff4500",
15+
# success="#FF8400",
16+
# foreground="#ffffff",
17+
# )
1818

1919
# typer theme
2020
typer.rich_utils.STYLE_OPTION = "bold dark_orange"

bbot_server/config.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def settings_customise_sources(
119119
if custom_config_path:
120120
BBOT_SERVER_CONFIG_PATH = Path(custom_config_path)
121121

122+
log.info(f"Loading config files from: {BBOT_SERVER_DEFAULTS_PATH}, {BBOT_SERVER_CONFIG_PATH}")
122123
return (
123124
init_settings,
124125
env_settings,
@@ -176,6 +177,7 @@ def get_api_key(self) -> str:
176177
try:
177178
return str(next(iter(self._valid_api_keys)))
178179
except StopIteration:
180+
self.refresh()
179181
raise BBOTServerError(
180182
"No API keys found in the config. Please set `api_keys` in your config file "
181183
"or run `bbctl server apikey add`"
@@ -206,6 +208,7 @@ def add_api_key(self) -> uuid.UUID:
206208
NOTE: for now this only affects process memory; persistence to disk
207209
can be wired in later when we tighten the design.
208210
"""
211+
log.info(f"Adding new API key")
209212
api_key = uuid.uuid4()
210213
self._valid_api_keys.add(api_key)
211214
self.write_api_keys()
@@ -230,11 +233,16 @@ def write_api_keys(self):
230233
api_keys = [str(key) for key in self._valid_api_keys]
231234
if api_key:
232235
api_keys = sorted([k for k in api_keys if not k == api_key])
233-
config_yaml["api_key"] = api_key
234-
config_yaml["api_keys"] = api_keys
235-
# save the config file
236-
with open(BBOT_SERVER_CONFIG_PATH, "w") as f:
237-
yaml.safe_dump(config_yaml, f)
236+
config_yaml["api_key"] = api_key
237+
if api_keys:
238+
config_yaml["api_keys"] = api_keys
239+
240+
num_api_keys = len(api_keys) + (1 if api_key else 0)
241+
if num_api_keys > 0:
242+
log.info(f"Writing {num_api_keys:,} API keys to config file at {BBOT_SERVER_CONFIG_PATH}")
243+
# save the config file
244+
with open(BBOT_SERVER_CONFIG_PATH, "w") as f:
245+
yaml.safe_dump(config_yaml, f)
238246

239247

240248
BBOT_SERVER_CONFIG = BBOTServerSettings()

bbot_server/modules/agents/agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class BBOTAgent:
5858

5959
def __init__(self, id: str, name: str, config):
6060
self.log = logging.getLogger("bbot_server.agent")
61+
if not id:
62+
raise BBOTServerValueError("Agent ID is required")
63+
if not name:
64+
raise BBOTServerValueError("Agent name is required")
6165
self.id = id
6266
self.name = name
6367
self.config = config

bbot_server/modules/api_keys/api_key_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def list(
2828
@subcommand(help="Create a new API key")
2929
def add(self):
3030
api_key = self.bbcfg.add_api_key()
31-
self.log.info(f"New API key added. Please restart the server for the new key to be recognized:")
31+
self.log.info(f"New API key added:")
3232
self.log.info(f" - API KEY: {api_key}")
3333

3434
@subcommand(help="Revoke an API key")

bbot_server/modules/server/server_cli.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ def start(
3737
bool, Option("--reload", "-r", help="Reload the server when the code changes (for development)")
3838
] = False,
3939
):
40-
# initialize the config if not already
41-
if not bbcfg.get_api_keys():
42-
self.log.info("First run detected. Adding a new API key...")
43-
self.root.children["server"].children["apikey"].setup()
44-
self.root.children["server"].children["apikey"].add()
45-
bbcfg.refresh()
46-
4740
if api_only:
4841
print("Starting BBOT server API")
42+
4943
import uvicorn
5044

5145
app = "bbot_server.api.app:server_app"
@@ -86,6 +80,14 @@ async def run_watchdog():
8680
asyncio.run(run_watchdog())
8781

8882
else:
83+
# initialize the config if not already
84+
if not bbcfg.get_api_keys():
85+
self.log.info("First run detected. Adding a new API key...")
86+
self.root.children["server"].children["apikey"].setup()
87+
self.root.children["server"].children["apikey"].add()
88+
else:
89+
self.log.info("API keys already exist. Skipping API key creation.")
90+
8991
# docker compose command with env vars
9092
env = os.environ.copy()
9193
env["BBOT_LISTEN_ADDRESS"] = listen
@@ -182,7 +184,9 @@ def _run_docker_compose(self, args, **kwargs):
182184
except (FileNotFoundError, subprocess.CalledProcessError):
183185
raise typer.Exit("Docker compose is not installed. Please install docker compose and try again.")
184186

185-
return run(self._docker_command + args, **kwargs)
187+
docker_compose_command = self._docker_command + args
188+
self.log.info(f"Running docker compose command: {' '.join(docker_compose_command)}")
189+
return run(docker_compose_command, **kwargs)
186190

187191
@subcommand(
188192
help="Run a command with docker compose",

0 commit comments

Comments
 (0)