Просмотр исходного кода

fix: correct test paths after moving to test/ directory

- cli.test.ts: fix qmdScript path from <root>/qmd.ts to <root>/src/qmd.ts
  (broke when tests moved from src/integration/ to test/)
- mcp.test.ts: forward Mcp-Session-Id header per MCP Streamable HTTP spec
Tobi Lutke 3 месяцев назад
Родитель
Сommit
edc9a87234
2 измененных файлов с 19 добавлено и 9 удалено
  1. 4 5
      test/cli.test.ts
  2. 15 4
      test/mcp.test.ts

+ 4 - 5
test/cli.test.ts

@@ -21,11 +21,10 @@ let testConfigDir: string;
 let fixturesDir: string;
 let testCounter = 0; // Unique counter for each test run
 
-// Get the directory where this test file lives (same as qmd.ts)
-const qmdDir = dirname(fileURLToPath(import.meta.url));
-const qmdSrcDir = join(qmdDir, "..");
-const projectRoot = join(qmdSrcDir, "..");
-const qmdScript = join(qmdSrcDir, "qmd.ts");
+// Get the directory where this test file lives
+const thisDir = dirname(fileURLToPath(import.meta.url));
+const projectRoot = join(thisDir, "..");
+const qmdScript = join(projectRoot, "src", "qmd.ts");
 // Resolve tsx binary from project's node_modules (not cwd-dependent)
 const tsxBin = (() => {
   const candidate = join(projectRoot, "node_modules", ".bin", "tsx");

+ 15 - 4
test/mcp.test.ts

@@ -946,17 +946,28 @@ describe("MCP HTTP Transport", () => {
   // MCP protocol over HTTP
   // ---------------------------------------------------------------------------
 
+  /** Track session ID returned by initialize (MCP Streamable HTTP spec) */
+  let sessionId: string | null = null;
+
   /** Send a JSON-RPC message to /mcp and return the parsed response.
    * MCP Streamable HTTP requires Accept header with both JSON and SSE. */
   async function mcpRequest(body: object): Promise<{ status: number; json: any; contentType: string | null }> {
+    const headers: Record<string, string> = {
+      "Content-Type": "application/json",
+      "Accept": "application/json, text/event-stream",
+    };
+    if (sessionId) headers["mcp-session-id"] = sessionId;
+
     const res = await fetch(`${baseUrl}/mcp`, {
       method: "POST",
-      headers: {
-        "Content-Type": "application/json",
-        "Accept": "application/json, text/event-stream",
-      },
+      headers,
       body: JSON.stringify(body),
     });
+
+    // Capture session ID from initialize responses
+    const sid = res.headers.get("mcp-session-id");
+    if (sid) sessionId = sid;
+
     const json = await res.json();
     return { status: res.status, json, contentType: res.headers.get("content-type") };
   }