Prevent stale resume downloads after deployment

This commit is contained in:
StormRunner06106
2026-10-02 06:39:39 -07:00
parent bf1bf7b9f8
commit e14d350287
3 changed files with 81 additions and 2 deletions
+9 -1
View File
@@ -25,7 +25,7 @@ resumes/ Matching HTML/PDF files for each generated version
The standalone generator reads `Alexander Herlan Resume 2024.md`, creates a self-contained HTML document, and prints that exact HTML to PDF using Python Playwright. The template and CSS are in `scripts/generate_resume.py`. The default `--layout original` retains the sidebar design with left-column section labels, right-column content, Letter pages, and green header accents. Section starts use normal-flow grid layout to preserve the PDF text reading order. Use `--layout ats` for the optional single-column layout. Both layouts use the same Markdown and local Raleway/Lato fonts when available, with Arial as a fallback. The original PDF is only a design reference, and is not needed to run the generator.
**Selected website resume: version 17.** The portfolio's **Open CV** link uses
`/api/resume`, which serves the styled `resumes/resume-v17.pdf` as
`/api/resume?v=resume-v17`, which serves the styled `resumes/resume-v17.pdf` as
`Alexander-Herlan-Resume-v17.pdf`. Its source is `resumes/resume-v17.md`, with
the corrected `alexherlandev@gmail.com` email and matching HTML/PDF files. Both
deployment configurations include the version 17 PDF. Version 18 remains the
@@ -38,6 +38,14 @@ Generating a new version does not automatically change the selected website
resume. PDF text extraction and Word reading order are checked locally; actual
application-field mapping depends on the receiving system.
The profile API derives the CV link's version from the selected `RESUME_PATH`,
so changing the selected PDF also changes the URL and bypasses previously cached
downloads. PDF responses send `Cache-Control: no-store`; the unversioned
`/api/resume` endpoint remains available. The query parameter is a cache marker,
not a selector for historical files. To check a deployment, follow the live
`/api/profile` response's `resume_url` and compare the downloaded PDF's bytes
with the selected file, rather than relying only on its filename.
Install the generator dependencies separately from the web backend:
+6 -1
View File
@@ -275,7 +275,11 @@ def scheduled_media_cleanup(authorization: str | None = Header(default=None)):
@app.get("/api/profile")
def profile() -> dict[str, Any]:
return read_data("profile.json")
# A new selection must bypass PDFs cached under the previous download URL.
return {
**read_data("profile.json"),
"resume_url": f"/api/resume?v={RESUME_PATH.stem}",
}
portfolio_content.register_routes(app, require_admin)
@@ -622,6 +626,7 @@ def resume() -> FileResponse:
media_type="application/pdf",
filename="Alexander-Herlan-Resume-v17.pdf",
content_disposition_type="inline",
headers={"Cache-Control": "no-store"},
)
+66
View File
@@ -0,0 +1,66 @@
"""Resume selection and cache behavior across deployments."""
from pathlib import Path
from tempfile import TemporaryDirectory
import unittest
from unittest.mock import patch
from fastapi.testclient import TestClient
from backend import main
class ResumeTests(unittest.TestCase):
def setUp(self):
self.client = TestClient(main.app)
def test_profile_link_serves_selected_pdf_without_caching(self):
profile = self.client.get("/api/profile").json()
response = self.client.get(profile["resume_url"])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, main.RESUME_PATH.read_bytes())
self.assertEqual(response.headers["content-type"], "application/pdf")
self.assertIn("Alexander-Herlan-Resume-v17.pdf",
response.headers["content-disposition"])
self.assertEqual(response.headers["cache-control"], "no-store")
def test_changing_selection_changes_link_without_mutating_profile_data(self):
with TemporaryDirectory() as directory:
original = dict(main.read_data("profile.json"))
urls = []
for version in (11, 17):
path = Path(directory) / f"resume-v{version}.pdf"
content = f"%PDF-1.7\nSelected resume {version}".encode()
path.write_bytes(content)
with patch.object(main, "RESUME_PATH", path):
url = self.client.get("/api/profile").json()["resume_url"]
urls.append(url)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, content)
self.assertNotEqual(urls[0], urls[1])
self.assertNotIn("/api/resume", urls)
self.assertEqual(main.read_data("profile.json"), original)
def test_old_links_and_pdf_range_requests_serve_current_selection(self):
expected = main.RESUME_PATH.read_bytes()
for url in ("/api/resume", "/api/resume?v=resume-v11"):
with self.subTest(url=url):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, expected)
self.assertEqual(response.headers["cache-control"], "no-store")
partial = self.client.get(url, headers={"Range": "bytes=0-31"})
self.assertEqual(partial.status_code, 206)
self.assertEqual(partial.content, expected[:32])
self.assertEqual(partial.headers["cache-control"], "no-store")
def test_missing_selected_file_does_not_fall_back_to_old_resume(self):
with TemporaryDirectory() as directory:
path = Path(directory) / "resume-missing.pdf"
with patch.object(main, "RESUME_PATH", path):
response = self.client.get("/api/resume")
self.assertEqual(response.status_code, 404)
if __name__ == "__main__":
unittest.main()