|
1 | 1 | """CPU-only guards for receipt ancestry and publication boundaries.""" |
2 | 2 | from pathlib import Path |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import sys |
3 | 6 |
|
4 | 7 | import yaml |
5 | 8 |
|
@@ -35,3 +38,28 @@ def test_testpypi_requires_successful_build_without_inheriting_receipt_skip(): |
35 | 38 | # An explicit status function avoids GitHub's implicit success() across the |
36 | 39 | # dependency chain, where the tag-only receipt job is skipped on dispatch. |
37 | 40 | assert job['if'] == "${{ !cancelled() && needs.build.result == 'success' }}" |
| 41 | + |
| 42 | + |
| 43 | +def test_docker_header_generation_creates_output_directory(tmp_path): |
| 44 | + """Run the recipe's shell prelude with a writer that requires its parent.""" |
| 45 | + dockerfile = (ROOT / 'install/docker/Dockerfile').read_text().replace('\\\n', '') |
| 46 | + run = next(line.removeprefix('RUN ') for line in dockerfile.splitlines() |
| 47 | + if line.startswith('RUN ') and 'grid-generate ' in line) |
| 48 | + # The following Python import/version print is independent of directory setup. |
| 49 | + command = run.split('&& python -c', 1)[0] |
| 50 | + command = command.replace('/opt/grid', str(tmp_path / 'grid')) |
| 51 | + executable = tmp_path / 'grid-generate' |
| 52 | + executable.write_text( |
| 53 | + f'#!{sys.executable}\n' |
| 54 | + 'import pathlib, sys\n' |
| 55 | + 'pathlib.Path(sys.argv[sys.argv.index("-o") + 1]).write_text("header\\n")\n' |
| 56 | + ) |
| 57 | + executable.chmod(0o755) |
| 58 | + env = dict(os.environ, PATH=str(tmp_path) + os.pathsep + os.environ['PATH']) |
| 59 | + # The original recipe omitted mkdir; the same writer must fail in that case. |
| 60 | + old_command = command[command.index('grid-generate '):] |
| 61 | + result = subprocess.run(['sh', '-ec', old_command], env=env, capture_output=True, |
| 62 | + text=True) |
| 63 | + assert result.returncode != 0 and 'FileNotFoundError' in result.stderr |
| 64 | + subprocess.run(['sh', '-ec', command], env=env, check=True, capture_output=True) |
| 65 | + assert (tmp_path / 'grid/iiwa14/grid.cuh').read_text() == 'header\n' |
0 commit comments