From 296a8ed71d8ee8402ebf4c6341011982ff4d4954 Mon Sep 17 00:00:00 2001 From: "Sharad." Date: Sat, 12 Sep 2026 14:05:25 +0000 Subject: [PATCH 1/2] test(config): assert loadConfig JSON errors include file path Co-authored-by: Sharad. --- test/config.test.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/config.test.ts b/test/config.test.ts index b1b20a2..8eb99bb 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from "vitest"; import { normalizeConfig, loadConfig, DEFAULT_CONFIG } from "../src/config.js"; -import { writeFile, rm } from "node:fs/promises"; -import { join } from "node:path"; +import { writeFile, rm, mkdir } from "node:fs/promises"; +import { join, resolve } from "node:path"; import { tmpdir } from "node:os"; describe("normalizeConfig", () => { @@ -45,16 +45,22 @@ describe("normalizeConfig", () => { }); describe("loadConfig", () => { - it("wraps JSON syntax errors with the file path", async () => { - const tmpFile = join(tmpdir(), `mcp-audit-test-${Math.random()}.json`); - await writeFile(tmpFile, "{ invalid json ", "utf8"); + it("wraps JSON syntax errors with the resolved file path", async () => { + const dir = join(tmpdir(), `mcp-audit-test-${Math.random()}`); + await mkdir(dir); + const relativePath = "broken.json"; + const absolutePath = resolve(dir, relativePath); + await writeFile(absolutePath, "{ invalid json ", "utf8"); + const previousCwd = process.cwd(); try { - await loadConfig({ explicitPath: tmpFile }); + process.chdir(dir); + await loadConfig({ explicitPath: relativePath }); expect.fail("Should have thrown"); } catch (err) { - expect((err as Error).message).toContain(tmpFile); + expect((err as Error).message).toContain(absolutePath); } finally { - await rm(tmpFile, { force: true }); + process.chdir(previousCwd); + await rm(dir, { recursive: true, force: true }); } }); }); From e54cf1af0ac8f2fa5ab9bdea3bf16b211f4b120d Mon Sep 17 00:00:00 2001 From: "Sharad." Date: Sat, 12 Sep 2026 14:05:26 +0000 Subject: [PATCH 2/2] fix(config): include file path in loadConfig JSON parse errors Co-authored-by: Sharad. --- src/config.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 5a8d4c2..35f6c6e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -102,12 +102,17 @@ export async function loadConfig(options: { const path = options.explicitPath ?? findConfigFile(options.cwd ?? process.cwd()); if (!path) return { config: DEFAULT_CONFIG }; - const raw = await readFile(resolve(path), "utf8"); + const absolute = resolve(path); + const raw = await readFile(absolute, "utf8"); let parsed: unknown; try { parsed = JSON.parse(raw); } catch (err) { - throw new Error(`Failed to parse config file ${path}: ${(err as Error).message}`); + throw new Error( + `Failed to parse config file ${absolute}: ${ + err instanceof Error ? err.message : String(err) + }`, + ); } return { config: normalizeConfig(parsed), path }; }