mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 05:24:34 -07:00
Merge remote-tracking branch 'origin/main' into fix-ask-hook
# Conflicts: # packages/a2a-server/src/agent/task.ts # packages/core/src/core/coreToolHookTriggers.test.ts # packages/core/src/core/coreToolHookTriggers.ts # packages/core/src/core/coreToolScheduler.ts # packages/core/src/scheduler/scheduler.ts # packages/core/src/tools/edit.ts # packages/core/src/tools/web-fetch.ts
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, beforeEach, afterEach } from 'vitest';
|
||||
import { TestRig } from './test-helper.js';
|
||||
|
||||
/**
|
||||
* integration test to ensure no node.js deprecation warnings are emitted.
|
||||
* must run for all supported node versions as warnings may vary by version.
|
||||
*/
|
||||
describe('deprecation-warnings', () => {
|
||||
let rig: TestRig;
|
||||
|
||||
beforeEach(() => {
|
||||
rig = new TestRig();
|
||||
});
|
||||
|
||||
afterEach(async () => await rig.cleanup());
|
||||
|
||||
it.each([
|
||||
{ command: '--version', description: 'running --version' },
|
||||
{ command: '--help', description: 'running with --help' },
|
||||
])(
|
||||
'should not emit any deprecation warnings when $description',
|
||||
async ({ command, description }) => {
|
||||
await rig.setup(
|
||||
`should not emit any deprecation warnings when ${description}`,
|
||||
);
|
||||
|
||||
const { stderr, exitCode } = await rig.runWithStreams([command]);
|
||||
|
||||
// node.js deprecation warnings: (node:12345) [DEP0040] DeprecationWarning: ...
|
||||
const deprecationWarningPattern = /\[DEP\d+\].*DeprecationWarning/i;
|
||||
const hasDeprecationWarning = deprecationWarningPattern.test(stderr);
|
||||
|
||||
if (hasDeprecationWarning) {
|
||||
const deprecationMatches = stderr.match(
|
||||
/\[DEP\d+\].*DeprecationWarning:.*/gi,
|
||||
);
|
||||
const warnings = deprecationMatches
|
||||
? deprecationMatches.map((m) => m.trim()).join('\n')
|
||||
: 'Unknown deprecation warning format';
|
||||
|
||||
throw new Error(
|
||||
`Deprecation warnings detected in CLI output:\n${warnings}\n\n` +
|
||||
`Full stderr:\n${stderr}\n\n` +
|
||||
`This test ensures no deprecated Node.js modules are used. ` +
|
||||
`Please update dependencies to use non-deprecated alternatives.`,
|
||||
);
|
||||
}
|
||||
|
||||
// only check exit code if no deprecation warnings found
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(
|
||||
`CLI exited with code ${exitCode} (expected 0). This may indicate a setup issue.\n` +
|
||||
`Stderr: ${stderr}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"functionCall":{"name":"run_shell_command","args":{"command":"ls -F"}}}]},"finishReason":"STOP","index":0}]},{"candidates":[{"content":{"parts":[{"text":"I ran ls -F"}]},"finishReason":"STOP","index":0}]}]}
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"I ran ls -F"}]},"finishReason":"STOP","index":0}]}]}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { join } from 'node:path';
|
||||
import { TestRig, GEMINI_DIR } from './test-helper.js';
|
||||
import fs from 'node:fs';
|
||||
|
||||
describe('User Policy Regression Repro', () => {
|
||||
let rig: TestRig;
|
||||
|
||||
beforeEach(() => {
|
||||
rig = new TestRig();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (rig) {
|
||||
await rig.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it('should respect policies in ~/.gemini/policies/allowed-tools.toml', async () => {
|
||||
rig.setup('user-policy-test', {
|
||||
fakeResponsesPath: join(import.meta.dirname, 'user-policy.responses'),
|
||||
});
|
||||
|
||||
// Create ~/.gemini/policies/allowed-tools.toml
|
||||
const userPoliciesDir = join(rig.homeDir!, GEMINI_DIR, 'policies');
|
||||
fs.mkdirSync(userPoliciesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
join(userPoliciesDir, 'allowed-tools.toml'),
|
||||
`
|
||||
[[rule]]
|
||||
toolName = "run_shell_command"
|
||||
commandPrefix = "ls -F"
|
||||
decision = "allow"
|
||||
priority = 100
|
||||
`,
|
||||
);
|
||||
|
||||
// Run gemini with a prompt that triggers ls -F
|
||||
// approvalMode: 'default' in headless mode will DENY if it hits ASK_USER
|
||||
const result = await rig.run({
|
||||
args: ['-p', 'Run ls -F', '--model', 'gemini-3.1-pro-preview'],
|
||||
approvalMode: 'default',
|
||||
});
|
||||
|
||||
expect(result).toContain('I ran ls -F');
|
||||
expect(result).not.toContain('Tool execution denied by policy');
|
||||
expect(result).not.toContain('Tool "run_shell_command" not found');
|
||||
|
||||
const toolLogs = rig.readToolLogs();
|
||||
const lsLog = toolLogs.find(
|
||||
(l) =>
|
||||
l.toolRequest.name === 'run_shell_command' &&
|
||||
l.toolRequest.args.includes('ls -F'),
|
||||
);
|
||||
expect(lsLog).toBeDefined();
|
||||
expect(lsLog?.toolRequest.success).toBe(true);
|
||||
});
|
||||
|
||||
it('should FAIL if policy is not present (sanity check)', async () => {
|
||||
rig.setup('user-policy-sanity-check', {
|
||||
fakeResponsesPath: join(import.meta.dirname, 'user-policy.responses'),
|
||||
});
|
||||
|
||||
// DO NOT create the policy file here
|
||||
|
||||
// Run gemini with a prompt that triggers ls -F
|
||||
const result = await rig.run({
|
||||
args: ['-p', 'Run ls -F', '--model', 'gemini-3.1-pro-preview'],
|
||||
approvalMode: 'default',
|
||||
});
|
||||
|
||||
// In non-interactive mode, it should be denied
|
||||
expect(result).toContain('Tool "run_shell_command" not found');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user