Test canonical browser opt-in in MCP import and Save

Retain exact saved-server equality after browser_bridge false normalization; execute stdio-only opt-in and unchanged-metadata controls through the real UI collector. Both engine import consumers now pass after matched base/failing-merge controls.

No production code, release metadata, installed target, Settings or Chrome changes. General CI failures remain attributed and unwaived.
This commit is contained in:
Ouroboros 2026-10-12 04:53:10 +05:00
parent 9985dfc960
commit 1fcd3bbb54
2 changed files with 38 additions and 1 deletions

View file

@ -764,8 +764,11 @@ def test_mcp_import_replaces_legacy_ui(direct_server_with_data, loopback, engine
disk = _disk(data_dir)
assert disk["legacy_docs"]["headers"] == {"Authorization": BASIC, "X-Api-Key": CUSTOM}
assert disk["legacy_docs"]["auth_token"] == "" and disk["legacy_docs"]["enabled"] is True
# Save normalizes every server's browser opt-in, including unselected import rows.
# HTTP entries remain ordinary MCP connections; the file cannot enable the bridge.
assert disk["keep_me"] == {**seed[1], "id": "keep_me", "name": "", "command": "", "args": [],
"auth_header": "Authorization", "auth_token": "", "allowed_tools": []}
"auth_header": "Authorization", "auth_token": "", "allowed_tools": [],
"browser_bridge": False}
assert disk["fresh"]["enabled"] is False and disk["fresh"]["url"].endswith("?k=synthetic-query")
seen_before = len(http_app.seen)
cards.nth(0).locator("[data-mcp-refresh]").click()

View file

@ -173,6 +173,40 @@ assert.equal(collectMcpSettings().MCP_SERVERS[0].args, 'unsupported');
assert result.returncode == 0, result.stderr
@pytest.mark.serial
@pytest.mark.parametrize("transport,opt_in,expected", [
("stdio", True, True),
("stdio", False, False),
("streamable_http", True, False),
("sse", True, False),
])
def test_mcp_ui_collection_keeps_browser_opt_in_stdio_only(transport, opt_in, expected):
"""Run the real Save projection without dropping other server metadata."""
script = r'''
import assert from 'node:assert/strict';
import { applyMcpSettings, collectMcpSettings } from './web/modules/mcp_settings.js';
const host = { innerHTML: '', querySelectorAll: () => [] };
globalThis.document = { getElementById: (id) => id === 'mcp-servers-list' ? host : null };
globalThis.fetch = async () => ({ ok: false });
const [transport, optIn, expected] = JSON.parse(process.argv[1]);
const server = { id: 'kept', enabled: false, transport, command: 'python3', args: ['server.py'],
url: 'https://example.test/mcp', headers: {'X-Keep': 'literal'},
allowed_tools: ['read'], browser_bridge: optIn, future_field: { retained: true } };
applyMcpSettings({ MCP_SERVERS: [server] });
const saved = collectMcpSettings().MCP_SERVERS[0];
for (const key of Object.keys(server)) {
assert.deepEqual(saved[key], key === 'browser_bridge' ? expected : server[key], key);
}
assert.equal(Object.hasOwn(saved, 'browser_bridge'), true);
'''
import json
result = subprocess.run([_node_bin(), '--input-type=module', '-e', script,
json.dumps([transport, opt_in, expected])], cwd=REPO_ROOT,
capture_output=True, text=True, timeout=15)
assert result.returncode == 0, result.stderr
def test_mcp_test_button_preserves_saved_url_only_credentials():
"""Exercise the registered click handler, not a copy of its payload expression."""
node = _node_bin()