refactor: implement browser preferences types and validation#294
refactor: implement browser preferences types and validation#294ArthurRodrigues4433 wants to merge 7 commits intoautoscrape-labs:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Opa, tudo bem? precisa de alguma ajuda com os erros? |
|
Sim, Está passando nos testes locais mas sempre falha nos teste aqui do GitHub! |
652071c to
b35cced
Compare
225164b to
c8731eb
Compare
d2c8b63 to
0ba0fa7
Compare
|
Hello @ArthurRodrigues4433, obrigado pela contribuição e perdao pela demora. Consegue dar uma olhada nos conflitos? |
📝 WalkthroughWalkthroughThis change implements type-safe browser preference management through TypedDict-based structures, validation schemas, and exception types. The Changes
Sequence DiagramssequenceDiagram
participant Client
participant ChromiumOptions
participant Validator
participant Storage
Client->>ChromiumOptions: set browser_preferences(prefs)
ChromiumOptions->>Validator: _validate_pref_path(path)
alt Invalid Path
Validator-->>ChromiumOptions: InvalidPreferencePath
ChromiumOptions-->>Client: Error
else Valid Path
ChromiumOptions->>Validator: _validate_pref_value(path, value)
alt Invalid Value
Validator-->>ChromiumOptions: InvalidPreferenceValue
ChromiumOptions-->>Client: Error
else Valid Value
ChromiumOptions->>Storage: merge/update preferences
Storage-->>ChromiumOptions: Success
ChromiumOptions-->>Client: Success
end
end
sequenceDiagram
participant Client
participant ChromiumOptions
participant Validator
participant Storage
Client->>ChromiumOptions: get browser_preferences
ChromiumOptions->>ChromiumOptions: _get_pref_path(path)
ChromiumOptions->>Validator: _validate_pref_path(path)
alt Invalid Path
Validator-->>ChromiumOptions: InvalidPreferencePath
ChromiumOptions-->>Client: Error
else Valid Path
ChromiumOptions->>Storage: retrieve value
Storage-->>ChromiumOptions: value
ChromiumOptions-->>Client: BrowserPreferences
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly Related Issues
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@pydoll/browser/options.py`:
- Around line 137-140: The check using preferences.get('prefs') in options.py is
only truthy and won’t catch keys with falsy values; change it to detect the
presence of the top-level key instead (e.g., use "'prefs' in preferences") so
that the WrongPrefsDict raised from this block (the same exception class
referenced) triggers whenever a top-level 'prefs' key exists, even if its value
is {} or None; keep the existing error message and surrounding logic unchanged.
In `@pydoll/browser/preference_types.py`:
- Around line 6-29: The TypedDicts DownloadPreferences and ProfilePreferences
are declared as fully required but _set_pref_path and the browser_preferences
property populate partial dicts (e.g., only prompt_for_download or only
password_manager_enabled); change DownloadPreferences and ProfilePreferences to
be partial by adding total=False (i.e., declare "class
DownloadPreferences(TypedDict, total=False)" and "class
ProfilePreferences(TypedDict, total=False)") so their types match runtime
construction and callers of browser_preferences won't expect missing keys.
|
Olá @thalissonvs, sem problema! |
Pull Request
Description
Esta PR refatora o sistema de preferências do browser (
ChromiumOptions) para adicionar tipagem forte, validação e melhor tratamento de erros. As principais mudanças incluem:TypedDictsparaBrowserPreferences,DownloadPreferenceseProfilePreferences, garantindo tipo seguro e autocomplete em IDEs.PREFERENCE_SCHEMApara validação de caminhos e tipos de valores._validate_pref_pathe_validate_pref_valueadicionados para checagem rigorosa de caminhos e tipos de preferências.browser_preferences,prompt_for_download,password_manager_enabled,open_pdf_externally) para refletirem tipagem correta e retornaremOptionalquando apropriado.WrongPrefsDict,InvalidPreferencePatheInvalidPreferenceValue.temp_dir_managere no tratamento de argumentos doChromiumOptions.Related Issue(s)
#289
Type of Change
How Has This Been Tested?
Testing Checklist
Screenshots
Implementation Details
API Changes
Não há mudanças na API pública. As alterações são internas e mantêm compatibilidade total com o código existente.
Additional Info
Checklist before requesting a review
poetry run task lintand fixed any issuespoetry run task testand all tests passSummary by CodeRabbit
Release Notes
New Features
InvalidPreferencePathorInvalidPreferenceValueexceptions.Bug Fixes
prompt_for_download,password_manager_enabled, andopen_pdf_externallynow correctly returnOptional[bool]to reflect possible absence of values.Tests