Refactor: reformat all code for lefthook using ruff and gofmt (#16585)

This commit is contained in:
Wang Qi
2026-07-03 12:53:39 +08:00
committed by GitHub
parent 19fcb4a981
commit 6a4b9be426
588 changed files with 11123 additions and 15412 deletions

View File

@@ -74,10 +74,7 @@ def step_01_open_login(
lowered = seeded_email.lower()
example_domain = "infiniflow.io"
if lowered.endswith(f"@{example_domain}"):
raise AssertionError(
"SEEDED_USER_EMAIL must be a real account (not *@example.com). "
"Set valid credentials or use DEMO_CREDS=1 for demo mode."
)
raise AssertionError("SEEDED_USER_EMAIL must be a real account (not *@example.com). Set valid credentials or use DEMO_CREDS=1 for demo mode.")
print(f"[AUTH] using email: {seeded_email} (source={source})", flush=True)
flow_state["seeded_email"] = seeded_email
flow_state["seeded_password"] = seeded_password
@@ -162,9 +159,9 @@ def step_03_verify_login(
return false;
}}
""".format(
post_login_path=post_login_path_js,
auth_status_selector=auth_status_selector,
)
post_login_path=post_login_path_js,
auth_status_selector=auth_status_selector,
)
with step("wait for success or error"):
try:
@@ -175,9 +172,7 @@ def step_03_verify_login(
except PlaywrightTimeoutError as exc:
snap("failure")
_debug_login_state(page, "wait_for_outcome_timeout")
raise AssertionError(
f"Login result did not resolve in time. url={page.url}"
) from exc
raise AssertionError(f"Login result did not resolve in time. url={page.url}") from exc
with step("verify authenticated UI marker"):
outcome = result.json_value()
@@ -185,18 +180,13 @@ def step_03_verify_login(
snap("error")
snap("failure")
_debug_login_state(page, "login_error")
raise AssertionError(
"Login error detected. "
f"url={page.url}"
)
raise AssertionError(f"Login error detected. url={page.url}")
path = urlparse(page.url).path
if post_login_path:
if not path.startswith(post_login_path):
snap("failure")
_debug_login_state(page, "post_login_path_mismatch")
raise AssertionError(
f"Post-login path mismatch. expected_prefix={post_login_path} url={page.url}"
)
raise AssertionError(f"Post-login path mismatch. expected_prefix={post_login_path} url={page.url}")
elif "/login" in path:
snap("failure")
_debug_login_state(page, "still_on_login_path")
@@ -209,9 +199,7 @@ def step_03_verify_login(
except AssertionError as exc:
snap("failure")
_debug_login_state(page, "login_form_still_visible")
raise AssertionError(
f"Login form still visible after login. url={page.url}"
) from exc
raise AssertionError(f"Login form still visible after login. url={page.url}") from exc
snap("success")

View File

@@ -26,9 +26,7 @@ def _debug_register_response(page, response_info: dict) -> None:
if isinstance(message, str) and len(message) > 300:
message = message[:300]
print(
"[auth-debug] register_response "
f"url={response_info.get('__url__')} status={response_info.get('__status__')} "
f"code={response_info.get('code')} message={message}",
f"[auth-debug] register_response url={response_info.get('__url__')} status={response_info.get('__status__')} code={response_info.get('code')} message={message}",
flush=True,
)
try:
@@ -54,7 +52,8 @@ def _wait_for_auth_not_loading(page, timeout_ms: int = 5000) -> None:
if (!status) return true;
return status.getAttribute('data-state') !== 'loading';
}
""" % auth_status_selector,
"""
% auth_status_selector,
timeout=timeout_ms,
)
@@ -166,15 +165,12 @@ def step_03_submit_registration(
),
snap("retry_submitted" if retried else "submitted"),
),
lambda resp: resp.request.method == "POST"
and "/api/v1/users" in resp.url,
lambda resp: resp.request.method == "POST" and "/api/v1/users" in resp.url,
timeout_ms=RESULT_TIMEOUT_MS,
)
except PlaywrightTimeoutError as exc:
snap("failure")
raise AssertionError(
f"Register response not received in time. url={page.url} email={current_email}"
) from exc
raise AssertionError(f"Register response not received in time. url={page.url} email={current_email}") from exc
_debug_register_response(page, response_info)

View File

@@ -27,9 +27,7 @@ def _debug_register_response(page, response_info: dict) -> None:
if isinstance(message, str) and len(message) > 300:
message = message[:300]
print(
"[auth-debug] register_response "
f"url={response_info.get('__url__')} status={response_info.get('__status__')} "
f"code={response_info.get('code')} message={message}",
f"[auth-debug] register_response url={response_info.get('__url__')} status={response_info.get('__status__')} code={response_info.get('code')} message={message}",
flush=True,
)
try:
@@ -41,9 +39,7 @@ def _debug_register_response(page, response_info: dict) -> None:
print(f"[auth-debug] sonner_toast_dump_failed: {exc}", flush=True)
def _wait_for_login_outcome(
page, post_login_path: str | None, timeout_ms: int = RESULT_TIMEOUT_MS
):
def _wait_for_login_outcome(page, post_login_path: str | None, timeout_ms: int = RESULT_TIMEOUT_MS):
auth_status_selector = json.dumps(AUTH_STATUS)
return page.wait_for_function(
"""
@@ -72,7 +68,8 @@ def _wait_for_login_outcome(
if (successByUrl || successMarker) return { state: 'success' };
return false;
}
""" % auth_status_selector,
"""
% auth_status_selector,
post_login_path,
timeout=timeout_ms,
)
@@ -171,15 +168,12 @@ def step_03_register_user(
auth_click(submit_button, "submit_register"),
snap("register_submitted"),
),
lambda resp: resp.request.method == "POST"
and "/api/v1/users" in resp.url,
lambda resp: resp.request.method == "POST" and "/api/v1/users" in resp.url,
timeout_ms=RESULT_TIMEOUT_MS,
)
except PlaywrightTimeoutError as exc:
snap("register_failure")
raise AssertionError(
f"Register response not received in time. url={page.url}"
) from exc
raise AssertionError(f"Register response not received in time. url={page.url}") from exc
_debug_register_response(page, response_info)
@@ -187,9 +181,7 @@ def step_03_register_user(
snap("register_error_response")
snap("register_failure")
raise AssertionError(
"Registration error detected. "
f"url={response_info.get('__url__')} status={response_info.get('__status__')} "
f"code={response_info.get('code')} message={response_info.get('message')}"
f"Registration error detected. url={response_info.get('__url__')} status={response_info.get('__status__')} code={response_info.get('code')} message={response_info.get('message')}"
)
snap("register_success_response")
@@ -258,9 +250,7 @@ def step_05_verify_login(
login_result = _wait_for_login_outcome(page, post_login_path)
except PlaywrightTimeoutError as exc:
snap("login_failure")
raise AssertionError(
f"Login result did not resolve in time. url={page.url}"
) from exc
raise AssertionError(f"Login result did not resolve in time. url={page.url}") from exc
login_outcome = login_result.json_value()
if login_outcome.get("state") == "error":
@@ -272,9 +262,7 @@ def step_05_verify_login(
if post_login_path:
if not path.startswith(post_login_path):
snap("login_failure")
raise AssertionError(
f"Post-login path mismatch. expected_prefix={post_login_path} url={page.url}"
)
raise AssertionError(f"Post-login path mismatch. expected_prefix={post_login_path} url={page.url}")
elif "/login" in path:
snap("login_failure")
raise AssertionError(f"URL still on login after submit. url={page.url}")

View File

@@ -37,9 +37,7 @@ def step_02_validate_page(ctx: FlowContext, step, snap):
input_count = page.locator("input").count()
logo_count = page.locator("img[alt='logo']").count()
if root_count + input_count + logo_count == 0:
raise AssertionError(
_format_diag(page, response, "No SPA root, inputs, or logo found")
)
raise AssertionError(_format_diag(page, response, "No SPA root, inputs, or logo found"))
STEPS = [
@@ -52,9 +50,7 @@ STEPS = [
@pytest.mark.p0
@pytest.mark.auth
@pytest.mark.parametrize("step_fn", flow_params(STEPS))
def test_auth_page_smoke_flow(
step_fn, flow_page, flow_state, base_url, smoke_login_url, step, snap
):
def test_auth_page_smoke_flow(step_fn, flow_page, flow_state, base_url, smoke_login_url, step, snap):
ctx = FlowContext(
page=flow_page,
state=flow_state,
@@ -73,7 +69,4 @@ def _format_diag(page, response, reason: str) -> str:
url = page.url
title = page.title()
snippet = page.content().strip().replace("\n", " ")[:500]
return (
f"{reason}. url={url} title={title} status={status} "
f"content_type={content_type} snippet={snippet}"
)
return f"{reason}. url={url} title={title} status={status} content_type={content_type} snippet={snippet}"

View File

@@ -44,7 +44,5 @@ STEPS = [
@pytest.mark.p1
@pytest.mark.auth
@pytest.mark.parametrize("step_fn", flow_params(STEPS))
def test_sso_optional_flow(
step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap
):
def test_sso_optional_flow(step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap):
step_fn(flow_page, flow_state, login_url, active_auth_context, step, snap)

View File

@@ -13,9 +13,7 @@ def step_01_open_login(flow_page, flow_state, login_url, active_auth_context, st
snap("open")
def step_02_switch_to_register(
flow_page, flow_state, login_url, active_auth_context, step, snap
):
def step_02_switch_to_register(flow_page, flow_state, login_url, active_auth_context, step, snap):
require(flow_state, "login_opened")
form, card = active_auth_context()
toggle_button = card.locator(REGISTER_TAB)
@@ -29,9 +27,7 @@ def step_02_switch_to_register(
snap("toggled_register")
def step_03_assert_register_visible(
flow_page, flow_state, login_url, active_auth_context, step, snap
):
def step_03_assert_register_visible(flow_page, flow_state, login_url, active_auth_context, step, snap):
require(flow_state, "login_opened", "register_toggle_available")
form, _ = active_auth_context()
nickname_input = form.locator(NICKNAME_INPUT)
@@ -40,9 +36,7 @@ def step_03_assert_register_visible(
snap("register_visible")
def step_04_switch_back_to_login(
flow_page, flow_state, login_url, active_auth_context, step, snap
):
def step_04_switch_back_to_login(flow_page, flow_state, login_url, active_auth_context, step, snap):
require(flow_state, "login_opened", "register_toggle_available")
form, card = active_auth_context()
toggle_back = card.locator(LOGIN_TAB)
@@ -52,9 +46,7 @@ def step_04_switch_back_to_login(
snap("toggled_login")
def step_05_assert_login_visible(
flow_page, flow_state, login_url, active_auth_context, step, snap
):
def step_05_assert_login_visible(flow_page, flow_state, login_url, active_auth_context, step, snap):
require(flow_state, "login_opened", "login_toggled_back")
form, _ = active_auth_context()
nickname_input = form.locator(NICKNAME_INPUT)
@@ -74,7 +66,5 @@ STEPS = [
@pytest.mark.p1
@pytest.mark.auth
@pytest.mark.parametrize("step_fn", flow_params(STEPS))
def test_toggle_login_register_flow(
step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap
):
def test_toggle_login_register_flow(step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap):
step_fn(flow_page, flow_state, login_url, active_auth_context, step, snap)

View File

@@ -5,9 +5,7 @@ from test.playwright.helpers.auth_selectors import EMAIL_INPUT, SUBMIT_BUTTON
from test.playwright.helpers.flow_steps import flow_params, require
def step_01_open_login(
flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click
):
def step_01_open_login(flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click):
page = flow_page
with step("open login page"):
page.goto(login_url, wait_until="domcontentloaded")
@@ -15,9 +13,7 @@ def step_01_open_login(
snap("open")
def step_02_submit_empty(
flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click
):
def step_02_submit_empty(flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click):
require(flow_state, "login_opened")
form, _ = active_auth_context()
expect(form.locator(EMAIL_INPUT)).to_have_count(1)
@@ -30,9 +26,7 @@ def step_02_submit_empty(
snap("submitted_empty")
def step_03_assert_validation(
flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click
):
def step_03_assert_validation(flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click):
require(flow_state, "login_opened", "submitted_empty")
form, _ = active_auth_context()
invalid_inputs = form.locator("input[aria-invalid='true']")
@@ -52,11 +46,7 @@ def step_03_assert_validation(
except AssertionError:
pass
raise AssertionError(
"No validation feedback detected after submitting an empty login form. "
"Expected aria-invalid inputs or visible error containers. "
"See artifacts for DOM evidence."
)
raise AssertionError("No validation feedback detected after submitting an empty login form. Expected aria-invalid inputs or visible error containers. See artifacts for DOM evidence.")
STEPS = [
@@ -69,7 +59,5 @@ STEPS = [
@pytest.mark.p1
@pytest.mark.auth
@pytest.mark.parametrize("step_fn", flow_params(STEPS))
def test_validation_presence_flow(
step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click
):
def test_validation_presence_flow(step_fn, flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click):
step_fn(flow_page, flow_state, login_url, active_auth_context, step, snap, auth_click)