Update hook priority references

This commit is contained in:
Nick Sweeting 2026-08-15 21:27:59 -07:00
parent 7d7e21f5d9
commit cc444b9920
8 changed files with 26 additions and 26 deletions

View File

@ -9,7 +9,7 @@ from django.utils import timezone
from archivebox.core.models import ArchiveResult, Snapshot
from archivebox.crawls.models import Crawl
from archivebox.tests.conftest import run_archivebox_cmd
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook, _snapshot_hook_name
from archivebox.tests.test_orm_helpers import use_archivebox_db
from archivebox.workers.models import RETRY_AT_MAX
@ -30,16 +30,6 @@ from .conftest import (
pytestmark = pytest.mark.django_db(transaction=True)
def _snapshot_hook_name(plugin_name: str) -> str:
from abx_dl.models import discover_plugins
plugin = discover_plugins().get(plugin_name)
assert plugin is not None, f"missing test plugin {plugin_name}"
hooks = plugin.filter_hooks("Snapshot")
assert hooks, f"missing Snapshot hooks for {plugin_name}"
return hooks[0].name
def _snapshot_state(cwd: Path, url: str) -> dict[str, object]:
with use_archivebox_db(cwd):
snapshot = Snapshot.objects.select_related("crawl", "crawl__created_by").get(url=url)
@ -155,7 +145,7 @@ def test_snapshot_pause_resume_api_cascades_active_archiveresults_and_preserves_
_failed_process, failed_result = _run_shipped_snapshot_hook(
snapshot,
plugin="git",
hook_name="on_Snapshot__05_git.finite.bg.py",
hook_name=_snapshot_hook_name("git"),
event_hook_name=_snapshot_hook_name("git"),
lib_dir=lib_dir,
expected_exit_codes=(1,),
@ -172,7 +162,7 @@ def test_snapshot_pause_resume_api_cascades_active_archiveresults_and_preserves_
)
Crawl.objects.filter(pk=snapshot.crawl_id).update(status=Crawl.StatusChoices.STARTED, retry_at=now)
snapshot.refresh_from_db()
[started_result] = snapshot.create_pending_archiveresults(hooks=[("wget", "on_Snapshot__06_wget.finite.bg")])
[started_result] = snapshot.create_pending_archiveresults(hooks=[("wget", _snapshot_hook_name("wget"))])
errors = []
def run_snapshot():
@ -317,7 +307,7 @@ def test_targeted_extract_retries_one_failed_archiveresult_through_normal_snapsh
_wget_process, wget_result = _run_shipped_snapshot_hook(
snapshot,
plugin="wget",
hook_name="on_Snapshot__06_wget.finite.bg.py",
hook_name=_snapshot_hook_name("wget"),
event_hook_name=_snapshot_hook_name("wget"),
lib_dir=lib_dir,
env={"WGET_WARC_ENABLED": "False"},

View File

@ -12,7 +12,7 @@ from django.utils import timezone
from archivebox.core.models import ArchiveResult, Snapshot
from archivebox.crawls.models import Crawl
from archivebox.tests.test_orm_helpers import use_archivebox_db
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook, _snapshot_hook_name
from archivebox.workers.models import RETRY_AT_MAX
from .conftest import (
@ -212,7 +212,7 @@ def test_crawl_pause_resume_api_cascades_archiveresults_and_leaves_finished_snap
Crawl.objects.filter(pk=crawl_id).update(status=Crawl.StatusChoices.STARTED, retry_at=now)
Snapshot.objects.filter(pk=active_snapshot.pk).update(status=Snapshot.StatusChoices.QUEUED, retry_at=now)
active_snapshot.refresh_from_db()
[active_started] = active_snapshot.create_pending_archiveresults(hooks=[("wget", "on_Snapshot__06_wget.finite.bg")])
[active_started] = active_snapshot.create_pending_archiveresults(hooks=[("wget", _snapshot_hook_name("wget"))])
errors = []
def run_snapshot():

View File

@ -17,6 +17,16 @@ from archivebox.tests.conftest import install_real_binary
pytestmark = pytest.mark.django_db(transaction=True)
def _snapshot_hook_name(plugin_name: str) -> str:
from abx_dl.models import discover_plugins
plugin = discover_plugins().get(plugin_name)
assert plugin is not None, f"missing test plugin {plugin_name}"
hooks = plugin.filter_hooks("Snapshot")
assert hooks, f"missing Snapshot hooks for {plugin_name}"
return hooks[0].name
def _cleanup_machine_process_rows() -> None:
from archivebox.machine.models import Process

View File

@ -663,7 +663,7 @@ def test_crawl_runner_resolves_persona_and_crawl_config_for_each_live_snapshot()
favicon_processes = [
process
for process in Process.objects.filter(process_type=Process.TypeChoices.HOOK).order_by("started_at")
if process.cmd and "on_Snapshot__11_favicon.finite.bg.py" in str(process.cmd[0])
if process.cmd and "on_Snapshot__37_favicon.finite.bg.py" in str(process.cmd[0])
]
providers = [process.env.get("FAVICON_PROVIDER") for process in favicon_processes]
@ -810,7 +810,7 @@ def test_abx_process_service_background_process_finishes_after_process_exit(tmp_
snap_dir = tmp_path / "snapshot"
plugin_output_dir = snap_dir / "wget"
plugin_output_dir.mkdir(parents=True)
hook_path = Path(str(files("abx_plugins.plugins.wget").joinpath("on_Snapshot__06_wget.finite.bg.py")))
hook_path = Path(str(files("abx_plugins.plugins.wget").joinpath("on_Snapshot__35_wget.finite.bg.py")))
wget_config = Path(str(files("abx_plugins.plugins.wget").joinpath("config.json")))
install_real_binary("wget", binproviders="env,apt,brew")
hook_env = resolve_abxpkg_binary_env(hermetic_lib_dir, deps_from=wget_config)

View File

@ -71,7 +71,7 @@ class TestBackgroundHookDetection:
assert all(".bg." in hook.name for hook in background_hooks)
assert all(".bg." not in hook.name for hook in foreground_hooks)
assert any(hook.name == "on_Snapshot__01_chrome_tab.daemon.bg.js" for hook in background_hooks)
assert any(hook.name == "on_Snapshot__06_wget.finite.bg.py" for hook in background_hooks)
assert any(hook.name == "on_Snapshot__35_wget.finite.bg.py" for hook in background_hooks)
assert any(hook.name == "on_Snapshot__93_hashes.py" for hook in foreground_hooks)
@ -229,7 +229,7 @@ class TestHookDiscovery:
hook_names = [h.name for h in hooks]
assert "on_Snapshot__01_chrome_tab.daemon.bg.js" in hook_names
assert "on_Snapshot__21_consolelog.daemon.bg.js" in hook_names
assert "on_Snapshot__06_wget.finite.bg.py" in hook_names
assert "on_Snapshot__35_wget.finite.bg.py" in hook_names
assert all(hook.is_file() for hook in hooks)
def test_discover_hooks_sorted_by_name(self):
@ -292,7 +292,7 @@ class TestHookDiscovery:
"snapshot": [hook.name for hook in discover_hooks("SnapshotEvent", filter_disabled=False)],
}
assert "on_CrawlSetup__90_chrome_launch.daemon.bg.js" in hook_names["crawl_setup"]
assert "on_Snapshot__06_wget.finite.bg.py" in hook_names["snapshot"]
assert "on_Snapshot__35_wget.finite.bg.py" in hook_names["snapshot"]
def test_discover_hooks_returns_empty_for_non_hook_lifecycle_events(self):
"""Lifecycle events without a hook family should return no hooks."""

View File

@ -13,7 +13,7 @@ from django.test import RequestFactory
from django.urls import reverse
from archivebox.tests.conftest import ADMIN_TEST_HOST
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook, _snapshot_hook_name
pytestmark = pytest.mark.django_db(transaction=True)
REPO_ROOT = Path(__file__).resolve().parents[2]
@ -85,7 +85,7 @@ def running_wget_projection(snapshot, blocking_http_server):
url=blocking_http_server.url,
)
snapshot.refresh_from_db()
[result] = snapshot.create_pending_archiveresults(hooks=[("wget", "on_Snapshot__06_wget.finite.bg")])
[result] = snapshot.create_pending_archiveresults(hooks=[("wget", _snapshot_hook_name("wget"))])
errors = []
def run_snapshot():

View File

@ -136,7 +136,7 @@ def test_plugin_detail_view_renders_shipped_plugin_config_in_dedicated_sections(
assert hooks_section["name"] == "Hooks"
assert hooks_section["fields"] == {}
assert "on_Snapshot__06_wget.finite.bg.py" in hooks_section["description"]
assert "on_Snapshot__35_wget.finite.bg.py" in hooks_section["description"]
assert metadata_section["name"] == "Plugin Metadata"
assert metadata_section["fields"] == {}

View File

@ -14,7 +14,7 @@ from django.utils import timezone
from archivebox.tests.conftest import ADMIN_TEST_HOST
from archivebox.tests.conftest import cli_env, resolve_abxpkg_binary_env, run_archivebox_cmd
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook
from archivebox.tests.test_archive_result_service import _run_shipped_snapshot_hook, _snapshot_hook_name
pytestmark = pytest.mark.django_db(transaction=True)
@ -220,7 +220,7 @@ class TestLiveProgressView:
url=blocking_http_server.url,
)
snapshot.refresh_from_db()
[result] = snapshot.create_pending_archiveresults(hooks=[("wget", "on_Snapshot__06_wget.finite.bg")])
[result] = snapshot.create_pending_archiveresults(hooks=[("wget", _snapshot_hook_name("wget"))])
errors = []
def run_snapshot():