test_cli_install.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env python3
  2. """
  3. Comprehensive tests for archivebox install command.
  4. Verify install detects and records binary dependencies in DB.
  5. """
  6. import os
  7. import subprocess
  8. import sqlite3
  9. from .fixtures import *
  10. def test_install_runs_successfully(tmp_path, process):
  11. """Test that install command runs without error."""
  12. os.chdir(tmp_path)
  13. result = subprocess.run(
  14. ['archivebox', 'install', '--dry-run'],
  15. capture_output=True,
  16. text=True,
  17. timeout=60,
  18. )
  19. # Dry run should complete quickly
  20. assert result.returncode in [0, 1] # May return 1 if binaries missing
  21. def test_install_creates_binary_records_in_db(tmp_path, process):
  22. """Test that install creates Binary records in database."""
  23. os.chdir(tmp_path)
  24. subprocess.run(
  25. ['archivebox', 'install', '--dry-run'],
  26. capture_output=True,
  27. timeout=60,
  28. )
  29. # Check that binary records were created
  30. conn = sqlite3.connect("index.sqlite3")
  31. c = conn.cursor()
  32. # Check machine_binary table exists
  33. tables = c.execute(
  34. "SELECT name FROM sqlite_master WHERE type='table' AND name='machine_binary'"
  35. ).fetchall()
  36. conn.close()
  37. assert len(tables) == 1
  38. def test_install_dry_run_does_not_install(tmp_path, process):
  39. """Test that --dry-run doesn't actually install anything."""
  40. os.chdir(tmp_path)
  41. result = subprocess.run(
  42. ['archivebox', 'install', '--dry-run'],
  43. capture_output=True,
  44. text=True,
  45. timeout=60,
  46. )
  47. # Should complete without actually installing
  48. assert 'dry' in result.stdout.lower() or result.returncode in [0, 1]
  49. def test_install_detects_system_binaries(tmp_path, process):
  50. """Test that install detects existing system binaries."""
  51. os.chdir(tmp_path)
  52. result = subprocess.run(
  53. ['archivebox', 'install', '--dry-run'],
  54. capture_output=True,
  55. text=True,
  56. timeout=60,
  57. )
  58. # Should detect at least some common binaries (python, curl, etc)
  59. assert result.returncode in [0, 1]
  60. def test_install_shows_binary_status(tmp_path, process):
  61. """Test that install shows status of binaries."""
  62. os.chdir(tmp_path)
  63. result = subprocess.run(
  64. ['archivebox', 'install', '--dry-run'],
  65. capture_output=True,
  66. text=True,
  67. timeout=60,
  68. )
  69. output = result.stdout + result.stderr
  70. # Should show some binary information
  71. assert len(output) > 50
  72. def test_install_updates_binary_table(tmp_path, process, disable_extractors_dict):
  73. """Test that install command runs successfully.
  74. Binary records are created lazily when binaries are first used, not during install.
  75. """
  76. os.chdir(tmp_path)
  77. # Run install - it should complete without errors or timeout (which is expected)
  78. # The install command starts the orchestrator which runs continuously
  79. try:
  80. result = subprocess.run(
  81. ['archivebox', 'install'],
  82. capture_output=True,
  83. timeout=30,
  84. env=disable_extractors_dict,
  85. )
  86. # If it completes, should be successful
  87. assert result.returncode == 0
  88. except subprocess.TimeoutExpired:
  89. # Timeout is expected since orchestrator runs continuously
  90. pass