Skip to content

Commit d368216

Browse files
committed
Updated comments in features
1 parent 97330c5 commit d368216

4 files changed

Lines changed: 116 additions & 10 deletions

File tree

tests/e2e/features/environment.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,25 @@ def _fetch_models_from_service() -> dict:
5050

5151

5252
def before_all(context: Context) -> None:
53-
"""Run before and after the whole shooting match."""
53+
"""Run before and after the whole shooting match.
54+
55+
Initialize global test environment before the test suite runs.
56+
57+
Sets context.deployment_mode from the E2E_DEPLOYMENT_MODE environment
58+
variable (default "server") and context.is_library_mode accordingly.
59+
60+
Attempts to detect a default LLM model and provider via
61+
_fetch_models_from_service() and stores results in context.default_model
62+
and context.default_provider; if detection fails, falls back to
63+
"gpt-4-turbo" and "openai".
64+
65+
Parameters:
66+
context (Context): Behave context into which this function writes:
67+
- deployment_mode (str): "server" or "library".
68+
- is_library_mode (bool): True when deployment_mode is "library".
69+
- default_model (str): Detected model id or fallback model.
70+
- default_provider (str): Detected provider id or fallback provider.
71+
"""
5472
# Detect deployment mode from environment variable
5573
context.deployment_mode = os.getenv("E2E_DEPLOYMENT_MODE", "server").lower()
5674
context.is_library_mode = context.deployment_mode == "library"
@@ -76,7 +94,18 @@ def before_all(context: Context) -> None:
7694

7795

7896
def before_scenario(context: Context, scenario: Scenario) -> None:
79-
"""Run before each scenario is run."""
97+
"""Run before each scenario is run.
98+
99+
Prepare scenario execution by skipping scenarios based on tags and
100+
selecting a scenario-specific configuration.
101+
102+
Skips the scenario if it has the `skip` tag, if it has the `local` tag
103+
while the test run is not in local mode, or if it has
104+
`skip-in-library-mode` when running in library mode. When the scenario is
105+
tagged with `InvalidFeedbackStorageConfig` or `NoCacheConfig`, sets
106+
`context.scenario_config` to the appropriate configuration file path for
107+
the current deployment mode (library-mode or server-mode).
108+
"""
80109
if "skip" in scenario.effective_tags:
81110
scenario.skip("Marked with @skip")
82111
return
@@ -100,7 +129,31 @@ def before_scenario(context: Context, scenario: Scenario) -> None:
100129

101130

102131
def after_scenario(context: Context, scenario: Scenario) -> None:
103-
"""Run after each scenario is run."""
132+
"""Run after each scenario is run.
133+
134+
Perform per-scenario teardown: restore scenario-specific configuration and,
135+
in server mode, attempt to restart and verify the Llama Stack container if
136+
it was previously running.
137+
138+
If the scenario used an alternate feedback storage or no-cache
139+
configuration, the original feature configuration is restored and the
140+
lightspeed-stack container is restarted. When not running in library mode
141+
and the context indicates the Llama Stack was running before the scenario,
142+
this function attempts to start the llama-stack container and polls its
143+
health endpoint until it becomes healthy or a timeout is reached.
144+
145+
Parameters:
146+
context (Context): Behave test context. Expected attributes used here include:
147+
- feature_config: path to the feature-level configuration to restore.
148+
- is_library_mode (bool): whether tests run in library mode.
149+
- llama_stack_was_running (bool, optional): whether llama-stack was
150+
running before the scenario.
151+
- hostname_llama, port_llama (str/int, optional): host and port
152+
used for the llama-stack health check.
153+
scenario (Scenario): Behave scenario whose tags determine which
154+
scenario-specific teardown actions to run (e.g.,
155+
"InvalidFeedbackStorageConfig", "NoCacheConfig").
156+
"""
104157
if "InvalidFeedbackStorageConfig" in scenario.effective_tags:
105158
switch_config(context.feature_config)
106159
restart_container("lightspeed-stack")
@@ -161,7 +214,10 @@ def after_scenario(context: Context, scenario: Scenario) -> None:
161214

162215

163216
def before_feature(context: Context, feature: Feature) -> None:
164-
"""Run before each feature file is exercised."""
217+
"""Run before each feature file is exercised.
218+
219+
Prepare per-feature test environment and apply feature-specific configuration.
220+
"""
165221
if "Authorized" in feature.tags:
166222
mode_dir = "library-mode" if context.is_library_mode else "server-mode"
167223
context.feature_config = (
@@ -178,7 +234,11 @@ def before_feature(context: Context, feature: Feature) -> None:
178234

179235

180236
def after_feature(context: Context, feature: Feature) -> None:
181-
"""Run after each feature file is exercised."""
237+
"""Run after each feature file is exercised.
238+
239+
Perform feature-level teardown: restore any modified configuration and
240+
clean up feedback conversations.
241+
"""
182242
if "Authorized" in feature.tags:
183243
switch_config(context.default_config_backup)
184244
restart_container("lightspeed-stack")

tests/e2e/features/steps/auth.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
@given("I set the Authorization header to {header_value}")
1010
def set_authorization_header_custom(context: Context, header_value: str) -> None:
11-
"""Set a custom Authorization header value."""
11+
"""Set a custom Authorization header value.
12+
13+
Parameters:
14+
header_value (str): The value to set for the `Authorization` header.
15+
"""
1216
if not hasattr(context, "auth_headers"):
1317
context.auth_headers = {}
1418
context.auth_headers["Authorization"] = header_value
@@ -29,6 +33,10 @@ def access_rest_api_endpoint_post(
2933
"""Send POST HTTP request with payload in the endpoint as parameter to tested service.
3034
3135
The response is stored in `context.response` attribute.
36+
37+
Parameters:
38+
endpoint (str): Endpoint path to call; will be normalized.
39+
user_id (str): Value used for the `user_id` query parameter (surrounding quotes are removed).
3240
"""
3341
endpoint = normalize_endpoint(endpoint)
3442
user_id = user_id.replace('"', "")

tests/e2e/features/steps/common.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88
@given("The service is started locally")
99
def service_is_started_locally(context: Context) -> None:
10-
"""Check the service status."""
10+
"""Check the service status.
11+
12+
Populate the Behave context with local service endpoint values read from
13+
environment variables.
14+
15+
Parameters:
16+
context (Context): Behave context object to receive the endpoint attributes.
17+
"""
1118
assert context is not None
1219
context.hostname = os.getenv("E2E_LSC_HOSTNAME", "localhost")
1320
context.port = os.getenv("E2E_LSC_PORT", "8080")
@@ -17,5 +24,15 @@ def service_is_started_locally(context: Context) -> None:
1724

1825
@given("The system is in default state")
1926
def system_in_default_state(context: Context) -> None:
20-
"""Check the default system state."""
27+
"""Check the default system state.
28+
29+
Ensure the Behave test context is present for steps that assume the system
30+
is in its default state.
31+
32+
Parameters:
33+
context (Context): Behave Context instance used to store and share test state.
34+
35+
Raises:
36+
AssertionError: If `context` is None.
37+
"""
2138
assert context is not None

tests/e2e/features/steps/health.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88

99
@given("The llama-stack connection is disrupted")
1010
def llama_stack_connection_broken(context: Context) -> None:
11-
"""Break llama_stack connection by stopping the container."""
11+
"""Break llama_stack connection by stopping the container.
12+
13+
Disrupts the Llama Stack service by stopping its Docker container and
14+
records whether it was running.
15+
16+
Checks whether the Docker container named "llama-stack" is running; if it
17+
is, stops the container, waits briefly for the disruption to take effect,
18+
and sets `context.llama_stack_was_running` to True so callers can restore
19+
state later. If the container is not running, the flag remains False. On
20+
failure to run Docker commands, prints a warning message describing the
21+
error.
22+
23+
Parameters:
24+
context (behave.runner.Context): Behave context used to store
25+
`llama_stack_was_running` and share state between steps.
26+
"""
1227
# Store original state for restoration
1328
context.llama_stack_was_running = False
1429

@@ -39,6 +54,12 @@ def llama_stack_connection_broken(context: Context) -> None:
3954

4055
@given("the service is stopped")
4156
def stop_service(context: Context) -> None:
42-
"""Stop service."""
57+
"""Stop service.
58+
59+
Stop a service used by the current test scenario.
60+
61+
Parameters:
62+
context (Context): Behave step context carrying scenario state and configuration.
63+
"""
4364
# TODO: add step implementation
4465
assert context is not None

0 commit comments

Comments
 (0)