mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
refactor(core): remove deprecated permission aliases from BeforeToolHookOutput (#14855)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
This commit is contained in:
@@ -8,7 +8,6 @@ import { describe, it, expect, vi } from 'vitest';
|
|||||||
import {
|
import {
|
||||||
createHookOutput,
|
createHookOutput,
|
||||||
DefaultHookOutput,
|
DefaultHookOutput,
|
||||||
BeforeToolHookOutput,
|
|
||||||
BeforeModelHookOutput,
|
BeforeModelHookOutput,
|
||||||
BeforeToolSelectionHookOutput,
|
BeforeToolSelectionHookOutput,
|
||||||
AfterModelHookOutput,
|
AfterModelHookOutput,
|
||||||
@@ -208,33 +207,6 @@ describe('Hook Output Classes', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BeforeToolHookOutput', () => {
|
|
||||||
it('isBlockingDecision should use permissionDecision from hookSpecificOutput', () => {
|
|
||||||
const output1 = new BeforeToolHookOutput({
|
|
||||||
hookSpecificOutput: { permissionDecision: 'block' },
|
|
||||||
});
|
|
||||||
expect(output1.isBlockingDecision()).toBe(true);
|
|
||||||
|
|
||||||
const output2 = new BeforeToolHookOutput({
|
|
||||||
hookSpecificOutput: { permissionDecision: 'approve' },
|
|
||||||
});
|
|
||||||
expect(output2.isBlockingDecision()).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getEffectiveReason should use permissionDecisionReason from hookSpecificOutput', () => {
|
|
||||||
const output1 = new BeforeToolHookOutput({
|
|
||||||
hookSpecificOutput: { permissionDecisionReason: 'compat reason' },
|
|
||||||
});
|
|
||||||
expect(output1.getEffectiveReason()).toBe('compat reason');
|
|
||||||
|
|
||||||
const output2 = new BeforeToolHookOutput({
|
|
||||||
reason: 'default reason',
|
|
||||||
hookSpecificOutput: { other: 'value' },
|
|
||||||
});
|
|
||||||
expect(output2.getEffectiveReason()).toBe('default reason');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('BeforeModelHookOutput', () => {
|
describe('BeforeModelHookOutput', () => {
|
||||||
it('getSyntheticResponse should return synthetic response if llm_response is present', () => {
|
it('getSyntheticResponse should return synthetic response if llm_response is present', () => {
|
||||||
const mockResponse: LLMResponse = { candidates: [] };
|
const mockResponse: LLMResponse = { candidates: [] };
|
||||||
|
|||||||
@@ -225,45 +225,9 @@ export class DefaultHookOutput implements HookOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific hook output class for BeforeTool events with compatibility support
|
* Specific hook output class for BeforeTool events.
|
||||||
*/
|
*/
|
||||||
export class BeforeToolHookOutput extends DefaultHookOutput {
|
export class BeforeToolHookOutput extends DefaultHookOutput {}
|
||||||
/**
|
|
||||||
* Get the effective blocking reason, considering compatibility fields
|
|
||||||
*/
|
|
||||||
override getEffectiveReason(): string {
|
|
||||||
// Check for compatibility fields first
|
|
||||||
if (this.hookSpecificOutput) {
|
|
||||||
if ('permissionDecisionReason' in this.hookSpecificOutput) {
|
|
||||||
const compatReason =
|
|
||||||
this.hookSpecificOutput['permissionDecisionReason'];
|
|
||||||
if (typeof compatReason === 'string') {
|
|
||||||
return compatReason;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.getEffectiveReason();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this output represents a blocking decision, considering compatibility fields
|
|
||||||
*/
|
|
||||||
override isBlockingDecision(): boolean {
|
|
||||||
// Check compatibility field first
|
|
||||||
if (
|
|
||||||
this.hookSpecificOutput &&
|
|
||||||
'permissionDecision' in this.hookSpecificOutput
|
|
||||||
) {
|
|
||||||
const compatDecision = this.hookSpecificOutput['permissionDecision'];
|
|
||||||
if (compatDecision === 'block' || compatDecision === 'deny') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.isBlockingDecision();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific hook output class for BeforeModel events
|
* Specific hook output class for BeforeModel events
|
||||||
@@ -395,8 +359,6 @@ export interface BeforeToolInput extends HookInput {
|
|||||||
export interface BeforeToolOutput extends HookOutput {
|
export interface BeforeToolOutput extends HookOutput {
|
||||||
hookSpecificOutput?: {
|
hookSpecificOutput?: {
|
||||||
hookEventName: 'BeforeTool';
|
hookEventName: 'BeforeTool';
|
||||||
permissionDecision?: HookDecision;
|
|
||||||
permissionDecisionReason?: string;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user