-
Notifications
You must be signed in to change notification settings - Fork 73
LCORE-1206: add tests for too long question #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
radofuchs
wants to merge
1
commit into
lightspeed-core:main
Choose a base branch
from
radofuchs:LCORE_1206_OLS_test_alignment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """E2E helpers to unregister and re-register Llama Stack shields via the client API. | ||
|
|
||
| Used by the @disable-shields tag: before the scenario we call client.shields.delete() | ||
| to unregister the shield; after the scenario we call client.shields.register() | ||
| to restore it. Only applies in server mode (Llama Stack as a separate service). | ||
| Requires E2E_LLAMA_STACK_URL or E2E_LLAMA_HOSTNAME/E2E_LLAMA_PORT. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| from llama_stack_client import ( | ||
| APIConnectionError, | ||
| AsyncLlamaStackClient, | ||
| APIStatusError, | ||
| ) | ||
|
|
||
|
|
||
| def _get_llama_stack_client() -> AsyncLlamaStackClient: | ||
| """Build an AsyncLlamaStackClient from env (for e2e test use).""" | ||
| base_url = os.getenv("E2E_LLAMA_STACK_URL") | ||
| if not base_url: | ||
| host = os.getenv("E2E_LLAMA_HOSTNAME", "localhost") | ||
| port = os.getenv("E2E_LLAMA_PORT", "8321") | ||
| base_url = f"http://{host}:{port}" | ||
| api_key = os.getenv("E2E_LLAMA_STACK_API_KEY", "xyzzy") | ||
| timeout = int(os.getenv("E2E_LLAMA_STACK_TIMEOUT", "60")) | ||
| return AsyncLlamaStackClient(base_url=base_url, api_key=api_key, timeout=timeout) | ||
|
|
||
|
|
||
| async def _unregister_shield_async(identifier: str) -> Optional[tuple[str, str]]: | ||
| """Unregister a shield by identifier; return (provider_id, provider_shield_id) for restore.""" | ||
| client = _get_llama_stack_client() | ||
| try: | ||
| shields = await client.shields.list() | ||
| provider_id = None | ||
| provider_shield_id = None | ||
| found = False | ||
| for shield in shields: | ||
| if getattr(shield, "identifier", None) == identifier: | ||
| provider_id = getattr(shield, "provider_id", None) | ||
| provider_shield_id = getattr( | ||
| shield, "provider_resource_id", None | ||
| ) or getattr(shield, "provider_shield_id", None) | ||
| found = True | ||
| break | ||
| if not found: | ||
| # Shield not registered; nothing to delete, scenario can proceed | ||
| return None | ||
| try: | ||
| await client.shields.delete(identifier) | ||
| except APIConnectionError: | ||
| raise | ||
| except APIStatusError as e: | ||
| # 400 "not found": shield already absent, scenario can proceed | ||
| if e.status_code == 400 and "not found" in str(e).lower(): | ||
| return None | ||
| raise | ||
| if provider_id is not None and provider_shield_id is not None: | ||
| return (provider_id, provider_shield_id) | ||
| return None | ||
| finally: | ||
| await client.close() | ||
|
|
||
|
|
||
| async def _register_shield_async( | ||
| shield_id: str, | ||
| provider_id: str, | ||
| provider_shield_id: str, | ||
| ) -> None: | ||
| """Register a shield (restore after unregister).""" | ||
| client = _get_llama_stack_client() | ||
| try: | ||
| await client.shields.register( | ||
| shield_id=shield_id, | ||
| provider_id=provider_id, | ||
| provider_shield_id=provider_shield_id, | ||
| ) | ||
| finally: | ||
| await client.close() | ||
|
|
||
|
|
||
| def unregister_shield( | ||
| identifier: str = "llama-guard", | ||
| ) -> Optional[tuple[str, str]]: | ||
| """Unregister the shield via client.shields.delete(); return (provider_id, provider_shield_id).""" | ||
| return asyncio.run(_unregister_shield_async(identifier)) | ||
|
|
||
|
|
||
| def register_shield( | ||
| shield_id: str = "llama-guard", | ||
| provider_id: Optional[str] = None, | ||
| provider_shield_id: Optional[str] = None, | ||
| ) -> None: | ||
| """Re-register the shield via client.shields.register().""" | ||
| if not provider_id: | ||
| provider_id = os.getenv("E2E_LLAMA_GUARD_PROVIDER_ID", "llama-guard") | ||
| if not provider_shield_id: | ||
| provider_shield_id = os.getenv( | ||
| "E2E_LLAMA_GUARD_PROVIDER_SHIELD_ID", | ||
| "openai/gpt-4o-mini", | ||
| ) | ||
| asyncio.run(_register_shield_async(shield_id, provider_id, provider_shield_id)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid unconditional shield re-registration; it can corrupt scenario isolation.
At Line 246,
register_shield(...)runs for every@disable-shieldsscenario. But Line 187 can returnNone(shield absent), and thenregister_shieldfalls back to defaults, potentially creating a shield that did not exist before the scenario.🔧 Suggested fix
Also applies to: 245-256
🤖 Prompt for AI Agents