From 2a585b0e62da2b154b28753f5b6956e8a6b61edf Mon Sep 17 00:00:00 2001 From: sanish-bruno Date: Wed, 28 Jan 2026 12:49:03 +0530 Subject: [PATCH] refactor: remove statistics tracking from HookManager and HooksRuntime --- packages/bruno-js/src/hook-manager.js | 29 +++---------------- .../bruno-js/src/runtime/hooks-runtime.js | 18 ------------ packages/bruno-js/tests/hook-manager.spec.js | 15 ---------- 3 files changed, 4 insertions(+), 58 deletions(-) diff --git a/packages/bruno-js/src/hook-manager.js b/packages/bruno-js/src/hook-manager.js index a8259a79f..389bd4799 100644 --- a/packages/bruno-js/src/hook-manager.js +++ b/packages/bruno-js/src/hook-manager.js @@ -60,14 +60,7 @@ class HookManager { this.listeners = {}; // Track cleanup functions for proper resource disposal this._cleanupFunctions = []; - this._disposed = false; this._state = HookManager.State.ACTIVE; - // Track execution statistics - this._stats = { - totalCalls: 0, - totalErrors: 0, - lastCallTime: null - }; } /** @@ -83,15 +76,7 @@ class HookManager { * @returns {boolean} True if disposed */ get isDisposed() { - return this._disposed; - } - - /** - * Get execution statistics - * @returns {object} Statistics object - */ - get stats() { - return { ...this._stats }; + return this._state === HookManager.State.DISPOSED; } /** @@ -111,10 +96,9 @@ class HookManager { * Should be called when the HookManager is no longer needed */ dispose() { - if (this._disposed) { + if (this._state === HookManager.State.DISPOSED) { return; } - this._disposed = true; this._state = HookManager.State.DISPOSED; // Call all registered cleanup functions @@ -138,7 +122,7 @@ class HookManager { * @throws {Error} If HookManager is disposed */ _validateState(operation) { - if (this._disposed) { + if (this._state === HookManager.State.DISPOSED) { throw new Error(`Cannot ${operation}: HookManager has been disposed`); } } @@ -161,7 +145,7 @@ class HookManager { */ async call(pattern, data, options = {}) { // Validate state - but allow calls on disposed manager to fail gracefully - if (this._disposed) { + if (this._state === HookManager.State.DISPOSED) { console.warn('HookManager.call() called on disposed instance'); if (options.collectErrors) { return { @@ -183,10 +167,6 @@ class HookManager { let handlersExecuted = 0; let handlersFailed = 0; - // Update stats - this._stats.totalCalls++; - this._stats.lastCallTime = Date.now(); - const patternList = [].concat(pattern).map((d) => String(d).trim()); const hasWildcard = patternList.includes('*'); @@ -202,7 +182,6 @@ class HookManager { if (!result.success) { handlersFailed++; - this._stats.totalErrors++; if (collectErrors && result.error) { errors.push(result.error); diff --git a/packages/bruno-js/src/runtime/hooks-runtime.js b/packages/bruno-js/src/runtime/hooks-runtime.js index 21e049882..9cc896f25 100644 --- a/packages/bruno-js/src/runtime/hooks-runtime.js +++ b/packages/bruno-js/src/runtime/hooks-runtime.js @@ -26,20 +26,6 @@ class HooksRuntime { */ constructor(props) { this.runtime = props?.runtime || 'quickjs'; - // Track statistics for performance monitoring - this._stats = { - vmCreations: 0, - runs: 0, - skippedRuns: 0 - }; - } - - /** - * Get execution statistics - * @returns {object} Statistics about hook execution - */ - get stats() { - return { ...this._stats }; } /** @@ -126,7 +112,6 @@ class HooksRuntime { // Lazy VM creation: If no hooks file, return early without creating a VM if (this._isEmptyContent(hooksFile)) { - this._stats.skippedRuns++; return { hookManager: activeHookManager, envVariables: cleanJson(envVariables), @@ -142,9 +127,6 @@ class HooksRuntime { }; } - this._stats.runs++; - this._stats.vmCreations++; - // Execute hooks script // Note: Hooks need the VM to persist so registered handlers can be called later // The cleanup function is registered with the HookManager and called when dispose() is invoked diff --git a/packages/bruno-js/tests/hook-manager.spec.js b/packages/bruno-js/tests/hook-manager.spec.js index 33fb61895..ce808f125 100644 --- a/packages/bruno-js/tests/hook-manager.spec.js +++ b/packages/bruno-js/tests/hook-manager.spec.js @@ -25,14 +25,6 @@ describe('HookManager', () => { expect(hookManager.state).toBe(HookManager.State.ACTIVE); expect(hookManager.isDisposed).toBe(false); }); - - it('should initialize stats', () => { - expect(hookManager.stats).toEqual({ - totalCalls: 0, - totalErrors: 0, - lastCallTime: null - }); - }); }); describe('on()', () => { @@ -146,13 +138,6 @@ describe('HookManager', () => { expect(normalHandler).toHaveBeenCalled(); }); - it('should update stats after call', async () => { - hookManager.on('test', jest.fn()); - await hookManager.call('test', {}); - expect(hookManager.stats.totalCalls).toBe(1); - expect(hookManager.stats.lastCallTime).not.toBeNull(); - }); - it('should collect errors when collectErrors is true', async () => { const errorHandler = jest.fn(() => { throw new Error('Test error'); }); hookManager.on('test', errorHandler);