From e56bd574e2ef5156c127f36797e6b9422400947a Mon Sep 17 00:00:00 2001 From: Lucas Winther Date: Sun, 6 Sep 2026 21:05:36 +0200 Subject: [PATCH] fix(tests): skip live container tests when OPENPROJECT_API_KEY is not set --- tests/client.test.ts | 18 ++++++------------ tests/mcp-server.test.ts | 11 ++++++----- tests/openapi.test.ts | 9 +++++---- tests/tools.test.ts | 13 +++++++------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/tests/client.test.ts b/tests/client.test.ts index 7a78e6d..0ea8ccb 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -531,16 +531,12 @@ describe("OpenProjectClient (Mocked Unit Tests)", () => { describe("OpenProject Live API Integration (Local Container)", () => { const liveBaseUrl = process.env.OPENPROJECT_BASE_URL || "http://localhost:8080"; const liveApiKey = process.env.OPENPROJECT_API_KEY; + const runLiveTests = liveApiKey ? test : test.skip; - test("fetches projects and work packages against live instance", async () => { - if (!liveApiKey) { - console.warn("Skipping live container test: OPENPROJECT_API_KEY not set"); - return; - } - + runLiveTests("fetches projects and work packages against live instance", async () => { const client = new OpenProjectClient({ baseUrl: liveBaseUrl, - apiKey: liveApiKey, + apiKey: liveApiKey!, }); // 1. Fetch projects @@ -582,7 +578,7 @@ describe("OpenProject Live API Integration (Local Container)", () => { expect(priorities.items.length).toBeGreaterThan(0); }); - test("live 401 authentication failure with invalid key", async () => { + runLiveTests("live 401 authentication failure with invalid key", async () => { const client = new OpenProjectClient({ baseUrl: liveBaseUrl, apiKey: "definitely-invalid-key-9999", @@ -593,12 +589,10 @@ describe("OpenProject Live API Integration (Local Container)", () => { ); }); - test("live 404 not found failure with non-existent project", async () => { - if (!liveApiKey) return; - + runLiveTests("live 404 not found failure with non-existent project", async () => { const client = new OpenProjectClient({ baseUrl: liveBaseUrl, - apiKey: liveApiKey, + apiKey: liveApiKey!, }); await expect(client.get("/api/v3/projects/9999999")).rejects.toBeInstanceOf( diff --git a/tests/mcp-server.test.ts b/tests/mcp-server.test.ts index a15efed..97058d8 100644 --- a/tests/mcp-server.test.ts +++ b/tests/mcp-server.test.ts @@ -190,10 +190,11 @@ describe("MCP Server Factory", () => { describe("End-to-End Live Tool Calling over MCP Client", () => { const baseUrl = process.env.OPENPROJECT_BASE_URL || "http://localhost:8080"; - const apiKey = process.env.OPENPROJECT_API_KEY || ""; + const apiKey = process.env.OPENPROJECT_API_KEY; + const runLiveTests = apiKey ? test : test.skip; - test("calls openproject_list_projects and openproject_get_work_package via Client", async () => { - const mcpServer = createServer({ baseUrl, apiKey, readOnly: false }); + runLiveTests("calls openproject_list_projects and openproject_get_work_package via Client", async () => { + const mcpServer = createServer({ baseUrl, apiKey: apiKey || "skip", readOnly: false }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await mcpServer.start(serverTransport); @@ -230,8 +231,8 @@ describe("End-to-End Live Tool Calling over MCP Client", () => { } }); - test("tool error propagation returns isError: true without crashing client", async () => { - const mcpServer = createServer({ baseUrl, apiKey, readOnly: false }); + runLiveTests("tool error propagation returns isError: true without crashing client", async () => { + const mcpServer = createServer({ baseUrl, apiKey: apiKey || "skip", readOnly: false }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await mcpServer.start(serverTransport); diff --git a/tests/openapi.test.ts b/tests/openapi.test.ts index cdf05aa..424f77c 100644 --- a/tests/openapi.test.ts +++ b/tests/openapi.test.ts @@ -240,10 +240,11 @@ describe("OpenApi MCP Tool Registration & Execution", () => { describe("Live Container OpenAPI Integration", () => { const liveBaseUrl = process.env.OPENPROJECT_BASE_URL || "http://localhost:8080"; - const liveApiKey = process.env.OPENPROJECT_API_KEY || ""; - const liveClient = new OpenProjectClient({ baseUrl: liveBaseUrl, apiKey: liveApiKey }); + const liveApiKey = process.env.OPENPROJECT_API_KEY; + const runLiveTests = liveApiKey ? test : test.skip; + const liveClient = new OpenProjectClient({ baseUrl: liveBaseUrl, apiKey: liveApiKey || "skip" }); - test("live query returns OpenProject API summary with paths and tags", async () => { + runLiveTests("live query returns OpenProject API summary with paths and tags", async () => { const summary = (await getOpenApiSpec({}, liveClient)) as OpenApiSummary; expect(summary.title).toContain("OpenProject API"); expect(summary.totalPaths).toBeGreaterThan(200); @@ -251,7 +252,7 @@ describe("Live Container OpenAPI Integration", () => { expect(summary.availablePaths).toContain("/api/v3/work_packages"); }); - test("live query fetches operation details for /api/v3/work_packages", async () => { + runLiveTests("live query fetches operation details for /api/v3/work_packages", async () => { const res = (await getOpenApiSpec({ path: "/api/v3/work_packages" }, liveClient)) as { path: string; operations: { diff --git a/tests/tools.test.ts b/tests/tools.test.ts index a3aeab2..d393c65 100644 --- a/tests/tools.test.ts +++ b/tests/tools.test.ts @@ -1156,10 +1156,11 @@ describe("Tool Execution Wrapper", () => { describe("Live Container Integration (All 10 MCP Tools)", () => { const baseUrl = process.env.OPENPROJECT_BASE_URL || "http://localhost:8080"; - const apiKey = process.env.OPENPROJECT_API_KEY || ""; - const liveClient = new OpenProjectClient({ baseUrl, apiKey }); + const apiKey = process.env.OPENPROJECT_API_KEY; + const runLiveTests = apiKey ? test : test.skip; + const liveClient = new OpenProjectClient({ baseUrl, apiKey: apiKey || "skip" }); - test("live: list projects and get project tool execution", async () => { + runLiveTests("live: list projects and get project tool execution", async () => { await runWithContext({ client: liveClient, isReadOnly: false }, async () => { const listRes = await handleListProjects({ pageSize: 5 }); expect(listRes.isError).toBeUndefined(); @@ -1177,7 +1178,7 @@ describe("Live Container Integration (All 10 MCP Tools)", () => { }); }); - test("live: list work packages and get work package tool execution", async () => { + runLiveTests("live: list work packages and get work package tool execution", async () => { await runWithContext({ client: liveClient, isReadOnly: false }, async () => { const listRes = await handleListWorkPackages({ pageSize: 5 }); expect(listRes.isError).toBeUndefined(); @@ -1193,7 +1194,7 @@ describe("Live Container Integration (All 10 MCP Tools)", () => { }); }); - test("live: list queries and get query tool execution", async () => { + runLiveTests("live: list queries and get query tool execution", async () => { await runWithContext({ client: liveClient, isReadOnly: false }, async () => { const listRes = await handleListQueries({}); expect(listRes.isError).toBeUndefined(); @@ -1209,7 +1210,7 @@ describe("Live Container Integration (All 10 MCP Tools)", () => { }); }); - test("live: metadata tools execution (types, statuses, priorities, users)", async () => { + runLiveTests("live: metadata tools execution (types, statuses, priorities, users)", async () => { await runWithContext({ client: liveClient, isReadOnly: false }, async () => { const typesRes = await handleListTypes({}); expect(typesRes.isError).toBeUndefined();