diff --git a/README.md b/README.md index b903705..9e078d0 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,22 @@ For the hardcore enthusiasts, you can use Hercules via the source code to get a ## 📝 Configuration Details +### Disabling Telemetry + +To disable telemetry, set the `TELEMETRY_ENABLED` environment variable to `0`: + +```bash +export TELEMETRY_ENABLED=0 +``` + +### Auto Mode + +If `AUTO_MODE` is set to `1`, Hercules will not request an email during the run: + +```bash +export AUTO_MODE=1 +``` + ### Understanding the Environment File (`.env`) To configure Hercules in detail: diff --git a/entrypoint.sh b/entrypoint.sh index dcacea4..25502af 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,5 +22,7 @@ if [ ! -d "/testzeus-hercules/opt" ]; then touch /testzeus-hercules/opt/test_data/td.txt fi +export AUTO_MODE=1 + # Execute the main application exec poetry run python testzeus_hercules diff --git a/helper_scripts/hercules_setup.sh b/helper_scripts/hercules_setup.sh new file mode 100755 index 0000000..32749fc --- /dev/null +++ b/helper_scripts/hercules_setup.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 + +# Create a new Python virtual environment named 'test' +python3 -m venv test + +# Activate the virtual environment +source test/bin/activate + +# Upgrade the 'testzeus-hercules' package +pip install --upgrade testzeus-hercules +playwright install --with-deps + +#Set Headless as false +export HEADLESS=false + +# create a new directory named 'opt' +mkdir -p opt/input opt/output opt/test_data + +# create a intput/test.feature file +echo "Feature: Open Google homepage\nScenario: User opens Google homepage\n Given I have a web browser open\n When I navigate to https://www.google.com\n Then I should see the Google homepage" > opt/input/test.feature + +# get gpt-4o model API key by asking user +echo "Enter your GPT-4o model API key:" +read -s GPT_4O_API_KEY + +# Run the 'testzeus-hercules' command with the specified parameters +testzeus-hercules \ + --input-file opt/input/test.feature \ + --output-path opt/output \ + --test-data-path opt/test_data \ + --llm-model gpt-4o \ + --llm-model-api-key $GPT_4O_API_KEY diff --git a/testzeus_hercules/telemetry.py b/testzeus_hercules/telemetry.py index 68817f3..38bd2f1 100644 --- a/testzeus_hercules/telemetry.py +++ b/testzeus_hercules/telemetry.py @@ -11,6 +11,7 @@ from pydantic import BaseModel from sentry_sdk.scrubber import DEFAULT_DENYLIST, DEFAULT_PII_DENYLIST, EventScrubber from sentry_sdk.types import Event, Hint +import json DSN = "https://d14d2ee82f26a3585b2a892fab7fffaa@o4508256143540224.ingest.us.sentry.io/4508256153042944" @@ -79,24 +80,66 @@ def my_before_send(event: Event, hint: Hint) -> Event | None: sentry_sdk.set_user(None) -def get_installation_id(file_path="installation_id.txt") -> str: - """Generate or load a unique installation ID.""" +def get_installation_id( + file_path: str = "installation_id.txt", is_manual_run: bool = True +) -> Dict[str, Any]: + """Generate or load installation data. + + If the file exists and contains a dict, return it. + If the file exists and contains only the installation ID, return a dict with default values. + If the file does not exist: + - If triggered manually by the user (is_manual_run is True), prompt for user_email. + - Generate a new installation ID and save all data as a dict. + - If not triggered manually, use default values for user_email. + """ if os.path.exists(file_path): + data = { + "user_email": "old_email@example.com", + } + rewrite_data = False with open(file_path, "r") as file: - return file.read().strip() + content = file.read().strip() + installation_id = content + data["installation_id"] = installation_id + try: + data = json.loads(content) + if isinstance(data, dict) and "installation_id" in data: + return data + except json.JSONDecodeError: + rewrite_data = True + if rewrite_data: + with open(file_path, "w") as file: + json.dump(data, file) else: installation_id = str(uuid.uuid4()) + user_email = "new_email@example.com" + if is_manual_run: + print( + "We need your email to inform you about any urgent security patches or issues detected in testzeus-hercules." + ) + n_user_email = input( + "Please provide your email (or press Enter to skip with empty email): " + ) + user_email = n_user_email if n_user_email else user_email + + data = { + "user_email": user_email, + "installation_id": installation_id, + } with open(file_path, "w") as file: - file.write(installation_id) - return installation_id + json.dump(data, file) + return data # Initialize the installation_id -installation_id = get_installation_id() +installation_data = get_installation_id( + is_manual_run=os.environ.get("AUTO_MODE", "0") == "0" +) # Global event collector with event_type buckets event_collector = { - "installation_id": installation_id, + "installation_id": installation_data["installation_id"], + "user_email": installation_data["user_email"], "buckets": {}, "start_time": datetime.now().isoformat(), } @@ -144,6 +187,7 @@ def build_final_message() -> Dict[str, Any]: """ message = { "installation_id": event_collector["installation_id"], + "user_email": event_collector["user_email"], "session_start": event_collector["start_time"], "buckets": { event_type_s: events