From d23620b88c2ccc2e6c325233082526a85ef2e6c3 Mon Sep 17 00:00:00 2001 From: Zekbot001 <280472700+Zekbot001@users.noreply.github.com> Date: Sun, 31 May 2026 20:16:39 +0200 Subject: [PATCH 1/2] fix(resume): defer OpenAI client construction --- src/lib/resume-parser.test.ts | 16 ++++++++++++++++ src/lib/resume-parser.ts | 13 +++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/lib/resume-parser.test.ts diff --git a/src/lib/resume-parser.test.ts b/src/lib/resume-parser.test.ts new file mode 100644 index 00000000..1ba2f780 --- /dev/null +++ b/src/lib/resume-parser.test.ts @@ -0,0 +1,16 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; + +afterEach(() => { + vi.unstubAllEnvs(); + vi.resetModules(); +}); + +describe("resume-parser module", () => { + it("can be imported without an OpenAI API key", async () => { + vi.stubEnv("OPENAI_API_KEY", ""); + + await expect(import("./resume-parser")).resolves.toHaveProperty( + "parseResumeFile" + ); + }); +}); diff --git a/src/lib/resume-parser.ts b/src/lib/resume-parser.ts index 62ac408f..881aef4a 100644 --- a/src/lib/resume-parser.ts +++ b/src/lib/resume-parser.ts @@ -34,9 +34,13 @@ export interface ParsedResumeProfile { }; } -const openai = new OpenAI({ - apiKey: process.env.OPENAI_API_KEY, -}); +function getOpenAIClient() { + const apiKey = process.env.OPENAI_API_KEY; + if (!apiKey) { + throw new Error("OPENAI_API_KEY is not configured"); + } + return new OpenAI({ apiKey }); +} // Use OpenAI to parse resume text into structured data async function parseWithOpenAI(text: string): Promise { @@ -79,9 +83,10 @@ Important: - For partial URLs like "github.com/user", prepend "https://" Resume text: -${text}`; + ${text}`; try { + const openai = getOpenAIClient(); const response = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ From 2b706ef7f6f2ba53fadc6d393aebd5de2e7bfa2c Mon Sep 17 00:00:00 2001 From: Zekbot001 <280472700+Zekbot001@users.noreply.github.com> Date: Sun, 31 May 2026 20:23:27 +0200 Subject: [PATCH 2/2] fix(resume): preserve prompt whitespace --- src/lib/resume-parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/resume-parser.ts b/src/lib/resume-parser.ts index 881aef4a..516c33c8 100644 --- a/src/lib/resume-parser.ts +++ b/src/lib/resume-parser.ts @@ -83,7 +83,7 @@ Important: - For partial URLs like "github.com/user", prepend "https://" Resume text: - ${text}`; +${text}`; try { const openai = getOpenAIClient();