Repository navigation
PPLT-6237: Read PERCY_SERVER_ADDRESS; certify Playwright 1.63 #179
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| playwright==1.40.* | ||
| # Playwright 1.63 requires Python >= 3.10; the 3.8/3.9 CI jobs keep the previous pin | ||
| playwright==1.63.*; python_version >= "3.10" | ||
|
Author
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. [Medium] Playwright 1.63 certification only exercised on Python 3.10 CI's test matrix is 3.8/3.9/3.10, so 1.63 runs only on 3.10; Suggestion: Document the certified scope (Python ≥3.10) and consider adding 3.11/3.12 to Reviewer: stack-percy-web-sdks-code-reviewer |
||
| playwright==1.40.*; python_version < "3.10" | ||
| requests==2.* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # pylint: disable=[abstract-class-instantiated, arguments-differ, protected-access, too-many-lines] | ||
| import os | ||
| import json | ||
| import unittest | ||
| import platform | ||
|
|
@@ -35,6 +36,7 @@ | |
| _resolve_readiness_config, | ||
| _wait_for_ready, | ||
| _deep_merge, | ||
| _get_cli_api_address, | ||
| ) | ||
| import percy.screenshot as local | ||
|
|
||
|
|
@@ -93,14 +95,14 @@ def mock_healthcheck( | |
| health_body = json.dumps(health_body) | ||
| httpretty.register_uri( | ||
| httpretty.GET, | ||
| "http://localhost:5338/percy/healthcheck", | ||
| f"{local.PERCY_CLI_API}/percy/healthcheck", | ||
| body=health_body, | ||
| adding_headers=health_headers, | ||
| status=health_status, | ||
| ) | ||
| httpretty.register_uri( | ||
| httpretty.GET, | ||
| "http://localhost:5338/percy/dom.js", | ||
| f"{local.PERCY_CLI_API}/percy/dom.js", | ||
| body=( | ||
| "window.PercyDOM = { serialize: () => { return { html: " | ||
| "document.documentElement.outerHTML } }, waitForResize: () => { " | ||
|
|
@@ -114,7 +116,7 @@ def mock_healthcheck( | |
| def mock_logger(): | ||
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| "http://localhost:5338/percy/log", | ||
| f"{local.PERCY_CLI_API}/percy/log", | ||
| body=json.dumps({"success": True}), | ||
| status=200, | ||
| ) | ||
|
|
@@ -123,7 +125,7 @@ def mock_logger(): | |
| def mock_snapshot(fail=False, data=False): | ||
| httpretty.register_uri( | ||
| httpretty.POST, | ||
| "http://localhost:5338/percy/snapshot", | ||
| f"{local.PERCY_CLI_API}/percy/snapshot", | ||
| body=json.dumps( | ||
| { | ||
| "success": "false" if fail else "true", | ||
|
|
@@ -1109,7 +1111,7 @@ def test_percy_automate_screenshot(self, mock_is_percy_enabled, mock_post): | |
| # Assertions | ||
| self.assertEqual(result, "screenshot_data") | ||
| mock_post.assert_called_once_with( | ||
| "http://localhost:5338/percy/automateScreenshot", | ||
| f"{local.PERCY_CLI_API}/percy/automateScreenshot", | ||
| json={ | ||
| "client_info": f"percy-playwright-python/{SDK_VERSION}", | ||
| "environment_info": [ | ||
|
|
@@ -1501,7 +1503,7 @@ def test_get_responsive_widths(self, mock_get): | |
| ], | ||
| ) | ||
| mock_get.assert_called_once_with( | ||
| "http://localhost:5338/percy/widths-config?widths=375,1280", | ||
| f"{local.PERCY_CLI_API}/percy/widths-config?widths=375,1280", | ||
| timeout=30, | ||
| ) | ||
|
|
||
|
|
@@ -1536,7 +1538,7 @@ def test_get_responsive_widths_with_none(self, mock_get): | |
| ], | ||
| ) | ||
| mock_get.assert_called_once_with( | ||
| "http://localhost:5338/percy/widths-config", | ||
| f"{local.PERCY_CLI_API}/percy/widths-config", | ||
| timeout=30, | ||
| ) | ||
|
|
||
|
|
@@ -1558,7 +1560,7 @@ def test_get_responsive_widths_with_empty_list(self, mock_get): | |
| ], | ||
| ) | ||
| mock_get.assert_called_once_with( | ||
| "http://localhost:5338/percy/widths-config", | ||
| f"{local.PERCY_CLI_API}/percy/widths-config", | ||
| timeout=30, | ||
| ) | ||
|
|
||
|
|
@@ -2081,5 +2083,27 @@ def test_expose_detach_error_suppressed(self): | |
| expose_closed_shadow_roots(page) | ||
|
|
||
|
|
||
| class TestCliApiAddress(unittest.TestCase): | ||
| def test_prefers_percy_cli_api(self): | ||
| with patch.dict("os.environ", { | ||
| "PERCY_CLI_API": "http://localhost:1111", | ||
| "PERCY_SERVER_ADDRESS": "http://localhost:2222", | ||
| }): | ||
| self.assertEqual(_get_cli_api_address(), "http://localhost:1111") | ||
|
|
||
| def test_falls_back_to_percy_server_address(self): | ||
| with patch.dict("os.environ", {"PERCY_SERVER_ADDRESS": "http://localhost:2222"}): | ||
| os.environ.pop("PERCY_CLI_API", None) | ||
|
Author
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. [Low] Prefer Works (patch.dict restores env), but inconsistent with Suggestion: Reviewer: stack:percy-web-sdks-code-review |
||
| self.assertEqual(_get_cli_api_address(), "http://localhost:2222") | ||
|
|
||
| def test_ignores_empty_values(self): | ||
| with patch.dict("os.environ", {"PERCY_CLI_API": "", "PERCY_SERVER_ADDRESS": ""}): | ||
| self.assertEqual(_get_cli_api_address(), "http://localhost:5338") | ||
|
|
||
| def test_defaults_to_5338(self): | ||
| with patch.dict("os.environ", {}, clear=True): | ||
| self.assertEqual(_get_cli_api_address(), "http://localhost:5338") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
|
Comment on lines
2083
to
2109
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. 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: set -eu
printf '%s\n' '--- focused diff ---'
git diff --unified=80 e0f07c1f815790f3d09c41f68c2e770b70d50523 0d038c1fcf1cecbb170b2715fcf1f8151c0944bb -- percy/screenshot.py tests/test_screenshot.py
printf '%s\n' '--- address symbols and consumers ---'
rg -n -F -e 'PERCY_CLI_API' -e '_get_cli_api_address' -e 'PERCY_SERVER_ADDRESS' -- percy tests
printf '%s\n' '--- screenshot module imports and address/request definitions ---'
sed -n '1,180p' percy/screenshot.py
printf '%s\n' '--- relevant test imports/setup and address tests ---'
sed -n '1,100p' tests/test_screenshot.py
sed -n '2020,2130p' tests/test_screenshot.pyRepository: percy/percy-playwright-python Length of output: 41459 Assert the module-level address during import.
Reload Suggested fix+import importlib
import os
import json
@@
class TestCliApiAddress(unittest.TestCase):
+ def test_initializes_module_constant_from_percy_server_address(self):
+ original_environment = os.environ.copy()
+ try:
+ with patch.dict(
+ os.environ,
+ {"PERCY_SERVER_ADDRESS": "http://localhost:2222"},
+ clear=True,
+ ):
+ importlib.reload(local)
+ self.assertEqual(
+ local.PERCY_CLI_API,
+ "http://localhost:2222",
+ )
+ finally:
+ os.environ.clear()
+ os.environ.update(original_environment)
+ importlib.reload(local)
+
def test_prefers_percy_cli_api(self):🤖 Prompt for AI Agents |
||
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.
[Low] Resolved address not normalised
A trailing slash in
PERCY_SERVER_ADDRESS/PERCY_CLI_APIproduces//percy/...URLs.Suggestion:
.rstrip("/")the resolved value.Reviewer: stack-percy-web-sdks-code-reviewer