Repository navigation
Fix PDF conversion after history rewrites and tag updates #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| from scripts.convert_pdfs import ( | ||
| discover_sources, | ||
| extract_frontmatter, | ||
| extract_notes, | ||
| frontmatter_value, | ||
|
|
@@ -14,6 +17,98 @@ | |
| ) | ||
|
|
||
|
|
||
| class DiscoverPdfSourcesTest(unittest.TestCase): | ||
| MISSING_BEFORE = "f" * 40 | ||
| MISSING_AFTER = "e" * 40 | ||
|
|
||
| def setUp(self): | ||
| original_cwd = Path.cwd() | ||
| temporary = tempfile.TemporaryDirectory() | ||
| self.addCleanup(temporary.cleanup) | ||
| self.root = Path(temporary.name) | ||
| os.chdir(self.root) | ||
| self.addCleanup(os.chdir, original_cwd) | ||
| self.git("init", "--quiet") | ||
| self.git("config", "user.name", "SourceBraid Test") | ||
| self.git("config", "user.email", "[email protected]") | ||
|
|
||
| def git(self, *args): | ||
| result = subprocess.run( | ||
| ["git", "-c", "core.hooksPath=/dev/null", "-c", "commit.gpgsign=false", *args], | ||
| check=True, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| return result.stdout.strip() | ||
|
|
||
| def write_source(self, slug, content=b"%PDF synthetic fixture"): | ||
| path = Path("web-clips/2026/11/assets") / slug / "source.pdf" | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| path.write_bytes(content) | ||
| return path | ||
|
|
||
| def commit(self): | ||
| self.git("add", "--all") | ||
| self.git("commit", "--quiet", "--allow-empty", "-m", "Synthetic fixture update") | ||
| return self.git("rev-parse", "HEAD") | ||
|
|
||
| def test_valid_range_discovers_only_added_and_modified_source_pdfs(self): | ||
| self.write_source("unchanged") | ||
| modified = self.write_source("modified") | ||
| removed = self.write_source("removed") | ||
| before = self.commit() | ||
|
|
||
| modified.write_bytes(b"%PDF changed synthetic fixture") | ||
| removed.unlink() | ||
| added = self.write_source("added", b"%PDF newly added synthetic fixture") | ||
| ignored = added.parent / "attachment.pdf" | ||
| ignored.write_bytes(b"%PDF unrelated attachment") | ||
| after = self.commit() | ||
| self.write_source("untracked") | ||
|
|
||
| self.assertEqual( | ||
| discover_sources(before, after, False), | ||
| sorted([added, modified]), | ||
| ) | ||
|
|
||
| def test_missing_before_discovers_current_pdfs_including_unchanged_sources(self): | ||
| unchanged = self.write_source("unchanged") | ||
| removed = self.write_source("removed") | ||
| self.commit() | ||
|
|
||
| removed.unlink() | ||
| added = self.write_source("added") | ||
| after = self.commit() | ||
|
|
||
| self.assertEqual( | ||
| discover_sources(self.MISSING_BEFORE, after, False), | ||
| sorted([added, unchanged]), | ||
| ) | ||
|
|
||
| def test_missing_before_without_pdfs_succeeds_without_docling(self): | ||
| after = self.commit() | ||
| script = Path(__file__).resolve().parents[1] / "scripts" / "convert_pdfs.py" | ||
| # Isolated Python without site packages verifies the no-work path needs no Docling. | ||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, "-I", "-S", str(script), | ||
| "--before", self.MISSING_BEFORE, "--after", after, | ||
| ], | ||
| check=True, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| self.assertIn("No queued source.pdf files found.", result.stdout) | ||
|
|
||
| def test_missing_before_does_not_hide_invalid_after(self): | ||
| self.write_source("current") | ||
| self.commit() | ||
|
|
||
| with self.assertRaises(subprocess.CalledProcessError): | ||
| discover_sources(self.MISSING_BEFORE, self.MISSING_AFTER, False) | ||
|
|
||
|
|
||
| class ConvertPdfHelpersTest(unittest.TestCase): | ||
| def test_rewrite_artifact_links_normalizes_absolute_and_relative_paths(self): | ||
| markdown = ( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.