11"""Implementation of common test steps."""
2+
23import os
34import time
45
@@ -70,7 +71,11 @@ def configure_service(context: Context, config_name: str) -> None:
7071 state, not only ``context``, so it survives per-scenario context resets),
7172 returns immediately: no backup, no copy, and sets
7273 ``context.lightspeed_stack_skip_restart`` so the next ``The service is
73- restarted`` step can no-op. Otherwise creates the backup on first use,
74+ restarted`` step can no-op—except after library-mode ``~/.llama`` was
75+ cleared by ``MCP toolgroups are reset for a new MCP configuration``, in
76+ which case the restart is not skipped so embedded Llama Stack can recreate
77+ SQLite schema. When the basename differs from the last apply, creates the
78+ backup on first use,
7479 copies the YAML, updates ``context.feature_config`` / override flags, and
7580 stores the basename for the next check. Cleared in ``before_feature`` so a
7681 new feature file always applies at least once.
@@ -88,7 +93,14 @@ def configure_service(context: Context, config_name: str) -> None:
8893 """
8994 config_name = config_name .strip ()
9095 if _active_lightspeed_stack_config_basename ["basename" ] == config_name :
91- context .lightspeed_stack_skip_restart = True
96+ # ``MCP toolgroups are reset for a new MCP configuration`` may have run
97+ # ``rm -rf ~/.llama`` in library mode; the next restart must not be
98+ # skipped or the process keeps stale handles / missing SQLite tables.
99+ if getattr (context , "force_lightspeed_restart_after_mcp_storage_clear" , False ):
100+ context .lightspeed_stack_skip_restart = False
101+ context .force_lightspeed_restart_after_mcp_storage_clear = False
102+ else :
103+ context .lightspeed_stack_skip_restart = True
92104 return
93105
94106 had_backup_before = os .path .exists ("lightspeed-stack.yaml.backup" )
@@ -135,10 +147,14 @@ def reset_mcp_toolgroups_for_new_configuration(context: Context) -> None:
135147 """Clear MCP toolgroups on Llama Stack (server) or ~/.llama storage (library).
136148
137149 Run before applying a different MCP-related ``lightspeed-stack-*.yaml`` in a
138- scenario so tool registration matches the new config.
150+ scenario so tool registration matches the new config. In library mode,
151+ clearing ``~/.llama`` forces the next ``The service uses ...`` / restart
152+ path to run a real container restart so conversation tables are recreated.
139153 """
140154 if context .is_library_mode :
141155 clear_llama_stack_storage ()
156+ context .force_lightspeed_restart_after_mcp_storage_clear = True
157+ context .lightspeed_stack_skip_restart = False
142158 else :
143159 unregister_mcp_toolgroups ()
144160
0 commit comments