Test: build the tool_auth_handler suite from real Contexts - #845
Open
AmaadMartin wants to merge 2 commits into
Open
Test: build the tool_auth_handler suite from real Contexts#845AmaadMartin wants to merge 2 commits into
AmaadMartin wants to merge 2 commits into
Conversation
added 2 commits
August 8, 2026 22:13
The suite forced object literals into the Context type with 'as unknown as', so it stubbed getAuthResponse, requestCredential and State. A change to the auth-response key derivation or to the State delta wiring could not fail a test. Every tool context is now a real Context over a real Session, the credential exchanger is one hoisted mock shared by each constructed instance, and the six incomplete apiKey scheme literals become one typed constant. All nine test titles and every assertion are unchanged apart from their receiver.
The hand-copied parameter and return types could drift from the interface they mock. Deriving the mock from BaseCredentialExchanger['exchange'] keeps them in step and drops two imports that only spelled the signature out.
This was referenced Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
N/A
Problem:
tool_auth_handler_test.tsforced object literals into theContexttype withas unknown as11 times. Each stub replacedgetAuthResponse,requestCredentialand the delta-awareStatewithvi.fn(), so the suite could not see the real key derivation or the real state plumbing. A drift in either one kept all nine tests green.Solution: Every tool context is now a real
Contextover a realSession, built by one local factory. The credential exchanger is a single hoisted mock, typed fromBaseCredentialExchanger['exchange']so it cannot drift from the interface it stands in for, shared by each constructed instance; that removes the last cast. The nine test titles and every assertion are unchanged apart from their receiver, plus two assertions that pin the effects the real methods now produce.Two deliberate deviations from the plan, both grounded in this file:
{type: 'apiKey'}literals become oneAPI_KEY_SCHEMEconstant instead of six repeated literals. ItsnameisX-API-Key, the value the file already used at its two complete literals.State.set) was predicted to be invisible to the old stubs. I measured it: the old fixtures also fail it, 3 tests. Mutation 9 below is the real gap.Collision check.
gh pr list --repo AmaadMartin/adk-js --state open --limit 300, thengh pr diff --name-onlyon every plausibly adjacent PR. Four open PRs touch this file and none of them does this change:name/into the six apiKey literals, keeps the castsAPI_KEY_SCHEMEconstant, keeps the castsdescribeblock at the end (plus a src change)This PR is based on
main, as the approved plan directs. Stacking is not possible on four independent bases. On a conflict with #742 or #764, take this branch's version of the file; #772 and #774 append and should merge cleanly.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
Commands, run at
d75eeaa4:No product code changed, so coverage is unchanged by construction.
Mutation proof. Each mutation is applied to
core/src/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.ts, then reverted.if (!this.authScheme)guardshould return done if no auth schemeCannot read properties of undefined (reading 'type')const authResponseCredential = undefined;should return done after exchange...,should store exchanged credential...,re-uses a credential persisted...expected 'pending' to be 'done'requestCredential(authConfig)callshould return pending and request credential...expected "requestCredential" to be called at least onceif (existingCredential)early returnshould return cached credential if available,re-uses a credential persisted...expected 'pending' to be 'done'state.set(key, credential)should store exchanged credential...,re-uses a credential persisted...,caches a static credential...expected undefined to be 'exchanged-token'?? this.authCredentialfallbackuses the credential the tool was configured with...,does not copy a static credential...,caches a static credential...expected 'pending' to be 'done'if (true)does not copy a static credential...expected { authType: 'apiKey', …(1) } to be undefinedif (authResponseCredential)caches a static credential...expected undefined to be 'exchanged-token'Each of the nine tests is killed by at least one mutation.
Two more mutations show what the stubs hid. Both were run against the old fixtures and the new ones.
auth_handler.ts: auth-response key prefixtemp:totemp_context.ts:requestCredentialstops writing toeventActions.requestedAuthConfigsexpected undefined to be definedManual End-to-End (E2E) Tests:
No E2E test. This is a test-fixture change with no product code in the diff, so there is no runtime behaviour to exercise. To check it by hand:
Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.