$ErrorActionPreference = "Stop" $scriptUnderTest = Join-Path (Split-Path $PSScriptRoot -Parent) "scripts\sync_mcp_registrations.ps1" $testDir = Join-Path ([IO.Path]::GetTempPath()) ("tools-sync-mcp-test-" + [guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Path $testDir | Out-Null $claudeConfig = Join-Path $testDir "claude.json" $codexConfig = Join-Path $testDir "config.toml" try { $claudeText = @' { "mcpServers": { "claude-only": {"type":"stdio","command":"python","args":["a.py"],"env":{"A":"1"}}, "same": {"type":"stdio","command":"python","args":["same.py"],"env":{}}, "drifted": {"type":"stdio","command":"python","args":["claude.py"],"env":{}} } } '@ [IO.File]::WriteAllText($claudeConfig, $claudeText, [Text.UTF8Encoding]::new($false)) $codexText = @' [mcp_servers.codex-only] command = "python" args = ["b.py"] [mcp_servers.same] command = "python" args = ["same.py"] env = { PYTHONIOENCODING = "utf-8", PYTHONUTF8 = "1" } [mcp_servers.drifted] command = "python" args = ["codex.py"] [mcp_servers.node_repl] command = "C:\\Users\\tester\\.codex\\runtimes\\node_repl.exe" '@ [IO.File]::WriteAllText($codexConfig, $codexText, [Text.UTF8Encoding]::new($false)) $oldErrorActionPreference = $ErrorActionPreference $ErrorActionPreference = "Continue" # -CodexSource Toml pins the read to the fixture; the default Auto path would query the # real `codex mcp list` and make this test measure the machine instead of the fixtures. $output = & powershell -NoProfile -ExecutionPolicy Bypass -File $scriptUnderTest ` -ClaudeConfig $claudeConfig -CodexConfig $codexConfig -CodexSource Toml -Verbose 2>&1 | Out-String $code = $LASTEXITCODE $ErrorActionPreference = $oldErrorActionPreference if ($code -ne 2) { throw "expected audit exit 2, got $code`n$output" } if ($output -notmatch 'Claude only\s*:\s*claude-only') { throw "Claude-only difference not detected`n$output" } if ($output -notmatch 'Codex only\s*:\s*codex-only') { throw "Codex-only difference not detected`n$output" } if ($output -notmatch 'Drift\s*:\s*drifted') { throw "drift not detected`n$output" } if ($output -notmatch 'Matched\s*:\s*same') { throw "Codex-only UTF-8 env should not cause drift`n$output" } if ($output -match 'Codex only\s*:.*node_repl') { throw "managed Codex MCP was not excluded`n$output" } Write-Host "PASS: bidirectional MCP audit fixtures" } finally { Remove-Item -LiteralPath $claudeConfig -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $codexConfig -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $testDir -Force -ErrorAction SilentlyContinue }