-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Fix Redis key generation to be stable across working directories #27025
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,8 @@ | |||||||||||
| VCR_VERBOSE_ENV = "LITELLM_VCR_VERBOSE" | ||||||||||||
| MAX_EPISODES_PER_CASSETTE = 50 | ||||||||||||
|
|
||||||||||||
| _REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||||||||||||
|
|
||||||||||||
| _log = logging.getLogger(__name__) | ||||||||||||
| _passed_by_cassette_key: dict[str, bool] = {} | ||||||||||||
|
|
||||||||||||
|
|
@@ -22,7 +24,11 @@ def mark_test_outcome_for_cassette(cassette_path: str, passed: bool) -> None: | |||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def redis_key_for(cassette_path: str) -> str: | ||||||||||||
| rel = os.path.relpath(str(cassette_path)) | ||||||||||||
| abs_path = os.path.abspath(str(cassette_path)) | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| try: | ||||||||||||
| rel = os.path.relpath(abs_path, start=_REPO_ROOT) | ||||||||||||
| except ValueError: | ||||||||||||
| rel = os.path.basename(abs_path) | ||||||||||||
|
Comment on lines
+30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| if rel.endswith(".yaml"): | ||||||||||||
| rel = rel[: -len(".yaml")] | ||||||||||||
| rel = rel.replace("/cassettes/", "/").lstrip("./") | ||||||||||||
|
|
||||||||||||
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.
os.path.abspathdoes not resolve symlinks, so_REPO_ROOTand a cassette path can represent the same physical location via different string prefixes (one through a symlink, one through the real path). In that caseos.path.relpath(abs_path, start=_REPO_ROOT)produces a../../…path which the subsequentlstrip("./")then silently mangles into a wrong key. Usingos.path.realpathfor both would make the prefix comparison reliable.