From cd7e7cd13243985273e7058ea26af712d68cfe72 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 2 Jun 2026 20:11:37 -0700 Subject: [PATCH] test: make extract cli setup deterministic --- archivebox/tests/test_cli_extract.py | 47 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/archivebox/tests/test_cli_extract.py b/archivebox/tests/test_cli_extract.py index 9d8c0104..fea68f7c 100644 --- a/archivebox/tests/test_cli_extract.py +++ b/archivebox/tests/test_cli_extract.py @@ -1,15 +1,10 @@ #!/usr/bin/env python3 -""" -Tests for archivebox extract command. -Verify extract re-runs extractors on existing snapshots. -""" - -import json +"""Tests for archivebox extract command.""" import pytest -from archivebox.core.models import Snapshot -from archivebox.tests.conftest import run_archivebox_cmd, cli_env +from archivebox.core.models import ArchiveResult, Snapshot +from archivebox.tests.conftest import cli_env, parse_jsonl_output, run_archivebox_cmd from archivebox.tests.test_orm_helpers import use_archivebox_db @@ -17,50 +12,56 @@ pytestmark = pytest.mark.django_db(transaction=True) def _create_snapshot(data_dir, env, url="https://example.com"): - record = json.dumps({"type": "Snapshot", "url": url}) - run_archivebox_cmd( - ["snapshot", "create"], + result = run_archivebox_cmd( + ["snapshot", "create", url], cwd=data_dir, - stdin=f"{record}\n", env=env, check=True, ) + snapshot = next(record for record in parse_jsonl_output(result.stdout) if record.get("type") == "Snapshot") + return snapshot def test_extract_runs_on_existing_snapshots(initialized_archive): - """Test that extract command runs on existing snapshots.""" + """Extract queues a requested plugin for an existing snapshot.""" env = cli_env(disable_extractors=True) - _create_snapshot(initialized_archive, env) + snapshot = _create_snapshot(initialized_archive, env) + snapshot_id = snapshot["id"] - # Run extract result = run_archivebox_cmd( - ["extract"], + ["extract", "--plugin=title", "--no-wait", snapshot_id], cwd=initialized_archive, env=env, timeout=30, ) - # Should complete - assert result.returncode in [0, 1] + assert result.returncode == 0, result.stderr or result.stdout + + with use_archivebox_db(initialized_archive): + archiveresult = ArchiveResult.objects.get(snapshot_id=snapshot_id, plugin="title") + extracted_snapshot = Snapshot.objects.get(id=snapshot_id) + + assert archiveresult.status == ArchiveResult.StatusChoices.QUEUED + assert extracted_snapshot.retry_at is not None def test_extract_preserves_snapshot_count(initialized_archive): - """Test that extract doesn't change snapshot count.""" + """Extract queues work without creating duplicate snapshots.""" env = cli_env(disable_extractors=True) - _create_snapshot(initialized_archive, env) + snapshot = _create_snapshot(initialized_archive, env) with use_archivebox_db(initialized_archive): count_before = Snapshot.objects.count() - # Run extract - run_archivebox_cmd( - ["extract", "--overwrite"], + result = run_archivebox_cmd( + ["extract", "--plugin=title", "--no-wait", snapshot["id"]], cwd=initialized_archive, env=env, timeout=30, ) + assert result.returncode == 0, result.stderr or result.stdout with use_archivebox_db(initialized_archive): count_after = Snapshot.objects.count()