fix(resume): defer OpenAI client construction#363
Conversation
Greptile SummaryThis PR fixes a module-load failure caused by constructing the OpenAI client eagerly at the top level, which threw when
Confidence Score: 5/5Safe to merge — the change is narrow and surgical, touching only how the OpenAI client is instantiated, with no impact on the parsing logic itself. The refactor is straightforward: one factory function replaces a module-level constructor call, and a regression test covers the targeted scenario. The only minor concern is that the factory call sits inside the existing try/catch, so a missing-key error gets logged under the 'OpenAI parsing error' label before being re-thrown — confusing in logs but not functionally broken. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant parseResumeFile
participant parseWithOpenAI
participant getOpenAIClient
participant OpenAI API
Caller->>parseResumeFile: parseResumeFile(buffer, mimeType)
parseResumeFile->>parseWithOpenAI: parseWithOpenAI(text)
parseWithOpenAI->>getOpenAIClient: getOpenAIClient()
alt OPENAI_API_KEY missing
getOpenAIClient-->>parseWithOpenAI: throw Error("OPENAI_API_KEY is not configured")
parseWithOpenAI-->>Caller: throw (propagates)
else key present
getOpenAIClient-->>parseWithOpenAI: OpenAI client instance
parseWithOpenAI->>OpenAI API: chat.completions.create(...)
OpenAI API-->>parseWithOpenAI: JSON response
parseWithOpenAI-->>parseResumeFile: ParsedResumeProfile
parseResumeFile-->>Caller: ParsedResumeProfile + _debug
end
Reviews (2): Last reviewed commit: "fix(resume): preserve prompt whitespace" | Re-trigger Greptile |
Summary
OPENAI_API_KEYis absentPaid task: https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e
Testing
corepack pnpm exec vitest run src/lib/resume-parser.test.tscorepack pnpm exec eslint src/lib/resume-parser.ts src/lib/resume-parser.test.tsgit diff --checkcorepack pnpm build(now passes/api/profile/importpage-data collection and proceeds into static generation; later blocked by pre-existing missing Supabase service-role configuration while prerendering/blog)