Skip to content

refactor(cloud_auth): deduplicate repeated logic - #3607

Merged
IsmaelMartinez merged 2 commits into
The-PR-Agent:mainfrom
high-tail:fix/refactoring-cloud_auth
Sep 22, 2026
Merged

IsmaelMartinez merged 2 commits into
The-PR-Agent:mainfrom
high-tail:fix/refactoring-cloud_auth

Conversation

@high-tail

Copy link
Copy Markdown
Contributor

What

  • Deduplication of repeated patterns/logics in claude_auth.py.
  • No new configuration, no prompt or settings edits.

Changes

Each commit extracts one helper and updates its call sites:

Helper Replaces
_rebind_to_globals(native, native_globals) 4 copies of the FunctionType rebind plus __kwdefaults__ copy (Azure OIDC token exchange, the entra companion factory, resolve_captured, initialize)
_require_http_auth_signature(original) 2 byte-identical copies of the api_key/headers/litellm_params parameter check guarding validate_environment

Testing

PYTHONPATH=. uv run pytest tests/unittest
================== 9193 passed, 33 skipped, 1 xfailed, 833 warnings in 74.94s (0:01:14) ==================
uv run ruff check pr_agent/algo/ai_handlers/cloud_auth.py
All checks passed!
uv run pre-commit run --files pr_agent/algo/ai_handlers/cloud_auth.py                                                        
check for added large files..............................................Passed
check python ast.........................................................Passed
check for case conflicts.................................................Passed
check json...........................................(no files to check)Skipped
check for merge conflicts................................................Passed
check toml...........................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
check illegal windows names..........................(no files to check)Skipped
check for broken symlinks............................(no files to check)Skipped
debug statements (python)................................................Passed
detect destroyed symlinks................................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
trim trailing whitespace.................................................Passed
Lint GitHub Actions workflow files...................(no files to check)Skipped
ruff check...............................................................Passed

@high-tail high-tail changed the title refactoring(cloud_auth): deduplicate repeated logic refactor(cloud_auth): deduplicate repeated logic Sep 22, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Deduplicate cloud authentication helper logic

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Centralizes native function rebinding while preserving positional and keyword defaults.
• Reuses one LiteLLM validator signature check across HTTP authentication guard bridges.
• Keeps cloud authentication behavior and configuration unchanged.
Diagram

graph TD
  Azure["Azure Auth Paths"] -->|"delegates"| Rebind["Rebind Helper"] -->|"constructs"| Function["FunctionType Rebind"]
  Guards["Raw Key Guards"] -->|"delegates"| Signature["Signature Helper"] -->|"inspects"| Inspect["Python Introspection"]
Loading
High-Level Assessment

The shared-helper approach is appropriate because both extracted patterns require exact, consistent behavior across multiple authentication paths. Retaining inline copies would increase compatibility drift, while broader abstractions would add unnecessary complexity for two narrowly defined operations.

Files changed (1) +23 / -23

Refactor (1) +23 / -23
cloud_auth.pyExtract shared function-rebinding and signature-validation helpers +23/-23

Extract shared function-rebinding and signature-validation helpers

• Adds '_rebind_to_globals' and applies it to four Azure authentication paths while preserving defaults, keyword defaults, closures, and captured globals. Adds '_require_http_auth_signature' and reuses it in both raw API-key guard installers without changing validation behavior.

pr_agent/algo/ai_handlers/cloud_auth.py

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review
  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping both extractions this tight. Approving: they are behaviour-preserving.

I rebuilt each rebind the old way and the new way and compared __code__, __name__, __defaults__, __kwdefaults__, __closure__, __qualname__ and __dict__. Identical, and the kwdefaults copy is still a copy rather than the native dict. The signature guard raises the same RuntimeError with the same message.

Coverage over the existing suite reaches all four rebind call sites and both guard call sites, so this is exercised rather than merely compiling.

@IsmaelMartinez
IsmaelMartinez merged commit 9d7b5c7 into The-PR-Agent:main Sep 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants