From a1b763974e4f329f6170c4820cec33aa23b1dbe0 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Sun, 30 Aug 2026 13:01:34 -0700 Subject: [PATCH] Handle unarchived static snapshot details --- archivebox/core/models.py | 1 + archivebox/templates/core/snapshot.html | 2 ++ archivebox/tests/test_cli_list.py | 20 ++++++++++++++++++++ archivebox/tests/test_crawl_runner.py | 2 -- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/archivebox/core/models.py b/archivebox/core/models.py index 9d9af6fa..a3b97467 100644 --- a/archivebox/core/models.py +++ b/archivebox/core/models.py @@ -3669,6 +3669,7 @@ class Snapshot(ModelWithDeleteAfter, ModelWithOutputDir, ModelWithConfig, ModelW from django.template.loader import render_to_string output_dir = Path(out_dir) if out_dir is not None else self.output_dir + output_dir.mkdir(parents=True, exist_ok=True) context = self.get_html_details_context(static_export_dir=output_dir) rendered_html = render_to_string("core/snapshot.html", context) atomic_write(str(output_dir / CONSTANTS.HTML_INDEX_FILENAME), rendered_html) diff --git a/archivebox/templates/core/snapshot.html b/archivebox/templates/core/snapshot.html index 8e88ac20..d48344a2 100644 --- a/archivebox/templates/core/snapshot.html +++ b/archivebox/templates/core/snapshot.html @@ -1515,7 +1515,9 @@
🌐 Open original URL + {% if not STATIC_EXPORT %} ✏️ Edit in admin + {% endif %}
diff --git a/archivebox/tests/test_cli_list.py b/archivebox/tests/test_cli_list.py index fdf261ae..d5ecc440 100644 --- a/archivebox/tests/test_cli_list.py +++ b/archivebox/tests/test_cli_list.py @@ -20,6 +20,26 @@ from archivebox.tests.test_orm_helpers import use_archivebox_db pytestmark = pytest.mark.django_db(transaction=True) +def test_static_export_creates_detail_page_for_unarchived_snapshot(snapshot): + from archivebox.config import CONSTANTS + + snapshot_dir = Path(snapshot.output_dir) + assert snapshot_dir.is_dir() + assert not any(snapshot_dir.iterdir()) + snapshot_dir.rmdir() + assert not snapshot_dir.exists() + + html = Snapshot.objects.filter(pk=snapshot.pk).to_html(with_headers=True) + + static_path = snapshot_dir.relative_to(CONSTANTS.DATA_DIR).as_posix() + detail_path = snapshot_dir / "index.html" + assert f"./{static_path}/index.html" in html + assert detail_path.exists() + detail_html = detail_path.read_text() + assert f"/snapshot/{snapshot.id.hex}" not in detail_html + assert "/admin/" not in detail_html + + def test_static_exports_use_filesystem_paths_not_live_django_routes(snapshot): from archivebox.config import CONSTANTS from archivebox.core.models import ArchiveResult diff --git a/archivebox/tests/test_crawl_runner.py b/archivebox/tests/test_crawl_runner.py index 42f04f50..fd3d99a8 100644 --- a/archivebox/tests/test_crawl_runner.py +++ b/archivebox/tests/test_crawl_runner.py @@ -15,8 +15,6 @@ pytestmark = pytest.mark.django_db def test_crawl_runner_creates_progress_reporter_without_a_tty(crawl): from archivebox.services.runner import CrawlRunner - assert not sys.stdout.isatty() - assert not sys.stderr.isatty() runner = CrawlRunner(crawl) runner.load_run_state()