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.

ci(os): take hn checks and slow downloads off the Harness OS critical path (#1348)

autonomousdevops2e1cfd50d979
diff --git a/.github/actions/vm-tools/action.yml b/.github/actions/vm-tools/action.yml
new file mode 100644
index 000000000..c220fed68
--- /dev/null
+++ b/.github/actions/vm-tools/action.yml
@@ -0,0 +1,39 @@
+name: Install VM test tools
+description: Install the QEMU, firmware and OCR packages the OS VM tests drive, reusing downloaded packages
+inputs:
+ packages:
+ description: Packages beyond the shared VM set
+ required: false
+ default: ''
+runs:
+ using: composite
+ steps:
+ # An Ubuntu mirror once served these 55 MB at 150 kB/s (6 minutes, Actions
+ # 38690409147) while another job fetched them in seconds. Keep the downloaded
+ # packages in the Actions cache, per runner image, so apt only fetches changes.
+ - id: key
+ shell: bash
+ env:
+ PACKAGES: ${{ inputs.packages }}
+ run: |
+ prefix="vm-apt-$ImageOS-"
+ echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
+ echo "key=$prefix$ImageVersion-$(printf '%s' "$PACKAGES" | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT"
+ - uses: actions/cache@v4
+ with:
+ path: ~/.cache/vm-apt
+ key: ${{ steps.key.outputs.key }}
+ restore-keys: ${{ steps.key.outputs.prefix }}
+ - shell: bash
+ env:
+ PACKAGES: ${{ inputs.packages }}
+ run: |
+ mkdir -p ~/.cache/vm-apt/partial
+ sudo apt-get update -qq
+ # shellcheck disable=SC2086 # PACKAGES is a space-separated list.
+ sudo apt-get install -y --no-install-recommends -o APT::Sandbox::User=root \
+ -o Dir::Cache::Archives="$HOME/.cache/vm-apt" \
+ qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr $PACKAGES
+ sudo rm -f ~/.cache/vm-apt/lock
+ sudo chown -R "$(id -u):$(id -g)" ~/.cache/vm-apt
+ if test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fi
diff --git a/.github/workflows/os.yml b/.github/workflows/os.yml
index 13d4191fd..77ce83663 100644
--- a/.github/workflows/os.yml
+++ b/.github/workflows/os.yml
@@ -203,16 +203,7 @@ jobs:
- name: Prepare native build tools
run: |
sudo apt-get update -qq
- sudo apt-get install -y musl-tools tmux zsh cryptsetup-bin btrfs-progs
- # Ubuntu's global zshrc runs compinit, which stops at "insecure directories ... continue [y]
- # or abort compinit [n]?" for the runner image's group-writable completion folders; a zsh
- # login shell under test then waits there (as cli-e2e.yml found). Fixed as zsh says.
- insecure=$(zsh -fc 'autoload -U compaudit && compaudit' 2>/dev/null | grep '^/' | sort -u || true)
- if [ -n "$insecure" ]; then
- echo "$insecure" | xargs sudo chown root:root
- echo "$insecure" | xargs sudo chmod g-w,o-w
- fi
- zsh -fc 'autoload -U compaudit && compaudit'
+ sudo apt-get install -y musl-tools cryptsetup-bin btrfs-progs
- name: Check encrypted cleanup with real device readers and stalled udev
run: |
# Fail early on real cleanup semantics, before compressing an ISO.
@@ -221,14 +212,6 @@ jobs:
- name: Build Harness from the exact OS source
run: |
make -C os runtime
- - name: Validate hn session behavior and native terminal lifecycle
- run: |
- npm --prefix cli run typecheck
- cd cli
- timeout 3m npx vitest run src/lib/engineInstall.spec.ts src/lib/engineLaunch.spec.ts --maxWorkers=2
- cd ..
- timeout 8m cargo test --manifest-path tui/Cargo.toml --locked --release --target x86_64-unknown-linux-musl
- python3 scripts/validate-tui-native.py tui/target/x86_64-unknown-linux-musl/release/harness-tui
- name: Build the pinned OS compositor
run: bash os/tools/build-compositor-container.sh os/work/compositor
- name: Build offline BIOS and UEFI image
@@ -238,6 +221,7 @@ jobs:
-e SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)" \
-e HARNESS_OS_SOURCE_SHA="$(git rev-parse HEAD)" \
-e HARNESS_OS_RUNTIME_DIR=/src/os/work/runtime \
+ -e HARNESS_OS_SQUASHFS_PROCESSORS="$(nproc)" \
archlinux:base-devel \
bash -c 'set -euo pipefail; pacman -Syu --noconfirm archiso python git; bash build.sh'
- name: Inspect image artifact
@@ -259,7 +243,6 @@ jobs:
with:
name: programmer-os-build-diagnostics
path: |
- .harness/validation/
os/test-results/cleanup-host/receipt.json
os/work/profile/profiledef.sh
os/work/profile/pacman.conf
@@ -268,6 +251,61 @@ jobs:
os/work/profile/airootfs/usr/share/harness-os/hardware/broadcom/manifest.json
retention-days: 7
+ runtime:
+ # hn's checks do not change the image, so they run beside its build; publish.py
+ # still requires this job for every image it releases.
+ if: ${{ !inputs.image_run_id && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'browser-suspend' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' && inputs.checks != 'lock-presentation' && inputs.checks != 'sign-in' }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 30
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+ - uses: actions/setup-node@v7
+ with:
+ node-version: '22.23.2'
+ cache: npm
+ cache-dependency-path: cli/package-lock.json
+ - uses: dtolnay/rust-toolchain@stable
+ with:
+ targets: x86_64-unknown-linux-musl
+ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6
+ with:
+ workspaces: tui
+ shared-key: tui-x86_64-unknown-linux-musl
+ cache-bin: false
+ - name: Prepare native build tools
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y musl-tools tmux zsh
+ # Ubuntu's global zshrc runs compinit, which stops at "insecure directories ... continue [y]
+ # or abort compinit [n]?" for the runner image's group-writable completion folders; a zsh
+ # login shell under test then waits there (as cli-e2e.yml found). Fixed as zsh says.
+ insecure=$(zsh -fc 'autoload -U compaudit && compaudit' 2>/dev/null | grep '^/' | sort -u || true)
+ if [ -n "$insecure" ]; then
+ echo "$insecure" | xargs sudo chown root:root
+ echo "$insecure" | xargs sudo chmod g-w,o-w
+ fi
+ zsh -fc 'autoload -U compaudit && compaudit'
+ - name: Build Harness from the exact OS source
+ run: |
+ make -C os runtime
+ - name: Validate hn session behavior and native terminal lifecycle
+ run: |
+ npm --prefix cli run typecheck
+ cd cli
+ timeout 3m npx vitest run src/lib/engineInstall.spec.ts src/lib/engineLaunch.spec.ts --maxWorkers=2
+ cd ..
+ timeout 8m cargo test --manifest-path tui/Cargo.toml --locked --release --target x86_64-unknown-linux-musl
+ python3 scripts/validate-tui-native.py tui/target/x86_64-unknown-linux-musl/release/harness-tui
+ - name: Retain hn validation diagnostics
+ if: failure()
+ uses: actions/upload-artifact@v6
+ with:
+ name: programmer-os-runtime-diagnostics
+ path: .harness/validation/
+ retention-days: 7
+
machine:
needs: image
if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'essentials' && inputs.checks != 'hardware' && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' && inputs.checks != 'lock-presentation' && inputs.checks != 'sign-in' && (needs.image.result == 'success' || inputs.image_run_id != '' || inputs.checks == 'browser-suspend') && !cancelled() }}
@@ -291,10 +329,7 @@ jobs:
run-id: ${{ inputs.image_run_id || github.run_id }}
github-token: ${{ github.token }}
- name: Install VM test tools
- run: |
- sudo apt-get update -qq
- sudo apt-get install -y qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr
- if test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fi
+ uses: ./.github/actions/vm-tools
- name: Install the disposable browser observer
if: ${{ inputs.checks == 'browser' || inputs.checks == 'browser-suspend' }}
run: sudo apt-get install -y wlrctl
@@ -484,14 +519,15 @@ jobs:
path: os/dist
run-id: ${{ inputs.image_run_id || github.run_id }}
github-token: ${{ github.token }}
- - name: Check the fixture and install VM tools
+ - name: Check the fixture
run: |
python3 -m unittest discover -s os/tests -p 'test_hardware*.py'
python3 -m py_compile os/tests/hardware_install_guest.py os/tests/hardware_install_vm.py
go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os.yml
- sudo apt-get update -qq
- sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr
- sudo chmod a+rw /dev/kvm
+ - name: Install VM test tools
+ uses: ./.github/actions/vm-tools
+ - name: Require KVM
+ run: test -w /dev/kvm
- name: Install the selected driver offline and reboot with 1 GiB
env:
HARNESS_TEST_EMAIL: ${{ secrets.HARNESS_TEST_EMAIL }}
@@ -528,12 +564,13 @@ jobs:
path: os/dist
run-id: ${{ inputs.image_run_id || github.run_id }}
github-token: ${{ github.token }}
- - name: Check the fixture and install VM tools
+ - name: Check the fixture
run: |
python3 -m py_compile os/tests/nvidia_install_guest.py os/tests/nvidia_install_vm.py
- sudo apt-get update -qq
- sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr
- sudo chmod a+rw /dev/kvm
+ - name: Install VM test tools
+ uses: ./.github/actions/vm-tools
+ - name: Require KVM
+ run: test -w /dev/kvm
- name: Install the selected NVIDIA driver offline and reboot encrypted
env:
HARNESS_TEST_EMAIL: ${{ secrets.HARNESS_TEST_EMAIL }}
@@ -569,10 +606,7 @@ jobs:
make -C os check
go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os.yml
- name: Install VM test tools
- run: |
- sudo apt-get update -qq
- sudo apt-get install -y qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr
- if test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fi
+ uses: ./.github/actions/vm-tools
- name: Exercise Wi-Fi and audio in the real image
run: python3 os/tests/essentials_vm.py --iso os/dist/*.iso --network-script os/network.py
- name: Retain hardware plumbing evidence
diff --git a/os/build.sh b/os/build.sh
index c88a3a35c..96af82b8a 100644
--- a/os/build.sh
+++ b/os/build.sh
@@ -16,6 +16,9 @@ BUILD_DIR=${HARNESS_OS_BUILD_DIR:-$OS_DIR/work}
RUNTIME_DIR=${HARNESS_OS_RUNTIME_DIR:-$OS_DIR/work/runtime}
COMPOSITOR_DIR=${HARNESS_OS_COMPOSITOR_DIR:-$OS_DIR/work/compositor}
PLATFORM=${HARNESS_OS_PLATFORM:-pc}
+# Two compressors keep a developer machine usable; CI passes all of its runner's CPUs.
+SQUASHFS_PROCESSORS=${HARNESS_OS_SQUASHFS_PROCESSORS:-2}
+[[ $SQUASHFS_PROCESSORS =~ ^[1-9][0-9]*$ ]] || { echo 'HARNESS_OS_SQUASHFS_PROCESSORS must be a positive number.' >&2; exit 1; }
[[ $PLATFORM == pc || $PLATFORM == apple-t2 ]] || { echo 'Unknown OS boot platform.' >&2; exit 1; }
[[ -s "$RUNTIME_DIR/source.json" && -x "$RUNTIME_DIR/harness-tui" ]] || {
echo 'Build the OS runtimes first with make -C os runtime on x86_64 Linux.' >&2
@@ -93,7 +96,7 @@ iso_application="Harness: boot into hn"
iso_version="$VERSION"
airootfs_image_type="squashfs"
# Match the measured compression profile and bound builder CPU/cache use.
-airootfs_image_tool_options=("-comp" "zstd" "-Xcompression-level" "19" "-b" "1M" "-processors" "2" "-mem" "1G")
+airootfs_image_tool_options=("-comp" "zstd" "-Xcompression-level" "19" "-b" "1M" "-processors" "$SQUASHFS_PROCESSORS" "-mem" "1G")
file_permissions=(
["/root"]="0:0:750"
)
diff --git a/os/tests/test_publication.py b/os/tests/test_publication.py
index 151bf30dc..97e300df4 100644
--- a/os/tests/test_publication.py
+++ b/os/tests/test_publication.py
@@ -203,6 +203,20 @@ class PublicationGuards(unittest.TestCase):
with self.assertRaises(ValueError):
publish.validate_receipts(manifest, receipts)
+ def test_image_build_requires_its_hn_runtime_validation(self):
+ manifest = {'source_commit': 'source-one'}
+ image = {'head_sha': 'source-one'}
+ publish.validate_image_build(manifest, image, [{'name': 'image', 'conclusion': 'success'},
+ {'name': 'runtime', 'conclusion': 'success'}])
+ # Image runs from before the split validated hn inside the image job.
+ publish.validate_image_build(manifest, image, [{'name': 'image', 'conclusion': 'success'}])
+ for jobs, commit in [([{'name': 'image', 'conclusion': 'success'}, {'name': 'runtime', 'conclusion': 'failure'}], 'source-one'),
+ ([{'name': 'image', 'conclusion': 'success'}, {'name': 'runtime', 'conclusion': 'skipped'}], 'source-one'),
+ ([{'name': 'image', 'conclusion': 'failure'}, {'name': 'runtime', 'conclusion': 'success'}], 'source-one'),
+ ([{'name': 'image', 'conclusion': 'success'}, {'name': 'runtime', 'conclusion': 'success'}], 'source-two')]:
+ with self.subTest(jobs=jobs, commit=commit), self.assertRaises(ValueError):
+ publish.validate_image_build(manifest, {'head_sha': commit}, jobs)
+
def test_only_complete_matching_machine_evidence_can_publish(self):
manifest = {'source_commit': 'source-one', 'iso': {'sha256': 'image-one'}}
receipts = [dict(firmware=fw, encrypted=encrypted, status='passed', iso_sha256='image-one',
diff --git a/os/tools/publish.py b/os/tools/publish.py
index 36f85dbe0..7ceae369f 100644
--- a/os/tools/publish.py
+++ b/os/tools/publish.py
@@ -222,6 +222,16 @@ def validate_examples(folder, kind):
return rows
+def validate_image_build(manifest, image, jobs):
+ conclusions = {job['name']: job['conclusion'] for job in jobs}
+ if image['head_sha'] != manifest['source_commit'] or conclusions.get('image') != 'success':
+ raise ValueError('The image does not match a successful build job.')
+ # hn's session and native terminal checks run beside the image build. Image
+ # runs from before that split checked them inside the image job instead.
+ if conclusions.get('runtime', 'success') != 'success':
+ raise ValueError('The image build has no successful hn runtime validation.')
+
+
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--input', type=Path, required=True)
@@ -249,8 +259,7 @@ def main():
jobs = json.loads(gh('api', f'repos/{args.repo}/actions/runs/{args.image}/jobs?filter=latest&per_page=100'))
if run['conclusion'] != 'success' or run['status'] != 'completed' or run['path'] != '.github/workflows/os.yml':
raise ValueError('The machine workflow did not finish successfully.')
- if image['head_sha'] != manifest['source_commit'] or not any(j['name'] == 'image' and j['conclusion'] == 'success' for j in jobs['jobs']):
- raise ValueError('The image does not match a successful build job.')
+ validate_image_build(manifest, image, jobs['jobs'])
hardware = None
if 'broadcom-offline' in manifest.get('capabilities', []):
if not any(j['name'] == 'hardware' and j['conclusion'] == 'success' for j in jobs['jobs']):