import { spawnSync } from "node:child_process"; import { resolve } from "node:path"; import { expect } from "vitest"; import { test } from "@openwork/testkit"; const repoRoot = resolve(import.meta.dirname, "../.."); const witnessName = "rolls back a new managed connection when the initial OAuth handshake fails|returns safe connection errors for DCR and protocol negotiation failures"; test("managed MCP handshake boundaries separate provider failures from internal defects", ({ evidence }) => { const result = spawnSync("pnpm", [ "--filter", "openwork-server", "test", "src/local-managed-mcp.e2e.test.ts", "--test-name-pattern", witnessName, ], { cwd: repoRoot, encoding: "utf8", timeout: 60_000, maxBuffer: 10 * 1024 * 1024, }); const output = `${result.stdout}${result.stderr}`; expect(result.error, output).toBeUndefined(); expect(result.status, output).toBe(0); expect(output).toContain("2 pass"); expect(output).toContain("0 fail"); expect(output).toContain("28 expect() calls"); evidence.recordAssertionEvidence( "Provider DCR and protocol negotiation failures cross a safe reconnect boundary", "The focused HTTP witness requires an unreachable endpoint plus DCR rejection and modern discovery or legacy initialize failures to return exactly managed_mcp_connection_failed/502, omit provider details, and leave no usable credential.", true, ); evidence.recordAssertionEvidence( "Recognized provider handshake failures stay out of telemetry", "The same witness requires the telemetry capture list to remain empty after DCR rejection plus modern discovery and legacy initialize failures.", true, ); evidence.recordAssertionEvidence( "Malformed SDK data remains an actionable internal defect", "The malformed registration witness must return the generic internal 500 while capturing exactly one non-ApiError EnterpriseMcpClientError with MCP_CONNECTION_HANDSHAKE_FAILED at mcp-discovery.", true, ); });