-
Notifications
You must be signed in to change notification settings - Fork 49
Wire up six dead config settings #542
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
amirfz
wants to merge
1
commit into
main
Choose a base branch
from
fix/wire-dead-config-settings
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
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
50 changes: 50 additions & 0 deletions
50
src/tests/unit_tests/scrape/test_file_scraper_size_limit.py
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,50 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from sherpa_ai.scrape.file_scraper import QuestionWithFileHandler | ||
|
|
||
|
|
||
| def _make_handler(): | ||
| return QuestionWithFileHandler( | ||
| question="what does this say?", | ||
| files=[{ | ||
| "id": "f1", | ||
| "filetype": "txt", | ||
| "mimetype": "text/plain", | ||
| "url_private_download": "https://example.com/f.txt", | ||
| }], | ||
| token="token", | ||
| user_id="user1", | ||
| team_id="team1", | ||
| llm=None, | ||
| ) | ||
|
|
||
|
|
||
| def _mock_response(content: bytes): | ||
| response = MagicMock() | ||
| response.status_code = 200 | ||
| response.content = content | ||
| return response | ||
|
|
||
|
|
||
| def test_download_file_rejects_oversized_file(): | ||
| handler = _make_handler() | ||
| oversized_content = b"x" * 10 | ||
|
|
||
| with patch("sherpa_ai.scrape.file_scraper.safe_get", return_value=_mock_response(oversized_content)), \ | ||
| patch("sherpa_ai.scrape.file_scraper.cfg.FILE_SIZE_LIMIT", 5): | ||
| result = handler.download_file(handler.files[0]) | ||
|
|
||
| assert result["status"] == "error" | ||
| assert "size" in result["message"].lower() | ||
|
|
||
|
|
||
| def test_download_file_accepts_file_within_limit(): | ||
| handler = _make_handler() | ||
| small_content = b"hello world" | ||
|
|
||
| with patch("sherpa_ai.scrape.file_scraper.safe_get", return_value=_mock_response(small_content)), \ | ||
| patch("sherpa_ai.scrape.file_scraper.cfg.FILE_SIZE_LIMIT", 1000): | ||
| result = handler.download_file(handler.files[0]) | ||
|
|
||
| assert result["status"] == "success" | ||
| assert result["data"] == "hello world" |
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.
Are we using this env var? MODEL_PRICING_CONFIG_PATH
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.
Yes — that's exactly what this PR wires up.
MODEL_PRICING_CONFIG_PATHwas previously defined inconfig/__init__.pybut never read anywhere (issue #517). This line (config_path or cfg.MODEL_PRICING_CONFIG_PATH) makesPricingManagerfall back to it when no explicitconfig_pathis passed in, so setting the env var now actually takes effect. Covered bytest_config_path_falls_back_to_env_setting(verified it fails if this fallback is removed).