Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Harness OS publication reads a job's newest evidence when it was run again (#1572)

Bubu-Dudu-52hze0de53688276
diff --git a/os/tests/test_publish.py b/os/tests/test_publish.py
new file mode 100644
index 000000000..5ba0d086c
--- /dev/null
+++ b/os/tests/test_publish.py
@@ -0,0 +1,47 @@
+import importlib.util
+import io
+import json
+from pathlib import Path
+import tempfile
+import unittest
+from unittest.mock import patch
+import zipfile
+
+spec = importlib.util.spec_from_file_location('publish', Path(__file__).resolve().parents[1] / 'tools/publish.py')
+publish = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(publish)
+
+
+def archive(receipt):
+ data = io.BytesIO()
+ with zipfile.ZipFile(data, 'w') as handle:
+ handle.writestr('receipt.json', json.dumps(receipt))
+ return data.getvalue()
+
+
+class Evidence(unittest.TestCase):
+ def test_a_job_run_again_is_read_from_its_newest_artifact(self):
+ listing = {'artifacts': [
+ {'id': 1, 'name': 'harness-os-hardware', 'created_at': '2026-10-22T09:02:56Z', 'expired': False},
+ {'id': 2, 'name': 'harness-os-hardware', 'created_at': '2026-10-22T09:12:34Z', 'expired': False},
+ {'id': 3, 'name': 'harness-os-hardware-x', 'created_at': '2026-10-22T09:20:00Z', 'expired': False},
+ ]}
+ zips = {1: archive({'status': 'failed'}), 2: archive({'status': 'passed'})}
+ asked = []
+ def check_output(command, **_):
+ asked.append(command)
+ return zips[int(command[2].split('/')[-2])]
+ with tempfile.TemporaryDirectory() as folder, \
+ patch.object(publish, 'gh', return_value=json.dumps(listing)), \
+ patch.object(publish.subprocess, 'check_output', side_effect=check_output):
+ publish.download_latest('o/r', 7, 'harness-os-hardware', Path(folder) / 'hardware')
+ self.assertEqual(json.loads((Path(folder) / 'hardware/receipt.json').read_text()), {'status': 'passed'})
+ self.assertEqual(asked, [['gh', 'api', 'repos/o/r/actions/artifacts/2/zip']])
+
+ def test_no_artifact_is_refused(self):
+ with patch.object(publish, 'gh', return_value='{"artifacts": []}'), self.assertRaisesRegex(ValueError, 'no harness-os-hardware'):
+ publish.download_latest('o/r', 7, 'harness-os-hardware', Path('/nonexistent'))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/os/tools/publish.py b/os/tools/publish.py
index 7ceae369f..21383443d 100644
--- a/os/tools/publish.py
+++ b/os/tools/publish.py
@@ -3,6 +3,7 @@
import argparse
from concurrent.futures import ThreadPoolExecutor
import hashlib
+import io
import json
from pathlib import Path
import re
@@ -43,6 +44,21 @@ def gh(*args):
return subprocess.check_output(['gh', *map(str, args)], text=True, timeout=120).strip()
+def download_latest(repo, run, name, folder):
+ """The newest artifact named [name] in [run], into [folder]. A job run again keeps the first
+ attempt's artifact beside its own under the same name, and `gh run download --name` took the
+ first: 0.1.10's publication read the failed attempt's hardware receipt after a passing rerun."""
+ listing = json.loads(gh('api', f'repos/{repo}/actions/runs/{run}/artifacts?per_page=100&name={name}'))
+ found = [a for a in listing.get('artifacts', []) if a.get('name') == name and not a.get('expired')]
+ if not found:
+ raise ValueError(f'The image build has no {name} artifact.')
+ newest = max(found, key=lambda artifact: artifact['created_at'])
+ data = subprocess.check_output(['gh', 'api', f'repos/{repo}/actions/artifacts/{newest["id"]}/zip'], timeout=600)
+ folder.mkdir(parents=True, exist_ok=True)
+ with zipfile.ZipFile(io.BytesIO(data)) as archive:
+ archive.extractall(folder)
+
+
def read(path):
return json.loads(path.read_text())
@@ -264,14 +280,14 @@ def main():
if 'broadcom-offline' in manifest.get('capabilities', []):
if not any(j['name'] == 'hardware' and j['conclusion'] == 'success' for j in jobs['jobs']):
raise ValueError('The image build has no successful hardware installation job.')
- gh('run', 'download', args.image, '--repo', args.repo, '--name', 'harness-os-hardware', '--dir', root / 'hardware')
+ download_latest(args.repo, args.image, 'harness-os-hardware', root / 'hardware')
hardware = read(root / 'hardware/receipt.json')
validate_hardware(manifest, hardware)
nvidia = None
if 'nvidia-offline' in manifest.get('capabilities', []):
if not any(j['name'] == 'nvidia' and j['conclusion'] == 'success' for j in jobs['jobs']):
raise ValueError('The image build has no successful NVIDIA installation job.')
- gh('run', 'download', args.image, '--repo', args.repo, '--name', 'harness-os-nvidia-install', '--dir', root / 'nvidia')
+ download_latest(args.repo, args.image, 'harness-os-nvidia-install', root / 'nvidia')
nvidia = read(root / 'nvidia/receipt.json')
validate_nvidia(manifest, nvidia)
examples = {}