mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 23:42:03 +00:00
Merge pull request #2656 from QwenLM/fix-issue-qwen-code
fix: resolve /clear command and ESC key lag caused by hooks system
This commit is contained in:
commit
cd935a5896
8 changed files with 297 additions and 25 deletions
|
|
@ -1582,4 +1582,37 @@ describe('Model Switching and Config Updates', () => {
|
|||
const updatedConfig = config.getContentGeneratorConfig();
|
||||
expect(updatedConfig['contextWindowSize']).toBe(128_000);
|
||||
});
|
||||
|
||||
describe('hasHooksForEvent', () => {
|
||||
it('should return false when hookSystem is not initialized', () => {
|
||||
const config = new Config(baseParams);
|
||||
expect(config.hasHooksForEvent('Stop')).toBe(false);
|
||||
});
|
||||
|
||||
it('should delegate to hookSystem.hasHooksForEvent when hookSystem exists', () => {
|
||||
const config = new Config(baseParams);
|
||||
const mockHasHooksForEvent = vi.fn().mockReturnValue(true);
|
||||
const mockHookSystem = {
|
||||
hasHooksForEvent: mockHasHooksForEvent,
|
||||
};
|
||||
// @ts-expect-error - accessing private for testing
|
||||
config['hookSystem'] = mockHookSystem;
|
||||
|
||||
expect(config.hasHooksForEvent('UserPromptSubmit')).toBe(true);
|
||||
expect(mockHasHooksForEvent).toHaveBeenCalledWith('UserPromptSubmit');
|
||||
});
|
||||
|
||||
it('should return false when hookSystem has no hooks for the event', () => {
|
||||
const config = new Config(baseParams);
|
||||
const mockHasHooksForEvent = vi.fn().mockReturnValue(false);
|
||||
const mockHookSystem = {
|
||||
hasHooksForEvent: mockHasHooksForEvent,
|
||||
};
|
||||
// @ts-expect-error - accessing private for testing
|
||||
config['hookSystem'] = mockHookSystem;
|
||||
|
||||
expect(config.hasHooksForEvent('Stop')).toBe(false);
|
||||
expect(mockHasHooksForEvent).toHaveBeenCalledWith('Stop');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1769,6 +1769,15 @@ export class Config {
|
|||
return this.hookSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fast-path check: returns true only when hooks are enabled AND there are
|
||||
* registered hooks for the given event name. Callers can use this to skip
|
||||
* expensive MessageBus round-trips when no hooks are configured.
|
||||
*/
|
||||
hasHooksForEvent(eventName: string): boolean {
|
||||
return this.hookSystem?.hasHooksForEvent(eventName) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if hooks are enabled.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue