fix(lint): F821 undefined 'e' in test_scm_configured; shfmt/ruff auto-fixes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

- test_scm_configured.py: remove reference to exception variable `e` outside
  its except block (F821); assert message doesn't need the code value
- shfmt auto-formatted install_steps.sh (spacing in write_env call)
- ruff auto-fixed one remaining issue
- 19/19 unit tests pass; lint PASS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
autonomic-bot
2026-06-11 22:17:19 +00:00
parent 4f8943d10e
commit 1be74fb9e1
12 changed files with 89 additions and 69 deletions

View File

@ -122,7 +122,10 @@ def test_fallback_skips_warm_entries(tmp_path, monkeypatch):
deps.write_run_state(mixed)
raw = deps.load_run_state()
cold_raw = [e for e in (raw if isinstance(raw, list) else list(raw.values()))
if isinstance(e, dict) and not e.get("warm")]
cold_raw = [
e
for e in (raw if isinstance(raw, list) else list(raw.values()))
if isinstance(e, dict) and not e.get("warm")
]
assert len(cold_raw) == 1
assert cold_raw[0]["recipe"] == "gitea"

View File

@ -39,7 +39,9 @@ def test_gitea_recipe_meta_health():
def test_gitea_recipe_meta_extra_env():
"""gitea EXTRA_ENV returns sqlite3 COMPOSE_FILE and relaxed access controls."""
m = _load("gitea")
ctx = types.SimpleNamespace(domain="gite-abc123.ci.commoninternet.net", base_url="", meta=m, deps={}, op=None)
ctx = types.SimpleNamespace(
domain="gite-abc123.ci.commoninternet.net", base_url="", meta=m, deps={}, op=None
)
env = meta_mod.extra_env(m, ctx)
assert "compose.sqlite3.yml" in env.get("COMPOSE_FILE", "")
assert env.get("GITEA_REQUIRE_SIGNIN_VIEW") == "false"
@ -75,15 +77,18 @@ def _fake_setup_gitea_oauth(provider_domain, parent_domain):
def test_enrich_deps_routes_gitea(monkeypatch):
"""_enrich_deps_with_sso returns a correctly shaped entry for the gitea dep."""
import importlib
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
# Import the orchestrator; monkeypatch sso.setup_gitea_oauth so no real deploy happens
import run_recipe_ci
from harness import sso
monkeypatch.setattr(sso, "setup_gitea_oauth", _fake_setup_gitea_oauth)
deps_list = [{"recipe": "gitea", "domain": "gite-aabbcc.ci.commoninternet.net"}]
result = run_recipe_ci._enrich_deps_with_sso("drone", "dron-112233.ci.commoninternet.net", deps_list)
result = run_recipe_ci._enrich_deps_with_sso(
"drone", "dron-112233.ci.commoninternet.net", deps_list
)
assert "gitea" in result
entry = result["gitea"]
@ -99,6 +104,7 @@ def test_enrich_deps_gitea_does_not_call_keycloak_path(monkeypatch):
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
import run_recipe_ci
from harness import sso
monkeypatch.setattr(sso, "setup_gitea_oauth", _fake_setup_gitea_oauth)
called_keycloak = []
@ -118,36 +124,39 @@ def test_enrich_deps_gitea_does_not_call_keycloak_path(monkeypatch):
# ---------------------------------------------------------------------------
@pytest.mark.parametrize("location_url,gitea_domain,client_id,expect_pass", [
# Correct redirect: Location header points to gitea dep's authorize endpoint with matching client_id
(
"https://gite-aabbcc.ci.commoninternet.net/login/oauth/authorize?client_id=abc-123&redirect_uri=x",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
True,
),
# Wrong domain: drone redirected to production gitea, not the dep
(
"https://git.autonomic.zone/login/oauth/authorize?client_id=abc-123",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
# Wrong path: not the OAuth authorize endpoint (e.g. gitea's /user/login after full-redirect-follow)
(
"https://gite-aabbcc.ci.commoninternet.net/user/login?client_id=abc-123",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
# Wrong client_id: drone is using a different OAuth app
(
"https://gite-aabbcc.ci.commoninternet.net/login/oauth/authorize?client_id=wrong-id",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
])
@pytest.mark.parametrize(
"location_url,gitea_domain,client_id,expect_pass",
[
# Correct redirect: Location header points to gitea dep's authorize endpoint with matching client_id
(
"https://gite-aabbcc.ci.commoninternet.net/login/oauth/authorize?client_id=abc-123&redirect_uri=x",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
True,
),
# Wrong domain: drone redirected to production gitea, not the dep
(
"https://git.autonomic.zone/login/oauth/authorize?client_id=abc-123",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
# Wrong path: not the OAuth authorize endpoint (e.g. gitea's /user/login after full-redirect-follow)
(
"https://gite-aabbcc.ci.commoninternet.net/user/login?client_id=abc-123",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
# Wrong client_id: drone is using a different OAuth app
(
"https://gite-aabbcc.ci.commoninternet.net/login/oauth/authorize?client_id=wrong-id",
"gite-aabbcc.ci.commoninternet.net",
"abc-123",
False,
),
],
)
def test_scm_redirect_assertions(location_url, gitea_domain, client_id, expect_pass):
"""Parametrized verification of the SCM-configured test assertion logic (no HTTP calls).