From 34a364cb74a4bf2f258d297d7e0b6704f3a13750 Mon Sep 17 00:00:00 2001 From: leslie Date: Tue, 7 Oct 2025 11:43:38 +0800 Subject: [PATCH] fix: guard performance_stop_trace when tracing inactive --- src/tools/performance.ts | 2 +- tests/tools/performance.test.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/performance.ts b/src/tools/performance.ts index 6f3af7c3..c9de76f7 100644 --- a/src/tools/performance.ts +++ b/src/tools/performance.ts @@ -111,7 +111,7 @@ export const stopTrace = defineTool({ }, schema: {}, handler: async (_request, response, context) => { - if (!context.isRunningPerformanceTrace) { + if (!context.isRunningPerformanceTrace()) { return; } const page = context.getSelectedPage(); diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts index ec14381e..b8ac5533 100644 --- a/tests/tools/performance.test.ts +++ b/tests/tools/performance.test.ts @@ -218,7 +218,11 @@ describe('performance', () => { it('does nothing if the trace is not running and does not error', async () => { await withBrowser(async (response, context) => { context.setIsRunningPerformanceTrace(false); + const selectedPage = context.getSelectedPage(); + const stopTracingStub = sinon.stub(selectedPage.tracing, 'stop'); await stopTrace.handler({params: {}}, response, context); + sinon.assert.notCalled(stopTracingStub); + assert.strictEqual(context.isRunningPerformanceTrace(), false); }); });