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
58 changes: 58 additions & 0 deletions core/test/utils/log_level_pin_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {getLogger} from '@google/adk';
import {Console} from 'node:console';
import {Writable} from 'node:stream';
import {describe, expect, it} from 'vitest';

/**
* Returns everything `fn` writes through the global console.
*
* The winston Console transport backing the ADK logger writes to the streams
* of whatever `globalThis.console` is at log time, so swapping in a `Console`
* bound to an in-memory stream captures it. Vitest installs its own `Console`
* in the worker, which is why spying on `process.stdout.write` or
* `console.log` captures nothing here.
*/
function captureConsoleOutput(fn: () => void): string {
const chunks: string[] = [];
const stream = new Writable({
write(chunk: unknown, _encoding: string, callback: () => void) {
chunks.push(String(chunk));
callback();
},
});
const original = globalThis.console;
globalThis.console = new Console({stdout: stream, stderr: stream});
try {
fn();
} finally {
globalThis.console = original;
}
return chunks.join('');
}

/**
* Pins the `setupFiles` wiring in `vitest.config.ts`. The log level is
* module-level state, so a `globalSetup` file running in the Vitest main
* process cannot reach the worker this test runs in; only a setup file can.
* There is no public accessor for the effective level, so these assert on what
* the logger writes.
*/
describe('test worker log level', () => {
it('suppresses info logs', () => {
expect(captureConsoleOutput(() => getLogger().info('info-pin-probe'))).toBe(
'',
);
});

it('still emits error logs', () => {
expect(
captureConsoleOutput(() => getLogger().error('error-pin-probe')),
).toContain('error-pin-probe');
});
});
15 changes: 0 additions & 15 deletions tests/global_setup.ts

This file was deleted.

16 changes: 16 additions & 0 deletions tests/setup_log_level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {LogLevel, setLogLevel} from '../core/src/utils/logger.js';

// Must run inside the test worker: vitest `globalSetup` executes in the main
// process, and the log level is module-level state a worker never inherits.
//
// Import the logger module directly, not the `@google/adk` barrel. Only the
// per-project `alias` maps that specifier to `core/src`; from here it resolves
// through the workspace symlink to the built `core/dist` bundle, which is a
// second module instance with its own log level (and need not exist yet).
setLogLevel(LogLevel.ERROR);
7 changes: 6 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default defineConfig({
test: {
name: 'unit:core',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
Expand All @@ -49,6 +50,7 @@ export default defineConfig({
test: {
name: 'unit:dev',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
Expand All @@ -63,6 +65,7 @@ export default defineConfig({
test: {
name: 'unit:integrations',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
Expand All @@ -77,6 +80,7 @@ export default defineConfig({
test: {
name: 'integration',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
hookTimeout: INTEGRATION_HOOK_TIMEOUT_MS,
testTimeout: INTEGRATION_TEST_TIMEOUT_MS,
alias: {
Expand All @@ -93,6 +97,7 @@ export default defineConfig({
test: {
name: 'e2e',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
Expand All @@ -107,6 +112,7 @@ export default defineConfig({
test: {
name: 'cross-language',
environment: 'node',
setupFiles: ['./tests/setup_log_level.ts'],
alias: {
'@google/adk': path.resolve(__dirname, './core/src'),
'@google/adk-integrations': path.resolve(
Expand Down Expand Up @@ -136,6 +142,5 @@ export default defineConfig({
lines: 86,
},
},
globalSetup: ['./tests/global_setup.ts'],
},
});
Loading