{"record":{"id":"3d505bacb47d77d2","repo":"santifer/career-ops","slug":"cv-section-order-diverges-from-cv-md-rendered-r","errorCode":null,"errorMessage":"CV section order diverges from cv.md: rendered ${renderedOrder}; cv.md ${sourceOrder}","messagePattern":"CV section order diverges from cv\\.md: rendered (.+?); cv\\.md (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"generate-pdf.mjs","lineNumber":269,"sourceCode":"  const sourcePositions = new Map(source.map((section, index) => [section.key, index]));\n  const renderedComparable = rendered.filter(section => sourcePositions.has(section.key));\n  if (renderedComparable.length < 2) return;\n\n  for (let i = 1; i < renderedComparable.length; i++) {\n    const previous = renderedComparable[i - 1];\n    const current = renderedComparable[i];\n    if (sourcePositions.get(current.key) < sourcePositions.get(previous.key)) {\n      const renderedOrder = renderedComparable.map(section => section.title).join(' -> ');\n      const sourceOrder = source\n        .filter(section => renderedComparable.some(renderedSection => renderedSection.key === section.key))\n        .map(section => section.title)\n        .join(' -> ');\n      const message = `CV section order diverges from cv.md: rendered ${renderedOrder}; cv.md ${sourceOrder}`;\n      if (allowReorder) {\n        console.warn(`⚠️  ${message} (proceeding — --allow-reorder set)`);\n        return;\n      }\n      throw new Error(message);\n    }\n  }\n}\n\n/**\n * Decide whether a rendered CV fits its configured page budget.\n *\n * This is deliberately separate from rendering: page count comes from the\n * PDF Chromium actually produced, and the renderer never changes layout to\n * force content under the limit.\n *\n * @param {number} pageCount - Actual pages in the rendered PDF.\n * @param {{ maxPages?: number, strictPages?: boolean }} [options]\n * @returns {void}\n */\nexport function enforcePageBudget(pageCount, { maxPages = 2, strictPages = false } = {}) {\n  if (!Number.isInteger(pageCount) || pageCount < 1) {\n    throw new Error(`Could not determine the rendered PDF page count (received ${pageCount}).`);","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/generate-pdf.mjs#L251-L287","documentation":"validateCvSectionOrder compares the section heading order in the rendered CV HTML against the order in cv.md. If the rendered order reverses the source order (a section appears before another that precedes it in cv.md), the validation throws — unless allowReorder (--allow-reorder) downgrades it to a console warning. This catches accidental reordering by an agent or a template that scrambles sections.","triggerScenarios":"An agent tailored the CV and moved Projects ahead of Experience; a custom HTML template has a fixed section order that differs from cv.md; cv.md sections were reordered but the HTML was not regenerated from the new source; the template injects a section (e.g. a sidebar) that shifts the perceived order.","commonSituations":"Tailoring a CV for a technical role moves Projects up intentionally; a template reorder is accidental (agent hallucination); the rendered extraction picks up non-content headings.","solutions":["If the reorder is intentional, pass --allow-reorder to downgrade the error to a warning.","If unintentional, fix the HTML template or the agent's section ordering to match cv.md.","Reorder cv.md itself if the source order is what you want the rendered order to be."],"exampleFix":"# before\nnode generate-pdf.mjs\n# throws: CV section order diverges from cv.md\n\n# after — intentional reorder\nnode generate-pdf.mjs --allow-reorder","handlingStrategy":"validation","validationCode":"// Validate before render if you have both html and cvMarkdown\nimport { validateCvSectionOrder } from './generate-pdf.mjs';\n\ntry {\n  validateCvSectionOrder(html, cvMarkdown, { allowReorder: intentionalReorder });\n} catch (err) {\n  console.warn('Section order divergence detected:', err.message);\n  if (!intentionalReorder) throw err;\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateCvSectionOrder(html, cvMarkdown);\n} catch (err) {\n  if (err.message.includes('section order diverges') && intentionalReorder) {\n    // Re-run with allowReorder instead\n    validateCvSectionOrder(html, cvMarkdown, { allowReorder: true });\n  } else {\n    throw err;\n  }\n}","preventionTips":["If section reordering is intentional for a role, pass --allow-reorder.","Keep cv.md and the HTML template in sync — edit one, regenerate the other.","After agent edits to a tailored CV, validate section order before generating the PDF."],"tags":["cv","validation","template","pdf","section-order"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}