Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

Fix PDF year ranges beside role titles (#3718)

Amruth Pillaibfc2d6b0919b
diff --git a/packages/pdf/src/ats-extraction.integration.test.tsx b/packages/pdf/src/ats-extraction.integration.test.tsx
index 971d498b5..a29a7663b 100644
--- a/packages/pdf/src/ats-extraction.integration.test.tsx
+++ b/packages/pdf/src/ats-extraction.integration.test.tsx
@@ -6,7 +6,13 @@ import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vite-plus/test";
import { getDocument, OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
import { createElement } from "react";
-import { analyzePdfResume, harvestPdfDocument, PDF_OPS } from "@reactive-resume/resume/ats-pdf";
+import {
+ analyzePdfResume,
+ buildExtractedDocument,
+ buildResumeSemantics,
+ harvestPdfDocument,
+ PDF_OPS,
+} from "@reactive-resume/resume/ats-pdf";
import { sampleResumeData } from "@reactive-resume/schema/resume/sample";
import { ResumeDocument } from "./document";
import { renderToBuffer } from "./forme/testing";
@@ -60,13 +66,34 @@ describe("PDF operator numbers", () => {
});
describe("a resume rendered by this app", () => {
+ it("recognizes dates in the static Onyx checker sample", async () => {
+ const bytes = new Uint8Array(
+ readFileSync(new URL("../../../apps/web/public/templates/pdf/onyx.pdf", import.meta.url)),
+ );
+ const { raw, report } = await analyze(bytes, { name: "onyx.pdf" });
+ const document = buildExtractedDocument(raw);
+ const { dates } = buildResumeSemantics(raw, document, { now: NOW });
+
+ expect(document.lines.map((line) => line.text)).toContain("Clinical Research Coordinator 2022 – Present");
+ expect(dates.map((date) => date.raw)).toEqual(["2022 – Present", "2019 – 2022", "2013 – 2017", "2023 – Present"]);
+ expect(dates.every((date) => date.kind === "range" && date.parsed)).toBe(true);
+ expect(failedCodes(report)).not.toContain("NO_DATES_FOUND");
+ });
+
/**
- * The regression guard for this whole feature: the app's own default single-column export has
+ * The regression guard for this whole feature: a single-column export with consistent dates has
* to come out clean. Anything the checker reports here, it reports to every user of this app,
* so a false positive shows up as a failing assertion rather than as lost trust.
*/
it("reports nothing that would cost a single-column export points", { timeout: 60_000 }, async () => {
- const { raw, report } = await analyze(await renderResume(sampleResumeData, "onyx"));
+ const data = structuredClone(sampleResumeData);
+ // Sample content mixes month/year and year-only periods; this fixture needs consistent dates.
+ for (const section of [...Object.values(data.sections), ...data.customSections]) {
+ for (const item of section.items) {
+ if ("period" in item) item.period = item.period.replace(/[A-Za-z]+\s+(?=\d{4})/g, "");
+ }
+ }
+ const { raw, report } = await analyze(await renderResume(data, "onyx"));
expect(raw.pages.length).toBeGreaterThan(0);
expect(raw.operatorsAvailable).toBe(true);
diff --git a/packages/resume/src/ats-pdf/analyze/dates.ts b/packages/resume/src/ats-pdf/analyze/dates.ts
index 0be3265ba..fc464dd99 100644
--- a/packages/resume/src/ats-pdf/analyze/dates.ts
+++ b/packages/resume/src/ats-pdf/analyze/dates.ts
@@ -11,16 +11,19 @@ const ENDPOINT = String.raw`(?:${MONTH_WORD}\s*'?\d{2,4}|\d{1,2}[/.\-]\d{2,4}|\d
const ONGOING = String.raw`(?:present|current|currently|now|ongoing|to\s?date|today)`;
const SEPARATOR = String.raw`\s*(?:[-–—~]|to|through|until)\s*`;
-const RANGE_PATTERN = new RegExp(`${ENDPOINT}${SEPARATOR}(?:${ENDPOINT}|${ONGOING})`, "gi");
+const RANGE_PATTERN = new RegExp(
+ String.raw`\b${ENDPOINT}${SEPARATOR}(?:${ENDPOINT}|${ONGOING})(?![\p{L}\p{N}_])`,
+ "giu",
+);
+const ONGOING_END_PATTERN = new RegExp(`${SEPARATOR}${ONGOING}$`, "i");
const SINGLE_PATTERN = new RegExp(String.raw`\b(?:${MONTH_WORD}\s+\d{4}|\d{1,2}/\d{4})\b`, "gi");
/** A numeric date whose first two components could each be a month or a day. */
const AMBIGUOUS_NUMERIC_PATTERN = /\b(0?[1-9]|1[0-2])[/.-](0?[1-9]|[12]\d|3[01])[/.-](\d{2}|\d{4})\b/g;
/**
- * `[A-Za-z]{3,9}` in the range pattern will happily match "Framework 2021 - 2023", which is a
- * product name next to two years, not a period. Every alphabetic run in a candidate therefore has
- * to be a month name or an ongoing marker in this locale before it counts as a date at all.
+ * `[A-Za-z]{3,9}` in the range pattern also matches non-month words such as "Framework".
+ * Every alphabetic run in a candidate must be a month name or an ongoing marker in this locale.
*
* The trade-off is deliberate: a misspelled month is dropped rather than reported unparseable.
* Claiming a date is malformed when it is not a date is the worse error.
@@ -49,7 +52,8 @@ const ONGOING_WORDS = new Set([
]);
function shapeOf(raw: string): DateToken["shape"] {
- if (/[A-Za-z]/.test(raw)) return "mon-year";
+ if (/[A-Za-z]/.test(raw.replace(ONGOING_END_PATTERN, "").replace(/\b(?:to|through|until)\b/gi, "")))
+ return "mon-year";
if (/\d{1,2}[/.-]\d/.test(raw)) return "numeric";
return "year";
}
@@ -115,7 +119,12 @@ export function analyzeDates(document: ExtractedDocument, locale: string, now: D
const ambiguousNumericDates: string[] = [];
document.lines.forEach((line, lineIndex) => {
- const ranges = (line.text.match(RANGE_PATTERN) ?? []).filter((raw) => looksLikeDateWords(raw, locale));
+ const ranges: string[] = [];
+ for (let match = RANGE_PATTERN.exec(line.text); match; match = RANGE_PATTERN.exec(line.text)) {
+ if (looksLikeDateWords(match[0], locale)) ranges.push(match[0]);
+ // Retry inside a rejected candidate: a role word must not swallow the year range beside it.
+ else RANGE_PATTERN.lastIndex = match.index + 1;
+ }
for (const raw of ranges) {
const token = toToken(raw.trim(), "range", line.page, lineIndex, locale, now);
tokens.push(token);
diff --git a/packages/resume/src/ats-pdf/rules.test.ts b/packages/resume/src/ats-pdf/rules.test.ts
index 7635569b9..818e8513b 100644
--- a/packages/resume/src/ats-pdf/rules.test.ts
+++ b/packages/resume/src/ats-pdf/rules.test.ts
@@ -2,7 +2,7 @@ import type { PdfRuleCode } from "./catalog";
import type { FixtureOptions } from "./test-fixtures";
import type { PdfAtsReport, RawExtraction } from "./types";
import { describe, expect, it } from "vite-plus/test";
-import { analyzePdfResume } from "./index";
+import { analyzePdfResume, buildExtractedDocument, buildResumeSemantics } from "./index";
import { healthyResume, healthyResumeLines, makeRawExtraction, scannedResume, twoColumnResume } from "./test-fixtures";
const NOW = new Date("2024-06-15T00:00:00Z");
@@ -286,6 +286,31 @@ describe("contact checks", () => {
});
describe("date checks", () => {
+ it.each([false, true])("recognizes Onyx year ranges beside role words (separate runs: %s)", (separateRuns) => {
+ const datedLines = [
+ ["Clinical Research Coordinator", "2022 – Present"],
+ ["Clinical Research Coordinator", "2019 – 2022"],
+ ["Clinical Research", "2013 – 2017"],
+ ["Community Skills Network", "2023 – Present"],
+ ] as const;
+ const raw = makeRawExtraction({
+ lines: datedLines.flatMap(([text, period], index) =>
+ separateRuns
+ ? [
+ { text, x: 56, y: 60 + index * 30 },
+ { text: period, x: 440, y: 60 + index * 30 },
+ ]
+ : [{ text: `${text} ${period}` }],
+ ),
+ });
+
+ const result = report(raw);
+ const { dates } = buildResumeSemantics(raw, buildExtractedDocument(raw), { now: NOW });
+ expect(dates.filter((date) => date.kind === "range" && date.parsed)).toHaveLength(4);
+ expect(statusOf(result, "NO_DATES_FOUND")).toBe("pass");
+ expect(statusOf(result, "MIXED_DATE_FORMATS")).toBe("pass");
+ });
+
it("caps a resume with no dates at all", () => {
const undated = healthyResumeLines.filter((line) => typeof line !== "string" || !/\d{4}/.test(line));
const result = report(makeRawExtraction({ lines: undated }));
@@ -306,10 +331,67 @@ describe("date checks", () => {
expect(codes).toContain("UNPARSEABLE_DATE_RANGE");
});
- it("does not read a product name beside two years as a date range", () => {
- // "Framework 2021 - 2023" matches the shape of a period and is not one.
+ it("does not report a product name beside years as a malformed date", () => {
const codes = codesOf(healthyResume({ lines: [...healthyResumeLines, "Built on Framework 2021 - 2023"] }));
expect(codes).not.toContain("UNPARSEABLE_DATE_RANGE");
});
+
+ it.each(["Presented", "Presenté", "20235", "2023suffix", "2023_suffix"])(
+ "does not accept an endpoint truncated from %s",
+ (endpoint) => {
+ const result = report(
+ withLines(["Research specialist delivering clinical studies.", `Framework 2021 - ${endpoint}`]),
+ );
+ expect(statusOf(result, "NO_DATES_FOUND")).toBe("fail");
+ expect(statusOf(result, "NO_CURRENT_ROLE_MARKER")).toBe("skip");
+ },
+ );
+
+ it.each(["to", "through", "until"])("treats completed and ongoing %s ranges as one year-only format", (separator) => {
+ const raw = withLines([
+ "Research specialist delivering clinical studies with multidisciplinary teams and patient groups.",
+ `Clinical Research 2011 ${separator} 2014`,
+ `Clinical Research 2014 ${separator} 2018`,
+ `Clinical Research 2020 ${separator} Present`,
+ `Clinical Research 2022 ${separator} Present`,
+ ]);
+ const { dates } = buildResumeSemantics(raw, buildExtractedDocument(raw), { now: NOW });
+ expect(dates).toHaveLength(4);
+ expect(dates.every((date) => date.parsed && date.shape === "year")).toBe(true);
+ expect(statusOf(report(raw), "MIXED_DATE_FORMATS")).toBe("pass");
+ });
+
+ it.each([
+ "Framework 20 - Product 22",
+ "Jan 2020 - Framework 2023",
+ "Framework 2021 - Product 2023",
+ "NotMay2020 - Present",
+ "12020 - 2023",
+ ])("rejects non-date words inside a range: %s", (text) => {
+ const result = report(
+ withLines([
+ "Research specialist delivering clinical studies with multidisciplinary teams and patient groups.",
+ text,
+ ]),
+ );
+ expect(statusOf(result, "UNPARSEABLE_DATE_RANGE")).toBe("pass");
+ expect(statusOf(result, "NO_CURRENT_ROLE_MARKER")).toBe("skip");
+ });
+
+ it("preserves localized months beside role titles", () => {
+ const result = report(
+ withLines(
+ [
+ "Ingenieur Januar 2020 – April 2022",
+ "Verantwortlich für die Entwicklung und den Betrieb interner Systeme in Berlin.",
+ ],
+ { metadata: { language: "de" } },
+ ),
+ );
+
+ expect(statusOf(result, "NO_DATES_FOUND")).toBe("pass");
+ expect(statusOf(result, "UNPARSEABLE_DATE_RANGE")).toBe("pass");
+ expect(statusOf(result, "NO_CURRENT_ROLE_MARKER")).toBe("fail");
+ });
});