Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
test(evals): add cover-letter prompt regression tests
Khuram Niaz6f50a8fa8805
diff --git a/evals/cover-letter/assertions.ts b/evals/cover-letter/assertions.tsnew file mode 100644index 0000000..bcf61aa--- /dev/null+++ b/evals/cover-letter/assertions.ts@@ -0,0 +1,139 @@+import { stripThinking } from '../../src/lib/ai/stripThinking';++type AssertionResult = { pass: boolean; score: number; reason: string };+type Context = { vars: Record<string, string> };++// Mirrors src/utils/streamCoverLetter.utils.ts, which does exactly+// stripThinking(raw).trim() — there is nothing else to parse, the whole+// response is the letter as saved and rendered.+const clean = (output: string) => stripThinking(output).trim();++// The prompt asks for 250-400; the floor here is deliberately lower because a+// well-grounded letter with no prior match guidance lands around 226 words and+// reads fine. Outside the range but inside TOLERANCE scores partial so a mild+// drift is visible without failing the whole row to zero.+const MIN_WORDS = 220;+const MAX_WORDS = 400;+const TOLERANCE = 0.15;++export function assertNotJsonOrFenced(output: string): AssertionResult {+ const text = clean(output);+ if (text.startsWith('{') || text.startsWith('[')) {+ return { pass: false, score: 0, reason: 'Output looks like raw JSON; expected a markdown letter' };+ }+ if (text.startsWith('```')) {+ const fence = text.split('\n', 1)[0].slice(0, 40);+ return { pass: false, score: 0, reason: `Output is wrapped in a code fence: "${fence}"` };+ }+ return { pass: true, score: 1, reason: 'Output is a bare markdown letter' };+}++// A preamble ("Here is your cover letter:") or a date/address header would be+// saved verbatim and exported to PDF, so the first line must be the salutation.+export function assertStartsWithSalutation(output: string): AssertionResult {+ const firstLine = clean(output).split('\n', 1)[0].trim();+ if (!/^dear\s+\S.*$/i.test(firstLine)) {+ return {+ pass: false,+ score: 0,+ reason: `First line must be the salutation; got: "${firstLine.slice(0, 80)}"`,+ };+ }+ return { pass: true, score: 1, reason: 'Starts with the salutation' };+}++// Trailing commentary ("Let me know if you'd like...") is the mirror-image+// regression to a preamble, so anchor the end on the sign-off block.+export function assertSignOff(output: string): AssertionResult {+ const lines = clean(output).split('\n').map((l) => l.trim()).filter(Boolean);+ const tail = lines.slice(-3).join('\n');+ if (!/(sincerely|kind regards|best regards|regards)\s*,/i.test(tail)) {+ return {+ pass: false,+ score: 0,+ reason: `No sign-off in the last lines: "${tail.slice(-80)}"`,+ };+ }+ const last = lines[lines.length - 1];+ if (/^(let me know|i hope|please feel free|note:|p\.?s\.?[:.])/i.test(last)) {+ return { pass: false, score: 0, reason: `Commentary after the sign-off: "${last.slice(0, 80)}"` };+ }+ return { pass: true, score: 1, reason: 'Ends with a sign-off, no trailing commentary' };+}++export function assertCandidateNameSignature(output: string): AssertionResult {+ const tail = clean(output).split('\n').slice(-4).join('\n');+ if (!/jordan\s+ellis/i.test(tail)) {+ return {+ pass: false,+ score: 0,+ reason: `Sign-off must carry the resume's name (Jordan Ellis); got: "${tail.trim().slice(-80)}"`,+ };+ }+ return { pass: true, score: 1, reason: "Signed with the resume's candidate name" };+}++export function assertWordCount(output: string): AssertionResult {+ const words = clean(output).split(/\s+/).filter(Boolean).length;+ if (words >= MIN_WORDS && words <= MAX_WORDS) {+ return { pass: true, score: 1, reason: `${words} words (within ${MIN_WORDS}-${MAX_WORDS})` };+ }+ const lower = Math.floor(MIN_WORDS * (1 - TOLERANCE));+ const upper = Math.ceil(MAX_WORDS * (1 + TOLERANCE));+ const near = words >= lower && words <= upper;+ return {+ pass: false,+ score: near ? 0.5 : 0,+ reason: `${words} words, outside the ${MIN_WORDS}-${MAX_WORDS} range`,+ };+}++// "Do NOT include placeholder brackets like [Company]". Markdown links are+// excluded so a genuine [text](url) isn't flagged — letters shouldn't have+// them, but that's a style call, not this assertion's job.+export function assertNoPlaceholders(output: string): AssertionResult {+ const text = clean(output);+ const hits = [...text.matchAll(/\[([^\]\n]{1,60})\](?!\()/g)].map((m) => m[0]);+ if (hits.length > 0) {+ return {+ pass: false,+ score: 0,+ reason: `Unfilled placeholder brackets: ${hits.slice(0, 3).join(', ')}`,+ };+ }+ return { pass: true, score: 1, reason: 'No placeholder brackets' };+}++// Deterministic half of the fabrication check: every number in the letter must+// trace back to the resume, the job, or the match guidance. Catches invented+// metrics, years of experience, and dates — the fabrications that do real+// damage on a submitted application. Digit runs only, so "40 million" matches+// the resume's "40M+" and spelled-out numbers are ignored.+export function assertNoInventedNumbers(+ output: string,+ context: Context,+): AssertionResult {+ const numbersIn = (text: string) =>+ [...(text || '').matchAll(/\d+(?:[.,]\d+)*/g)].map((m) =>+ m[0].replace(/,/g, ''),+ );++ const allowed = new Set(+ [context.vars.resumeText, context.vars.jobDescription, context.vars.guidance]+ .filter(Boolean)+ .flatMap((source) => numbersIn(source)),+ );++ const invented = [...new Set(numbersIn(clean(output)))].filter(+ (n) => !allowed.has(n),+ );++ if (invented.length > 0) {+ return {+ pass: false,+ score: 0,+ reason: `Numbers not present in the inputs: ${invented.slice(0, 5).join(', ')}`,+ };+ }+ return { pass: true, score: 1, reason: 'Every number traces to the inputs' };+}diff --git a/evals/cover-letter/fixtures/match-guidance.txt b/evals/cover-letter/fixtures/match-guidance.txtnew file mode 100644index 0000000..bebef6c--- /dev/null+++ b/evals/cover-letter/fixtures/match-guidance.txt@@ -0,0 +1,11 @@+## Keywords+- Go+- Kubernetes+- AWS (EKS, RDS, S3, Lambda)+- Prometheus, Grafana, OpenTelemetry+- Distributed systems: queues, caching, rate limiting, circuit breakers++## Tailoring Tips+- Lead with the Kubernetes migration at Meridian Technologies — it maps directly to the job's "drive our Kubernetes migration" responsibility.+- Quantify the Go search indexing rewrite (12K to 95K documents/second) as evidence of production Go depth.+- Mention mentoring 6 engineers, which covers the "mentor engineers and raise the engineering bar" expectation.diff --git a/evals/cover-letter/prompt.ts b/evals/cover-letter/prompt.tsnew file mode 100644index 0000000..8dd1523--- /dev/null+++ b/evals/cover-letter/prompt.ts@@ -0,0 +1,16 @@+import { COVER_LETTER_SYSTEM_PROMPT } from '../../src/lib/ai/prompts/cover-letter/system';+import { buildCoverLetterPrompt } from '../../src/lib/ai/prompts/cover-letter/user';++export default function prompt({ vars }: { vars: Record<string, string> }) {+ return [+ { role: 'system', content: COVER_LETTER_SYSTEM_PROMPT },+ {+ role: 'user',+ content: buildCoverLetterPrompt(+ vars.resumeText,+ vars.jobDescription,+ vars.guidance || null,+ ),+ },+ ];+}diff --git a/evals/cover-letter/promptfooconfig.yaml b/evals/cover-letter/promptfooconfig.yamlnew file mode 100644index 0000000..e8be483--- /dev/null+++ b/evals/cover-letter/promptfooconfig.yaml@@ -0,0 +1,90 @@+description: Cover letter prompt regression tests++providers:+ - id: openai:chat:deepseek-v4-flash+ config:+ apiBaseUrl: https://api.deepseek.com+ apiKeyEnvar: DEEPSEEK_API_KEY+ showThinking: false+ temperature: 0+ max_tokens: 8192++prompts:+ - file://./prompt.ts++# The letter is generated at a creative temperature in the app (TEMPERATURES.+# FEEDBACK), but evals run at 0 for repeatability — same trade-off as the other+# markdown prompts here.+tests:+ - description: Backend resume vs backend JD - no prior match guidance+ vars:+ resumeText: file://../job-match/fixtures/backend-resume.txt+ jobDescription: file://../job-match/fixtures/backend-job.txt+ assert:+ - type: javascript+ value: file://./assertions.ts:assertNotJsonOrFenced+ - type: javascript+ value: file://./assertions.ts:assertStartsWithSalutation+ - type: javascript+ value: file://./assertions.ts:assertSignOff+ - type: javascript+ value: file://./assertions.ts:assertCandidateNameSignature+ - type: javascript+ value: file://./assertions.ts:assertWordCount+ - type: javascript+ value: file://./assertions.ts:assertNoPlaceholders+ - type: javascript+ value: file://./assertions.ts:assertNoInventedNumbers+ # Letter must engage the JD's actual must-haves, not generic enthusiasm.+ - type: icontains-any+ value:+ - "Kubernetes"+ - "Go"+ - "AWS"+ - type: llm-rubric+ provider:+ id: openai:chat:deepseek-v4-flash+ config:+ apiBaseUrl: https://api.deepseek.com+ apiKeyEnvar: DEEPSEEK_API_KEY+ temperature: 0+ value: >-+ Every employer, job title, date, degree, certification, and metric in+ the letter must appear in the candidate's resume below. Fail if the+ letter names any employer, title, school, degree, or certification the+ resume does not contain, or states an achievement the resume does not+ support. Company names taken from the job posting are acceptable when+ used as the employer being applied to. Resume:++ {{resumeText}}++ - description: Backend resume vs backend JD - with saved match guidance+ vars:+ resumeText: file://../job-match/fixtures/backend-resume.txt+ jobDescription: file://../job-match/fixtures/backend-job.txt+ guidance: file://./fixtures/match-guidance.txt+ assert:+ - type: javascript+ value: file://./assertions.ts:assertNotJsonOrFenced+ - type: javascript+ value: file://./assertions.ts:assertStartsWithSalutation+ - type: javascript+ value: file://./assertions.ts:assertSignOff+ - type: javascript+ value: file://./assertions.ts:assertCandidateNameSignature+ - type: javascript+ value: file://./assertions.ts:assertWordCount+ - type: javascript+ value: file://./assertions.ts:assertNoPlaceholders+ - type: javascript+ value: file://./assertions.ts:assertNoInventedNumbers+ # The guidance block is the only untested branch of+ # buildCoverLetterPrompt: its Tailoring Tips must actually land.+ - type: icontains+ value: "Meridian Technologies"+ - type: icontains-any+ value:+ - "95K"+ - "95,000"+ - "documents per second"+ - "documents/second"diff --git a/evals/dispatch-prompt.ts b/evals/dispatch-prompt.tsindex 6680d01..81a4775 100644--- a/evals/dispatch-prompt.ts+++ b/evals/dispatch-prompt.ts@@ -6,6 +6,8 @@ import { AUTOMATION_JOB_MATCH_SYSTEM_PROMPT } from '../src/lib/ai/prompts/automaimport { buildAutomationJobMatchPrompt } from '../src/lib/ai/prompts/automation-match/user';import { RESUME_IMPORT_SYSTEM_PROMPT } from '../src/lib/ai/prompts/resume-import/system';import { buildResumeImportPrompt } from '../src/lib/ai/prompts/resume-import/user';+import { COVER_LETTER_SYSTEM_PROMPT } from '../src/lib/ai/prompts/cover-letter/system';+import { buildCoverLetterPrompt } from '../src/lib/ai/prompts/cover-letter/user';// Single prompt entry so every task's test cases render as rows in one table.// Each test supplies a `task` var selecting which real src prompt to exercise.@@ -26,6 +28,18 @@ export default function prompt({ vars }: { vars: Record<string, string> }) {{ role: 'system', content: AUTOMATION_JOB_MATCH_SYSTEM_PROMPT },{ role: 'user', content: buildAutomationJobMatchPrompt(vars.resumeText, vars.jobDescription) },];+ case 'cover-letter':+ return [+ { role: 'system', content: COVER_LETTER_SYSTEM_PROMPT },+ {+ role: 'user',+ content: buildCoverLetterPrompt(+ vars.resumeText,+ vars.jobDescription,+ vars.guidance || null,+ ),+ },+ ];case 'resume-import':// Import rows override the provider to json_object mode (see the combined// config), mirroring the route's Output.object; append the JSON hint thatdiff --git a/evals/package.json b/evals/package.jsonindex 06dcf35..f6ddff9 100644--- a/evals/package.json+++ b/evals/package.json@@ -6,6 +6,7 @@"eval:resume-review": "promptfoo eval --env-file ../.env --config resume-review/promptfooconfig.yaml","eval:job-match": "promptfoo eval --env-file ../.env --config job-match/promptfooconfig.yaml","eval:automation-match": "promptfoo eval --env-file ../.env --config job-match/automation.promptfooconfig.yaml",+ "eval:cover-letter": "promptfoo eval --env-file ../.env --config cover-letter/promptfooconfig.yaml","eval:resume-import": "promptfoo eval --env-file ../.env --config resume-import/promptfooconfig.yaml","eval:mcp-tools": "tsx mcp-tools/generate-tools.ts && promptfoo eval --env-file ../.env --config mcp-tools/promptfooconfig.yaml","eval:all": "promptfoo eval --env-file ../.env --config promptfooconfig.yaml",diff --git a/evals/promptfooconfig.yaml b/evals/promptfooconfig.yamlindex 7a61e07..18b00a9 100644--- a/evals/promptfooconfig.yaml+++ b/evals/promptfooconfig.yaml@@ -1,4 +1,4 @@-description: All prompt regression tests (resume-review + job-match + automation + resume-import) in one table+description: All prompt regression tests (resume-review + job-match + automation + cover-letter + resume-import) in one tableproviders:- id: openai:chat:deepseek-v4-flash@@ -145,6 +145,79 @@ tests:- type: javascriptvalue: file://./job-match/assertions.ts:assertWeakMatchLow+ # Cover letter (free-form markdown letter, no scores line)+ - description: "[cover-letter] backend resume vs backend JD - no guidance"+ vars:+ task: cover-letter+ resumeText: file://./job-match/fixtures/backend-resume.txt+ jobDescription: file://./job-match/fixtures/backend-job.txt+ assert:+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNotJsonOrFenced+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertStartsWithSalutation+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertSignOff+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertCandidateNameSignature+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertWordCount+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNoPlaceholders+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNoInventedNumbers+ - type: icontains-any+ value:+ - "Kubernetes"+ - "Go"+ - "AWS"+ - type: llm-rubric+ provider:+ id: openai:chat:deepseek-v4-flash+ config:+ apiBaseUrl: https://api.deepseek.com+ apiKeyEnvar: DEEPSEEK_API_KEY+ temperature: 0+ value: >-+ Every employer, job title, date, degree, certification, and metric in+ the letter must appear in the candidate's resume below. Fail if the+ letter names any employer, title, school, degree, or certification the+ resume does not contain, or states an achievement the resume does not+ support. Company names taken from the job posting are acceptable when+ used as the employer being applied to. Resume:++ {{resumeText}}++ - description: "[cover-letter] backend resume vs backend JD - with match guidance"+ vars:+ task: cover-letter+ resumeText: file://./job-match/fixtures/backend-resume.txt+ jobDescription: file://./job-match/fixtures/backend-job.txt+ guidance: file://./cover-letter/fixtures/match-guidance.txt+ assert:+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNotJsonOrFenced+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertStartsWithSalutation+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertSignOff+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertCandidateNameSignature+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertWordCount+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNoPlaceholders+ - type: javascript+ value: file://./cover-letter/assertions.ts:assertNoInventedNumbers+ - type: icontains+ value: "Meridian Technologies"+ - type: icontains-any+ value:+ - "95K"+ - "95,000"+ - "documents per second"+ - "documents/second"+# Resume import (structured JSON via Output.object). These rows override the# provider to JSON mode; the shared markdown provider above can't be reused# because it would force JSON onto the review/match tasks too.