Fix: drop the dead nodejs-vertexai mock from the VertexAiSessionService tests - #563
Open
AmaadMartin wants to merge 1 commit into
Open
Fix: drop the dead nodejs-vertexai mock from the VertexAiSessionService tests#563AmaadMartin wants to merge 1 commit into
AmaadMartin wants to merge 1 commit into
Conversation
…ervice tests
The test file opened with a vi.mock('nodejs-vertexai', ...) factory and the
comment "Mock the unreleased nodejs-vertexai package so the import resolves".
No such package is declared in any package.json or the lockfile, nothing in the
tree imports it, and the mocked SessionsClient symbol was referenced only by its
own declaration inside that factory. The suite exercises the real
@google-cloud/vertexai Sessions surface instead, so Vitest registered a factory
for a specifier that is never resolved and the factory body never ran.
The vi import stays: it is still used by vi.fn in the client stub, the fake
timer helpers, and six vi.spyOn call sites.
Test count is unchanged at 57 passing in 1 file.
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
Link to an existing issue (if applicable):
No existing issue. The block being removed was introduced with the file itself in Add support for Agent Engine Sessions google/adk-js#249 ("Add support for Agent Engine Sessions").
Or, if no issue exists, describe the change:
Problem:
core/test/sessions/vertex_ai_session_service_test.tsopened with avi.mock('nodejs-vertexai', ...)factory carrying the comment// Mock the unreleased nodejs-vertexai package so the import resolves. That premise is false — there is no import to resolve:nodejs-vertexaiis declared nowhere. Not in the rootpackage.json, not incore/package.json, not inpackage-lock.json, and no file undercore/,dev/,integrations/ortests/imports it. Before this change a repo-wide search returned exactly two hits, both in this one file: the comment and thevi.mockcall.SessionsClienthad exactly one reference in the whole repo — its own declaration inside that factory. Nothing constructed or imported it.Sessionsfrom@google-cloud/vertexai, whichcore/package.jsondeclares as"@google-cloud/vertexai": "^1.12.0", and that is the same packagecore/src/sessions/vertex_ai_session_service.tsimportsClient,Sessionsand its request/response types from.The net effect was a mock factory registered for a specifier that is never resolved, so the factory body never executed. It was inert but actively misleading: a reader would reasonably conclude the suite depends on an unreleased Vertex AI client.
Solution: Delete the comment and the
vi.mockfactory — 11 lines, one file, 0 insertions. Why this rather than anything larger: the block is dead, so deletion is the whole fix; no production code, nopackage.json, no config, and no other mock, import, fixture or assertion is touched. The 57 existing test cases are the regression signal and are left byte-identical.vistays imported deliberately. It is still used byvi.fn()in thebeforeEachclient stub, byvi.useFakeTimers()/vi.runAllTimersAsync()/vi.useRealTimers(), and by sixvi.spyOn(...)call sites. Dropping it would trip@typescript-eslint/no-unused-vars.The two import groups keep their existing contents and order; only the now-redundant second blank line between them goes with the block (leaving both blank lines fails
npm run format:checkunderprettier-plugin-organize-imports).Collision check (run before any code was written):
gh pr list --repo AmaadMartin/adk-js --state open --limit 1000across all open PRs, filtered for vertex/mock/dead/remove in titles and branch names, thengh pr diff --name-onlyon every candidate touching or adjacent to this file (#503, #287, #270, #201, #474, #303, #475, #439, #515, #274, #512, #460). Result:fix/vertexai-deep-import-adapter) overlaps and deletes this same block as collateral of a much larger change — it introduces a newcore/src/utils/vertex_ai_internal.tsadapter and rewrites this test'sSessionsimport to point at it, across 8 files including production source. This PR is the standalone deletion with no source changes; if Fix: contain @google-cloud/vertexai build-output deep imports behind one adapter module #303 lands first, this becomes a no-op and can be closed, and if Fix: contain @google-cloud/vertexai build-output deep imports behind one adapter module #303's unrelated test cleanup is dropped in review, this still stands on its own. Stacking on Fix: contain @google-cloud/vertexai build-output deep imports behind one adapter module #303's branch was not viable: the mock is already gone there, so the stacked diff would be empty.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.
No new tests, deliberately. This removes dead code and adds zero executable lines, so the coverage requirement is satisfied vacuously — and a test asserting the absence of a mock would be noise. No existing test was added, removed, renamed, retitled or restructured; the 57 cases are unchanged in name, order and count.
[x] All unit tests pass locally.
npm run ts:checkreportsFound 281 errors in 41 filesboth with and without this change (checked by restoring the file from the parent commit and re-running) — a pre-existing repo-wide condition in the test tree that this diff neither adds to nor relieves. It is not one of the gates in.github/workflows/validation.yaml.Full
unit:coreproject:Test Files 1 failed | 167 passed (168),Tests 3 failed | 2348 passed (2351). The 3 failures are all incore/test/code_executors/unsafe_local_code_executor_test.tsand are pre-existing and unrelated — verified bygit stashing this change and re-running that file against the untouched base, which reproduces the identical 3 failures (Tests 3 failed | 15 passed (18)).Proof the deleted code was genuinely dead. There is no new assertion to falsify, so the standard mutation check does not apply. The equivalent proof is a positive one, and I ran it rather than merely asserting it:
vi.mock('nodejs-vertexai', () => { throw new Error('DEADNESS PROBE: the nodejs-vertexai factory executed'); })) and re-ran the suite. Result:Test Files 1 passed (1) | Tests 57 passed (57). The throw never fired, so the factory body never executed.@google/genai, a specifier this file does import. Result:Test Files 1 failed (1) | Tests no tests, withCaused by: Error: CONTROL PROBE: an imported specifier factory executed.A throwing factory on an imported specifier detonates the file; the same throwing factory on
nodejs-vertexaichanges nothing. That is direct evidence the removed block was unreachable.Static postconditions, all verified after the edit:
Manual End-to-End (E2E) Tests:
Not applicable — this is a test-only deletion with no runtime behaviour, no public API surface, and no code path to exercise. The equivalent manual verification is the static audit above plus the two CI-mirroring checks (
npm run lint,npm run format:check), both clean. Per the change's scope, the integration and e2e projects were not run: nothing undertests/integration/ortests/e2e/references this mock.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.