Skip to content

Commit 54e8b69

Browse files
committed
Address code review feedback
- Fix setupBidi leak: defer state.bidi.set() until all listeners are wired up - Fix close_current_window missing state.bidi.delete() cleanup - Add after hook to Session Isolation test for reliable cleanup - Use node:assert/strict for consistency with other test files - Add bidi.test.mjs and bidi.html to AGENTS.md file tree
1 parent da2cf3e commit 54e8b69

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ mcp-selenium/
3737
├── browser.test.mjs ← start_browser, close_session, take_screenshot, multi-session
3838
├── navigation.test.mjs ← navigate, all 6 locator strategies
3939
├── interactions.test.mjs ← click, send_keys, get_element_text, hover, double_click, right_click, press_key, drag_and_drop, upload_file
40+
├── bidi.test.mjs ← BiDi enablement, console/error/network capture, session isolation
4041
└── fixtures/ ← HTML files loaded via file:// URLs
4142
├── locators.html
4243
├── interactions.html
4344
├── mouse-actions.html
4445
├── drag-drop.html
45-
└── upload.html
46+
├── upload.html
47+
└── bidi.html
4648
```
4749

4850
### Key Files in Detail

src/lib/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const newBidiState = () => ({
6767

6868
async function setupBidi(driver, sessionId) {
6969
const bidi = newBidiState();
70-
state.bidi.set(sessionId, bidi);
7170

7271
const logInspector = await LogInspector(driver);
7372
await logInspector.onConsoleEntry((entry) => {
@@ -106,6 +105,7 @@ async function setupBidi(driver, sessionId) {
106105
});
107106

108107
bidi.available = true;
108+
state.bidi.set(sessionId, bidi);
109109
}
110110

111111
function registerBidiTool(name, description, logKey, emptyMessage, unavailableMessage) {
@@ -787,6 +787,7 @@ server.tool(
787787
console.error(`Error quitting driver for session ${sessionId}:`, quitError);
788788
}
789789
state.drivers.delete(sessionId);
790+
state.bidi.delete(sessionId);
790791
state.currentSession = null;
791792
return {
792793
content: [{ type: 'text', text: 'Last window closed. Session ended.' }]

test/bidi.test.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, after, before } from 'node:test';
2-
import assert from 'node:assert';
2+
import assert from 'node:assert/strict';
33
import { McpClient, getResponseText, fixture } from './mcp-client.mjs';
44

55
describe('BiDi Diagnostic Tools', () => {
@@ -136,6 +136,10 @@ describe('BiDi Diagnostic Tools', () => {
136136
});
137137

138138
describe('Session Isolation', () => {
139+
after(async () => {
140+
try { await client.callTool('close_session', {}); } catch (_) {}
141+
});
142+
139143
it('should reset BiDi logs when starting a new session', async () => {
140144
await client.callTool('start_browser', {
141145
browser: 'chrome',

0 commit comments

Comments
 (0)