test_deploy_checkout.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Check upload candidates without copying secrets or developer machine artifacts."""
  2. import os
  3. from pathlib import Path
  4. import shutil
  5. import subprocess
  6. import sys
  7. import tempfile
  8. import unittest
  9. ROOT = Path(__file__).resolve().parents[2]
  10. class CheckoutTests(unittest.TestCase):
  11. def test_git_upload_only_checkout_has_deployment_inputs(self):
  12. result = subprocess.run(['git', '-c', f'core.excludesFile={os.devnull}', 'ls-files', '-z',
  13. '--cached', '--others', '--exclude-standard'], cwd=ROOT,
  14. capture_output=True, check=True)
  15. names = {os.fsdecode(name) for name in result.stdout.split(b'\0') if name}
  16. required = {'deploy.sh', '.python-version', 'pyproject.toml', 'uv.lock',
  17. 'scripts/deploy.py', 'scripts/deploy_models.py', 'scripts/check-runtime.py',
  18. 'src/step1_knowledge_prepare/summarize.py', 'src/step2_knowledge_ingest/__main__.py',
  19. 'src/step4_api/__main__.py', 'reference/qa.json'}
  20. self.assertTrue(required <= names, required - names)
  21. with tempfile.TemporaryDirectory() as temporary:
  22. root = Path(temporary) / 'uploaded checkout'
  23. root.mkdir()
  24. for name in names:
  25. # Never read or copy real dotenv even if a user explicitly tracked it.
  26. if Path(name).name.startswith('.env'):
  27. continue
  28. source = ROOT / name
  29. if not source.is_file(): # An existing staged deletion is not an upload.
  30. continue
  31. target = root / name
  32. target.parent.mkdir(parents=True, exist_ok=True)
  33. shutil.copyfile(source, target)
  34. for name in ('models', 'knowledge/prepared', '.venv', 'output', 'AGENTS.md',
  35. 'feature_list.json', 'scripts/check-harness.ps1'):
  36. self.assertFalse((root / name).exists(), name)
  37. (root / '.env').write_text('# synthetic server configuration\n')
  38. # -S proves the controller/help can load without this machine's packages.
  39. check = subprocess.run([sys.executable, '-S', str(root / 'scripts/deploy.py'), '--help'],
  40. cwd=temporary, capture_output=True, text=True, timeout=15)
  41. self.assertEqual(check.returncode, 0, check.stderr)
  42. self.assertIn('update-knowledge', check.stdout)
  43. if __name__ == '__main__':
  44. unittest.main()