From 51bd5cc9bcdceecf6ba830d7b74c7f1685afa47a Mon Sep 17 00:00:00 2001 From: Gayan Weerakutti Date: Wed, 30 Jul 2025 17:10:46 +0900 Subject: [PATCH 1/2] Validate session flag format in subset command The --session flag is not validated when the observation mode is on, resulting in an internal error. This commit fixes it. --- launchable/commands/helper.py | 5 +++-- launchable/commands/subset.py | 2 +- launchable/utils/session.py | 6 +++++- tests/test_session.py | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/launchable/commands/helper.py b/launchable/commands/helper.py index 685ab6e20..34b0b70e2 100644 --- a/launchable/commands/helper.py +++ b/launchable/commands/helper.py @@ -9,7 +9,7 @@ from ..app import Application from ..utils.launchable_client import LaunchableClient -from ..utils.session import parse_session, read_build, read_session +from ..utils.session import read_build, read_session, validate_session_format def require_session( @@ -22,7 +22,7 @@ def require_session( See https://github.com/launchableinc/cli/pull/342 """ if session: - parse_session(session) # make sure session is in the right format + validate_session_format(session) return session session = read_session(require_build()) @@ -89,6 +89,7 @@ def find_or_create_session( from .record.session import session as session_command if session: + validate_session_format(session) _check_observation_mode_status(session, is_observation, tracking_client=tracking_client, app=context.obj) return session diff --git a/launchable/commands/subset.py b/launchable/commands/subset.py index 3cedd5e0a..e0ec48e4a 100644 --- a/launchable/commands/subset.py +++ b/launchable/commands/subset.py @@ -58,7 +58,7 @@ @click.option( '--session', 'session', - help='Test session ID', + help='In the format builds//test_sessions/', type=str, ) @click.option( diff --git a/launchable/utils/session.py b/launchable/utils/session.py index ff217970b..d94bff54a 100644 --- a/launchable/utils/session.py +++ b/launchable/utils/session.py @@ -98,11 +98,15 @@ def clean_session_files(days_ago: int = 0) -> None: remove_session() -def parse_session(session: str): +def validate_session_format(session: str): # session format: # builds//test_sessions/ if session.count("/") != 3: raise ParseSessionException(session=session) + +def parse_session(session: str): + validate_session_format(session) + _, build_name, _, session_id = session.split("/") return build_name, session_id diff --git a/tests/test_session.py b/tests/test_session.py index 2eb7a0c8f..a1d1c578c 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -3,8 +3,9 @@ import tempfile from unittest import TestCase -from launchable.utils.session import (SESSION_DIR_KEY, clean_session_files, parse_session, read_build, - read_session, remove_session, write_build, write_session) +from launchable.utils.exceptions import ParseSessionException +from launchable.utils.session import (SESSION_DIR_KEY, clean_session_files, parse_session, read_build, read_session, + remove_session, validate_session_format, write_build, write_session) class SessionTestClass(TestCase): @@ -44,3 +45,17 @@ def test_parse_session(self): with self.assertRaises(Exception): parse_session("hoge/fuga") + + def test_validate_session_format(self): + # Test with a valid session format + validate_session_format("builds/build-name/test_sessions/123") + + # Test with invalid session formats + invalid_sessions = [ + "123", # Only id + "workspaces/mothership/builds/123/test_sessions/13" # Too many parts + ] + + for invalid_session in invalid_sessions: + with self.assertRaises(ParseSessionException): + validate_session_format(invalid_session) From 4e0e2abaac65121c91eeb16bdd2de05f740fc0d4 Mon Sep 17 00:00:00 2001 From: Gayan Weerakutti Date: Fri, 1 Aug 2025 13:40:42 +0900 Subject: [PATCH 2/2] Update --session flag description for attachment and tests command --- launchable/commands/record/attachment.py | 2 +- launchable/commands/record/tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/launchable/commands/record/attachment.py b/launchable/commands/record/attachment.py index d1d2878a8..5ffb6de56 100644 --- a/launchable/commands/record/attachment.py +++ b/launchable/commands/record/attachment.py @@ -10,7 +10,7 @@ @click.option( '--session', 'session', - help='Test session ID', + help='In the format builds//test_sessions/', type=str, ) @click.argument('attachments', nargs=-1) # type=click.Path(exists=True) diff --git a/launchable/commands/record/tests.py b/launchable/commands/record/tests.py index a04efffc8..64415692a 100644 --- a/launchable/commands/record/tests.py +++ b/launchable/commands/record/tests.py @@ -56,7 +56,7 @@ def _validate_group(ctx, param, value): @click.option( '--session', 'session', - help='Test session ID', + help='In the format builds//test_sessions/', type=str, ) @click.option(