Example Article
This is test content for mercury parser.
""" Integration tests for mercury plugin Tests verify: 1. Hook script exists 2. Dependencies installed via validation hooks 3. Verify deps with abx-pkg 4. Mercury extraction works on https://example.com 5. JSONL output is correct 6. Filesystem output contains extracted content 7. Config options work """ import json import subprocess import sys import tempfile from pathlib import Path import pytest PLUGIN_DIR = Path(__file__).parent.parent PLUGINS_ROOT = PLUGIN_DIR.parent MERCURY_HOOK = PLUGIN_DIR / 'on_Snapshot__53_mercury.py' MERCURY_INSTALL_HOOK = PLUGIN_DIR / 'on_Crawl__00_install_mercury.py' TEST_URL = 'https://example.com' def test_hook_script_exists(): """Verify on_Snapshot hook exists.""" assert MERCURY_HOOK.exists(), f"Hook not found: {MERCURY_HOOK}" def test_mercury_install_hook(): """Test mercury install hook checks for postlight-parser.""" # Run mercury install hook result = subprocess.run( [sys.executable, str(MERCURY_INSTALL_HOOK)], capture_output=True, text=True, timeout=30 ) # Hook exits 0 if binary found, 1 if not found (with Dependency record) if result.returncode == 0: # Binary found - verify Binary JSONL output found_binary = False for line in result.stdout.strip().split('\n'): if line.strip(): try: record = json.loads(line) if record.get('type') == 'Binary': assert record['name'] == 'postlight-parser' assert record['abspath'] found_binary = True break except json.JSONDecodeError: pass assert found_binary, "Should output Binary record when binary found" else: # Binary not found - verify Dependency JSONL output found_dependency = False for line in result.stdout.strip().split('\n'): if line.strip(): try: record = json.loads(line) if record.get('type') == 'Dependency': assert record['bin_name'] == 'postlight-parser' assert 'npm' in record['bin_providers'] found_dependency = True break except json.JSONDecodeError: pass assert found_dependency, "Should output Dependency record when binary not found" def test_verify_deps_with_abx_pkg(): """Verify postlight-parser is available via abx-pkg.""" from abx_pkg import Binary, NpmProvider, EnvProvider, BinProviderOverrides # Verify postlight-parser is available mercury_binary = Binary( name='postlight-parser', binproviders=[NpmProvider(), EnvProvider()], overrides={'npm': {'packages': ['@postlight/parser']}} ) mercury_loaded = mercury_binary.load() # If validate hook found it (exit 0), this should succeed # If validate hook didn't find it (exit 1), this may fail unless binprovider installed it if mercury_loaded and mercury_loaded.abspath: assert True, "postlight-parser is available" else: pytest.skip("postlight-parser not available - Dependency record should have been emitted") def test_extracts_with_mercury_parser(): """Test full workflow: extract with postlight-parser from real HTML via hook.""" # Prerequisites checked by earlier test with tempfile.TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) # Create HTML source that mercury can parse (tmpdir / 'singlefile').mkdir() (tmpdir / 'singlefile' / 'singlefile.html').write_text( '
This is test content for mercury parser.