File size: 2,574 Bytes
bbc23ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80174e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Exercise the deployment overlay with real files, including clone timestamp collisions."""
import os
from pathlib import Path
import shlex
import shutil
import subprocess

import pytest


def test_deployment_copies_same_size_changes_with_identical_timestamps(tmp_path):
    rsync = shutil.which('rsync')
    if not rsync:
        pytest.skip('rsync is required by the deployment runner')
    source, space = tmp_path/'source', tmp_path/'space'
    source.mkdir(); space.mkdir()
    new, old = source/'api.py', space/'api.py'
    new.write_text('version="1.7.1"\n'); old.write_text('version="1.7.0"\n')
    for file in (new, old):
        os.utime(file, (1700000000, 1700000000))
    assert new.stat().st_size == old.stat().st_size
    # Space-only files must survive the overlay.
    retained = space/'space-only.txt'
    retained.write_text('keep')
    workflow = Path(__file__).parents[1]/'.github/workflows/deploy-huggingface.yml'
    command = next(line.strip() for line in workflow.read_text().splitlines()
                   if line.strip().startswith('rsync '))
    arguments = shlex.split(command)
    subprocess.run([rsync, *arguments[1:-2], str(source)+'/', str(space)+'/'], check=True)
    assert old.read_bytes() == new.read_bytes()
    assert retained.read_text() == 'keep'


def test_deployment_removes_retired_contact_files_only(tmp_path):
    root = Path(__file__).parents[1]
    manifest = root/'deploy/huggingface/removed-files.txt'
    retired = [line for line in manifest.read_text().splitlines()
               if line and not line.startswith('#')]
    for name in retired:
        assert not (root/name).exists()
        path = tmp_path/name
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text('old deployment source')
    retained = tmp_path/'baseball_batting/space-only.txt'
    retained.write_text('keep')
    shared = tmp_path/'baseball_batting/tracking_vision.py'
    shared.write_text('shared bat/ball inference')
    workflow = (root/'.github/workflows/deploy-huggingface.yml').read_text()
    start = workflow.index('          while IFS= read -r path')
    end = workflow.index('done < deploy/huggingface/removed-files.txt', start)
    command = workflow[start:end] + 'done < deploy/huggingface/removed-files.txt'
    subprocess.run(['bash', '-c', command], cwd=root,
                   env={**os.environ, 'workspace': str(tmp_path)}, check=True)
    assert all(not (tmp_path/name).exists() for name in retired)
    assert retained.read_text() == 'keep'
    assert shared.read_text() == 'shared bat/ball inference'