Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Adds guard to project name

elijahbenizzya15b2b7c2656
diff --git a/burr/tracking/client.py b/burr/tracking/client.py
index 97fda069..9ff3dfbd 100644
--- a/burr/tracking/client.py
+++ b/burr/tracking/client.py
@@ -2,9 +2,11 @@ import datetime
import json
import logging
import os
+import re
import traceback
from typing import Any, Dict, Optional
+from burr import system
from burr.core import Action, ApplicationGraph, State
from burr.core.persistence import BaseStateLoader, PersistedStateData
from burr.integrations.base import require_plugin
@@ -15,7 +17,6 @@ from burr.lifecycle import (
PreRunStepHook,
PreStartSpanHook,
)
-from burr.system import IS_WINDOWS
from burr.tracking.common.models import (
ApplicationMetadataModel,
ApplicationModel,
@@ -44,6 +45,16 @@ def _format_exception(exception: Exception) -> Optional[str]:
return "".join(traceback.format_exception(type(exception), exception, exception.__traceback__))
+def _allowed_project_name(project_name: str, on_windows: bool) -> bool:
+ allowed_chars = "a-zA-Z0-9_\-"
+ if not on_windows:
+ allowed_chars += ":"
+ pattern = f"^[{allowed_chars}]+$"
+
+ # Use regular expression to check if the string is valid
+ return bool(re.match(pattern, project_name))
+
+
class LocalTrackingClient(
PostApplicationCreateHook,
PreRunStepHook,
@@ -81,9 +92,10 @@ class LocalTrackingClient(
"""
self.f = None
- if ":" in project and IS_WINDOWS:
+ if not _allowed_project_name(project, on_windows=system.IS_WINDOWS):
raise ValueError(
- "Project name cannot contain ':' -- this is purely as we're using the filesystem as a storage utility."
+ f"Project: {project} is not valid. Project name cannot contain non-alphanumeric (except _ and -) characters."
+ "We will be relaxing this restriction later but for now please rename your project!"
)
self.storage_dir = LocalTrackingClient.get_storage_path(project, storage_dir)
self.project_id = project
diff --git a/pyproject.toml b/pyproject.toml
index 87a95273..7d6ab7ba 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "burr"
-version = "0.15.0"
+version = "0.15.1rc1"
dependencies = [] # yes, there are none
requires-python = ">=3.9"
authors = [
diff --git a/telemetry/ui/src/examples/Chatbot.tsx b/telemetry/ui/src/examples/Chatbot.tsx
index cbb586e7..c66a0aeb 100644
--- a/telemetry/ui/src/examples/Chatbot.tsx
+++ b/telemetry/ui/src/examples/Chatbot.tsx
@@ -20,7 +20,7 @@ const DEFAULT_CHAT_HISTORY: ChatItem[] = [
content:
'πŸ“– Select a conversation from the list to get started! ' +
'The left side of this is a simple chatbot. The right side is the same' +
- ' Burr Telemetry app you can see if you click through the [chatbot demo](/projects/demo:chatbot) project. Note that images ' +
+ ' Burr Telemetry app you can see if you click through the [chatbot demo](/projects/demo_chatbot) project. Note that images ' +
"will likely stop displaying after a while due to OpenAI's persistence policy. So generate some new ones! πŸ“–",
type: ChatItem.type.TEXT
},
diff --git a/tests/tracking/test_local_tracking_client.py b/tests/tracking/test_local_tracking_client.py
index f897cafa..3390c7fe 100644
--- a/tests/tracking/test_local_tracking_client.py
+++ b/tests/tracking/test_local_tracking_client.py
@@ -8,6 +8,7 @@ import pytest
import burr
from burr.core import Result, State, action, default, expr
from burr.tracking import LocalTrackingClient
+from burr.tracking.client import _allowed_project_name
from burr.tracking.common.models import (
ApplicationModel,
BeginEntryModel,
@@ -118,3 +119,18 @@ def test_application_tracks_end_to_end_broken(tmpdir: str):
assert len(pre_run) == 2
assert len(post_run) == 2
assert len(post_run[-1].exception) > 0 and "Broken" in post_run[-1].exception
+
+
+ "input_string, on_windows, expected_result",
+ [
+ ("Hello-World_123", False, True),
+ ("Hello:World_123", False, True),
+ ("Hello:World_123", True, False),
+ ("Invalid:Chars*", False, False),
+ ("Just$ymbols", True, False),
+ ("Normal_Text", True, True),
+ ],
+)
+def test__allowed_project_name(input_string, on_windows, expected_result):
+ assert _allowed_project_name(input_string, on_windows) == expected_result