Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/test/sessions/vertex_ai_session_service_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import {Sessions} from '@google-cloud/vertexai/build/src/genai/sessions.js';
import type {Session} from '@google/adk';
import {createEvent, State, VertexAiSessionService} from '@google/adk';
import {Session} from '@google/adk/sessions/session.js';
import {ApiError} from '@google/genai';
import {beforeEach, describe, expect, it, vi} from 'vitest';

Expand All @@ -24,8 +24,8 @@ vi.mock('nodejs-vertexai', () => ({
import {
isVertexAiConnectionString,
quoteFilterLiteral,
} from '@google/adk/sessions/vertex_ai_session_service.js';
import {logger} from '@google/adk/utils/logger.js';
} from '../../src/sessions/vertex_ai_session_service.js';
import {logger} from '../../src/utils/logger.js';

describe('isVertexAiConnectionString', () => {
it('returns true for vertexai://', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import {Client} from '@google-cloud/vertexai';
import {AgentEngineSandboxCodeExecutor, LlmAgent} from '@google/adk';
import {responseProcessor} from '@google/adk/agents/processors/code_execution_request_processor.js';
import {FinishReason} from '@google/genai';
import {describe, expect, it, vi} from 'vitest';
import {responseProcessor} from '../../../core/src/agents/processors/code_execution_request_processor.js';
import {
createRunner,
GeminiWithMockResponses,
Expand Down
57 changes: 57 additions & 0 deletions tests/integration/vitest_alias_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {describe, expect, it} from 'vitest';
import {workspaceAliases} from '../../vitest.config.js';

const REPO_ROOT = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../..',
);

/**
* Applies the alias entries the way `@rollup/plugin-alias` does for a `RegExp`
* `find`, so a silent revert to the prefix-matching string form matches nothing
* and fails these tests.
*/
function matchingAliases(specifier: string) {
return workspaceAliases.filter(
(entry) => entry.find instanceof RegExp && entry.find.test(specifier),
);
}

describe('workspaceAliases', () => {
it('matches only the bare package specifiers', () => {
expect(matchingAliases('@google/adk')).toHaveLength(1);
expect(matchingAliases('@google/adk-integrations')).toHaveLength(1);

for (const deepSpecifier of [
'@google/adk/sessions/session.js',
'@google/adk/agents/processors/code_execution_request_processor.js',
'@google/adk-integrations/foo.js',
'@google/adk-devtools',
]) {
expect(matchingAliases(deepSpecifier)).toEqual([]);
}
});

it('resolves each package to its source root', () => {
expect(matchingAliases('@google/adk')).toEqual([
{
find: expect.any(RegExp),
replacement: path.resolve(REPO_ROOT, 'core/src'),
},
]);
expect(matchingAliases('@google/adk-integrations')).toEqual([
{
find: expect.any(RegExp),
replacement: path.resolve(REPO_ROOT, 'integrations/src'),
},
]);
});
});
70 changes: 28 additions & 42 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ const INTEGRATION_HOOK_TIMEOUT_MS = 120000;
*/
const INTEGRATION_TEST_TIMEOUT_MS = 60000;

/**
* Maps the workspace package names onto their source trees, shared by every
* test project.
*
* The patterns are anchored regexes rather than plain strings: a string `find`
* matches the package root *and every subpath under it*, so `'@google/adk'`
* also rewrote `@google/adk/sessions/session.js` to
* `core/src/sessions/session.js`. `core/package.json` and
* `integrations/package.json` export only `"."`, so that subpath resolves for
* nobody outside vitest: the alias made the harness accept imports that `tsc`
* (`moduleResolution: nodenext`) and Node both reject.
*
* Import an internal symbol through a relative `../src/...` path instead.
*/
export const workspaceAliases = [
{find: /^@google\/adk$/, replacement: path.resolve(__dirname, './core/src')},
{
find: /^@google\/adk-integrations$/,
replacement: path.resolve(__dirname, './integrations/src'),
},
];

export default defineConfig({
test: {
poolOptions: {
Expand All @@ -35,41 +57,23 @@ export default defineConfig({
test: {
name: 'unit:core',
environment: 'node',
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['core/test/**/*_test.ts'],
},
},
{
test: {
name: 'unit:dev',
environment: 'node',
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['dev/test/**/*_test.ts'],
},
},
{
test: {
name: 'unit:integrations',
environment: 'node',
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['integrations/test/**/*_test.ts'],
},
},
Expand All @@ -79,41 +83,23 @@ export default defineConfig({
environment: 'node',
hookTimeout: INTEGRATION_HOOK_TIMEOUT_MS,
testTimeout: INTEGRATION_TEST_TIMEOUT_MS,
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['tests/integration/**/*_test.ts'],
},
},
{
test: {
name: 'e2e',
environment: 'node',
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['tests/e2e/**/*_test.ts'],
},
},
{
test: {
name: 'cross-language',
environment: 'node',
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
__dirname,
'./integrations/src',
),
},
alias: workspaceAliases,
include: ['tests/cross_language/**/*_test.ts'],
},
},
Expand Down
Loading