Skip to content

feat: add auth preprocessor and update auth handler.#227

Open
kalenkevich wants to merge 3 commits intofeat/oauth_part2from
feat/oauth_part3
Open

feat: add auth preprocessor and update auth handler.#227
kalenkevich wants to merge 3 commits intofeat/oauth_part2from
feat/oauth_part3

Conversation

@kalenkevich
Copy link
Copy Markdown
Collaborator

Overview

This PR improves the test coverage and fixes inconsistencies in the authentication handling logic for the ADK-JS project. It addresses a bug in AuthHandler where exchange results were stored incorrectly, enhances existing tests to verify actual generated values (like URLs and states), and introduces a new unit test suite for the AuthPreprocessor.

Key Changes

Bug Fixes

AuthHandler

  • Removed a type inconsistency in parseAndStoreAuthResponse where the full ExchangeResult object was unintentionally stored in session state. Now, it correctly stores only the nested AuthCredential (exchangedCredential.credential), aligning with how getAuthResponse retrieves it.

Testing Enhancements

AuthHandler Tests

  • New Coverage: Added comprehensive unit tests for parseAndStoreAuthResponse to cover:
    • Non-OAuth2 storage mechanics.
    • Early-return conditions for unsupported schemes.
    • Successful OAuth2 exchanges.
  • Improved Assertions:
    • generateAuthUri tests now assert the actual generated URL string and query parameters (such as client_id, redirect_uri, scope, and dynamic state) rather than returning stubs.
    • generateAuthRequest tests assert usage of the generated credentials.

[NEW] AuthPreprocessor Tests

  • Created unit tests covering AuthPreprocessor.runAsync generator logic:
    • Verification of early-return scenarios:
      • Agent is not an LlmAgent.
      • Active session has no events or user content.
      • Message history contains no adk_request_credential tool-resume responses.
    • Successful tool resumption scenario: verifies the preprocessor intercepts a user's credential input, updates state storage, parses resume target tool calls, and delegates continuity via handleFunctionCallsAsync.
  • Standardized Vitest mocking conventions and TypeScript types for handleFunctionCallsAsync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants