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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Add in-place Harness updates and refine the OS first experience (#689)
Deea773ab90800e
diff --git a/.github/workflows/os.yml b/.github/workflows/os.ymlindex 5e7b24274..66db74866 100644--- a/.github/workflows/os.yml+++ b/.github/workflows/os.yml@@ -46,6 +46,12 @@ on:required: falsedefault: falsetype: boolean+ checks:+ description: 'Image journey, focused lock/suspend checks, or simulated Wi-Fi/audio essentials; use image_run_id to reuse an image'+ required: false+ default: image+ type: choice+ options: [image, session, essentials]push:branches: ['os/**']paths: ['os/**', 'tui/**', 'cli/**', '.github/workflows/os.yml']@@ -55,7 +61,7 @@ permissions:actions: readconcurrency:- group: programmer-os-${{ github.ref }}-${{ inputs.memory_mib || '2048' }}-${{ inputs.live_transport || 'cdrom' }}-${{ inputs.development_update && 'update' || inputs.dsh && 'dsh' || inputs.workloads && 'workloads' || 'image' }}+ group: programmer-os-${{ github.ref }}-${{ inputs.memory_mib || '2048' }}-${{ inputs.live_transport || 'cdrom' }}-${{ inputs.development_update && 'update' || inputs.checks == 'session' && 'session' || inputs.checks == 'essentials' && 'essentials' || inputs.dsh && 'dsh' || inputs.workloads && 'workloads' || 'image' }}cancel-in-progress: falsejobs:@@ -136,7 +142,7 @@ jobs:machine:needs: image- if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && (needs.image.result == 'success' || inputs.image_run_id != '') && !cancelled() }}+ if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'essentials' && (needs.image.result == 'success' || inputs.image_run_id != '') && !cancelled() }}runs-on: ubuntu-24.04timeout-minutes: 65strategy:@@ -164,6 +170,11 @@ jobs:sudo apt-get update -qqsudo apt-get install -y qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocrif test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fi+ - name: Check the focused session test and workflow+ if: ${{ inputs.checks == 'session' }}+ run: |+ make -C os check+ go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os.yml- name: Restore prior generated workload projectsif: ${{ inputs.workload_seed_run_id != '' && matrix.firmware == 'bios' }}uses: actions/download-artifact@v6@@ -173,11 +184,15 @@ jobs:run-id: ${{ inputs.workload_seed_run_id }}github-token: ${{ github.token }}- name: Boot, operate, install and reboot the real image+ if: ${{ inputs.checks != 'session' }}env:OS_WORKLOAD_SOURCE_RUN: ${{ inputs.workload_seed_run_id }}OS_MEMORY_MIB: ${{ inputs.memory_mib || '2048' }}OS_LIVE_TRANSPORT: ${{ inputs.live_transport || 'cdrom' }}run: python3 os/tests/vm.py --iso os/dist/*.iso --memory "$OS_MEMORY_MIB" --live-transport "$OS_LIVE_TRANSPORT" --firmware '${{ matrix.firmware }}' ${{ matrix.encryption }} ${{ matrix.agents }} ${{ matrix.cpu }} ${{ (inputs.workloads || inputs.workload_seed_run_id != '') && matrix.firmware == 'bios' && '--workloads' || '' }} ${{ inputs.dsh && matrix.firmware == 'bios' && '--dsh' || '' }} ${{ inputs.workload_seed_run_id != '' && matrix.firmware == 'bios' && '--workload-seed os/work/workload-seed' || '' }}+ - name: Exercise password lock and actual suspend/resume+ if: ${{ inputs.checks == 'session' }}+ run: python3 os/tests/session_vm.py --iso os/dist/*.iso --firmware '${{ matrix.firmware }}' --session-file os/root/usr/lib/harness-os/session --theme-directory os/root/usr/share/plymouth/themes/harness- name: Show machine failure diagnosticsif: failure()run: |@@ -197,6 +212,43 @@ jobs:os/test-results/**/dsh/**retention-days: 14+ essentials:+ needs: image+ if: ${{ always() && inputs.checks == 'essentials' && !inputs.publish_run_id && !inputs.development_update && (needs.image.result == 'success' || inputs.image_run_id != '') && !cancelled() }}+ runs-on: ubuntu-24.04+ timeout-minutes: 25+ steps:+ - uses: actions/checkout@v7+ - uses: actions/download-artifact@v6+ with:+ name: programmer-os-x86_64+ path: os/dist+ run-id: ${{ inputs.image_run_id || github.run_id }}+ github-token: ${{ github.token }}+ - name: Validate test and workflow+ run: |+ 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+ - name: Exercise Wi-Fi and audio in the real image+ run: python3 os/tests/essentials_vm.py --iso os/dist/*.iso+ - name: Retain hardware plumbing evidence+ if: always()+ uses: actions/upload-artifact@v6+ with:+ name: harness-os-essentials+ path: |+ os/test-results/essentials/*.json+ os/test-results/essentials/*.txt+ os/test-results/essentials/*.log+ os/test-results/essentials/*.png+ os/test-results/essentials/*.wav+ retention-days: 14+development-update:if: ${{ inputs.development_update && !inputs.publish_run_id }}runs-on: ubuntu-24.04@@ -238,8 +290,9 @@ jobs:if test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fimake -C os runtimepython3 os/tools/build-package.py --runtime os/work/runtime --output os/work/development-update --development+ python3 os/tests/build-update-fixture.py- name: Exercise apply, rollback, running work and encrypted reboot- run: python3 os/tests/update_vm.py --iso os/dist/*.iso --bundle os/work/development-update+ run: python3 os/tests/update_vm.py --iso os/dist/*.iso --bundle os/work/development-update --fast-fixture os/work/fast-update-fixture- name: Show update failure diagnosticsif: failure()run: |diff --git a/os/DEVELOPMENT.md b/os/DEVELOPMENT.mdindex 54b353f50..11fbcd053 100644--- a/os/DEVELOPMENT.md+++ b/os/DEVELOPMENT.md@@ -9,6 +9,53 @@ This plan was recorded on October 3, 2026. Preview 4 and its optional small-packupdate are published. Native update/rollback acceptance passed; remote-launcherargument tests passed but remote display/SSH interaction is still unverified.+## Next release priorities++The next preview improves the complete experience before expanding the interface.+Keep the existing terminal, agents and optional browser. Hardware integration must+not introduce a desktop, control panel or extra launcher. Update checks use a+short-lived user timer; there is no resident update process.++1. Refine USB welcome, offline installation, Wi-Fi setup, trial, first conversation+ and disk unlock. Review actual screens, keyboard navigation, narrow displays,+ cancellation and recoverable errors. Keep the Naming System and text artwork+ consistent across these steps.+2. Verify the essentials of daily use: networking, brightness, audio, locking,+ sleep/wake, browser switching, updates and recovery. Preserve running work+ through display restarts and session transitions. Agents can use the ordinary+ system tools; the user should not need to configure basic hardware to start.+3. Expand hardware coverage by family: older Intel Macs without T2 first, NVIDIA+ desktops next. Prepare separate boot/platform paths for T2, Apple Silicon and+ Raspberry Pi. Detect devices rather than hard-coding one person's computer.+4. Exercise real development work and retain installation, boot, idle-resource and+ recovery evidence for the actual candidate image. Publish measured results and+ an honest compatibility table; upstream driver availability is not a physical+ Harness test.++`checks=session` with an `image_run_id` in the Harness OS workflow exercises+the published image's live session, then its installed session with the candidate+`os/root/usr/lib/harness-os/session` launcher. The receipt records both the base+image and that file's hash; a reboot activates the candidate before lock,+wrong-password input isolation and actual virtual ACPI suspend/resume checks.+The same terminal process, heartbeat and project must survive. This is a quick+integration check, followed by a fresh final image test. It does not establish+physical laptop suspend, radio, audio or battery behavior.++The focused sleep test uses QEMU standard VGA (`bochs-drm`), whose pinned LTS+driver implements display suspend/resume. The normal install tests retain+`virtio-vga`. Preview 4's Virtio display resumed with a working guest and terminal+process but no visible output after S3; the pinned Virtio GPU driver has no+freeze/restore callbacks. Keep that VM limitation separate from physical laptop+acceptance. `--video virtio-vga` reproduces that configuration; do not count an+unavailable display as successful sleep/wake.++`checks=essentials` reuses the chosen image to test NetworkManager and PipeWire.+The fixture adds a simulated WPA2 access point in an isolated guest network+namespace and a virtual HDA codec, operates the actual hn network form and media+keys, and checks DHCP, DNS, HTTP, reconnection and non-silent audio output. Access+point tools are installed only inside the disposable guest, never in the ISO.+Physical radio, backlight, speaker and microphone tests remain separate.+## The feedback loop| Work being tested | Best environment | What it proves |@@ -55,6 +102,61 @@ results for current performance measurements.## Small development updates+### Fast hn updates++The installed OS checks the existing public hn and CLI release channels every+15 minutes, with a small randomized delay. Complete, checksum-verified runtimes+are prepared under the user's state directory. The OS-owned copy remains an+offline fallback. Neither downloading nor checking restarts working processes.+OS windows use hn's local session storage (`HARNESS_TUI_DESK=off`), so their+layout and pane references survive reconnects without signing into the cloud.+This setting is confined to the OS launcher; ordinary hn installs are unchanged.++`Update ready · Super+U` appears in the bottom bar. Super+U opens the keyboard+update action (Ctrl+B, Shift+U remains an alias). Enter applies the prepared+runtime through a transient user service. An hn-only change reconnects just the+screen; a CLI change also restarts its supervised service. Failure restores the+previous selection. Restore previous version holds the rejected versions until+a newer release arrives. Ordinary macOS/Linux hn shortcuts are unchanged.++This fast track is independent of OS releases. The system channel is checked+once daily; S in Updates installs the published OS package with an administrator+password. Root independently fetches the official release metadata, verifies a+private download, makes a checkpoint, updates any required Arch base first, and+rebuilds the encrypted boot image. System packages never apply or reboot on a+timer. After an OS package changes, fast updates wait for a reboot. Publishing an+ISO is not a requirement for a TUI update. The public preview+4 ISO predates this feature and needs the small integration bundle from the+validated preview 5 release; it does not need to be flashed again.++`development_update=true` builds a private, deliberately unpublished `999.0.1`+hn/CLI fixture. The installed VM's actual timer stages it, then real Super+U and+Enter keys apply hn and CLI independently. Acceptance checks the same terminal+process, a live OpenCode process, keyboard input, rollback and an unchanged boot+ID. Those fixture binaries are never included in the package or public channel.+The same installed VM restores the public package and upgrades through a private+loopback OS channel, rejects a corrupt asset, keeps its running agent alive, and+reboots the rebuilt encrypted image. This does not depend on a public test release.++The OS feed is `os-preview-updates/metadata.json` in the repository's release+assets. It names the exact package and manifest, their byte sizes and SHA-256+hashes. HTTPS authenticates the channel; these are not custom package signatures.+Cross-version packages list the exact validated `upgrades_from` bases. Direct+local bundles cannot skip a required full Arch upgrade. A lower or equal package+version is never offered by the public channel. The publisher must retain exact+source and native acceptance evidence before advancing that feed.++After the matching ISO preview is published, prepare its update assets with+`tools/publish-update.py --bundle BUNDLE --receipt receipt.json --run RUN --output OUTPUT`.+Review the resulting metadata and bundle, then use `--publish` with a fresh+output directory. The publisher requires the exact passing native source and+package, uploads immutable versioned assets, verifies their public bytes, and+only then advances the preview channel. Its first channel is uploaded and+download-verified as a draft before publication. Retain `publication.json` as+the publication receipt; this does not replace recording the total request time.++### Local OS integration bundles+`tools/build-package.py` assembles the same `harness-os` package used by the ISO.On a clean x86 Linux checkout, build a bundle with:@@ -108,13 +210,12 @@ rollback took 1.083 seconds. Actual post-update keyboard and masked-unlock captuwere reviewed. Public package/guide/evidence downloads were fully SHA-256 and sizeverified. Physical ThinkPad update behavior and timings remain unverified.-Shared hn changes in preview 4 are still on the OS branch. Ordinary Mac/Linux hn+Shared hn changes in preview 4 were merged to main in PR #669. Ordinary Mac/Linux hnkeeps its usual home and detach/quit behavior; live USB and installed OS welcomeactions require explicit OS mode. Opening Terminal directly is a shared chooser-change, explicitly approved for all platforms. It needs normal TUI release review-along with the shared agent-discovery-and OpenCode compatibility fixes; publishing the ISO did not release these through-the general TUI channel. The small updater adds no changes to `tui/` or `cli/`.+change, explicitly approved for all platforms. Publishing the ISO did not release+these through the general TUI channel. The small updater adds no changes to `tui/`+or `cli/`.## Optional remote VM controls@@ -141,12 +242,22 @@ validated Harness OS hardware target by preview 4.| Target | Approach | Current Harness OS status || --- | --- | --- |-| Older Intel Mac, 64-bit CPU and EFI, without T2 | Reuse x86-64 userspace and validate firmware, graphics, Wi-Fi, input, sleep and installation per model | First physical Mac target; no tested model yet |+| Older Intel Mac, 64-bit CPU and EFI, without T2 | Reuse x86-64 userspace, select drivers by detected hardware, and validate representative Air/Pro families | First Mac target family; no tested model yet || Intel Mac with T2 | Add the T2 kernel/driver and firmware integration; validate built-in input at encrypted unlock | Separate hardware profile, not covered by generic x86 VM success || Apple Silicon | Build arm64 userspace and integrate the Asahi boot/kernel/graphics/firmware stack | Port required; current x86-64 ISO cannot install natively |+| Raspberry Pi | Evaluate a maintained ARM64 board kernel, firmware and boot image with the same Harness session | Separate board image required; not covered by the PC ISO or an ARM VM || Native Harness app/TUI on macOS | Existing arm64 and x64 app/runtime releases | Separate from installing the Linux OS |-The initial Intel scope excludes 32-bit-only CPUs/EFI. T2 machines need specific+The initial Intel scope excludes 32-bit-only CPUs/EFI. The bundled OpenCode trial+also requires SSE4.2. A preview 4 probe under actual Core 2 Duo TCG execution+reached the USB welcome and successfully ran hn, Node and Chromium version+commands, but OpenCode exited with SIGILL (132). This is an instruction-set+finding, not physical Mac or full browser validation. Older CPUs need a separately+validated agent path; do not describe them as ready for the default trial.+[Bun's executable targets](https://bun.com/docs/bundler/executables) document the+SSE4.2 baseline used by its compiled runtime.++T2 machines need specifickernel support for built-in input and other hardware; their firmware and installpreparation differs from an ordinary PC. The maintained references are the[t2linux Arch install guide](https://wiki.t2linux.org/distributions/arch/installation/),diff --git a/os/INSTALL.md b/os/INSTALL.mdindex f67498ba0..06f3e49a3 100644--- a/os/INSTALL.md+++ b/os/INSTALL.md@@ -1,38 +1,40 @@# Install Harness on a ThinkPad-These instructions are for **0.1.0-preview.4**, using a Mac to prepare the USB.+These instructions are for **0.1.0-preview.5**, using a Mac to prepare the USB.The USB starts a live session. Installation begins only when you choose **Install**in the installer; it erases the entire selected disk.## 1. Prepare-- An x86-64 Intel or AMD ThinkPad. A 32-bit-only CPU is not supported.+- An x86-64 Intel or AMD ThinkPad with SSE4.2 for bundled OpenCode. Core 2 and+ 32-bit-only CPUs are outside the default agent trial's supported baseline.- A USB stick of at least 4 GB. Flashing replaces its contents.- An internal disk of at least 12 GiB, with important files backed up elsewhere.- AC power. Installation works offline; trying a cloud agent needs a connection.-Start with 2 GiB RAM or more. This preview passed installation, reboot, recovery-and a first OpenCode conversation in 1 GiB VMs. Allow more memory for browser+Start with 2 GiB RAM or more. Preview 4 passed installation, reboot, recovery+and a first OpenCode conversation in 1 GiB VMs; each new image repeats the native+installation and boot checks before publication. Allow more memory for browsertabs, concurrent agents and local models.-Preview 2 was installed and booted on a physical ThinkPad. Wi-Fi, suspend and GPU+Preview 4 was installed, booted and used on a physical ThinkPad by the user. Wi-Fi, suspend and GPUcompute still need testing on the actual hardware.## 2. Download and verify on the Mac-From the [preview 4 release](https://github.com/autonomous-ai/openharness/releases/tag/os-v0.1.0-preview.4),+From the [preview 5 release](https://github.com/autonomous-ai/openharness/releases/tag/os-v0.1.0-preview.5),download both files into the same folder:-- `harness-0.1.0-preview.4-x86_64.iso`-- `harness-0.1.0-preview.4-x86_64.iso.sha256`+- `harness-0.1.0-preview.5-x86_64.iso`+- `harness-0.1.0-preview.5-x86_64.iso.sha256`If they are in Downloads, open Terminal and run:```shcd ~/Downloads-shasum -a 256 -c harness-0.1.0-preview.4-x86_64.iso.sha256+shasum -a 256 -c harness-0.1.0-preview.5-x86_64.iso.sha256```-The result must say `harness-0.1.0-preview.4-x86_64.iso: OK`.+The result must say `harness-0.1.0-preview.5-x86_64.iso: OK`.If it does not, download the files again before flashing.## 3. Flash the USB@@ -126,13 +128,38 @@ below mean **Shift + letter**.| Super+B | Open/focus Chromium, or return to Harness || Super+Enter | Focus Harness || Super+L | Lock; unlock with the account password |+| Super+U | Updates || `hn-browser http://localhost:3000` | Open a local project in the browser || `sudo systemctl poweroff` | Shut down |Claude Code, Codex, OpenCode and pi each run in their own pane. Let the agentinstall the tools the project needs. Save work under `~/Projects`.-## 8. First manual test+## 8. Updates++A small **Update ready · Super+U** notice appears when a new hn or CLI release+has downloaded and passed its checks. Press **Super+U**, then Enter to apply it.+The screen reconnects; your running agents and terminal processes remain.+Use **R** in Updates to restore the previous runtime if needed.++System updates use **S** in the same screen and ask for your account password.+They retain a recovery checkpoint and rebuild the boot image. When the screen+offers **Restart now**, save your work and press Enter when ready. Downloads do+not restart the computer, and routine updates do not require another USB flash.++Preview 4 needs the small bootstrap bundle from the new preview release once.+Verify and extract that bundle, open a terminal in its folder, and run:++```sh+sha256sum -c SHA256SUMS+sudo python3 apply-update.py apply "$PWD"+```++Reboot when it finishes; subsequent updates are available through Super+U.+If the bootstrap fails, use `sudo python3 apply-update.py rollback` from that+same folder before trying again.++## 9. First manual test1. Boot with the USB removed. Confirm disk unlock and the Harness home screen.2. Connect Wi-Fi, open a terminal, type a command, and exit with Ctrl+D.@@ -150,7 +177,7 @@ unlock screen and the time from submitting the password to Harness separately.If something fails, keep the exact error and ThinkPad model. `hn-os status` and`hn-os measure` provide system information. Keep passwords and agent tokens private.-The [OS README](https://github.com/autonomous-ai/openharness/blob/os/boot-to-hn/os/README.md#updates-and-recovery) describes updates and recovery.+The [OS README](https://github.com/autonomous-ai/openharness/blob/main/os/README.md#updates-and-recovery) describes updates and recovery.## Older USB imagesdiff --git a/os/README.md b/os/README.mdindex 3ede5d878..ce56816e4 100644--- a/os/README.md+++ b/os/README.md@@ -11,25 +11,29 @@ audience, not its name.Product names and interface copy follow the [Naming System](../docs/naming-system.md).-**Preview 4:** the USB welcome offers **Install Harness** or **Try without installing**.+**Preview 5:** the USB welcome offers **Install Harness** or **Try without installing**.Install works offline. Try opens Wi-Fi setup when needed, then bundled OpenCodewith its upstream default settings. The installer has four fields and one Installaction; encrypted boot shows the Harness wordmark and a masked password prompt.Both the live and installed system use `me@harness`.+`Super+U` opens Updates. Frequent hn/CLI releases download in the background;+you choose when to reconnect the screen. Running agents and terminals stay alive.-[Download preview 4](https://github.com/autonomous-ai/openharness/releases/tag/os-v0.1.0-preview.4)+[Download preview 5](https://github.com/autonomous-ai/openharness/releases/tag/os-v0.1.0-preview.5)· [Mac → USB → ThinkPad installation guide](INSTALL.md)· [Standalone HTML/CSS landing page](../website/public/os/README.md)· [Development feedback loop and Mac support targets](DEVELOPMENT.md)-The exact image passed BIOS/plain and UEFI/encrypted USB installation, boot,-update retry and recovery at 1 GiB and 4 GiB RAM. First-use model conversations,-four programmer projects and three DSH exercises passed the checks described below.-The release includes the matching installation guide and validation evidence.+Each published image includes its matching installation guide and exact validation+evidence. Preview 4 passed BIOS/plain and UEFI/encrypted USB installation, boot,+update retry and recovery at 1 GiB and 4 GiB RAM. Its first-use model conversations,+four programmer projects and three DSH exercises passed the checks described below;+those historical measurements are labeled separately from each new image's receipt.The user confirmed preview 2 installation and boot from a physical ThinkPad'sinternal disk with the USB removed. Its first-use feedback informed this revision.-Preview 4 still needs physical Wi-Fi, suspend and NVIDIA testing. A working older+The user also confirmed preview 4 installation, boot and use on a ThinkPad.+Physical Wi-Fi, suspend and NVIDIA validation remain outstanding. A working olderinstallation does not need reinstalling solely for the USB payload-location fix.## Design@@ -110,7 +114,9 @@ or full-experience demonstration.Write the **whole ISO** to a USB stick using an image writer such as Etcher, thenboot an x86-64 PC with Secure Boot disabled. TPM can remain enabled. A 32-bit-only-ThinkPad cannot boot this image. The [installation guide](INSTALL.md) covers the+ThinkPad cannot boot this image. Bundled OpenCode also requires SSE4.2: a Core 2+machine can reach Harness but is not supported for the bundled agent trial.+The [installation guide](INSTALL.md) covers theMac download, checksum, flashing and ThinkPad boot menu in full.On the USB welcome, press **Enter** to install or **T** to try Harness. Installation@@ -144,20 +150,26 @@ normal Linux administrator control.## Updates and recovery+Preview 5 prepares hn/CLI releases automatically and shows a small bottom-bar+notice. `Super+U` opens Updates; Enter activates an available runtime and+reconnects the screen without a computer reboot. **R** restores the previous+runtime. System updates use **S**, ask for the account password, retain a+checkpoint and offer a restart when ready. Neither channel automatically+interrupts working agents. See [update development](DEVELOPMENT.md#fast-hn-updates).++Preview 4 needs the matching bootstrap bundle from the+[preview 5 release](https://github.com/autonomous-ai/openharness/releases/tag/os-v0.1.0-preview.5)+once. Verify its `SHA256SUMS`, run `sudo python3 apply-update.py apply "$PWD"`+from the extracted folder, and reboot. Later updates use the installed screen;+routine updates do not require another USB flash.+`sudo hn-os update` saves a checkpoint and upgrades the whole system to yesterday'scomplete Arch repository snapshot. Use `--snapshot YYYY/MM/DD` to choose a complete-snapshot at or after the current one. Packages remain signed by Arch; the OS does not-run an updater or download anything on a schedule.+snapshot at or after the current one. Packages remain signed by Arch; this full+system transaction runs only when requested.The bundled hn and OS integration are pinned to this preview's source build;this command updates Arch packages, not the bundled Harness runtime.-An optional [7.4 MB development bundle](https://github.com/autonomous-ai/openharness/releases/download/os-v0.1.0-preview.4/harness-update-preview.4-42c22cece-x86_64.zip)-adds small Harness package updates and rollback to an installed preview 4 system.-It includes its bootstrap, checksums, instructions and native VM evidence; see-[development updates](DEVELOPMENT.md#small-development-updates). It is separate-from the ISO and from ordinary hn on Mac/Linux. The first bundle's terminal and-CLI binaries match the ISO; future interface fixes can use this update path.-A failed or interrupted update blocks ordinary package transactions until`sudo hn-os update` completes successfully. Fix the reportedcause and retry; it keeps the original recovery checkpoint, including acrossdiff --git a/os/build.sh b/os/build.shindex 466d3d9e3..d419aee13 100644--- a/os/build.sh+++ b/os/build.sh@@ -42,7 +42,9 @@ Server = https://archive.archlinux.org/repos/$SNAPSHOT/\$repo/os/\$archServer = https://archive.archlinux.org/repos/$SNAPSHOT/\$repo/os/\$archEOF# Reuse the same package assembly for fresh images and small development updates.-python3 tools/build-package.py --runtime "$RUNTIME_DIR" --output "$BUILD_DIR/repo"+# Use the same source-versioned identity as its update-channel package. An ISO+# installation should not immediately be offered this identical build again.+python3 tools/build-package.py --runtime "$RUNTIME_DIR" --output "$BUILD_DIR/repo" --developmentrepo-add "$BUILD_DIR/repo/harness-build.db.tar.gz" "$BUILD_DIR/repo/"*.pkg.tar.gzcp -a live/. "$PROFILE/airootfs/"mkdir -p "$PROFILE/airootfs/root" "$PROFILE/airootfs/etc/pacman.d/hooks"diff --git a/os/installer.py b/os/installer.pyindex b88574895..cc81aff22 100644--- a/os/installer.py+++ b/os/installer.py@@ -2,6 +2,7 @@"""Offline full-disk installer. Nothing is erased until the exact disk is confirmed."""from __future__ import annotationsimport argparse+from contextlib import contextmanagerimport cursesfrom datetime import datetime, timezoneimport hashlib@@ -9,6 +10,7 @@ import jsonimport osfrom pathlib import Pathimport re+import shleximport shutilimport subprocessimport sys@@ -17,11 +19,37 @@ import timeMIN_DISK_BYTES = 12 * 1024**3LIVE_PAYLOADS = (Path('/run/archiso/copytoram/airootfs.sfs'),Path('/run/archiso/bootmnt/arch/x86_64/airootfs.sfs'))+WORDMARK = ('█ █ ▄▀█ █▀█ █▄ █ █▀▀ █▀ █▀', '█▀█ █▀█ █▀▄ █ ▀█ ██▄ ▄█ ▄█')+COMMAND_LOG = None+INSTALL_LOG = Path('/var/log/harness-install.log')+LAST_LOG = None+++@contextmanager+def command_log(path):+ """Keep command output off the form. Never record stdin (which may be a password)."""+ global COMMAND_LOG+ previous = COMMAND_LOG+ fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600)+ try:+ os.fchmod(fd, 0o600)+ with os.fdopen(fd, 'w') as output:+ fd = None+ COMMAND_LOG = output+ yield output+ finally:+ COMMAND_LOG = previous+ if fd is not None:+ os.close(fd)def run(*args, input=None, capture=False):+ if COMMAND_LOG:+ COMMAND_LOG.write('\n$ ' + shlex.join(str(a) for a in args) + '\n')+ COMMAND_LOG.flush()result = subprocess.run([str(a) for a in args], input=input, check=True,- stdout=subprocess.PIPE if capture else None)+ stdout=subprocess.PIPE if capture else COMMAND_LOG,+ stderr=COMMAND_LOG if capture else subprocess.STDOUT if COMMAND_LOG else None)return result.stdout.decode().strip() if capture else None@@ -121,13 +149,14 @@ def preflight(config, source):kernel = json.loads(run('unsquashfs', '-cat', source, 'usr/share/harness-os/kernel.json', capture=True))if not re.fullmatch(r'usr/lib/modules/[a-zA-Z0-9._+-]+/vmlinuz', kernel.get('path', '')) or not re.fullmatch(r'[a-f0-9]{64}', kernel.get('sha256', '')):raise ValueError('The image has an invalid kernel manifest.')- payload = subprocess.check_output(['unsquashfs', '-cat', str(source), kernel['path']])+ payload = subprocess.check_output(['unsquashfs', '-cat', str(source), kernel['path']], stderr=COMMAND_LOG)if hashlib.sha256(payload).hexdigest() != kernel['sha256']:raise ValueError('The installation kernel failed verification. No disk has been erased.')return kernel-def install(config, source, target):+def install(config, source, target, progress=None):+ report = progress or (lambda message: print(message, flush=True))validate_config(config)# Inspect again immediately before partitioning, rather than trusting the picker.selected_disk(config)@@ -137,6 +166,7 @@ def install(config, source, target):raise ValueError('Installation mountpoint is not empty.')if config.get('confirm_erase') != config['disk']:raise ValueError('Explicit confirmation of the exact disk is required.')+ report('Checking installation files…')kernel = preflight(config, source)selected_disk(config)started = time.monotonic()@@ -147,7 +177,7 @@ def install(config, source, target):opened = Falsemounted = Falsetry:- print(f'Erasing {disk} and installing Harness...', flush=True)+ report('Preparing the disk…')run('sgdisk', '--zap-all', disk)run('sgdisk', '-n', '1:1MiB:+2MiB', '-t', '1:ef02', '-c', '1:HN BIOS','-n', '2:0:+1GiB', '-t', '2:ef00', '-c', '2:HN BOOT',@@ -175,7 +205,7 @@ def install(config, source, target):for name, subvol in [('home', '@home'), ('.snapshots', '@snapshots')]:(target / name).mkdir()run('mount', '-o', f'subvol={subvol},compress=zstd:1,noatime', root_device, target / name)- print('Copying the verified offline system...', flush=True)+ report('Copying Harness…')# Unsquashfs defaults to 512 MiB of caches. Bound them so installation# still fits on a 1 GiB machine after trying the bundled agent/browser.run('unsquashfs', '-mem', '64M', '-f', '-no-progress', '-d', target, source)@@ -196,7 +226,7 @@ def install(config, source, target):# mkarchiso moves the live /boot files out of SquashFS. Regenerate the# disk initramfs around this verified, package-owned kernel instead.shutil.copyfile(target / kernel['path'], target / 'boot/vmlinuz-linux-lts')- print('Configuring account, boot and recovery...', flush=True)+ report('Setting up your account…')# The live image is immutable. No live passwords, SSH keys or sessions are copied.for path in ['etc/sudoers.d/10-live', 'etc/mkinitcpio.conf.d/archiso.conf','etc/systemd/system/[email protected]/live.conf',@@ -263,6 +293,7 @@ def install(config, source, target):shutil.copytree(networks, target / 'etc/NetworkManager/system-connections', dirs_exist_ok=True)chroot(target, 'systemctl', 'enable', 'NetworkManager', 'systemd-resolved', 'systemd-timesyncd')chroot(target, 'systemctl', 'disable', 'sshd.service')+ report('Preparing startup and recovery…')chroot(target, '/usr/lib/harness-os/init-keyring')chroot(target, 'mkinitcpio', '-P')chroot(target, 'grub-install', '--target=i386-pc', '--recheck', disk)@@ -272,8 +303,10 @@ def install(config, source, target):'duration_seconds': round(time.monotonic() - started, 3), 'encrypted': config['encrypt'],'disk_bytes': selected_size(config), 'root_uuid': root_uuid, 'boot_uuid': boot_uuid}write(target, '/var/lib/harness-os/install.json', json.dumps(receipt, indent=2) + '\n')+ report('Finishing installation…')run('sync')- print(f"Installed in {receipt['duration_seconds']:.1f}s. Shut down, remove the USB, and boot the disk.", flush=True)+ if progress is None:+ print(f"Installed in {receipt['duration_seconds']:.1f}s. Shut down, remove the USB, and boot the disk.", flush=True)finally:if mounted:run('umount', '-R', target)@@ -291,9 +324,13 @@ def display_text(value):return ''.join(c if c.isprintable() else '?' for c in str(value or '')).strip()-def disk_label(disk):+def disk_label(disk, width=None):size = f"{int(disk['size']) / 1_000_000_000:.1f}".removesuffix('.0')- return f"{display_text(disk.get('model')) or 'Disk'} {size} GB"+ model = display_text(disk.get('model')) or 'Disk'+ suffix = f' {size} GB'+ if width is not None and len(model) + len(suffix) > width:+ model = model[:max(1, width - len(suffix) - 1)] + '…'+ return model + suffixclass InstallForm:@@ -306,13 +343,24 @@ class InstallForm:self.error = ''self.title = Noneself.cursor_visible = None+ self.top, self.left, self.width = 0, 2, 60+ self.accent = curses.A_BOLD+ try:+ if curses.has_colors():+ curses.start_color()+ curses.use_default_colors()+ curses.init_pair(1, curses.COLOR_YELLOW, -1)+ self.accent = curses.color_pair(1) | curses.A_BOLD+ except curses.error:+ pass- def line(self, row, text, active=False, bold=False):+ def line(self, row, text, active=False, bold=False, accent=False):height, width = self.screen.getmaxyx()+ row += self.topif row >= height or width < 5:return- attr = curses.A_REVERSE if active else curses.A_BOLD if bold else curses.A_NORMAL- self.screen.addnstr(row, 2, text, width - 4, attr)+ attr = curses.A_REVERSE if active else self.accent if accent else curses.A_BOLD if bold else curses.A_NORMAL+ self.screen.addnstr(row, self.left, text, min(self.width, width - self.left - 1), attr)def cursor(self, visible):if visible == self.cursor_visible:@@ -330,6 +378,7 @@ class InstallForm:else:self.screen.erase()height, width = self.screen.getmaxyx()+ self.top, self.left, self.width = 0, 2, max(1, width - 4)if height < 18 or width < 54:self.cursor(False)self.line(0, 'Resize terminal to at least 54 columns and 18 rows.')@@ -338,6 +387,13 @@ class InstallForm:if self.key() == '\x1b':raise KeyboardInterrupt('Cancelled.')return False+ self.width = min(60, width - 4)+ self.left = (width - self.width) // 2+ self.top = max(0, (height - (22 if height >= 24 else 18)) // 2)+ if height >= 24:+ for row, word in enumerate(WORDMARK):+ self.line(row, word.center(self.width), accent=True)+ self.top += 4self.line(1, title, bold=True)return True@@ -357,12 +413,14 @@ class InstallForm:if not self.begin('Select disk'):continueheight, _ = self.screen.getmaxyx()- count = max(1, height - 8)+ count = max(1, height - self.top - 7)start = (selected // count) * countfor index in range(start, min(start + count, len(self.disks))):disk = self.disks[index]row = 4 + index - start- self.line(row, ('> ' if index == selected else ' ') + disk_label(disk) + ' ' + disk['name'], index == selected)+ name = display_text(disk['name'])+ label = disk_label(disk, self.width - len(name) - 4)+ self.line(row, ('> ' if index == selected else ' ') + label + ' ' + name, index == selected)self.cursor(False)self.screen.refresh()key = self.key()@@ -403,9 +461,13 @@ class InstallForm:if not self.begin('Install Harness'):continuedisk = self.disks[self.selected]- self.line(4, f"{'Disk':18}{disk_label(disk)}", self.focus == 0)+ # Identical models/capacities need a visible discriminator after selection.+ duplicate = sum(disk_label(d) == disk_label(disk) for d in self.disks) > 1+ suffix = ' ' + Path(disk['name']).name if duplicate else ''+ label = disk_label(disk, self.width - 18 - len(suffix)) + suffix+ self.line(4, f"{'Disk':18}{label}", self.focus == 0)self.line(6, f"{'Encryption':18}[{'x' if self.encrypt else ' '}]", self.focus == 1)- capacity = min(32, self.screen.getmaxyx()[1] - 24)+ capacity = min(32, self.width - 21)for index, label in enumerate(('Password', 'Repeat password')):position = self.positions[index]offset = max(0, position - capacity + 1)@@ -417,7 +479,8 @@ class InstallForm:self.cursor(self.focus in (2, 3))if self.focus in (2, 3):position = self.positions[self.focus - 2]- self.screen.move(8 + (self.focus - 2) * 2, 21 + min(position, capacity - 1))+ self.screen.move(self.top + 8 + (self.focus - 2) * 2,+ self.left + 19 + min(position, capacity - 1))self.screen.refresh()key = self.key()if key == '\x1b':@@ -475,22 +538,16 @@ def completion(screen):"""Keep success visible when the installer owns an hn pane, then shut down on request."""screen.keypad(True)curses.flushinp()- try:- curses.curs_set(0)- except curses.error:- pass+ view = InstallForm(screen, [], 'me', 'harness', True)+ view.cursor(False)selected = 0while True:- screen.erase()- height, width = screen.getmaxyx()- rows = [(1, 'Harness is installed.', curses.A_BOLD),- (4, 'Remove the USB after shutdown.', curses.A_NORMAL),- (5, 'Then turn on this computer.', curses.A_NORMAL),- (8, '[ Shut down ]', curses.A_REVERSE if selected == 0 else curses.A_NORMAL),- (10, 'Back to Harness', curses.A_REVERSE if selected == 1 else curses.A_NORMAL)]- for row, text, attr in rows:- if row < height and width >= 5:- screen.addnstr(row, 2, text, width - 4, attr)+ if not view.begin('Harness is installed.'):+ continue+ view.line(4, 'Remove the USB after shutdown.')+ view.line(5, 'Then turn on this computer.')+ view.line(8, '[ Shut down ]', active=selected == 0)+ view.line(10, 'Back to Harness', active=selected == 1)screen.refresh()key = screen.get_wch()if key in ('\x1b', '\x03'):@@ -501,6 +558,44 @@ def completion(screen):return selected == 0+def install_with_progress(screen, config, source, target):+ """A static text view: real stages, no invented percentage or extra process."""+ view = InstallForm(screen, [], config['username'], config['hostname'], config['encrypt'])+ view.cursor(False)++ def render(message):+ # A resize must never pause a disk operation waiting for keyboard input.+ screen.erase()+ height, width = screen.getmaxyx()+ view.width = max(1, min(60, width - 4))+ view.left = max(0, (width - view.width) // 2)+ view.top = max(0, (height - 12) // 2)+ if height >= 18:+ for row, word in enumerate(WORDMARK):+ view.line(row, word.center(view.width), accent=True)+ view.top += 4+ view.line(1, 'Installing Harness', bold=True)+ view.line(4, message)+ view.line(6, 'Keep this computer powered on.')+ screen.refresh()++ def progress(message):+ if COMMAND_LOG:+ COMMAND_LOG.write('\n' + message + '\n')+ COMMAND_LOG.flush()+ try:+ render(message)+ except curses.error:+ # A display resize or lost terminal is not a reason to interrupt a+ # disk transaction. Its diagnostics and final status are retained.+ pass++ global LAST_LOG+ with command_log(INSTALL_LOG):+ LAST_LOG = INSTALL_LOG+ install(config, source, target, progress=progress)++def arguments():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument('--config', type=Path)@@ -532,8 +627,10 @@ def main(args=None):config = interactive(username=args.username if args.username is not None else 'me',hostname=args.hostname if args.hostname is not None else 'harness',encrypt=not args.no_encryption)- install(config, source, Path('/mnt/harness-os'))- if not args.config:+ if args.config:+ install(config, source, Path('/mnt/harness-os'))+ else:+ curses.wrapper(lambda screen: install_with_progress(screen, config, source, Path('/mnt/harness-os')))if curses.wrapper(completion):run('systemctl', 'poweroff')@@ -546,6 +643,8 @@ def entrypoint():return 130except (ValueError, OSError, curses.error, subprocess.CalledProcessError) as error:print(f'Installation stopped: {error}', file=sys.stderr, flush=True)+ if not args.config and LAST_LOG is not None:+ print(f'Details: {LAST_LOG}', file=sys.stderr, flush=True)# An installer launched from the USB welcome owns its pane. Retain the# error until it has been read instead of closing the pane immediately.# Unattended configuration files and piped callers never wait for input.diff --git a/os/live_update.py b/os/live_update.pynew file mode 100644index 000000000..3fb00e566--- /dev/null+++ b/os/live_update.py@@ -0,0 +1,548 @@+#!/usr/bin/env python3+"""Stage ordinary hn/CLI releases for Harness OS without replacing OS-owned files.++The short-lived user timer downloads verified releases. Only an explicit action+switches the runtime and reconnects the screen; terminal owners remain alive.+The packaged runtime is always available as the offline fallback.+"""+from __future__ import annotations+import argparse+from contextlib import contextmanager+import curses+import fcntl+import hashlib+import importlib.util+import json+import os+from pathlib import Path+import re+import shutil+import subprocess+import sys+import tempfile+import time+from urllib.parse import urlparse+from urllib.request import Request, urlopen++STATE = Path.home() / '.local/state/harness-os/updates'+BUNDLED = Path('/usr/lib/harness')+BASE_ID = Path('/usr/share/harness-os/runtime.json')+FEEDS = {+ 'hn': 'https://storage.googleapis.com/s3-autonomous-upgrade-3/harness/tui/metadata.json',+ 'cli': 'https://storage.googleapis.com/s3-autonomous-upgrade-3/harness/cli/metadata.json',+}+FILES = ('harness-tui', 'cli.mjs', 'notify.mjs')+LIMIT = 64 * 1024 * 1024+RESTART_REQUIRED = Path('/run/harness-os-restart-required')+SYSTEM_LOCK = Path('/run/lock/hn-os.lock')+++def version(value):+ if not isinstance(value, str) or not re.fullmatch(r'\d{1,8}\.\d{1,8}\.\d{1,8}', value):+ raise ValueError('Invalid release version.')+ return tuple(map(int, value.split('.')))+++def digest(path):+ with path.open('rb') as handle:+ return hashlib.file_digest(handle, 'sha256').hexdigest()+++def read(path, default=None):+ return json.loads(path.read_text()) if path.exists() else default+++def sync_directory(path):+ descriptor = os.open(path, os.O_RDONLY)+ try:+ os.fsync(descriptor)+ finally:+ os.close(descriptor)+++def write(path, data):+ with tempfile.NamedTemporaryFile(mode='w', dir=path.parent, delete=False) as handle:+ temporary = Path(handle.name)+ try:+ json.dump(data, handle)+ handle.write('\n')+ handle.flush()+ os.fsync(handle.fileno())+ temporary.replace(path)+ sync_directory(path.parent)+ finally:+ temporary.unlink(missing_ok=True)+++@contextmanager+def locked():+ STATE.mkdir(parents=True, exist_ok=True, mode=0o700)+ with (STATE / 'lock').open('a') as handle:+ try:+ fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)+ except BlockingIOError as error:+ raise ValueError('An update is already in progress.') from error+ # OS package replacement and fast activation cannot run concurrently.+ # The root-owned file is created by tmpfiles before the user session.+ system_lock = SYSTEM_LOCK.open('r') if SYSTEM_LOCK.exists() else None+ try:+ if system_lock:+ try:+ fcntl.flock(system_lock, fcntl.LOCK_SH | fcntl.LOCK_NB)+ except BlockingIOError as error:+ raise ValueError('A system update is in progress. Try again when it finishes.') from error+ yield+ finally:+ if system_lock:+ system_lock.close()+++def check_system(force=False):+ cached = read(STATE / 'system.json', {})+ if not force and time.time() - cached.get('checked_at', 0) < 86400:+ return cached+ try:+ spec = importlib.util.spec_from_file_location('harness_os_release_update', Path(__file__).with_name('release_update.py'))+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ release = module.discover()+ cached = {'checked_at': time.time(), 'available': bool(release and release['available']),+ 'version': release['version'] if release else None}+ except (ValueError, OSError, KeyError, TypeError, subprocess.SubprocessError) as error:+ # An unavailable system channel must not hold up an independent hn fix.+ cached = {'checked_at': time.time(), 'available': False, 'error': str(error)}+ write(STATE / 'system.json', cached)+ return cached+++def allowed_url(value):+ if not isinstance(value, str):+ raise ValueError('Invalid download address.')+ parsed = urlparse(value)+ # Loopback is useful for developer fixtures; production feeds are HTTPS.+ if parsed.username or parsed.password or not parsed.hostname or not (+ parsed.scheme == 'https' or+ parsed.scheme == 'http' and parsed.hostname in ('localhost', '127.0.0.1', '::1')+ ):+ raise ValueError('Updates require HTTPS.')+ return value+++def fetch(url, limit):+ request = Request(allowed_url(url), headers={'User-Agent': 'Harness-Updates/1'})+ with urlopen(request, timeout=20) as response:+ allowed_url(response.url)+ size = response.headers.get('Content-Length')+ if size and (not size.isdigit() or int(size) > limit):+ raise ValueError('Update exceeds its download size limit.')+ data = response.read(limit + 1)+ if len(data) > limit:+ raise ValueError('Update exceeds its download size limit.')+ return data+++def release(feed, component):+ meta = json.loads(fetch(feed, 65536))+ if not isinstance(meta, dict):+ raise ValueError('Invalid release manifest.')+ if component == 'hn':+ builds = meta.get('builds')+ if not isinstance(builds, dict):+ raise ValueError('Invalid hn release manifest.')+ value, refs = meta.get('version'), {'harness-tui': builds.get('linux-x64')}+ else:+ entry = meta.get('cli', {})+ if not isinstance(entry, dict):+ raise ValueError('Invalid Harness release manifest.')+ value, refs = entry.get('version'), {'cli.mjs': entry.get('cli'), 'notify.mjs': entry.get('notify')}+ version(value)+ for ref in refs.values():+ if not isinstance(ref, dict) or not re.fullmatch(r'[a-fA-F0-9]{64}', str(ref.get('sha256', ''))):+ raise ValueError('Release is missing its checksum.')+ allowed_url(ref.get('url'))+ size = ref.get('size')+ if size is not None and (type(size) is not int or not 0 < size <= LIMIT):+ raise ValueError('Invalid release size.')+ return value, refs+++def run(*args, timeout=45, **kwargs):+ return subprocess.run([str(a) for a in args], check=True, text=True,+ capture_output=True, timeout=timeout, **kwargs).stdout.strip()+++def versions(folder):+ # Version probes do not open a terminal, start a daemon or require a network.+ hn = run(folder / 'harness-tui', '--version', env=dict(os.environ, HN_AS_TMUX='0'))+ match = re.fullmatch(r'hn (\d+\.\d+\.\d+)(?: \(tmux [^\r\n]+\))?', hn)+ if not match:+ raise ValueError('The hn build did not pass its version check.')+ cli = run('/usr/bin/node', folder / 'cli.mjs', 'version')+ version(cli)+ return {'hn': match[1], 'cli': cli}+++def selected():+ pointer = STATE / 'current'+ if not pointer.exists():+ return BUNDLED+ path = pointer.resolve()+ if path.parent != (STATE / 'builds').resolve():+ raise ValueError('Invalid selected runtime; use the packaged runtime to recover.')+ if not (path / 'base.json').is_file() or (path / 'base.json').read_bytes() != BASE_ID.read_bytes():+ return BUNDLED+ return path+++def verify(folder):+ record = read(folder / 'release.json')+ if not record or set(record.get('files', {})) != set(FILES):+ raise ValueError('The prepared update is incomplete.')+ for name, info in record['files'].items():+ path = folder / name+ if path.is_symlink() or not path.is_file() or path.stat().st_size != info['bytes'] or digest(path) != info['sha256']:+ raise ValueError('The prepared update failed verification. Check for updates again.')+ if versions(folder) != record['versions']:+ raise ValueError('The prepared update version changed.')+ return record+++def prepared():+ record = read(STATE / 'ready.json')+ if not record:+ return None+ identity = record.get('id', '')+ if not re.fullmatch(r'[a-f0-9]{64}', identity):+ raise ValueError('Invalid prepared update.')+ folder = STATE / 'builds' / identity+ if not (folder / 'base.json').is_file() or (folder / 'base.json').read_bytes() != BASE_ID.read_bytes():+ return None+ return folder+++def notice(message):+ # Only OS configuration renders this option. No shared hn welcome/UI change.+ try:+ run('/usr/bin/hn', 'set-option', '-g', '@harness-update', message)+ except (OSError, subprocess.SubprocessError):+ pass # A stopped screen will receive the notice on the next check.+++def prune():+ # Retain only the active, previous and ready builds. Check/apply own the lock,+ # so a half-download here can only be left by an interrupted earlier check.+ keep = {path.resolve() for path in (selected(), prepared()) if path is not None}+ pointer = STATE / 'current'+ if pointer.is_symlink():+ # A newly installed OS package changes base.json before the old session+ # exits. Keep its files until its raw selection is actually replaced.+ keep.add(pointer.resolve())+ receipt = read(STATE / 'applied.json', {})+ if receipt.get('previous'):+ keep.add(Path(receipt['previous']).resolve())+ transaction = read(STATE / 'transaction.json', {})+ if transaction.get('status') == 'applying' and transaction.get('previous'):+ keep.add(Path(transaction['previous']).resolve())+ folder = STATE / 'builds'+ if folder.exists():+ for path in folder.iterdir():+ if path.resolve() not in keep and not path.is_symlink() and path.is_dir() and (+ re.fullmatch(r'[a-f0-9]{64}', path.name) or path.name.startswith('.download-')+ ):+ shutil.rmtree(path)+++def check(feeds=None, progress=lambda _: None, force_system=False):+ with locked():+ if RESTART_REQUIRED.exists():+ notice(('Restart ready' if read(RESTART_REQUIRED, {}).get('status') == 'ready' else 'System update needs attention') + ' · Super+U')+ return False+ recover_interrupted()+ current = selected()+ running = versions(current)+ ready = prepared()+ if ready and ready != current:+ try:+ verify(ready)+ except (ValueError, OSError, KeyError, TypeError, subprocess.SubprocessError):+ # An interrupted or damaged staged build must be downloadable+ # again. Keep the active runtime untouched while checking feeds.+ (STATE / 'ready.json').unlink(missing_ok=True)+ ready = None+ base = ready if ready and ready.exists() else current+ base_versions = verify(base)['versions'] if base != BUNDLED else running+ changes, target_versions, errors = {}, dict(base_versions), []+ ignored = read(STATE / 'ignored.json', {})+ for component, url in (feeds or FEEDS).items():+ try:+ candidate, refs = release(url, component)+ if ignored.get(component) == candidate:+ continue+ if version(candidate) > version(base_versions[component]):+ progress('Downloading hn…' if component == 'hn' else 'Downloading Harness…')+ component_files = {}+ for name, ref in refs.items():+ data = fetch(ref['url'], ref.get('size', LIMIT))+ if hashlib.sha256(data).hexdigest() != ref['sha256'].lower() or (+ ref.get('size') is not None and len(data) != ref['size']+ ):+ raise ValueError('Download checksum or size does not match the release.')+ component_files[name] = data+ changes.update(component_files)+ target_versions[component] = candidate+ except (ValueError, OSError, KeyError, TypeError) as error:+ errors.append(f'{component}: {error}')+ # Each component is complete before staging; an unavailable CLI release+ # must not hold up an independent hn fix (or leave only half a CLI pair).+ if changes:+ builds = STATE / 'builds'+ builds.mkdir(exist_ok=True)+ with tempfile.TemporaryDirectory(prefix='.download-', dir=builds) as temp:+ folder = Path(temp)+ for name in FILES:+ if name in changes:+ (folder / name).write_bytes(changes[name])+ else:+ shutil.copyfile(base / name, folder / name)+ (folder / name).chmod(0o755 if name == 'harness-tui' else 0o644)+ with (folder / name).open('rb') as handle:+ os.fsync(handle.fileno())+ (folder / 'hn').symlink_to('harness-tui')+ shutil.copyfile(BASE_ID, folder / 'base.json')+ with (folder / 'base.json').open('rb') as handle:+ os.fsync(handle.fileno())+ record = {'versions': target_versions, 'files': {name: {+ 'sha256': digest(folder / name), 'bytes': (folder / name).stat().st_size+ } for name in FILES}}+ write(folder / 'release.json', record)+ verify(folder)+ identity = hashlib.sha256(json.dumps(record, sort_keys=True).encode() + BASE_ID.read_bytes()).hexdigest()+ ready = builds / identity+ if ready.exists() and ready != current:+ try:+ verify(ready)+ except (ValueError, OSError, KeyError, TypeError, subprocess.SubprocessError):+ # This owned, inactive build failed verification. Replace+ # it with the complete, independently verified download.+ shutil.rmtree(ready)+ if not ready.exists():+ # TemporaryDirectory can safely clean its now-missing old name.+ folder.rename(ready)+ sync_directory(builds)+ write(STATE / 'ready.json', {'id': identity})+ write(STATE / 'check.json', {'checked_at': time.time(), 'errors': errors})+ available = ready is not None and ready != current+ system = check_system(force_system) if feeds is None else {}+ notice('Update ready · Super+U' if available or system.get('available') else '')+ prune()+ if errors and not available:+ raise ValueError('Could not check for updates. Connect to the internet and try again.')+ return available+++def select(folder):+ pointer = STATE / 'current'+ if folder == BUNDLED:+ pointer.unlink(missing_ok=True)+ sync_directory(STATE)+ return+ temporary = STATE / '.current-next'+ temporary.unlink(missing_ok=True)+ temporary.symlink_to(folder.relative_to(STATE))+ temporary.replace(pointer)+ sync_directory(STATE)+++def restart(cli_changed):+ if cli_changed:+ run('systemctl', '--user', 'restart', 'harness-daemon.service', timeout=180)+ run('/usr/lib/harness-os/wait-runtime')+ # The terminal surface is separate from the processes that own agent PTYs.+ run('systemctl', '--user', 'restart', 'hn-screen.service')+ run('systemctl', '--user', 'is-active', '--quiet', 'hn-screen.service')+++def screen_ready(target):+ """Wait for an attached client executing the selected binary, not just foot."""+ deadline = time.monotonic() + 30+ observed = {}+ while time.monotonic() < deadline:+ try:+ # list-clients deliberately includes the backing tmux connections.+ # hn-list-clients identifies hn's own rendering clients instead.+ clients = run('/usr/bin/hn', 'hn-list-clients', '-F', '#{client_pid}', timeout=3)+ for pid in clients.splitlines():+ if pid.isdigit():+ executable = Path('/proc') / pid / 'exe'+ observed[pid] = str(executable.resolve())+ if executable.samefile(target / 'harness-tui'):+ write(STATE / 'screen.json', {'pid': int(pid), 'executable': observed[pid], 'target': str(target)})+ return+ except (OSError, subprocess.SubprocessError):+ pass+ time.sleep(.25)+ write(STATE / 'screen.json', {'target': str(target), 'observed': observed, 'status': 'failed'})+ raise ValueError('The new hn screen did not become ready. Restoring the previous build.')+++def recovery_target(value):+ target = Path(value)+ if target == BUNDLED:+ return target+ if target.parent.resolve() != (STATE / 'builds').resolve() or not re.fullmatch(r'[a-f0-9]{64}', target.name):+ raise ValueError('Invalid runtime recovery path.')+ if (target / 'base.json').read_bytes() != BASE_ID.read_bytes():+ return BUNDLED+ verify(target)+ return target+++def recover_interrupted():+ transaction = read(STATE / 'transaction.json', {})+ if transaction.get('status') != 'applying':+ return+ previous = recovery_target(transaction['previous'])+ select(previous)+ # Holding the update lock proves the previous activation is no longer alive.+ # Restore its known runtime even if a power cut lost its final receipt.+ restart(True)+ screen_ready(previous)+ write(STATE / 'transaction.json', {'status': 'interrupted', 'previous': str(previous)})+++def apply(rollback=False):+ with locked():+ if RESTART_REQUIRED.exists():+ raise ValueError('Restart to finish the system update before changing hn.')+ recover_interrupted()+ previous = selected()+ receipt = read(STATE / 'applied.json', {})+ target = (Path(receipt['previous']) if rollback and receipt.get('previous') else None) if rollback else prepared()+ if target is None or target == previous:+ raise ValueError('No update to roll back.' if rollback else 'Harness is up to date.')+ if target != BUNDLED:+ if target.parent.resolve() != (STATE / 'builds').resolve() or not re.fullmatch(r'[a-f0-9]{64}', target.name):+ raise ValueError('Invalid runtime recovery path.')+ if (target / 'base.json').read_bytes() != BASE_ID.read_bytes():+ raise ValueError('That runtime belongs to an earlier OS package.')+ candidate = verify(target)['versions']+ else:+ candidate = versions(BUNDLED)+ old = versions(previous)+ write(STATE / 'transaction.json', {'previous': str(previous), 'target': str(target), 'status': 'applying'})+ select(target)+ try:+ restart(candidate['cli'] != old['cli'])+ screen_ready(target)+ except BaseException:+ select(previous)+ write(STATE / 'transaction.json', {'status': 'failed', 'previous': str(previous)})+ restart(candidate['cli'] != old['cli'])+ notice('Update failed · Super+U')+ raise+ write(STATE / 'applied.json', {'previous': str(previous), 'current': str(target), 'at': time.time()})+ if rollback:+ write(STATE / 'ignored.json', old)+ write(STATE / 'transaction.json', {'status': 'applied'})+ (STATE / 'ready.json').unlink(missing_ok=True)+ notice('')+ prune()+++def screen(window):+ curses.curs_set(0)+ window.keypad(True)+ message = ''+ def draw(status=''):+ window.erase()+ height, width = window.getmaxyx()+ ready = prepared()+ available = ready is not None and ready != selected()+ checked = read(STATE / 'check.json', {})+ system = read(STATE / 'system.json', {})+ failed = read(STATE / 'transaction.json', {}).get('status') == 'failed'+ system_state = read(RESTART_REQUIRED, {}).get('status')+ reboot = system_state == 'ready'+ recovery = system_state == 'failed'+ if system_state:+ available = False+ summary = 'Could not check for updates.' if checked.get('errors') else (+ 'Harness is up to date.' if checked.get('checked_at') else 'Updates are checked automatically.')+ lines = ['harness', '', status or message or (+ 'Restore the previous system to recover.' if recovery else+ 'Restart to finish the system update.' if reboot else+ 'The system is updating…' if system_state else+ 'Update failed. Previous version restored.' if failed else 'An update is ready.' if available else summary), '',+ 'Enter Restart now' if reboot else 'Enter Try update again' if available and failed else+ 'Enter Update now' if available else 'C Check for updates',+ 'R Restore previous system' if recovery else+ 'R Restore previous version' if not system_state and read(STATE / 'applied.json') else '',+ 'S System update ready' if system.get('available') else 'S System updates', '', 'Esc Back']+ top, left = max(0, (height - len(lines)) // 2), max(0, (width - 46) // 2)+ for index, line in enumerate(lines):+ if top + index < height - 1:+ window.addnstr(top + index, left, line, max(0, width - left - 1), curses.A_BOLD if index == 0 else 0)+ window.refresh()+ return available+ while True:+ available = draw()+ key = window.getch()+ if key in (27, ord('q')):+ return+ try:+ if key in (10, 13) and read(RESTART_REQUIRED, {}).get('status') == 'ready':+ return 'reboot'+ if key in (ord('r'), ord('R')) and read(RESTART_REQUIRED, {}).get('status') == 'failed':+ return 'restore-system'+ if key in (ord('c'), ord('C')) or key in (10, 13) and not available:+ draw('Checking for updates…')+ check(progress=draw, force_system=True)+ message = ''+ elif key in (10, 13) and available or key in (ord('r'), ord('R')):+ action = 'rollback' if key in (ord('r'), ord('R')) else 'apply'+ draw('Updating… Your agents keep running.')+ # A transient unit survives the screen it restarts; no extra daemon.+ run('systemd-run', '--user', '--collect', '--unit=harness-apply-update',+ '/usr/bin/python3', '/usr/lib/harness-os/live_update.py', action)+ return+ elif key in (ord('s'), ord('S')):+ return 'system'+ except (ValueError, OSError, subprocess.SubprocessError) as error:+ message = str(error)+++def main(argv=None):+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('action', choices=['check', 'screen', 'apply', 'rollback', 'status'], nargs='?', default='screen')+ parser.add_argument('--feeds', type=Path, help='Explicit developer feed map; never used by the installed timer')+ args = parser.parse_args(argv)+ if os.geteuid() == 0 or Path('/etc/harness-live').exists():+ parser.error('Open Updates as your normal user on an installed Harness system.')+ STATE.mkdir(parents=True, exist_ok=True, mode=0o700)+ if args.action == 'check':+ check(read(args.feeds) if args.feeds else None)+ elif args.action == 'screen':+ while True:+ action = curses.wrapper(screen)+ if action == 'reboot':+ subprocess.run(['systemctl', 'reboot'], check=True)+ break+ if action not in ('system', 'restore-system'):+ break+ subprocess.run(['sudo', '/usr/bin/harness', 'rollback' if action == 'restore-system' else 'upgrade'], check=False)+ (STATE / 'system.json').unlink(missing_ok=True)+ input('Press Enter to return to Updates.')+ elif args.action in ('apply', 'rollback'):+ apply(rollback=args.action == 'rollback')+ else:+ print(json.dumps({'runtime': str(selected()), 'versions': versions(selected()),+ 'ready': str(prepared()) if prepared() else None,+ 'restart_required': RESTART_REQUIRED.exists(),+ 'system': read(STATE / 'system.json'), 'check': read(STATE / 'check.json')}, indent=2))+++if __name__ == '__main__':+ try:+ main()+ except (ValueError, OSError, subprocess.SubprocessError) as error:+ raise SystemExit('Harness update: ' + str(error))diff --git a/os/lock.json b/os/lock.jsonindex 120837695..c6c8f6457 100644--- a/os/lock.json+++ b/os/lock.json@@ -1,5 +1,8 @@{- "version": "0.1.0-preview.4",+ "version": "0.1.0-preview.5","arch_snapshot": "2026/10/01",- "architecture": "x86_64"+ "architecture": "x86_64",+ "upgrades_from": [+ {"version": "0.1.0-preview.4", "arch_snapshot": "2026/10/01"}+ ]}diff --git a/os/release_update.py b/os/release_update.pynew file mode 100644index 000000000..c766145b4--- /dev/null+++ b/os/release_update.py@@ -0,0 +1,148 @@+#!/usr/bin/env python3+"""Discover and apply a published Harness OS package from the official channel.++The unprivileged screen may cache availability. Root independently fetches the+official metadata and verifies a private download before changing the machine.+TLS authenticates the release channel; SHA-256 verifies its published assets.+"""+from __future__ import annotations+import argparse+import hashlib+import importlib.util+import json+import os+from pathlib import Path+import re+import subprocess+import tempfile+from urllib.error import HTTPError+from urllib.parse import urlparse+from urllib.request import Request, urlopen++FEED = 'https://github.com/autonomous-ai/openharness/releases/download/os-preview-updates/metadata.json'+ASSETS = 'https://github.com/autonomous-ai/openharness/releases/download/'+LOCK = Path('/usr/share/harness-os/lock.json')+++def load_runtime_updater():+ spec = importlib.util.spec_from_file_location('harness_os_runtime_update', Path(__file__).with_name('runtime_update.py'))+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def fetch(url, maximum, fixture=False):+ parsed = urlparse(url)+ if parsed.username or parsed.password or not (parsed.scheme == 'https' or fixture and parsed.scheme == 'http' and parsed.hostname in ('127.0.0.1', 'localhost', '::1')):+ raise ValueError('System updates require HTTPS.')+ with urlopen(Request(url, headers={'User-Agent': 'Harness-OS-Updates/1'}), timeout=30) as response:+ if not fixture and urlparse(response.url).scheme != 'https':+ raise ValueError('System update redirected away from HTTPS.')+ data = response.read(maximum + 1)+ if len(data) > maximum:+ raise ValueError('System update exceeds its size limit.')+ return data+++def asset(value, maximum, fixture=False):+ if not isinstance(value, dict) or type(value.get('bytes')) is not int or not 0 < value['bytes'] <= maximum or not re.fullmatch(r'[a-f0-9]{64}', str(value.get('sha256', ''))):+ raise ValueError('Invalid system update asset.')+ url = value.get('url', '')+ if not isinstance(url, str):+ raise ValueError('Invalid system package URL.')+ parsed = urlparse(url)+ if not (url.startswith(ASSETS) or fixture and parsed.scheme == 'http' and parsed.hostname in ('localhost', '127.0.0.1', '::1')):+ raise ValueError('System packages must come from the official Harness release repository.')+ return value+++def verified(value, fixture=False):+ data = fetch(value['url'], value['bytes'], fixture)+ if len(data) != value['bytes'] or hashlib.sha256(data).hexdigest() != value['sha256']:+ raise ValueError('System update download failed its checksum or size check.')+ return data+++def discover(feed=FEED):+ fixture = feed != FEED+ try:+ metadata = json.loads(fetch(feed, 65536, fixture))+ except HTTPError as error:+ if error.code == 404:+ return None+ raise+ if not isinstance(metadata, dict) or metadata.get('schema') != 1 or metadata.get('channel') != 'preview' or metadata.get('architecture') != 'x86_64':+ raise ValueError('Invalid Harness OS update channel.')+ asset(metadata.get('manifest'), 1024 * 1024, fixture)+ asset(metadata.get('package'), 128 * 1024 * 1024, fixture)+ manifest = json.loads(verified(metadata['manifest'], fixture))+ if not isinstance(manifest, dict):+ raise ValueError('Invalid system package manifest.')+ package = manifest.get('package', {})+ if not isinstance(package, dict) or any(package.get(key) != metadata['package'][key] for key in ['bytes', 'sha256']):+ raise ValueError('System package and channel identity differ.')+ value = package.get('version', '')+ if not isinstance(value, str) or not re.fullmatch(r'[0-9A-Za-z.+_-]+', value):+ raise ValueError('Invalid system package version.')+ current = subprocess.check_output(['pacman', '-Q', 'harness-os'], text=True).strip().split()+ if len(current) != 2 or current[0] != 'harness-os' or not re.fullmatch(r'[0-9A-Za-z.+_-]+', current[1]):+ raise ValueError('Cannot identify the installed Harness system package.')+ newer = int(subprocess.check_output(['vercmp', value, current[1]], text=True)) > 0+ if newer:+ base = json.loads(LOCK.read_text())+ load_runtime_updater().validate_base(manifest, base)+ return {'available': newer, 'version': value, 'manifest': manifest, 'assets': metadata, 'feed': feed}+++def apply(feed=FEED):+ if os.geteuid() != 0 or Path('/etc/harness-live').exists():+ raise ValueError('Use sudo on the installed Harness computer.')+ release = discover(feed)+ if not release or not release['available']:+ print('Your Harness system is up to date.')+ return+ updater = load_runtime_updater()+ system = updater.system_module()+ # Never trust the UI's user-owned download or cached availability as root.+ with tempfile.TemporaryDirectory(prefix='harness-system-update-') as temporary:+ folder = Path(temporary)+ manifest = release['manifest']+ name = manifest['package'].get('name', '')+ if not re.fullmatch(r'harness-os-[0-9A-Za-z.+_-]+-x86_64\.pkg\.tar\.gz', name):+ raise ValueError('Invalid system package filename.')+ (folder / name).write_bytes(verified(release['assets']['package'], feed != FEED))+ (folder / 'package-manifest.json').write_text(json.dumps(manifest))+ with system.operation_lock():+ installation = system.installed()+ previous = updater.latest()+ if previous and previous['status'] not in ('applied', 'rolled-back'):+ raise ValueError('Restore the previous Harness package before starting another system update.')+ base = json.loads(LOCK.read_text())+ updater.validate_bundle(folder, base)+ date = system.snapshot_date(manifest['arch_snapshot'])+ text = system.PACMAN_CONFIG.read_text()+ dates = set(re.findall(r'https://archive\.archlinux\.org/repos/(\d{4}/\d{2}/\d{2})/', text))+ if len(dates) != 1:+ raise ValueError('Custom repository configuration needs a manual full system upgrade.')+ current = next(iter(dates))+ if system.pending_update() or date > current:+ system.update(max(current, date))+ updater.apply(folder, system, base, installation)+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('action', choices=['check', 'apply'])+ parser.add_argument('--feed', default=FEED, help='Explicit development feed; installed UI always uses the official channel')+ args = parser.parse_args()+ if args.action == 'check':+ print(json.dumps(discover(args.feed)))+ else:+ apply(args.feed)+++if __name__ == '__main__':+ try:+ main()+ except (ValueError, OSError, KeyError, TypeError, subprocess.SubprocessError) as error:+ raise SystemExit('Harness system update: ' + str(error))diff --git a/os/root/usr/bin/harness b/os/root/usr/bin/harnessindex 827bbcce5..139bf0d8c 100644--- a/os/root/usr/bin/harness+++ b/os/root/usr/bin/harness@@ -5,11 +5,20 @@ if [ "${1:-}" = install ]; thenfiif [ "${1:-}" = upgrade ]; thenshift+ if [ "$#" = 0 ]; then+ exec /usr/bin/python3 /usr/lib/harness-os/release_update.py apply+ fiexec /usr/bin/python3 /usr/lib/harness-os/runtime_update.py apply "$@"fiif [ "${1:-}" = rollback ]; thenshiftexec /usr/bin/python3 /usr/lib/harness-os/runtime_update.py rollback "$@"fi+if [ "${1:-}" = updates ]; then+ shift+ exec /usr/bin/python3 /usr/lib/harness-os/live_update.py "$@"+fi+. /usr/lib/harness-os/runtime-path+# The OS owns activation so an update cannot race its systemd supervisor.export ADAPTER_UPDATE_DISABLE=true-exec /usr/bin/node /usr/lib/harness/cli.mjs "$@"+exec /usr/bin/node "$harness_runtime/cli.mjs" "$@"diff --git a/os/root/usr/bin/hn b/os/root/usr/bin/hnindex 484395a31..ea022fd6d 100644--- a/os/root/usr/bin/hn+++ b/os/root/usr/bin/hn@@ -1,13 +1,16 @@#!/bin/sh-export HARNESS_TUI_BIN=/usr/lib/harness/hn+. /usr/lib/harness-os/runtime-path# The OS already supervises the daemon. Run the native client directly instead# of keeping a second Node process resident for the lifetime of the screen.export HARNESS_CLI=/usr/bin/harnessexport HARNESS_CLI_ARGS='[]'+# This computer's working tabs must survive an update without a cloud account or+# network. hn's ordinary local sessions retain their complete pane references.+export HARNESS_TUI_DESK=offif [ -f /etc/harness-live ]; thenexport HARNESS_OS_LIVE=1export HARNESS_TUI_TMUX_CONF=/usr/share/harness-os/tmux-live.confelseunset HARNESS_OS_LIVEfi-exec /usr/lib/harness/hn "$@"+exec "$harness_runtime/hn" "$@"diff --git a/os/root/usr/lib/harness-os/open-updates b/os/root/usr/lib/harness-os/open-updatesnew file mode 100644index 000000000..025044a65--- /dev/null+++ b/os/root/usr/lib/harness-os/open-updates@@ -0,0 +1,4 @@+#!/bin/sh+# Reuse hn's existing surface, including when the browser has focus.+[ ! -f /etc/harness-live ] || exit 0+hn select-window -t Updates 2>/dev/null || hn new-window -n Updates '/usr/bin/harness updates'diff --git a/os/root/usr/lib/harness-os/runtime-path b/os/root/usr/lib/harness-os/runtime-pathnew file mode 100644index 000000000..9c0d13709--- /dev/null+++ b/os/root/usr/lib/harness-os/runtime-path@@ -0,0 +1,12 @@+#!/bin/sh+# Sourced by the two OS launchers. Fast updates are per-user and never replace+# pacman's packaged fallback. Privileged commands always use packaged code.+harness_runtime=/usr/lib/harness+if [ "$(id -u)" != 0 ] && [ ! -f /etc/harness-live ]; then+ harness_candidate="$HOME/.local/state/harness-os/updates/current"+ if [ -x "$harness_candidate/harness-tui" ] && [ -f "$harness_candidate/cli.mjs" ] && [ -f "$harness_candidate/notify.mjs" ] &&+ cmp -s "$harness_candidate/base.json" /usr/share/harness-os/runtime.json; then+ harness_runtime=$harness_candidate+ fi+fi+export HARNESS_TUI_BIN="$harness_runtime/hn"diff --git a/os/root/usr/lib/harness-os/session b/os/root/usr/lib/harness-os/sessionindex 75095fa7c..6a181d3fe 100644--- a/os/root/usr/lib/harness-os/session+++ b/os/root/usr/lib/harness-os/session@@ -20,9 +20,20 @@ mkdir -p "$HOME/.local/bin" "$HOME/Projects" "$HOME/.local/state/harness-os"# Use the systemd user's existing bus so activation and the compositor share one# environment. A second dbus-run-session bus would split those services.export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"+# The graphical keyboard belongs to Wayland. In particular, an autologin TTY+# must not interpret Ctrl+C as SIGINT for the compositor's foreground group.+# Restore the console before using hn's text fallback or leaving the session.+tty_state=$(stty -g 2>/dev/null || true)+restore_tty() {+ if [ -n "$tty_state" ]; then stty "$tty_state" 2>/dev/null || true; fi+}+trap restore_tty EXIT+if [ -n "$tty_state" ]; then stty -echo -icanon -isig; fiif labwc -C /usr/share/harness-os/labwc > "$HOME/.local/state/harness-os/display.log" 2>&1; thenexit 0fi+restore_tty+trap - EXIT# A missing/broken GPU driver must not strand the programmer at a blank screen.# Stay in hn on the Linux console; an agent can install drivers and arrange a reboot.systemctl --user stop harness-os.target || truediff --git a/os/root/usr/lib/systemd/user/harness-os.target b/os/root/usr/lib/systemd/user/harness-os.targetindex a50598f1c..0a05254e0 100644--- a/os/root/usr/lib/systemd/user/harness-os.target+++ b/os/root/usr/lib/systemd/user/harness-os.target@@ -1,4 +1,4 @@[Unit]Description=The hn screen-Wants=hn-screen.service harness-idle.service+Wants=hn-screen.service harness-idle.service harness-update.timerAfter=graphical-session-pre.targetdiff --git a/os/root/usr/lib/systemd/user/harness-update.service b/os/root/usr/lib/systemd/user/harness-update.servicenew file mode 100644index 000000000..43f752b41--- /dev/null+++ b/os/root/usr/lib/systemd/user/harness-update.service@@ -0,0 +1,9 @@+[Unit]+Description=Check and prepare Harness updates+ConditionPathExists=!/etc/harness-live++[Service]+Type=oneshot+ExecStart=/usr/bin/python3 /usr/lib/harness-os/live_update.py check+TimeoutStartSec=3min+Nice=10diff --git a/os/root/usr/lib/systemd/user/harness-update.timer b/os/root/usr/lib/systemd/user/harness-update.timernew file mode 100644index 000000000..238854688--- /dev/null+++ b/os/root/usr/lib/systemd/user/harness-update.timer@@ -0,0 +1,11 @@+[Unit]+Description=Check Harness releases during the day+ConditionPathExists=!/etc/harness-live++[Timer]+OnStartupSec=2min+OnUnitInactiveSec=15min+RandomizedDelaySec=30s++[Install]+WantedBy=default.targetdiff --git a/os/root/usr/lib/systemd/user/hn-screen.service b/os/root/usr/lib/systemd/user/hn-screen.serviceindex d4c3ae472..70b52defc 100644--- a/os/root/usr/lib/systemd/user/hn-screen.service+++ b/os/root/usr/lib/systemd/user/hn-screen.service@@ -10,6 +10,7 @@ Type=execEnvironment=ADAPTER_UPDATE_DISABLE=trueEnvironment=HARNESS_TUI_BIN=/usr/lib/harness/hnEnvironment=HARNESS_TUI_NOTIFY=off+Environment=HARNESS_TUI_DESK=offEnvironment=HARNESS_TUI_TMUX_CONF=/usr/share/harness-os/tmux.confEnvironment=PATH=%h/.local/bin:/usr/local/bin:/usr/binEnvironment=npm_config_prefix=%h/.localdiff --git a/os/root/usr/lib/tmpfiles.d/harness-os.conf b/os/root/usr/lib/tmpfiles.d/harness-os.confnew file mode 100644index 000000000..6bda91aca--- /dev/null+++ b/os/root/usr/lib/tmpfiles.d/harness-os.conf@@ -0,0 +1 @@+f /run/lock/hn-os.lock 0644 root root -diff --git a/os/root/usr/share/harness-os/AGENTS.md b/os/root/usr/share/harness-os/AGENTS.mdindex c01eae762..68e0b8913 100644--- a/os/root/usr/share/harness-os/AGENTS.md+++ b/os/root/usr/share/harness-os/AGENTS.md@@ -10,6 +10,12 @@ is required.## System operations+- `Super+U` opens Updates inside hn; `harness updates` is the shell equivalent.+ The user timer checks hn and CLI releases and prepares verified downloads.+ Activation is explicit. An hn-only change restarts its screen, keeping terminal+ owners and agents alive. System packages use the separate checkpointed action.+ Do not replace `/usr/lib/harness` manually or enable the CLI's independent+ daemon handoff updater: this OS supervises activation with systemd.- This is Arch Linux with systemd, the LTS kernel, labwc, foot and Chromium.- Use the ordinary package manager; no private package ecosystem is required.On the live USB, `sudo systemctl start harness-keyring` waits for its one-timediff --git a/os/root/usr/share/harness-os/labwc/rc.xml b/os/root/usr/share/harness-os/labwc/rc.xmlindex f3f9700d4..6fde89d62 100644--- a/os/root/usr/share/harness-os/labwc/rc.xml+++ b/os/root/usr/share/harness-os/labwc/rc.xml@@ -17,6 +17,10 @@<keybind key="W-Return"><action name="ForEach"><query identifier="hn" /><then><action name="Raise" /><action name="Focus" /></then></action></keybind><keybind key="A-Tab"><action name="NextWindowImmediate" /></keybind><keybind key="W-l"><action name="Execute" command="swaylock -f -c 000000" /></keybind>+ <keybind key="W-u">+ <action name="Execute" command="/usr/lib/harness-os/open-updates" />+ <action name="ForEach"><query identifier="hn" /><then><action name="Raise" /><action name="Focus" /></then></action>+ </keybind><keybind key="XF86MonBrightnessUp"><action name="Execute" command="brightnessctl set +5%" /></keybind><keybind key="XF86MonBrightnessDown"><action name="Execute" command="brightnessctl set 5%-" /></keybind><keybind key="XF86AudioRaiseVolume"><action name="Execute" command="wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ -l 1" /></keybind>diff --git a/os/root/usr/share/harness-os/tmux-live.conf b/os/root/usr/share/harness-os/tmux-live.confindex 6ea5f2822..54feb2d97 100644--- a/os/root/usr/share/harness-os/tmux-live.conf+++ b/os/root/usr/share/harness-os/tmux-live.conf@@ -1,3 +1,4 @@# Direct system actions remain available while trying an agent from USB.source-file /usr/share/harness-os/tmux.conf+unbind Ubind I new-window -n Install 'sudo /usr/bin/harness install'diff --git a/os/root/usr/share/harness-os/tmux.conf b/os/root/usr/share/harness-os/tmux.confindex db68a5514..83c158baa 100644--- a/os/root/usr/share/harness-os/tmux.conf+++ b/os/root/usr/share/harness-os/tmux.conf@@ -3,6 +3,9 @@ unbind dunbind Dunbind C-zbind W new-window -n Wi-Fi '/usr/bin/hn-os wifi'+bind U new-window -n Updates '/usr/bin/harness updates'+set -g status-right '#{@harness-update} "#H" %H:%M'+set -g status-right-length 60set -g @hn-animations offset -g exit-empty offset -g exit-unattached offdiff --git a/os/root/usr/share/plymouth/themes/harness/harness.script b/os/root/usr/share/plymouth/themes/harness/harness.scriptindex 8ae946067..2060e1173 100644--- a/os/root/usr/share/plymouth/themes/harness/harness.script+++ b/os/root/usr/share/plymouth/themes/harness/harness.script@@ -3,7 +3,8 @@Window.SetBackgroundTopColor(0.063, 0.063, 0.063);Window.SetBackgroundBottomColor(0.063, 0.063, 0.063);-logo_text = " _ \n| |__ __ _ _ __ _ __ ___ ___ ___\n| '_ \\ / _` | '__| '_ \\ / _ \\/ __/ __|\n| | | | (_| | | | | | | __/\\__ \\__ \\\n|_| |_|\\__,_|_| |_| |_|\\___||___/___/";+# ASCII keeps the early-boot wordmark legible on the minimal text renderer.+logo_text = " _ _ _ ____ _ _ _____ ____ ____ \n| | | | / \\ | _ \\| \\ | | ____/ ___/ ___|\n| |_| | / _ \\ | |_) | \\| | _| \\___ \\___ \\\n| _ |/ ___ \\| _ <| |\\ | |___ ___) |__) |\n|_| |_/_/ \\_\\_| \\_\\_| \\_|_____|____/____/";logo_image = Image.Text(logo_text, 0.85, 0.78, 0.1, 1, "monospace 16", "left");logo = Sprite(logo_image);logo.SetPosition(Window.GetX() + (Window.GetWidth() - logo_image.GetWidth()) / 2,diff --git a/os/runtime_update.py b/os/runtime_update.pyindex a68cf5590..280f35389 100644--- a/os/runtime_update.py+++ b/os/runtime_update.py@@ -22,6 +22,7 @@ STATE = Path('/var/lib/harness-os/runtime-updates')RUNTIME = Path('/usr/share/harness-os/runtime.json')LOCK = Path('/usr/share/harness-os/lock.json')PACKAGE_DB = Path('/var/lib/pacman/local')+RESTART_REQUIRED = Path('/run/harness-os-restart-required')def digest(path):@@ -104,12 +105,25 @@ def inspect_package(path, version, runtime=None):raise ValueError('Runtime checksum mismatch: ' + name)-def validate_bundle(folder, base):- manifest = read_json(folder / 'package-manifest.json')+def validate_base(manifest, base):if not isinstance(manifest, dict) or manifest.get('schema') != 1 or manifest.get('kind') != 'harness-os-package':raise ValueError('Not a Harness package bundle.')- if manifest.get('architecture') != 'x86_64' or manifest.get('requires_os_version') != base['version'] or manifest.get('arch_snapshot') != base['arch_snapshot']:+ base_identity = {'version': base['version'], 'arch_snapshot': base['arch_snapshot']}+ same_base = manifest.get('requires_os_version') == base['version'] and manifest.get('arch_snapshot') == base['arch_snapshot']+ migrations = manifest.get('upgrades_from', [])+ if not isinstance(migrations, list) or len(migrations) > 32 or any(+ not isinstance(item, dict) or set(item) != {'version', 'arch_snapshot'} or+ not isinstance(item['version'], str) or not isinstance(item['arch_snapshot'], str) for item in migrations+ ):+ raise ValueError('Invalid system migration list.')+ migration = base_identity in migrations+ if manifest.get('architecture') != 'x86_64' or not (same_base or migration):raise ValueError('This package requires a different Harness base image or architecture.')+++def validate_bundle(folder, base):+ manifest = read_json(folder / 'package-manifest.json')+ validate_base(manifest, base)commit = manifest.get('source_commit', '')runtime = manifest.get('runtime', {})if not re.fullmatch(r'[0-9a-f]{40}', commit) or runtime.get('source_commit') != commit or runtime.get('dirty') is not False or runtime.get('target') != 'x86_64-unknown-linux-musl':@@ -207,6 +221,11 @@ def apply(folder, system, base, installation):if previous and previous['status'] not in ('applied', 'rolled-back'):raise ValueError('The previous Harness update did not finish. Run rollback first; its checkpoint is retained.')manifest, source_package = validate_bundle(folder, base)+ target_date = system.snapshot_date(manifest['arch_snapshot'])+ if target_date > base['arch_snapshot']:+ dates = set(re.findall(r'https://archive\.archlinux\.org/repos/(\d{4}/\d{2}/\d{2})/', system.PACMAN_CONFIG.read_text()))+ if len(dates) != 1 or next(iter(dates)) < target_date or system.pending_update():+ raise ValueError('Complete the full system upgrade to ' + target_date + ' before installing this package.')old_version, old_runtime = installed_version(), read_json(RUNTIME)if old_version == manifest['package']['version']:verify_runtime(manifest['runtime'])@@ -233,14 +252,22 @@ def apply(folder, system, base, installation):system.write_json(saved / 'receipt.json', receipt)system.write_json(STATE / 'latest.json', {'id': identity})try:+ # The fast user updater must not mix a running old session with newly+ # installed OS integration. /run clears this only on a real reboot.+ system.write_json(RESTART_REQUIRED, {'status': 'applying', 'package': manifest['package']['version']})install_package(incoming / source_package.name, manifest['package']['version'], manifest['runtime'])+ # Plymouth and other initramfs assets may change without a kernel+ # package transaction, so rebuild them on this path as well.+ system.run('mkinitcpio', '-P')except BaseException:receipt.update(status='failed', finished_at=now())system.write_json(saved / 'receipt.json', receipt)+ system.write_json(RESTART_REQUIRED, {'status': 'failed'})print('Update did not complete. Roll back with this same updater; the original checkpoint is retained.', file=sys.stderr)raisereceipt.update(status='applied', finished_at=now())system.write_json(saved / 'receipt.json', receipt)+ system.write_json(RESTART_REQUIRED, {'status': 'ready', 'package': manifest['package']['version']})print('Harness updated. Reboot when ready to use the new session. Your running work has not been restarted.')@@ -260,9 +287,12 @@ def rollback(system, installation):inspect_package(backup, receipt['previous_version'], receipt['previous_runtime'])receipt.update(status='rolling-back', rollback_started_at=now())system.write_json(folder / 'receipt.json', receipt)+ system.write_json(RESTART_REQUIRED, {'status': 'failed'})install_package(backup, receipt['previous_version'], receipt['previous_runtime'])+ system.run('mkinitcpio', '-P')receipt.update(status='rolled-back', rollback_finished_at=now())system.write_json(folder / 'receipt.json', receipt)+ system.write_json(RESTART_REQUIRED, {'status': 'ready', 'package': receipt['previous_version']})print('Previous Harness build restored. Reboot when ready to use it.')diff --git a/os/tests/build-update-fixture.py b/os/tests/build-update-fixture.pynew file mode 100644index 000000000..ab1131ca4--- /dev/null+++ b/os/tests/build-update-fixture.py@@ -0,0 +1,52 @@+#!/usr/bin/env python3+"""Build unpublished real runtimes for the private VM update feed. Never publish these."""+import hashlib+import json+import os+from pathlib import Path+import re+import shutil+import subprocess+import tempfile++source = Path(__file__).resolve().parents[2]+output = source / 'os/work/fast-update-fixture'+output.mkdir(parents=True, exist_ok=False)+fixture_version = '999.0.1'+base_url = 'http://127.0.0.1:19447/'+runtime = source / 'os/work/runtime'+# Keep the production runtime/package already built from clean source untouched.+with tempfile.TemporaryDirectory(prefix='harness-update-fixture-') as temporary:+ project = Path(temporary) / 'tui'+ shutil.copytree(source / 'tui', project, ignore=shutil.ignore_patterns('target', '.git'))+ manifest = project / 'Cargo.toml'+ manifest.write_text(re.sub(r'(?m)^version = "[^"]+"', f'version = "{fixture_version}"', manifest.read_text(), count=1))+ lock = project / 'Cargo.lock'+ lock.write_text(re.sub(r'(name = "harness-tui"\nversion = ")[^"]+', r'\g<1>' + fixture_version, lock.read_text()))+ subprocess.run(['cargo', 'build', '--locked', '--release', '--target', 'x86_64-unknown-linux-musl',+ '--manifest-path', str(manifest)], check=True,+ env=dict(os.environ, CARGO_TARGET_DIR=str(source / 'tui/target')))+ shutil.copyfile(source / 'tui/target/x86_64-unknown-linux-musl/release/harness-tui', output / 'harness-tui')+subprocess.run(['node', 'build-bundle.mjs'], cwd=source / 'cli', check=True,+ env=dict(os.environ, ADAPTER_VERSION=fixture_version))+shutil.copyfile(source / 'cli/dist/cli.js', output / 'cli.mjs')+shutil.copyfile(source / 'cli/dist/notify.mjs', output / 'notify.mjs')+shutil.copyfile(runtime / 'cli.js', output / 'cli-current.mjs')+current_cli = subprocess.check_output(['node', str(output / 'cli-current.mjs'), 'version'], text=True).strip()++def ref(name):+ data = (output / name).read_bytes()+ return {'url': base_url + name, 'sha256': hashlib.sha256(data).hexdigest(), 'size': len(data)}++documents = {+ 'hn.json': {'version': fixture_version, 'builds': {'linux-x64': ref('harness-tui')}},+ 'cli.json': {'cli': {'version': fixture_version, 'cli': ref('cli.mjs'), 'notify': ref('notify.mjs')}},+ 'cli-current.json': {'cli': {'version': current_cli, 'cli': ref('cli-current.mjs'), 'notify': ref('notify.mjs')}},+ 'feeds-hn.json': {'hn': base_url + 'hn.json', 'cli': base_url + 'cli-current.json'},+ 'feeds-both.json': {'hn': base_url + 'hn.json', 'cli': base_url + 'cli.json'},+}+for name, data in documents.items():+ (output / name).write_text(json.dumps(data) + '\n')+(output / 'fixture.json').write_text(json.dumps({'version': fixture_version, 'published': False,+ 'source_commit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),+ 'files': {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in output.iterdir() if p.is_file()}}, indent=2) + '\n')diff --git a/os/tests/essentials_vm.py b/os/tests/essentials_vm.pynew file mode 100644index 000000000..49fd355f6--- /dev/null+++ b/os/tests/essentials_vm.py@@ -0,0 +1,230 @@+#!/usr/bin/env python3+"""Exercise real network/audio plumbing in a disposable Harness VM.++The radio and audio codec are simulated hardware, not substitutes for physical+Wi-Fi reception, laptop backlight, speakers or microphone acceptance. Test-only+access point tools never enter the image or its installed payload.+"""+import argparse+import array+import hashlib+import json+import os+from pathlib import Path+import re+import shlex+import subprocess+import time+import wave+from session_vm import put, screen_text+from vm import VM++SSID = 'harness-test'+PASSWORD = 'wifi-test-123'+USER_ENV = 'runuser -u me -- env XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus '+++AP_SETUP = '''#!/bin/bash+set -euo pipefail+modprobe mac80211_hwsim radios=2+udevadm settle+mapfile -t phys < <(find /sys/class/ieee80211 -mindepth 1 -maxdepth 1 -printf '%f\\n' | sort)+test "${#phys[@]}" = 2+ip netns add harness-ap+iw phy "${phys[0]}" set netns name harness-ap+ap=$(ip netns exec harness-ap iw dev | awk '/Interface/{print $2; exit}')+station=$(iw dev | awk '/Interface/{print $2; exit}')+ip netns exec harness-ap ip link set lo up+ip netns exec harness-ap ip addr add 10.77.0.1/24 dev "$ap"+cat > /run/harness-ap.conf <<EOF+interface=$ap+driver=nl80211+ssid=harness-test+hw_mode=g+channel=1+wpa=2+wpa_key_mgmt=WPA-PSK+rsn_pairwise=CCMP+wpa_passphrase=wifi-test-123+EOF+chmod 600 /run/harness-ap.conf+ip netns exec harness-ap hostapd -B -P /run/harness-ap.pid -f /run/harness-ap.log /run/harness-ap.conf+ip netns exec harness-ap dnsmasq --interface="$ap" --bind-interfaces --except-interface=lo \\+ --dhcp-range=10.77.0.20,10.77.0.30,255.255.255.0,1h --dhcp-option=3,10.77.0.1 \\+ --dhcp-option=6,10.77.0.1 --address=/harness.test/10.77.0.1 --no-resolv \\+ --pid-file=/run/harness-dnsmasq.pid --log-facility=/run/harness-dnsmasq.log+mkdir -p /run/harness-network-test+printf '%s\\n' 'harness-wifi-success' > /run/harness-network-test/index.html+ip netns exec harness-ap python3 -m http.server 8080 --bind 10.77.0.1 \\+ --directory /run/harness-network-test > /run/harness-http.log 2>&1 &+nmcli radio wifi on+nmcli device set "$station" managed yes+printf '%s' "$station" > /run/harness-station+for n in $(seq 1 30); do+ if nmcli -t -f SSID device wifi list ifname "$station" | grep -Fx harness-test; then exit 0; fi+ sleep 1+done+exit 1+'''+++def wait_screen(vm, words, name, timeout=20):+ deadline = time.monotonic() + timeout+ while True:+ text = screen_text(vm, name)+ if all(word.lower() in text for word in words):+ return text+ if time.monotonic() >= deadline:+ raise AssertionError('Expected screen text not rendered: ' + repr(words) + '; saw: ' + text)+ time.sleep(.25)+++def wireless(vm, result):+ print('Preparing simulated WPA2 access point inside the disposable guest', flush=True)+ vm.command('systemctl start harness-keyring', timeout=240)+ output, _ = vm.command('pacman -S --needed --noconfirm hostapd dnsmasq iw', timeout=180)+ (vm.folder / 'test-only-packages.log').write_text(output)+ put(vm, '/tmp/harness-test-access-point', AP_SETUP)+ vm.command('bash /tmp/harness-test-access-point', timeout=60)+ # Make the actual wireless route necessary; serial control is independent.+ vm.command("nmcli -t -f DEVICE,TYPE device | awk -F: '$2 == \"ethernet\" {print $1}' > /run/harness-ethernet; "+ 'while read -r dev; do nmcli device disconnect "$dev"; nmcli device set "$dev" managed no; done < /run/harness-ethernet')+ vm.command('! ip route show default | grep -v "dev $(cat /run/harness-station)"')+ vm.command(USER_ENV + 'hn new-window -n Wi-Fi ' + shlex.quote('hn-os wifi'))+ wait_screen(vm, ['harness-test'], 'wifi-01-networks')+ # nmtui lists saved Ethernet profiles even when their device is unmanaged.+ # The first row is Wired connection 1; select the scanned wireless row.+ vm.keys('down')+ vm.keys('ret')+ wait_screen(vm, ['password'], 'wifi-02-password')+ vm.type_probe(PASSWORD)+ text = screen_text(vm, 'wifi-03-password-masked')+ assert PASSWORD not in text, 'Wi-Fi password was visible in the form'+ vm.keys('ret')+ vm.command('for n in $(seq 1 40); do '+ 'if nmcli -t -f GENERAL.STATE device show "$(cat /run/harness-station)" | grep -q "100"; then exit 0; fi; '+ 'sleep .5; done; exit 1', timeout=30)+ # A real HTTP response and DNS lookup through the radio, not a mocked state.+ output, _ = vm.command('ip route; resolvectl query harness.test; '+ 'test "$(curl --noproxy "*" -fsS --max-time 10 http://harness.test:8080)" = harness-wifi-success')+ (vm.folder / 'wifi-route-and-dns.txt').write_text(output)+ vm.screenshot('wifi-04-connected')+ vm.keys('esc')+ vm.command(USER_ENV + 'hn list-panes -a -F "#{pane_current_command}"')+ result['checks'].append('Actual hn Wi-Fi screen scans a simulated radio, masks WPA2 password, connects with DHCP and resolves/fetches HTTP over wireless with Ethernet disconnected')+ # Connection must survive a radio toggle, without another password prompt.+ vm.command('nmcli radio wifi off; sleep 1; nmcli radio wifi on; '+ 'for n in $(seq 1 45); do if curl --noproxy "*" -fsS --max-time 2 http://harness.test:8080 | '+ 'grep -Fx harness-wifi-success; then exit 0; fi; sleep 1; done; exit 1', timeout=100)+ vm.command('find /etc/NetworkManager/system-connections -name "*.nmconnection" -exec stat -c "%a %U %n" {} \\;')+ result['checks'].append('Wireless reconnects after a radio off/on cycle using its stored profile')+ # Cancel setup while offline, return to Harness, then reopen it.+ vm.command('nmcli device disconnect "$(cat /run/harness-station)"')+ vm.command(USER_ENV + 'hn new-window -n Try ' + shlex.quote('hn-os try'))+ wait_screen(vm, ['harness-test'], 'wifi-05-trial-offline')+ vm.keys('esc')+ wait_screen(vm, ['connect to wi-fi', 'press enter'], 'wifi-06-cancelled')+ vm.keys('ret')+ vm.command(USER_ENV + 'systemctl --user is-active --quiet hn-screen')+ vm.command('! pgrep -u 1000 -x opencode')+ result['checks'].append('Cancelling offline trial network setup explains how to connect and returns to Harness without launching a disconnected agent')+ vm.command('nmcli connection up ' + SSID, timeout=60)+ vm.command('while read -r dev; do nmcli device set "$dev" managed yes; nmcli device connect "$dev"; done < /run/harness-ethernet')+++def sound(vm, result):+ print('Checking PipeWire, media keys and audible samples from the virtual codec', flush=True)+ # wpctl get-volume can return zero while printing an unresolved default ID.+ # Wait for an actual output value as WirePlumber finishes codec discovery.+ vm.command(USER_ENV + 'sh -c ' + shlex.quote('for n in $(seq 1 30); do wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null | grep -q "^Volume:" && exit 0; sleep 1; done; exit 1'))+ def volume():+ output, _ = vm.command(USER_ENV + 'wpctl get-volume @DEFAULT_AUDIO_SINK@')+ match = re.search(r'Volume: ([0-9.]+)([^\r\n]*)', output)+ assert match, 'No default audio output'+ return float(match.group(1)), '[MUTED]' in match.group(2)+ vm.command(USER_ENV + 'wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.5')+ vm.command(USER_ENV + 'wpctl set-mute @DEFAULT_AUDIO_SINK@ 0')+ vm.keys('volumeup')+ time.sleep(.4)+ assert volume() == (.55, False), ('Volume up did not reach PipeWire', volume())+ vm.keys('volumedown')+ time.sleep(.4)+ assert volume() == (.5, False), ('Volume down did not reach PipeWire', volume())+ vm.keys('audiomute')+ time.sleep(.4)+ assert volume() == (.5, True), ('Mute did not reach PipeWire', volume())+ vm.keys('audiomute')+ time.sleep(.4)+ assert volume() == (.5, False), ('Unmute did not reach PipeWire', volume())+ tone = '''import array, math, wave+with wave.open('/tmp/harness-tone.wav', 'wb') as output:+ output.setnchannels(2); output.setsampwidth(2); output.setframerate(48000)+ samples = array.array('h', (int(12000 * math.sin(2*math.pi*440*n/48000)) for n in range(96000) for channel in range(2)))+ output.writeframes(samples.tobytes())+'''+ put(vm, '/tmp/harness-tone.py', tone)+ vm.command('python3 /tmp/harness-tone.py')+ vm.command(USER_ENV + 'pw-play /tmp/harness-tone.wav')+ output, _ = vm.command(USER_ENV + 'wpctl status')+ (vm.folder / 'audio-routing.txt').write_text(output)+ result['checks'].append('Volume up/down and mute/unmute key events change the real PipeWire default output, and pw-play completes on the virtual HDA codec')+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--iso', type=Path, required=True)+ parser.add_argument('--output', type=Path, default=Path('os/test-results/essentials'))+ args = parser.parse_args()+ if not os.access('/dev/kvm', os.R_OK | os.W_OK):+ parser.error('Use native x86 KVM for these hardware-plumbing checks.')+ iso = args.iso.resolve()+ manifest = json.loads(iso.with_name('manifest.json').read_text())+ with iso.open('rb') as handle:+ assert hashlib.file_digest(handle, 'sha256').hexdigest() == manifest['iso']['sha256']+ folder = args.output.resolve()+ folder.mkdir(parents=True, exist_ok=False)+ vm = VM(folder, iso, 'bios', 2048, audio=True)+ result = {'status': 'running', 'scope': 'simulated wireless and audio, not physical hardware',+ 'image_source_commit': manifest['source_commit'], 'iso_sha256': manifest['iso']['sha256'],+ 'test_source_commit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),+ 'started_at_unix': time.time(), 'checks': []}+ try:+ vm.start(live=True)+ vm.wait(r'root@[^\r\n]*[#] ')+ vm.shell_ready = True+ vm.command('stty -echo')+ vm.command(USER_ENV + '/usr/lib/harness-os/wait-runtime')+ vm.command(USER_ENV + 'sh -c ' + shlex.quote('for n in $(seq 1 60); do systemctl --user is-active --quiet hn-screen && pgrep -u 1000 -x foot >/dev/null && exit 0; sleep .25; done; exit 1'))+ sound(vm, result)+ wireless(vm, result)+ vm.stop()+ with wave.open(str(folder / 'audio-1.wav'), 'rb') as recording:+ samples = array.array('h', recording.readframes(recording.getnframes()))+ assert samples and max(abs(v) for v in samples) > 100, 'The virtual audio backend received silence'+ result['captured_audio'] = {'sample_rate': recording.getframerate(), 'frames': recording.getnframes(),+ 'peak': max(abs(v) for v in samples)}+ result['checks'].append('QEMU captures non-silent PCM samples produced through the guest audio stack')+ result['status'] = 'passed'+ except BaseException as error:+ result['status'], result['error'] = 'failed', str(error)+ if vm.process and vm.process.poll() is None:+ try:+ vm.screenshot('failure')+ output, _ = vm.command('journalctl -b -u NetworkManager --no-pager; '+ 'cat /run/harness-ap.log /run/harness-dnsmasq.log /run/harness-http.log; '+ 'ip address; ip route; nmcli device; ' + USER_ENV + 'wpctl status', check=False, timeout=20)+ (folder / 'diagnostics.log').write_text(output)+ except Exception:+ pass+ raise+ finally:+ result['finished_at_unix'] = time.time()+ (folder / 'receipt.json').write_text(json.dumps(result, indent=2) + '\n')+ vm.stop()+ vm.log.close()+ vm.stderr.close()+ vm.control.cleanup()+++if __name__ == '__main__':+ main()diff --git a/os/tests/fast_update_vm.py b/os/tests/fast_update_vm.pynew file mode 100644index 000000000..ecaf249b0--- /dev/null+++ b/os/tests/fast_update_vm.py@@ -0,0 +1,132 @@+"""Keyboard acceptance on the installed VM, using real private test releases."""+import json+import shlex+import subprocess+import time+from session_vm import put, screen_text, PROBE+++def wait_text(vm, text, name, status_bar=False):+ def observed():+ if not status_bar:+ return screen_text(vm, name)+ # Full-screen OCR skips this small status text. Include foot's bottom+ # padding so the crop retains the complete glyphs, not just their tails.+ from PIL import Image+ vm.screenshot(name)+ with Image.open(vm.folder / (name + '.png')) as frame:+ bar = frame.crop((0, frame.height - 32, frame.width, frame.height))+ bar.resize((bar.width * 3, bar.height * 3)).save(vm.folder / (name + '-bar.png'))+ result = subprocess.check_output(['tesseract', str(vm.folder / (name + '-bar.png')),+ 'stdout', '--psm', '7'], text=True,+ stderr=subprocess.DEVNULL, timeout=10)+ (vm.folder / (name + '-bar.txt')).write_text(result)+ return ' '.join(result.lower().split())++ deadline = time.monotonic() + 25+ while text.lower() not in observed():+ if time.monotonic() > deadline:+ raise AssertionError('Missing update screen: ' + text)+ time.sleep(.25)+++def exercise(vm, fixture, host_url):+ vm.command('sudo nmcli networking on')+ vm.command('nm-online -q --timeout=30', timeout=35)+ vm.command('mkdir -p /tmp/fast-updates')+ for path in fixture.iterdir():+ if path.is_file():+ vm.command('curl --fail --silent --show-error --retry 2 --retry-connrefused --max-time 90 ' ++ shlex.quote(host_url + '/fast/' + path.name) + ' -o ' + shlex.quote('/tmp/fast-updates/' + path.name), timeout=100)+ vm.command('systemd-run --user --collect --unit=harness-test-feed python3 -m http.server 19447 '+ '--bind 127.0.0.1 --directory /tmp/fast-updates')+ vm.command('for n in $(seq 1 30); do curl -fsS http://127.0.0.1:19447/fixture.json && exit 0; sleep .2; done; exit 1')+ # The radio/network can remain off: only the loopback test release is used.+ vm.command('sudo nmcli networking off')+ put(vm, '/tmp/update-session-probe.py', PROBE)+ vm.command('hn new-window -n update-probe ' + shlex.quote('python3 /tmp/update-session-probe.py'))+ vm.command('for n in $(seq 1 40); do test -s ~/Projects/session-probe/pid && exit 0; sleep .25; done; exit 1')+ vm.command('cp ~/Projects/session-probe/pid /tmp/fast-original-pid; cat /proc/$(cat /tmp/fast-original-pid)/stat > /tmp/fast-original-stat')+ vm.command('systemctl --user show harness-daemon -p MainPID --value > /tmp/fast-original-daemon')+ vm.command('hn new-window -n live-agent opencode')+ vm.command('for n in $(seq 1 80); do pgrep -u 1000 -x opencode > /tmp/fast-original-agent && exit 0; sleep .25; done; exit 1')+ vm.command('cat /proc/sys/kernel/random/boot_id > /tmp/fast-original-boot')+ vm.command('mkdir -p ~/.config/systemd/user/harness-update.service.d ~/.config/systemd/user/harness-update.timer.d')+ put(vm, '/tmp/update-service.conf', '[Service]\nExecStart=\nExecStart=/usr/bin/python3 /usr/lib/harness-os/live_update.py check --feeds /tmp/fast-updates/feeds-hn.json\n')+ put(vm, '/tmp/update-timer.conf', '[Timer]\nOnStartupSec=\nOnUnitInactiveSec=\nRandomizedDelaySec=0\nOnActiveSec=1s\n')+ vm.command('cp /tmp/update-service.conf ~/.config/systemd/user/harness-update.service.d/fixture.conf; '+ 'cp /tmp/update-timer.conf ~/.config/systemd/user/harness-update.timer.d/fixture.conf; '+ 'systemctl --user daemon-reload; systemctl --user restart harness-update.timer')+ state = '~/.local/state/harness-os/updates'+ vm.command('for n in $(seq 1 120); do test -s ' + state + '/ready.json && exit 0; sleep .5; done; '+ 'journalctl --user -u harness-update --no-pager; exit 1', timeout=75)+ wait_text(vm, 'update ready', 'fast-01-notice', status_bar=True)+ checks = ['User timer discovers, verifies and stages a real hn release without changing the running selection']+ vm.command('test ! -e ' + state + '/current')++ def alive(name):+ expression = '''from pathlib import Path+import time+pid = Path('/tmp/fast-original-pid').read_text().strip()+assert Path('/proc/'+pid+'/stat').read_text().split()[21] == Path('/tmp/fast-original-stat').read_text().split()[21]+root = Path.home() / 'Projects/session-probe'+before = (root/'heartbeat').stat().st_mtime_ns+time.sleep(.6)+assert (root/'heartbeat').stat().st_mtime_ns != before+'''+ vm.command('python3 -c ' + shlex.quote(expression))+ vm.command('while read -r pid; do kill -0 "$pid" || exit 1; done < /tmp/fast-original-agent; '+ 'cmp /tmp/fast-original-boot /proc/sys/kernel/random/boot_id')+ vm.command('for n in $(seq 1 80); do hn select-window -t update-probe && exit 0; sleep .25; done; exit 1')+ wait_text(vm, 'visible lock probe', name + '-restored')+ vm.type_probe(name)+ vm.keys('ret')+ vm.command('for n in $(seq 1 30); do grep -Fx ' + shlex.quote(name) ++ ' ~/Projects/session-probe/input && exit 0; sleep .1; done; exit 1')+ vm.screenshot(name + '-accepted-input')++ def activate(expect_failure=False):+ vm.keys('meta_l', 'u')+ # After a failed activation the same screen offers a retry.+ wait_text(vm, 'system updates', 'fast-02-update-action')+ vm.keys('ret')+ condition = ('grep -q ' + shlex.quote('"status": "failed"') + ' ' + state + '/transaction.json' if expect_failure else+ 'test ! -e ' + state + '/ready.json && test -s ' + state + '/applied.json')+ vm.command('for n in $(seq 1 120); do ' + condition + ' && systemctl --user is-active --quiet hn-screen && exit 0; sleep .5; done; '+ 'sudo journalctl _UID=1000 --no-pager; exit 1', timeout=90)++ # A real systemd start failure for the new binary must restore the old+ # selection and layout. The fault is a private guest-only unit override.+ vm.command('mkdir -p ~/.config/systemd/user/hn-screen.service.d')+ put(vm, '/tmp/hn-fail-new-screen.sh', '#!/bin/sh\n/usr/bin/hn --version | grep -q "hn 999.0.1 " && exit 1\nexit 0\n')+ put(vm, '/tmp/hn-screen-fault.conf', '[Service]\nExecStartPre=/bin/sh /tmp/hn-fail-new-screen.sh\n')+ vm.command('cp /tmp/hn-screen-fault.conf ~/.config/systemd/user/hn-screen.service.d/fixture.conf; systemctl --user daemon-reload')+ activate(expect_failure=True)+ vm.command('test ! -e ' + state + '/current; ! hn --version | grep -F "999.0.1"')+ alive('failed-update-restored')+ checks.append('A real new-screen start failure restores the previous binary and visible tabs while the same agent and terminal remain alive')+ vm.command('rm ~/.config/systemd/user/hn-screen.service.d/fixture.conf; systemctl --user daemon-reload')++ activate()+ vm.command('hn --version | grep -F "999.0.1"')+ vm.command('test "$(systemctl --user show harness-daemon -p MainPID --value)" = "$(cat /tmp/fast-original-daemon)"')+ alive('hn-update')+ checks.append('Super+U and Enter activate the real new hn binary; daemon PID, live OpenCode, terminal PID, keyboard input and boot ID survive')+ # Add a CLI release through the same channel, independently of hn's version.+ vm.command('harness updates check --feeds /tmp/fast-updates/feeds-both.json', timeout=90)+ activate()+ vm.command('test "$(harness version)" = 999.0.1')+ vm.command('test "$(systemctl --user show harness-daemon -p MainPID --value)" != "$(cat /tmp/fast-original-daemon)"')+ alive('cli-update')+ checks.append('A separate CLI release restarts its supervised service while the same OpenCode and terminal processes remain alive')+ vm.command('systemd-run --user --collect --unit=harness-test-rollback /usr/bin/python3 /usr/lib/harness-os/live_update.py rollback')+ vm.command('for n in $(seq 1 120); do test "$(harness version)" != 999.0.1 && '+ 'systemctl --user is-active --quiet hn-screen && exit 0; sleep .5; done; exit 1', timeout=90)+ alive('after-rollback')+ checks.append('Rollback restores the prior CLI while retaining the fast hn release, live agent and terminal input')+ output, _ = vm.command('harness updates status; systemctl --user status harness-update.timer --no-pager; '+ 'sudo journalctl _UID=1000 --no-pager')+ (vm.folder / 'fast-updates.log').write_text(output)+ receipt = {'status': 'passed', 'fixture': json.loads((fixture / 'fixture.json').read_text()), 'checks': checks}+ (vm.folder / 'fast-update-receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')+ return receiptdiff --git a/os/tests/release_update_vm.py b/os/tests/release_update_vm.pynew file mode 100644index 000000000..fec151e1e--- /dev/null+++ b/os/tests/release_update_vm.py@@ -0,0 +1,54 @@+"""Exercise the actual OS release transport on a disposable installed VM."""+import json+import shlex+from session_vm import put+++def exercise(vm, manifest):+ # Retain the new bootstrap outside pacman-owned paths before restoring the+ # public preview. It has no updater; this is its one-time migration path.+ vm.command('mkdir -p /tmp/system-channel; cp /usr/lib/harness-os/release_update.py '+ '/usr/lib/harness-os/runtime_update.py /tmp/system-channel/')+ vm.command('cp /home/me/update-bundle/package-manifest.json /tmp/fast-updates/; '+ 'cp /home/me/update-bundle/' + shlex.quote(manifest['package']['name']) + ' /tmp/fast-updates/')+ builder = '''import hashlib, json, pathlib+root = pathlib.Path('/tmp/fast-updates')+manifest = json.loads((root/'package-manifest.json').read_text())+def asset(name):+ data = (root/name).read_bytes()+ return dict(url='http://127.0.0.1:19447/'+name, bytes=len(data), sha256=hashlib.sha256(data).hexdigest())+metadata = dict(schema=1, channel='preview', architecture='x86_64',+ manifest=asset('package-manifest.json'), package=asset(manifest['package']['name']))+(root/'os-metadata.json').write_text(json.dumps(metadata))+'''+ put(vm, '/tmp/system-channel/make-feed.py', builder)+ vm.command('python3 /tmp/system-channel/make-feed.py')+ vm.command('sudo harness rollback', timeout=180)+ feed = ' --feed http://127.0.0.1:19447/os-metadata.json'+ updater = 'python3 /tmp/system-channel/release_update.py '+ def available(expected):+ vm.command(updater + 'check' + feed + ' > /tmp/system-channel/discovery.json')+ vm.command('python3 -c ' + shlex.quote("import json; assert json.load(open('/tmp/system-channel/discovery.json'))['available'] is " + str(expected)))+ available(True)+ checks = ['Restored public preview discovers the newer real OS package through the verified release manifest']+ package = '/tmp/fast-updates/' + manifest['package']['name']+ vm.command('cp ' + shlex.quote(package) + ' /tmp/good-os-package; printf broken > ' + shlex.quote(package))+ _, status = vm.command('sudo ' + updater + 'apply' + feed, timeout=180, check=False)+ assert status != 0, 'A corrupt channel package was accepted'+ checks.append('A corrupt download is rejected before the package transaction')+ vm.command('cp /tmp/good-os-package ' + shlex.quote(package))+ output, _ = vm.command('sudo ' + updater + 'apply' + feed, timeout=180)+ (vm.folder / 'system-channel-apply.log').write_text(output)+ vm.command('test "$(pacman -Q harness-os)" = ' + shlex.quote('harness-os ' + manifest['package']['version']))+ vm.command('while read -r pid; do kill -0 "$pid" || exit 1; done < /tmp/fast-original-agent; '+ 'kill -0 "$(cat /tmp/fast-original-pid)"; cmp /tmp/fast-original-boot /proc/sys/kernel/random/boot_id')+ vm.command('python3 -c ' + shlex.quote("import json; assert json.load(open('/run/harness-os-restart-required'))['status'] == 'ready'"))+ available(False)+ checks.append('Private root download applies offline from loopback, rebuilds initramfs, preserves live processes and offers no duplicate update')+ _, status = vm.command('harness updates apply', check=False)+ assert status != 0, 'Fast runtime changed before the OS restart'+ checks.append('Fast activation stays paused until the OS reboot')+ receipt = {'status': 'passed', 'source_commit': manifest['source_commit'],+ 'package': manifest['package'], 'checks': checks}+ (vm.folder / 'system-channel-receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')+ return receiptdiff --git a/os/tests/session_vm.py b/os/tests/session_vm.pynew file mode 100644index 000000000..da8781c80--- /dev/null+++ b/os/tests/session_vm.py@@ -0,0 +1,298 @@+#!/usr/bin/env python3+"""Observe locking and suspend/resume on a disposable installed Harness machine."""+import argparse+import base64+import hashlib+import json+import os+from pathlib import Path+import re+import shlex+import subprocess+import time+from vm import VM+++PROBE = '''import os, pathlib, sys, threading, time+root = pathlib.Path.home() / 'Projects/session-probe'+root.mkdir(exist_ok=True)+(root / 'pid').write_text(str(os.getpid()))+(root / 'input').write_text('')+def heartbeat():+ while True:+ (root / 'heartbeat').write_text(str(time.time_ns()))+ time.sleep(0.2)+threading.Thread(target=heartbeat, daemon=True).start()+print('HARNESS VISIBLE LOCK PROBE', flush=True)+for line in sys.stdin:+ with (root / 'input').open('a') as output: output.write(line)+ print('received: ' + line.rstrip(), flush=True)+'''+++def put(vm, path, data):+ encoded = base64.b64encode(data.encode()).decode()+ scratch = shlex.quote(path + '.base64')+ vm.command(': > ' + scratch)+ for start in range(0, len(encoded), 1800):+ vm.command('printf %s ' + encoded[start:start + 1800] + ' >> ' + scratch)+ vm.command('base64 -d ' + scratch + ' > ' + shlex.quote(path) + ' && rm ' + scratch)+++def screen_text(vm, name):+ vm.screenshot(name)+ text = subprocess.check_output(['tesseract', str(vm.folder / (name + '.png')), 'stdout', '--psm', '11'],+ text=True, stderr=subprocess.DEVNULL, timeout=10)+ (vm.folder / (name + '.txt')).write_text(text)+ return ' '.join(text.lower().split())+++def wait_lock(vm, locked, timeout=15):+ # -f returns only after the compositor acknowledges the lock, then its child+ # calls setsid(). A matching process alone includes the pre-lock parent/PAM+ # helper and can race the screen and keyboard grab.+ command = ("ps -u 1000 -o pid=,sid=,comm= | awk '$1 == $2 && $3 == \"swaylock\" {ready=1} END {exit !ready}'"+ if locked else '! pgrep -u 1000 -x swaylock >/dev/null')+ vm.command('for n in $(seq 1 ' + str(timeout * 4) + '); do if ' + command + '; then exit 0; fi; sleep 0.25; done; exit 1', timeout=timeout + 5)+++def live_lock(vm, user):+ """No password has been chosen on the USB; a lock must not strand the user."""+ results = []+ for name, trigger in [('shortcut', lambda: vm.keys('meta_l', 'l')),+ ('idle-event', lambda: vm.command('pkill -USR1 -u 1000 -x swayidle'))]:+ print('Checking live ' + name, flush=True)+ trigger()+ time.sleep(1)+ _, status = vm.command('pgrep -u 1000 -x swaylock', check=False)+ if status == 0:+ vm.screenshot('live-' + name + '-locked')+ vm.keys('ret')+ wait_lock(vm, False, timeout=10)+ results.append(name + ': live password lock exited after Enter with the empty live password')+ else:+ results.append(name + ': no password lock remained active on the passwordless live account')+ vm.command(user('systemctl --user is-active --quiet hn-screen'))+ vm.screenshot('live-after-lock-probe')+ return results+++def installed_session(vm, config, result):+ put(vm, '/tmp/harness-session-probe.py', PROBE)+ vm.command('hn new-window -n session-probe ' + shlex.quote('python3 /tmp/harness-session-probe.py'))+ vm.command('for n in $(seq 1 60); do test -s ~/Projects/session-probe/pid && test -s ~/Projects/session-probe/heartbeat && exit 0; sleep 0.25; done; exit 1')+ vm.command('cp ~/Projects/session-probe/pid /tmp/session-original-pid')+ time.sleep(1)+ assert 'visible lock probe' in screen_text(vm, 'session-before-lock'), 'The visible terminal probe was not rendered'+ accepted = []++ def work_survives():+ vm.command('test "$(cat ~/Projects/session-probe/pid)" = "$(cat /tmp/session-original-pid)" && kill -0 "$(cat /tmp/session-original-pid)"')+ vm.command('before=$(cat ~/Projects/session-probe/heartbeat); sleep 0.5; test "$before" != "$(cat ~/Projects/session-probe/heartbeat)"')+ expected = ''.join(word + '\n' for word in accepted)+ expression = ('from pathlib import Path; import time\n'+ 'p = Path.home()/"Projects/session-probe/input"\n'+ 'expected = ' + repr(expected) + '\n'+ 'deadline = time.monotonic() + 3\n'+ 'while p.read_text() != expected and time.monotonic() < deadline: time.sleep(.05)\n'+ 'actual = p.read_text()\n'+ 'assert actual == expected, (repr(actual), repr(expected))')+ vm.command('python3 -c ' + shlex.quote(expression))++ def unlock(name):+ wait_lock(vm, True)+ assert 'visible lock probe' not in screen_text(vm, name + '-locked'), 'Locked screen exposed terminal content'+ # These must go to the lock, never to the terminal or its agent.+ for label, keys in [('escape', ('esc',)), ('interrupt', ('ctrl', 'c')), ('clear', ('ctrl', 'u'))]:+ vm.keys(*keys)+ wait_lock(vm, True, timeout=2)+ work_survives()+ vm.screenshot(name + '-after-' + label)+ vm.type_probe('wrong-password')+ vm.keys('ret')+ time.sleep(4)+ wait_lock(vm, True)+ work_survives()+ vm.screenshot(name + '-wrong-password')+ vm.keys('ctrl', 'u')+ vm.type_probe(config['password'])+ vm.keys('ret')+ wait_lock(vm, False)+ deadline = time.monotonic() + 10+ while 'visible lock probe' not in screen_text(vm, name + '-unlocked'):+ if time.monotonic() >= deadline:+ raise AssertionError('Unlock did not restore the terminal')+ time.sleep(.25)+ work_survives()+ word = 'accepted-' + name+ vm.type_probe(word)+ vm.keys('ret')+ accepted.append(word)+ time.sleep(0.5)+ work_survives()+ vm.screenshot(name + '-accepted-input')++ vm.keys('meta_l', 'l')+ print('Checking installed manual lock', flush=True)+ unlock('manual')+ result['checks'].append('Super+L hides the terminal, rejects a wrong password and Esc/Ctrl+C, accepts the account password, and does not leak lock input into the running terminal')+ vm.command('systemctl --user is-active --quiet harness-idle && pkill -USR1 -u 1000 -x swayidle')+ print('Checking installed idle lock', flush=True)+ unlock('idle')+ result['checks'].append('The idle event runs the same working password lock; the test sends SIGUSR1 rather than waiting ten minutes')+ capabilities = vm.monitor('query-current-machine')+ assert capabilities.get('wakeup-suspend-support'), 'The test machine does not support QMP wake from suspend'+ output, _ = vm.command('cat /sys/power/state /sys/power/mem_sleep; systemd-inhibit --list --no-pager')+ (vm.folder / 'sleep-capabilities.txt').write_text(output)+ started = time.monotonic()+ print('Checking actual ACPI suspend and wake', flush=True)+ vm.command('sudo systemctl suspend --no-block')+ deadline = time.monotonic() + 30+ while time.monotonic() < deadline:+ status = vm.monitor('query-status')+ if status['status'] == 'suspended':+ break+ time.sleep(0.25)+ else:+ raise RuntimeError('The guest did not reach ACPI suspend; last QMP status: ' + json.dumps(status))+ result['suspend_seconds'] = round(time.monotonic() - started, 3)+ vm.screenshot('sleep-suspended')+ vm.monitor('system_wakeup')+ resumed = time.monotonic()+ # QMP acknowledges CPU wake before the guest UART is ready. Do not send a+ # command into its short hardware FIFO while the serial driver is resuming.+ # Only blank lines are retried; a real shell prompt acknowledges input.+ deadline = time.monotonic() + 30+ while True:+ vm.send('\n')+ try:+ vm.wait(r'\[me@harness [^\r\n]*\]\$ ', timeout=2)+ break+ except TimeoutError:+ if time.monotonic() >= deadline:+ raise TimeoutError('The guest serial console did not resume within 30 seconds')+ vm.command('true', timeout=60)+ unlock('resume')+ result['resume_check_seconds_including_wrong_password_and_automated_typing'] = round(time.monotonic() - resumed, 3)+ output, _ = vm.command('sudo journalctl -b -u systemd-suspend.service --no-pager; journalctl --user -b -u harness-idle --no-pager')+ (vm.folder / 'sleep-journal.log').write_text(output)+ result['checks'].append('Guest actually enters ACPI suspend and wakes through QMP; it resumes locked and the same terminal process, input and project survive password unlock')+ vm.command('hn kill-window')+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--iso', type=Path, required=True)+ parser.add_argument('--firmware', choices=['bios', 'uefi'], required=True)+ parser.add_argument('--output', type=Path)+ parser.add_argument('--video', choices=['VGA', 'virtio-vga'], default='VGA',+ help='QEMU display; bochs VGA has suspend/resume callbacks in the pinned LTS kernel')+ parser.add_argument('--session-file', type=Path,+ help='Explicitly test this candidate launcher over the verified base ISO; records its hash and reboots before checking')+ parser.add_argument('--theme-directory', type=Path,+ help='Explicitly test the candidate Plymouth theme after regenerating the installed initramfs')+ args = parser.parse_args()+ if not os.access('/dev/kvm', os.R_OK | os.W_OK):+ parser.error('Use native x86 KVM for session and suspend acceptance.')+ iso = args.iso.resolve()+ manifest = json.loads(iso.with_name('manifest.json').read_text())+ with iso.open('rb') as handle:+ assert hashlib.file_digest(handle, 'sha256').hexdigest() == manifest['iso']['sha256']+ folder = (args.output or Path('os/test-results') / (args.firmware + '-session')).resolve()+ folder.mkdir(parents=True, exist_ok=False)+ vm = VM(folder, iso, args.firmware, 2048, video=args.video)+ config = dict(disk='/dev/vda', expected_serial='HN_OS_TEST', confirm_erase='/dev/vda',+ username='me', hostname='harness', password='test-password-123',+ encrypt=args.firmware == 'uefi', serial_console=True)+ result = {'status': 'running', 'scope': 'password lock, input isolation and virtual ACPI suspend/resume',+ 'firmware': args.firmware, 'encrypted': config['encrypt'], 'memory_mib': 2048,+ 'video': args.video,+ 'iso_sha256': manifest['iso']['sha256'], 'image_source_commit': manifest['source_commit'],+ 'test_source_commit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),+ 'started_at_unix': time.time(), 'checks': []}+ user = lambda command: 'runuser -u me -- env XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus ' + command+ try:+ print('Booting the verified image for live-session checks', flush=True)+ vm.start(live=True)+ vm.wait(r'root@[^\r\n]*[#] ')+ vm.shell_ready = True+ vm.command('stty -echo')+ vm.command(user('/usr/lib/harness-os/wait-runtime'))+ vm.command(user('systemctl --user is-active --quiet hn-screen harness-idle'))+ time.sleep(2)+ try:+ result['live_lock_observations'] = live_lock(vm, user)+ except Exception as error:+ result['live_lock_error'] = str(error)+ vm.screenshot('live-lock-failure')+ # Recover this disposable fixture so installed locking can still be diagnosed.+ vm.command('pkill -u 1000 -x swaylock || true')+ put(vm, '/tmp/install-config.json', json.dumps(config))+ vm.command('nmcli networking off')+ print('Installing offline into the disposable test disk', flush=True)+ output, _ = vm.command('harness install --config /tmp/install-config.json --yes-erase-disk', timeout=360)+ (folder / 'install.log').write_text(output)+ vm.command('sync')+ vm.stop()+ vm.start(live=False)+ print('Booting the installed session', flush=True)+ vm.login_installed(config)+ vm.command('printf %s ' + shlex.quote(config['password'] + '\n') + ' | sudo -S -v')+ tty_probe = "sudo -n stty -a -F /dev/tty1; ps -u 1000 -o pid,ppid,sid,tpgid,tty,comm --width 200"+ output, _ = vm.command(tty_probe)+ (folder / 'base-console-state.txt').write_text(output)+ if args.session_file:+ candidate = args.session_file.read_bytes()+ result['candidate_session'] = {'path': str(args.session_file), 'sha256': hashlib.sha256(candidate).hexdigest(),+ 'scope': 'Only /usr/lib/harness-os/session replaced in disposable installed guest; other files are the verified base image'}+ put(vm, '/tmp/session-candidate', candidate.decode())+ vm.command('test "$(sha256sum /tmp/session-candidate | cut -d " " -f 1)" = ' + shlex.quote(result['candidate_session']['sha256']))+ vm.command('sudo install -o root -g root -m 755 /tmp/session-candidate /usr/lib/harness-os/session; sync')+ if args.theme_directory and config['encrypt']:+ result['candidate_theme'] = {'path': str(args.theme_directory), 'files': {}}+ for name in ['harness.plymouth', 'harness.script']:+ candidate = (args.theme_directory / name).read_bytes()+ checksum = hashlib.sha256(candidate).hexdigest()+ result['candidate_theme']['files'][name] = checksum+ put(vm, '/tmp/' + name, candidate.decode())+ vm.command('test "$(sha256sum /tmp/' + name + ' | cut -d " " -f 1)" = ' + shlex.quote(checksum))+ vm.command('sudo install -o root -g root -m 644 /tmp/' + name + ' /usr/share/plymouth/themes/harness/' + name)+ output, _ = vm.command('sudo mkinitcpio -P && sudo lsinitcpio -l /boot/initramfs-linux-lts.img | grep -E "Plymouth.*ttf|harness\\.(script|plymouth)"', timeout=180)+ (folder / 'candidate-initramfs.txt').write_text(output)+ if args.session_file or (args.theme_directory and config['encrypt']):+ # VM.stop is a power cut, not an orderly guest shutdown. Flush the+ # rebuilt initramfs before testing that exact candidate at boot.+ vm.command('sync')+ vm.stop()+ vm.start(live=False)+ vm.login_installed(config)+ vm.command('printf %s ' + shlex.quote(config['password'] + '\n') + ' | sudo -S -v')+ output, _ = vm.command(tty_probe)+ (folder / 'candidate-console-state.txt').write_text(output)+ installed_session(vm, config, result)+ assert 'live_lock_error' not in result, 'The unconfigured live session could not be unlocked'+ result['status'] = 'passed'+ except BaseException as error:+ result['status'] = 'failed'+ result['error'] = str(error)+ try:+ vm.screenshot('failure')+ if vm.shell_ready:+ output, _ = vm.command('sudo -n journalctl -b -o short-monotonic --no-pager; '+ 'cat ~/.local/state/harness-os/display.log; ps -eo pid,ppid,sid,comm,args --width 240; '+ 'cat /sys/class/drm/card*-*/status /sys/class/drm/card*-*/dpms; '+ 'sudo -n sh -c "cat /sys/kernel/debug/dri/*/state"; '+ 'cat ~/Projects/session-probe/input',+ check=False, timeout=15)+ (folder / 'session-diagnostics.log').write_text(output)+ except Exception:+ pass+ raise+ finally:+ result['finished_at_unix'] = time.time()+ (folder / 'receipt.json').write_text(json.dumps(result, indent=2) + '\n')+ vm.stop()+++if __name__ == '__main__':+ main()diff --git a/os/tests/test_installer.py b/os/tests/test_installer.pyindex 6b8ac93f8..58a01e389 100644--- a/os/tests/test_installer.py+++ b/os/tests/test_installer.py@@ -5,6 +5,8 @@ import ioimport jsonfrom pathlib import Pathimport tempfile+import subprocess+import sysimport unittestfrom unittest.mock import patch@@ -167,6 +169,9 @@ class InteractiveInstall(unittest.TestCase):self.output = io.StringIO()context.enter_context(redirect_stdout(self.output))self.argv = ['install.py']+ log_directory = context.enter_context(tempfile.TemporaryDirectory())+ context.enter_context(patch.object(installer, 'INSTALL_LOG', Path(log_directory) / 'install.log'))+ context.enter_context(patch.object(installer, 'LAST_LOG', None))context.enter_context(patch.object(installer.sys, 'argv', self.argv))context.enter_context(patch.object(installer.os, 'geteuid', return_value=0))self.disk = dict(name='/dev/vda', type='disk', ro=False, size=32 * 1024**3,@@ -269,10 +274,25 @@ class InteractiveInstall(unittest.TestCase):config = self.install.call_args.args[0]self.assertEqual((config['disk'], config['confirm_erase'], config['expected_serial']),('/dev/vdb', '/dev/vdb', 'SECOND_DISK'))- picker = next(f for f in self.screen.frames if f.startswith('Select disk'))+ picker = next(f for f in self.screen.frames if 'Select disk' in f.splitlines())disk_rows = [r for r in picker.splitlines() if '/dev/' in r]self.assertEqual(len(disk_rows), 2)self.assertTrue(all('Test SSD' in r and 'GB' in r for r in disk_rows))+ self.assertTrue(any('vdb' in row for row in self.screen.frames[-1].splitlines() if row.startswith('Disk')))++ def test_long_disk_model_keeps_size_and_device_visible_on_a_small_screen(self):+ self.screen.size = (18, 54)+ self.disk['model'] = 'A very long manufacturer and model name' * 3+ self.screen.keys.extend(['\n', '\n'])+ self.fill_passwords()+ self.confirm()+ installer.main()+ picker = next(f for f in self.screen.frames if 'Select disk' in f.splitlines())+ disk_row = next(row for row in picker.splitlines() if '/dev/' in row)+ self.assertIn('34.4 GB', disk_row)+ self.assertTrue(disk_row.endswith('/dev/vda'))+ self.assertIn('…', disk_row)+ self.assertTrue(any('34.4 GB' in row for row in self.screen.frames[-1].splitlines() if row.startswith('Disk')))def test_escaping_disk_picker_preserves_original_selection(self):self.inventory.return_value.append(dict(self.disk, name='/dev/vdb', serial='SECOND_DISK'))@@ -383,5 +403,58 @@ class InstallerExit(unittest.TestCase):acknowledge.assert_not_called()+class InstallerOutput(unittest.TestCase):+ def test_display_resize_does_not_abort_installation(self):+ config = dict(username='me', hostname='harness', encrypt=True)+ screen = Screen()+ with tempfile.TemporaryDirectory() as temp, \+ patch.object(installer, 'INSTALL_LOG', Path(temp) / 'install.log'), \+ patch.object(installer, 'LAST_LOG', None), \+ patch.object(installer.curses, 'curs_set'), \+ patch.object(screen, 'erase', side_effect=installer.curses.error), \+ patch.object(installer, 'install', side_effect=lambda *args, progress: progress('Copying Harness…')) as install:+ installer.install_with_progress(screen, config, Path('/unused'), Path('/unused-target'))+ install.assert_called_once()+ self.assertIn('Copying Harness…', installer.INSTALL_LOG.read_text())++ def test_command_log_retains_diagnostics_and_excludes_password_input(self):+ with tempfile.TemporaryDirectory() as temp:+ log = Path(temp) / 'install.log'+ log.write_text('stale log')+ log.chmod(0o644)+ with installer.command_log(log):+ installer.run(sys.executable, '-c',+ "import sys; sys.stdin.read(); print('copied'); print('diagnostic', file=sys.stderr)",+ input=b'private-password-123')+ self.assertEqual(installer.run(sys.executable, '-c', "print('metadata')", capture=True), 'metadata')+ text = log.read_text()+ self.assertIn('copied', text)+ self.assertIn('diagnostic', text)+ self.assertNotIn('private-password-123', text)+ self.assertNotIn('stale log', text)+ self.assertEqual(log.stat().st_mode & 0o777, 0o600)+ self.assertIsNone(installer.COMMAND_LOG)++ def test_failed_command_is_not_success_and_log_redirection_is_restored(self):+ with tempfile.TemporaryDirectory() as temp:+ log = Path(temp) / 'install.log'+ with self.assertRaises(subprocess.CalledProcessError):+ with installer.command_log(log):+ installer.run(sys.executable, '-c', "import sys; print('disk error', file=sys.stderr); sys.exit(9)")+ self.assertIn('disk error', log.read_text())+ self.assertIsNone(installer.COMMAND_LOG)++ def test_log_cannot_follow_a_symlink(self):+ with tempfile.TemporaryDirectory() as temp:+ target = Path(temp) / 'unrelated'+ target.write_text('preserve')+ log = Path(temp) / 'install.log'+ log.symlink_to(target)+ with self.assertRaises(OSError):+ with installer.command_log(log):+ self.fail('A symlink must never be opened as the installer log')+ self.assertEqual(target.read_text(), 'preserve')++if __name__ == '__main__':unittest.main()diff --git a/os/tests/test_live_update.py b/os/tests/test_live_update.pynew file mode 100644index 000000000..d28cb034d--- /dev/null+++ b/os/tests/test_live_update.py@@ -0,0 +1,217 @@+import hashlib+import fcntl+import importlib.util+import json+from pathlib import Path+import subprocess+import tempfile+import unittest+from unittest.mock import patch++spec = importlib.util.spec_from_file_location('live_update', Path(__file__).parents[1] / 'live_update.py')+update = importlib.util.module_from_spec(spec)+spec.loader.exec_module(update)+++class FastUpdates(unittest.TestCase):+ def setUp(self):+ temporary = tempfile.TemporaryDirectory()+ self.addCleanup(temporary.cleanup)+ self.root = Path(temporary.name)+ self.state, self.bundled = self.root / 'state', self.root / 'bundled'+ self.base = self.root / 'runtime.json'+ self.base.write_text('{"source_commit":"initial"}\n')+ self.bundled.mkdir()+ for name in update.FILES:+ (self.bundled / name).write_bytes(('old ' + name).encode())+ self.patches = [patch.object(update, 'STATE', self.state), patch.object(update, 'BUNDLED', self.bundled),+ patch.object(update, 'BASE_ID', self.base),+ patch.object(update, 'RESTART_REQUIRED', self.root / 'restart-required'),+ patch.object(update, 'SYSTEM_LOCK', self.root / 'system.lock'),+ patch.object(update, 'check_system', return_value={}),+ patch.object(update, 'screen_ready'),+ patch.object(update, 'notice'), patch.object(update, 'versions', side_effect=self.versions)]+ for item in self.patches:+ item.start()+ self.addCleanup(item.stop)++ def versions(self, folder):+ return {component: '1.1.0' if (folder / name).read_bytes().startswith(b'new') else '1.0.0'+ for component, name in [('hn', 'harness-tui'), ('cli', 'cli.mjs')]}++ def feed(self, fail=None):+ assets = {name: ('new ' + name).encode() for name in update.FILES}+ refs = {name: dict(url='https://example.test/' + name, sha256=hashlib.sha256(data).hexdigest(), size=len(data))+ for name, data in assets.items()}+ manifests = {+ update.FEEDS['hn']: json.dumps(dict(version='1.1.0', builds={'linux-x64': refs['harness-tui']})).encode(),+ update.FEEDS['cli']: json.dumps(dict(cli=dict(version='1.1.0', cli=refs['cli.mjs'], notify=refs['notify.mjs']))).encode(),+ }+ def fetch(url, limit):+ if fail and fail in url:+ return b'broken download'+ return manifests[url] if url in manifests else assets[url.rsplit('/', 1)[1]]+ return patch.object(update, 'fetch', side_effect=fetch)++ def test_version_and_transport_reject_malformed_and_unsafe_releases(self):+ for value in ['1.0', '1.0.1-dev.local', '999999999.0.0', '../1.0.0', None]:+ with self.subTest(value=value), self.assertRaises(ValueError):+ update.version(value)+ for value in ['file:///etc/passwd', 'http://example.test/code', 'https://user:password@host/code', None]:+ with self.subTest(url=value), self.assertRaises(ValueError):+ update.allowed_url(value)+ self.assertEqual(update.allowed_url('http://127.0.0.1:19447/test'), 'http://127.0.0.1:19447/test')++ def test_background_check_stages_complete_release_without_activation_or_restarts(self):+ with self.feed(), patch.object(update, 'restart') as restart:+ self.assertTrue(update.check())+ target = update.prepared()+ record = update.verify(target)+ self.assertEqual(record['versions'], {'hn': '1.1.0', 'cli': '1.1.0'})+ self.assertEqual(update.selected(), self.bundled)+ restart.assert_not_called()+ self.assertEqual((self.bundled / 'harness-tui').read_bytes(), b'old harness-tui')+ self.assertTrue(update.check())+ self.assertEqual(update.prepared(), target)+ self.assertEqual(len(list((self.state / 'builds').iterdir())), 1)++ def test_bad_cli_hook_does_not_stage_half_a_pair_or_block_independent_hn(self):+ with self.feed(fail='notify.mjs'):+ self.assertTrue(update.check())+ target = update.prepared()+ self.assertEqual(update.verify(target)['versions'], {'hn': '1.1.0', 'cli': '1.0.0'})+ self.assertEqual((target / 'cli.mjs').read_bytes(), b'old cli.mjs')+ self.assertEqual((target / 'notify.mjs').read_bytes(), b'old notify.mjs')+ self.assertTrue(update.read(self.state / 'check.json')['errors'])++ def test_corrupt_hn_does_not_replace_current_build_and_valid_cli_can_still_stage(self):+ with self.feed(fail='harness-tui'):+ self.assertTrue(update.check())+ self.assertEqual(update.verify(update.prepared())['versions'], {'hn': '1.0.0', 'cli': '1.1.0'})+ self.assertEqual(update.selected(), self.bundled)++ def test_staged_file_changed_after_download_is_rejected_before_selection(self):+ with self.feed():+ update.check()+ (update.prepared() / 'cli.mjs').write_bytes(b'tampered')+ with patch.object(update, 'restart') as restart, self.assertRaisesRegex(ValueError, 'verification'):+ update.apply()+ restart.assert_not_called()+ self.assertEqual(update.selected(), self.bundled)+ with self.feed(), patch.object(update, 'restart') as restart:+ self.assertTrue(update.check())+ self.assertEqual(update.verify(update.prepared())['versions'], {'hn': '1.1.0', 'cli': '1.1.0'})+ self.assertEqual(update.selected(), self.bundled)+ restart.assert_not_called()+ update.apply()+ self.assertNotEqual(update.selected(), self.bundled)++ def test_failed_activation_restores_previous_selection(self):+ with self.feed():+ update.check()+ error = subprocess.CalledProcessError(1, 'systemctl')+ with patch.object(update, 'restart', side_effect=[error, None]) as restart:+ with self.assertRaises(subprocess.CalledProcessError):+ update.apply()+ self.assertEqual(restart.call_count, 2)+ self.assertEqual(update.selected(), self.bundled)+ self.assertEqual(update.read(self.state / 'transaction.json')['status'], 'failed')++ def test_hn_only_activation_does_not_restart_the_daemon_and_rollback_holds_bad_version(self):+ with self.feed(fail='notify.mjs'):+ update.check()+ with patch.object(update, 'restart') as restart:+ update.apply()+ restart.assert_called_once_with(False)+ self.assertNotEqual(update.selected(), self.bundled)+ with patch.object(update, 'restart'):+ update.apply(rollback=True)+ self.assertEqual(update.selected(), self.bundled)+ self.assertEqual(update.read(self.state / 'ignored.json')['hn'], '1.1.0')+ with self.feed():+ update.check()+ self.assertEqual(update.verify(update.prepared())['versions']['hn'], '1.0.0')++ def test_concurrent_check_cannot_mutate_a_pending_transaction(self):+ with update.locked(), self.feed(), self.assertRaisesRegex(ValueError, 'already in progress'):+ update.check()+ self.assertFalse((self.state / 'ready.json').exists())++ def test_ready_pointer_cannot_escape_the_update_directory(self):+ self.state.mkdir()+ update.write(self.state / 'ready.json', {'id': '../../other'})+ with self.assertRaises(ValueError):+ update.prepared()++ def test_new_os_package_uses_its_matching_runtime_until_a_fresh_update_is_prepared(self):+ with self.feed(), patch.object(update, 'restart'):+ update.check()+ update.apply()+ self.assertNotEqual(update.selected(), self.bundled)+ self.base.write_text('{"source_commit":"next-os-build"}\n')+ self.assertEqual(update.selected(), self.bundled)+ with self.feed(), patch.object(update, 'restart'):+ update.check()+ update.apply()+ self.assertNotEqual(update.selected(), self.bundled)++ def test_old_downloads_are_removed_but_unknown_files_are_preserved(self):+ with self.feed():+ update.check()+ builds = self.state / 'builds'+ for name in ['a' * 64, '.download-interrupted', 'user-notes']:+ (builds / name).mkdir()+ with update.locked():+ update.prune()+ self.assertFalse((builds / ('a' * 64)).exists())+ self.assertFalse((builds / '.download-interrupted').exists())+ self.assertTrue((builds / 'user-notes').is_dir())+ self.assertTrue(update.prepared().exists())++ def test_interrupted_selection_recovers_before_another_background_check(self):+ with self.feed():+ update.check()+ target = update.prepared()+ update.write(self.state / 'transaction.json', {'status': 'applying', 'previous': str(self.bundled), 'target': str(target)})+ update.select(target)+ with self.feed(), patch.object(update, 'restart') as restart:+ update.check()+ restart.assert_called_once_with(True)+ self.assertEqual(update.selected(), self.bundled)+ self.assertEqual(update.read(self.state / 'transaction.json')['status'], 'interrupted')++ def test_ready_service_with_no_attached_client_rolls_back(self):+ with self.feed():+ update.check()+ with patch.object(update, 'screen_ready', side_effect=ValueError('No attached client')), patch.object(update, 'restart'):+ with self.assertRaisesRegex(ValueError, 'No attached client'):+ update.apply()+ self.assertEqual(update.selected(), self.bundled)++ def test_system_update_holds_fast_updates_until_reboot(self):+ update.RESTART_REQUIRED.write_text('{"status":"ready"}')+ with patch.object(update, 'fetch', side_effect=AssertionError('No download before restart')):+ self.assertFalse(update.check())+ with self.assertRaisesRegex(ValueError, 'Restart'):+ update.apply()++ def test_root_system_transaction_excludes_fast_activation(self):+ with update.SYSTEM_LOCK.open('w') as root_lock:+ fcntl.flock(root_lock, fcntl.LOCK_EX | fcntl.LOCK_NB)+ with self.assertRaisesRegex(ValueError, 'system update is in progress'):+ with update.locked():+ self.fail('The root transaction must hold this lock exclusively')++ def test_new_os_base_does_not_delete_runtime_used_by_the_running_old_session(self):+ with self.feed(), patch.object(update, 'restart'):+ update.check()+ update.apply()+ old_runtime = update.selected()+ self.base.write_text('{"source_commit":"new-os"}\n')+ with update.locked():+ update.prune()+ self.assertTrue(old_runtime.is_dir())+++if __name__ == '__main__':+ unittest.main()diff --git a/os/tests/test_publish_update.py b/os/tests/test_publish_update.pynew file mode 100644index 000000000..d95945b47--- /dev/null+++ b/os/tests/test_publish_update.py@@ -0,0 +1,57 @@+import copy+import importlib.util+import json+from pathlib import Path+import unittest+import test_runtime_update++spec = importlib.util.spec_from_file_location('publish_update', Path(__file__).parents[1] / 'tools/publish-update.py')+publish = importlib.util.module_from_spec(spec)+spec.loader.exec_module(publish)+++class PublicationGuards(unittest.TestCase):+ def setUp(self):+ self.fixture = test_runtime_update.BundleGuards()+ self.fixture.setUp()+ self.addCleanup(self.fixture.doCleanups)+ self.fixture.runtime['versions'] = {'hn': '0.1.12', 'cli': '0.3.57'}+ self.fixture.make_package()+ self.bundle = self.fixture.root+ (self.bundle / 'apply-update.py').write_text('# fixture bootstrap\n')+ (self.bundle / 'SHA256SUMS').write_text(''.join(publish.digest(path) + ' ' + path.name + '\n' for path in+ [self.fixture.package, self.bundle / 'package-manifest.json', self.bundle / 'apply-update.py']))+ self.run = dict(status='completed', conclusion='success', path='.github/workflows/os.yml', head_sha='a' * 40)+ self.receipt = dict(status='passed', update=dict(status='passed', source_commit='a' * 40, candidate=self.fixture.manifest['package']),+ fast_updates=dict(status='passed'), system_channel=dict(status='passed', package=self.fixture.manifest['package'],+ reboot_keyboard={'confirmed_seconds_since_boot': 12}))++ def test_exact_package_and_complete_receipt_can_be_prepared(self):+ self.assertEqual(publish.validate(self.bundle, self.receipt, self.run)['source_commit'], 'a' * 40)++ def test_failed_stale_or_missing_native_scopes_cannot_advance_the_feed(self):+ for field in ['update', 'fast_updates', 'system_channel']:+ bad = copy.deepcopy(self.receipt)+ bad[field]['status'] = 'failed'+ with self.subTest(field=field), self.assertRaises(ValueError):+ publish.validate(self.bundle, bad, self.run)+ bad = copy.deepcopy(self.receipt)+ del bad['system_channel']['reboot_keyboard']+ with self.assertRaisesRegex(ValueError, 'encrypted reboot'):+ publish.validate(self.bundle, bad, self.run)+ for change in [{'conclusion': 'failure'}, {'status': 'in_progress'}, {'head_sha': 'b' * 40}, {'path': '.github/workflows/ci.yml'}]:+ with self.subTest(change=change), self.assertRaises(ValueError):+ publish.validate(self.bundle, self.receipt, dict(self.run, **change))++ def test_private_runtime_fixture_and_changed_bootstrap_are_never_published(self):+ (self.bundle / 'apply-update.py').write_text('# changed after packaging\n')+ with self.assertRaisesRegex(ValueError, 'bootstrap bundle'):+ publish.validate(self.bundle, self.receipt, self.run)+ self.fixture.runtime['versions']['hn'] = '999.0.1'+ self.fixture.make_package()+ with self.assertRaisesRegex(ValueError, 'private fixtures'):+ publish.validate(self.bundle, self.receipt, self.run)+++if __name__ == '__main__':+ unittest.main()diff --git a/os/tests/test_release_update.py b/os/tests/test_release_update.pynew file mode 100644index 000000000..a80fd5c91--- /dev/null+++ b/os/tests/test_release_update.py@@ -0,0 +1,155 @@+import copy+from contextlib import nullcontext+import hashlib+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer+import importlib.util+import json+from pathlib import Path+import tempfile+import threading+from types import SimpleNamespace+import unittest+from unittest.mock import Mock, patch++spec = importlib.util.spec_from_file_location('release_update', Path(__file__).parents[1] / 'release_update.py')+update = importlib.util.module_from_spec(spec)+spec.loader.exec_module(update)+++class ReleaseChannel(unittest.TestCase):+ def setUp(self):+ temporary = tempfile.TemporaryDirectory()+ self.addCleanup(temporary.cleanup)+ self.root = Path(temporary.name)+ self.lock = self.root / 'lock.json'+ self.base = dict(version='0.1.0-preview.4', arch_snapshot='2026/10/01')+ self.lock.write_text(json.dumps(self.base))+ self.patch = patch.object(update, 'LOCK', self.lock)+ self.patch.start()+ self.addCleanup(self.patch.stop)+ self.content = {}+ content = self.content+ class Handler(BaseHTTPRequestHandler):+ def do_GET(self):+ if self.path not in content:+ self.send_error(404)+ return+ data = content[self.path]+ self.send_response(200)+ self.send_header('Content-Length', str(len(data)))+ self.end_headers()+ self.wfile.write(data)+ def log_message(self, *args):+ pass+ self.server = ThreadingHTTPServer(('127.0.0.1', 0), Handler)+ self.thread = threading.Thread(target=self.server.serve_forever, kwargs={'poll_interval': .01}, daemon=True)+ self.thread.start()+ self.addCleanup(self.server.server_close)+ self.addCleanup(self.server.shutdown)+ self.url = f'http://127.0.0.1:{self.server.server_port}'+ self.package = b'private package fixture'+ self.manifest = dict(schema=1, kind='harness-os-package', architecture='x86_64',+ requires_os_version=self.base['version'], arch_snapshot=self.base['arch_snapshot'],+ package=dict(name='harness-os-0.1.0pre4.r2-1-x86_64.pkg.tar.gz', version='0.1.0pre4.r2-1',+ bytes=len(self.package), sha256=hashlib.sha256(self.package).hexdigest()))+ self.publish()+ self.commands = patch.object(update.subprocess, 'check_output', side_effect=lambda args, **kw:+ 'harness-os 0.1.0pre4-1\n' if args[0] == 'pacman' else '1\n')+ self.commands.start()+ self.addCleanup(self.commands.stop)++ def publish(self):+ manifest = json.dumps(self.manifest).encode()+ self.metadata = dict(schema=1, channel='preview', architecture='x86_64',+ manifest=dict(url=self.url + '/manifest.json', bytes=len(manifest), sha256=hashlib.sha256(manifest).hexdigest()),+ package=dict(url=self.url + '/package.pkg.tar.gz', bytes=len(self.package), sha256=hashlib.sha256(self.package).hexdigest()))+ self.content.update({'/metadata.json': json.dumps(self.metadata).encode(), '/manifest.json': manifest,+ '/package.pkg.tar.gz': self.package})++ def test_actual_http_discovery_verifies_manifest_and_does_not_download_or_install_the_package(self):+ del self.content['/package.pkg.tar.gz']+ result = update.discover(self.url + '/metadata.json')+ self.assertTrue(result['available'])+ self.assertEqual(result['version'], self.manifest['package']['version'])+ with patch.object(update.subprocess, 'check_output', side_effect=['harness-os 0.1.0pre4.r3-1', '-1']):+ self.assertFalse(update.discover(self.url + '/metadata.json')['available'])++ def test_missing_channel_is_empty_but_invalid_or_truncated_channel_is_an_error(self):+ self.assertIsNone(update.discover(self.url + '/missing'))+ original = copy.deepcopy(self.metadata)+ for field, value in [('architecture', 'aarch64'), ('schema', 2), ('channel', 'stable')]:+ self.content['/metadata.json'] = json.dumps(dict(original, **{field: value})).encode()+ with self.subTest(field=field), self.assertRaises(ValueError):+ update.discover(self.url + '/metadata.json')+ self.publish()+ self.content['/manifest.json'] = self.content['/manifest.json'][:-1]+ with self.assertRaisesRegex(ValueError, 'checksum or size'):+ update.discover(self.url + '/metadata.json')++ def test_unrelated_repository_and_unbounded_asset_are_rejected(self):+ for url in ['https://github.com/other/repository/releases/download/test/file',+ 'https://github.com.evil.test/autonomous-ai/openharness/releases/download/file',+ 'http://example.test/file', 'file:///etc/passwd']:+ ref = dict(self.metadata['package'], url=url)+ with self.subTest(url=url), self.assertRaises(ValueError):+ update.asset(ref, 128 * 1024 * 1024)+ for size in [True, -1, 0, 128 * 1024 * 1024 + 1]:+ with self.subTest(size=size), self.assertRaises(ValueError):+ update.asset(dict(self.metadata['package'], bytes=size), 128 * 1024 * 1024, fixture=True)++ def test_migration_must_explicitly_include_the_installed_base(self):+ self.manifest['requires_os_version'] = '0.1.0-preview.5'+ self.publish()+ with self.assertRaisesRegex(ValueError, 'different Harness base'):+ update.discover(self.url + '/metadata.json')+ self.manifest['upgrades_from'] = [self.base]+ self.publish()+ self.assertTrue(update.discover(self.url + '/metadata.json')['available'])+ self.manifest['upgrades_from'] = []+ self.publish()+ with patch.object(update.subprocess, 'check_output', side_effect=['harness-os 0.1.0pre6-1', '-1']):+ self.assertFalse(update.discover(self.url + '/metadata.json')['available'])++ def fake_updater(self):+ config = self.root / 'pacman.conf'+ config.write_text('Server = https://archive.archlinux.org/repos/2026/09/30/$repo/os/$arch\n')+ self.events = []+ system = SimpleNamespace(operation_lock=lambda: nullcontext(), installed=lambda: {'root_uuid': 'fixture'},+ snapshot_date=lambda date: date, PACMAN_CONFIG=config, pending_update=lambda: None,+ update=lambda date: self.events.append(('system', date)))+ def apply(folder, system, base, installation):+ self.assertEqual((folder / self.manifest['package']['name']).read_bytes(), self.package)+ self.assertEqual(folder.stat().st_mode & 0o777, 0o700)+ self.events.append(('harness', folder))+ return SimpleNamespace(system_module=lambda: system, validate_bundle=Mock(),+ validate_base=update.load_runtime_updater().validate_base, latest=lambda: None, apply=apply)++ def test_root_download_is_private_and_full_base_upgrade_precedes_package_application(self):+ updater = self.fake_updater()+ with patch.object(update.os, 'geteuid', return_value=0), patch.object(update, 'load_runtime_updater', return_value=updater):+ update.apply(self.url + '/metadata.json')+ self.assertEqual(self.events[0], ('system', '2026/10/01'))+ self.assertEqual(self.events[1][0], 'harness')+ self.assertFalse(self.events[1][1].exists(), 'Root download is removed after the transaction')+ updater.validate_bundle.assert_called_once()++ def test_corrupt_package_never_touches_the_system(self):+ updater = self.fake_updater()+ self.content['/package.pkg.tar.gz'] = b'wrong package'+ with patch.object(update.os, 'geteuid', return_value=0), patch.object(update, 'load_runtime_updater', return_value=updater):+ with self.assertRaisesRegex(ValueError, 'checksum or size'):+ update.apply(self.url + '/metadata.json')+ self.assertEqual(self.events, [])+ updater.validate_bundle.assert_not_called()++ def test_failed_harness_transaction_blocks_advancing_the_arch_base(self):+ updater = self.fake_updater()+ updater.latest = lambda: {'status': 'failed'}+ with patch.object(update.os, 'geteuid', return_value=0), patch.object(update, 'load_runtime_updater', return_value=updater):+ with self.assertRaisesRegex(ValueError, 'Restore the previous'):+ update.apply(self.url + '/metadata.json')+ self.assertEqual(self.events, [])+++if __name__ == '__main__':+ unittest.main()diff --git a/os/tests/test_runtime_update.py b/os/tests/test_runtime_update.pyindex 09b14d259..220460212 100644--- a/os/tests/test_runtime_update.py+++ b/os/tests/test_runtime_update.py@@ -75,6 +75,20 @@ class BundleGuards(unittest.TestCase):with self.subTest(args=args), self.assertRaises(ValueError):update.validate_bundle(self.root, self.base)+ def test_release_migration_requires_an_explicit_matching_base(self):+ self.manifest['requires_os_version'] = '0.1.0-preview.5'+ self.write_manifest()+ with self.assertRaisesRegex(ValueError, 'different Harness base'):+ update.validate_bundle(self.root, self.base)+ self.manifest['upgrades_from'] = [self.base]+ self.write_manifest()+ self.assertEqual(update.validate_bundle(self.root, self.base)[1], self.package)+ for value in [None, {}, 'any', [{'version': self.base['version']}]]:+ self.manifest['upgrades_from'] = value+ self.write_manifest()+ with self.subTest(value=value), self.assertRaisesRegex(ValueError, 'migration list'):+ update.validate_bundle(self.root, self.base)+def test_archive_cannot_escape_system_paths_or_execute_install_script(self):for name in ['../escape', '/etc/escape', 'home/me/project', '.INSTALL', 'usr/../escape', 'usr/lib/harness/cli.mjs']:member = tarfile.TarInfo(name)diff --git a/os/tests/update_vm.py b/os/tests/update_vm.pyindex 1fbad5c39..d18f14c60 100644--- a/os/tests/update_vm.py+++ b/os/tests/update_vm.py@@ -20,6 +20,7 @@ def main():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument('--iso', type=Path, required=True)parser.add_argument('--bundle', type=Path, required=True)+ parser.add_argument('--fast-fixture', type=Path)parser.add_argument('--output', type=Path, default=Path('os/test-results/runtime-update'))args = parser.parse_args()if not os.access('/dev/kvm', os.R_OK | os.W_OK):@@ -33,6 +34,8 @@ def main():served = folder / 'served'shutil.copytree(bundle, served)shutil.copyfile(Path(__file__).with_name('update_guest.py'), served / 'update_guest.py')+ if args.fast_fixture:+ shutil.copytree(args.fast_fixture, served / 'fast')server = ThreadingHTTPServer(('127.0.0.1', 0), partial(SimpleHTTPRequestHandler, directory=str(served)))thread = threading.Thread(target=server.serve_forever, daemon=True)thread.start()@@ -56,15 +59,17 @@ def main():vm.login_installed(config)receipt['checks'].append('Published preview 4 installs offline and boots from its encrypted internal disk')vm.command('printf %s ' + shlex.quote(config['password'] + '\n') + ' | sudo -S -v')- vm.command('mkdir /tmp/update-bundle')+ # Reuse the exact bundle after encrypted reboot; /tmp is intentionally+ # volatile on the installed system.+ vm.command('mkdir /home/me/update-bundle')url = f'http://10.0.2.2:{server.server_port}'for name in [p.name for p in served.iterdir() if p.is_file()]:vm.command('curl --fail --silent --show-error --max-time 90 ' + shlex.quote(url + '/' + name) +- ' -o ' + shlex.quote('/tmp/update-bundle/' + name), timeout=100)- vm.command('cd /tmp/update-bundle && sha256sum -c SHA256SUMS')+ ' -o ' + shlex.quote('/home/me/update-bundle/' + name), timeout=100)+ vm.command('cd /home/me/update-bundle && sha256sum -c SHA256SUMS')# The actual update/rollback must not require a package repository or network.vm.command('sudo nmcli networking off')- output, status = vm.command('python3 /tmp/update-bundle/update_guest.py /tmp/update-bundle', timeout=600, check=False)+ output, status = vm.command('python3 /home/me/update-bundle/update_guest.py /home/me/update-bundle', timeout=600, check=False)(folder / 'update.log').write_text(output)assert status == 0, 'Update acceptance failed; see update.log'marker = 'HN_UPDATE_ACCEPTANCE='@@ -80,11 +85,29 @@ def main():vm.command('test -s ~/Projects/update-survivor/keep.txt')receipt['keyboard'] = check_graphical_keyboard(vm, 'updated')receipt['checks'].append('Updated encrypted machine reboots to hn, accepts physical-keyboard input and retains the project')+ if args.fast_fixture:+ vm.command('printf %s ' + shlex.quote(config['password'] + '\n') + ' | sudo -S -v')+ from fast_update_vm import exercise+ receipt['fast_updates'] = exercise(vm, args.fast_fixture, url)+ from release_update_vm import exercise as release_exercise+ receipt['system_channel'] = release_exercise(vm, manifest)+ vm.command('sync')+ vm.stop()+ vm.start(live=False)+ vm.login_installed(config)+ vm.command('test ! -e /run/harness-os-restart-required; test -s ~/Projects/update-survivor/keep.txt')+ receipt['system_channel']['reboot_keyboard'] = check_graphical_keyboard(vm, 'system-channel-reboot')+ receipt['checks'].append('The OS-channel update boots its rebuilt encrypted image and accepts keyboard input')receipt['status'] = 'passed'except BaseException as error:+ receipt['status'] = 'failed'receipt['error'] = str(error)try:vm.screenshot('failure')+ output, _ = vm.command('sudo journalctl _UID=1000 --no-pager; '+ 'cat ~/.local/state/harness-os/updates/*.json; hn list-windows -a; hn list-panes -a; '+ 'ps -u 1000 -o pid,ppid,args --width 200', timeout=30, check=False)+ (folder / 'update-diagnostics.log').write_text(output)except Exception:passraisediff --git a/os/tests/vm.py b/os/tests/vm.pyindex 61098ef11..baad5bbcf 100644--- a/os/tests/vm.py+++ b/os/tests/vm.py@@ -25,10 +25,14 @@ import uuidclass VM:- def __init__(self, folder, iso, firmware, memory, live_transport='cdrom', cpu=None):+ def __init__(self, folder, iso, firmware, memory, live_transport='cdrom', cpu=None, video='virtio-vga', audio=False):self.folder, self.iso, self.firmware, self.memory = folder, iso, firmware, memoryself.live_transport = live_transportself.cpu = cpu+ if video not in ('virtio-vga', 'VGA'):+ raise ValueError('Unsupported test display: ' + video)+ self.video = video+ self.audio = audioself.unlock_count = 0self.boot_count = 0self.process = None@@ -62,13 +66,16 @@ class VM:acceleration = 'kvm' if os.access('/dev/kvm', os.R_OK | os.W_OK) else 'tcg'self.acceleration = accelerationargs = ['qemu-system-x86_64', '-accel', acceleration, '-m', str(self.memory), '-smp', '2',- '-cpu', self.cpu or ('host' if acceleration == 'kvm' else 'max'), '-device', 'virtio-vga',+ '-cpu', self.cpu or ('host' if acceleration == 'kvm' else 'max'), '-device', self.video,'-display', 'none', '-no-reboot','-drive', f'file={self.disk},format=qcow2,if=none,id=target','-device', f'virtio-blk-pci,drive=target,serial=HN_OS_TEST,bootindex={2 if live else 1}','-device', 'virtio-net-pci,netdev=net', '-netdev', 'user,id=net','-serial', f'unix:{self.control_path / "serial.sock"},server=on,wait=off','-qmp', f'unix:{self.control_path / "qmp.sock"},server=on,wait=off']+ if self.audio:+ args += ['-audiodev', f'wav,id=sound,path={self.folder / ("audio-" + str(self.boot_count) + ".wav")}',+ '-device', 'intel-hda', '-device', 'hda-duplex,audiodev=sound']if live:# UEFI remembers the installed disk in NVRAM. Explicit device boot# indices are needed to select the recovery ISO again on later boots.@@ -444,9 +451,9 @@ if (rows.some(row => row.engine !== 'terminal')) throw new Error('A plain shelldef install_interactively(vm, config, folder):- # The shipped form and installer run on a real guest TTY. The only test- # addition is serial-console boot output, needed to observe the next boot.- bootstrap = f'''import importlib.util+ # Drive the actual graphical form. The sole installer addition is serial boot+ # output so the following installed boot remains observable to this fixture.+ bootstrap = f'''import importlib.util, tracebackfrom pathlib import Pathspec = importlib.util.spec_from_file_location('installer', '/usr/lib/harness-os/install.py')installer = importlib.util.module_from_spec(spec)@@ -454,48 +461,79 @@ spec.loader.exec_module(installer)expected = {config!r}installer.selected_disk(expected)original_install = installer.install-def observed_install(actual, source, target):+def observed_install(actual, source, target, **kwargs):assert actual == {{k: v for k, v in expected.items() if k != 'serial_console'}}, 'Interactive installation choices differ from test input'actual['serial_console'] = True- return original_install(actual, source, target)+ return original_install(actual, source, target, **kwargs)installer.install = observed_install-installer.main()+status = 0+try:+ installer.main()+except BaseException:+ traceback.print_exc()+ status = 1+finally:+ Path('/run/hn-interactive-status').write_text(str(status))+if status:+ input('Installation test failed. Press Enter to close.')'''encoded = base64.b64encode(bootstrap.encode()).decode()assert len(encoded) < 3000, 'Keep serial-console commands below the line discipline limit.'vm.command(f"printf %s {shlex.quote(encoded)} | base64 -d > /run/hn-interactive-test.py; chmod 600 /run/hn-interactive-test.py")- vm.command('stty rows 24 cols 80')- marker = 'HN_INTERACTIVE_' + uuid.uuid4().hex- vm.send('(TERM=xterm-256color python3 /run/hn-interactive-test.py); '- f"hn_status=$?; printf '\\n{marker}:%s\\n' \"$hn_status\"\n")+ user = lambda command: 'runuser -u me -- env XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus ' + command+ _, progress_status = vm.command("grep -q '^def install_with_progress(' /usr/lib/harness-os/install.py", check=False)+ vm.command(user('hn new-window -n Install ' + shlex.quote('sudo python3 /run/hn-interactive-test.py')))transcript = []- def wait(pattern, timeout=30):- output = vm.wait(pattern, timeout)++ def wait_screen(pattern, timeout=30):+ command = ('for n in $(seq 1 ' + str(timeout * 2) + '); do '+ 'hn capture-pane -p > /tmp/hn-install-screen; '+ 'grep -Eq ' + shlex.quote(pattern) + ' /tmp/hn-install-screen && exit 0; '+ 'test ! -e /run/hn-interactive-status || exit 1; sleep .5; done; exit 1')+ _, status = vm.command(user('sh -c ' + shlex.quote(command)), timeout=timeout + 15, check=False)+ output, _ = vm.command('cat /tmp/hn-install-screen')transcript.append(output)+ assert status == 0, 'Graphical installer did not show ' + pattern + '; see installer-ui.log'return output+try:- wait(r'All data on this disk will be erased')- vm.send('\n')- wait(r'Select disk')- vm.send('\x1b')- wait(r'All data on this disk will be erased')- vm.send('\n')- wait(r'Select disk')- vm.send('\n')- wait(r'All data on this disk will be erased')- vm.send('\t' + ('' if config['encrypt'] else ' ') + '\t')- vm.send(config['password'] + '\n' + config['password'] + '\n')- # Password entry focuses Install. Only its explicit activation starts it.- time.sleep(.25)- vm.send('\n')- output = wait(r'Harness is installed|\r?\n' + marker + r':\d+\r?\n', timeout=900)- assert 'Harness is installed' in output, 'Interactive installation failed; see installer-ui.log'- vm.send('\x1b') # Completion remains visible; return to the live system for the receipt.- output = wait(r'\r?\n' + marker + r':\d+\r?\n', timeout=900)- status = int(re.search(r'\r?\n' + marker + r':(\d+)\r?\n', output).group(1))- assert status == 0, 'Interactive installation failed; see installer-ui.log'+ wait_screen('All data on this disk will be erased')+ vm.screenshot('install-01-form')+ vm.keys('ret')+ wait_screen('Select disk')+ vm.screenshot('install-02-disks')+ vm.keys('esc')+ wait_screen('All data on this disk will be erased')+ vm.keys('ret')+ wait_screen('Select disk')+ vm.keys('ret')+ wait_screen('All data on this disk will be erased')+ vm.keys('tab')+ if not config['encrypt']:+ vm.keys('spc')+ vm.keys('tab')+ vm.type_probe(config['password'])+ vm.keys('ret')+ vm.type_probe(config['password'])+ vm.keys('ret')+ output = wait_screen('All data on this disk will be erased')+ assert config['password'] not in output and '*' * len(config['password']) in output, 'Password fields must be masked'+ vm.screenshot('install-03-ready')+ # Finishing password entry only focuses Install. No disk has changed yet.+ vm.command('test "$(lsblk -n -o TYPE /dev/vda | wc -l)" -eq 1')+ vm.keys('ret')+ if progress_status == 0:+ wait_screen('Installing Harness', timeout=30)+ vm.screenshot('install-04-progress')+ wait_screen('Harness is installed', timeout=900)+ vm.screenshot('install-05-complete')+ vm.keys('esc')+ vm.command('for n in $(seq 1 30); do test -s /run/hn-interactive-status && break; sleep .25; done; test "$(cat /run/hn-interactive-status)" = 0')finally:- (folder / 'installer-ui.log').write_text(''.join(transcript))+ (folder / 'installer-ui.log').write_text('\n'.join(transcript))+ output, _ = vm.command('cat /var/log/harness-install.log 2>/dev/null', check=False)+ (folder / 'installer-commands.log').write_text(output)+ assert config['password'] not in output, 'Installation diagnostics must not contain the password'def main():diff --git a/os/tools/build-package.py b/os/tools/build-package.pyindex 6bf5106ae..b82559c7a 100644--- a/os/tools/build-package.py+++ b/os/tools/build-package.py@@ -43,6 +43,8 @@ def stage(source, runtime, destination, commit):'os/installer.py': 'usr/lib/harness-os/install.py','os/system.py': 'usr/lib/harness-os/system.py','os/runtime_update.py': 'usr/lib/harness-os/runtime_update.py',+ 'os/live_update.py': 'usr/lib/harness-os/live_update.py',+ 'os/release_update.py': 'usr/lib/harness-os/release_update.py','os/tools/hn-os': 'usr/bin/hn-os','os/lock.json': 'usr/share/harness-os/lock.json',}@@ -106,7 +108,9 @@ def main():parser.error('Expected a versioned x86-64 OS preview.')version = lock['version'].replace('-preview.', 'pre')if args.development:- version += '.r' + git(source, 'rev-list', '--count', 'HEAD') + '.g' + commit[:10]+ # Shallow CI checkouts all have a revision count of one. Use the source+ # commit time so independent packages do not sort by random Git hashes.+ version += '.r' + str(timestamp) + '.g' + commit[:10]version += '-1'folder = args.output.resolve()folder.mkdir(parents=True, exist_ok=True)@@ -129,6 +133,8 @@ def main():'requires_os_version': lock['version'], 'arch_snapshot': lock['arch_snapshot'],'runtime': runtime,'package': {'name': package.name, 'version': version, 'bytes': package.stat().st_size, 'sha256': digest(package)}}+ if lock.get('upgrades_from'):+ manifest['upgrades_from'] = lock['upgrades_from'](folder / 'package-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')(folder / (package.name + '.sha256')).write_text(f'{manifest["package"]["sha256"]} {package.name}\n')# A preview 4 installation can bootstrap the updater from this same bundle.diff --git a/os/tools/build-runtime.sh b/os/tools/build-runtime.shindex cb638e6ad..15913e429 100644--- a/os/tools/build-runtime.sh+++ b/os/tools/build-runtime.sh@@ -11,12 +11,17 @@ mkdir -p os/work/runtimecp tui/target/x86_64-unknown-linux-musl/release/harness-tui os/work/runtime/cp cli/dist/cli.js cli/dist/notify.mjs os/work/runtime/python3 - <<'PY'-import json, pathlib, subprocess+import json, pathlib, subprocess, tomllibdef output(*args):return subprocess.check_output(args, text=True).strip()data = {'source_commit': output('git', 'rev-parse', 'HEAD'),'dirty': bool(output('git', 'status', '--porcelain', '--untracked-files=no')),'node': output('node', '--version'), 'rust': output('rustc', '--version'),'target': 'x86_64-unknown-linux-musl'}+expected_hn = tomllib.loads(pathlib.Path('tui/Cargo.toml').read_text())['package']['version']+expected_cli = json.loads(pathlib.Path('cli/package.json').read_text())['version']+assert output('os/work/runtime/harness-tui', '--version').startswith('hn ' + expected_hn + ' ')+assert output('node', 'cli/dist/cli.js', 'version') == expected_cli+data['versions'] = {'hn': expected_hn, 'cli': expected_cli}pathlib.Path('os/work/runtime/source.json').write_text(json.dumps(data, indent=2) + '\n')PYdiff --git a/os/tools/inspect_image.py b/os/tools/inspect_image.pyindex a54f4ce2a..5959359a8 100644--- a/os/tools/inspect_image.py+++ b/os/tools/inspect_image.py@@ -32,6 +32,9 @@ def inspect(iso):files = {str(p.relative_to(source / 'root')): p for p in (source / 'root').rglob('*') if p.is_file()}files.update({'usr/lib/harness-os/install.py': source / 'installer.py','usr/lib/harness-os/system.py': source / 'system.py',+ 'usr/lib/harness-os/runtime_update.py': source / 'runtime_update.py',+ 'usr/lib/harness-os/live_update.py': source / 'live_update.py',+ 'usr/lib/harness-os/release_update.py': source / 'release_update.py','usr/bin/hn-os': source / 'tools/hn-os','usr/share/harness-os/lock.json': source / 'lock.json'})for path, expected in files.items():@@ -62,7 +65,11 @@ def inspect(iso):names = set(inventory)version = json.loads(read('usr/share/harness-os/lock.json'))['version']assert version == manifest['version'], 'Image version differs from the build manifest'- assert inventory['harness-os'] == version.replace('-preview.', 'pre') + '-1', 'OS package version differs from the image version'+ package_version = inventory['harness-os']+ expected_version = re.escape(version.replace('-preview.', 'pre')) + r'\.r\d+\.g' + manifest['source_commit'][:10] + '-1'+ assert re.fullmatch(expected_version, package_version), 'OS package version differs from the image source'+ assert package_version == manifest['package_version'], 'OS package version differs from the manifest'+ assert set(manifest['capabilities']) == {'runtime-updates', 'system-updates'}, 'Update capabilities are missing from the manifest'wanted = {row.strip() for row in (source / 'packages.x86_64').read_text().splitlines() if row.strip() and not row.startswith('#')}assert wanted.issubset(names), f'Missing packages: {wanted - names}'config = read('etc/pacman.conf').decode()diff --git a/os/tools/manifest.py b/os/tools/manifest.pyindex 990355d95..8b2bfe328 100644--- a/os/tools/manifest.py+++ b/os/tools/manifest.py@@ -18,11 +18,20 @@ with iso.open('rb') as handle:(out / (iso.name + '.sha256')).write_text(f'{digest} {iso.name}\n')packages = (root / 'usr/share/harness-os/packages.txt').read_text()(out / 'packages.txt').write_text(packages)+capabilities = []+if all((root / path).is_file() for path in [+ 'usr/lib/harness-os/live_update.py',+ 'usr/lib/systemd/user/harness-update.timer']):+ capabilities.append('runtime-updates')+if (root / 'usr/lib/harness-os/release_update.py').is_file():+ capabilities.append('system-updates')manifest = {'version': lock['version'], 'architecture': 'x86_64','source_commit': os.environ.get('HARNESS_OS_SOURCE_SHA') or subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),'built_at_unix': int(time.time()), 'arch_snapshot': lock['arch_snapshot'],'iso': {'name': iso.name, 'bytes': iso.stat().st_size, 'sha256': digest},+ 'capabilities': capabilities,+ 'package_version': dict(row.split(maxsplit=1) for row in packages.splitlines())['harness-os'],'harness_inputs': json.loads((root / 'usr/share/harness-os/runtime.json').read_text()), 'validation': 'pending',}(out / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')diff --git a/os/tools/publish-update.py b/os/tools/publish-update.pynew file mode 100644index 000000000..c2ba87e98--- /dev/null+++ b/os/tools/publish-update.py@@ -0,0 +1,155 @@+#!/usr/bin/env python3+"""Prepare a tested OS update; advance its public feed only after asset verification."""+import argparse+import hashlib+import importlib.util+import json+from pathlib import Path+import re+import subprocess+import tempfile+from urllib.request import urlopen+import zipfile++REPO = 'autonomous-ai/openharness'+CHANNEL = 'os-preview-updates'+++def digest(path):+ with path.open('rb') as handle:+ return hashlib.file_digest(handle, 'sha256').hexdigest()+++def gh(*args):+ return subprocess.check_output(['gh', *map(str, args)], text=True, timeout=120).strip()+++def validate(bundle, receipt, run):+ spec = importlib.util.spec_from_file_location('harness_runtime_update', Path(__file__).parents[1] / 'runtime_update.py')+ updater = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(updater)+ manifest = json.loads((bundle / 'package-manifest.json').read_text())+ updater.validate_bundle(bundle, {'version': manifest['requires_os_version'], 'arch_snapshot': manifest['arch_snapshot']})+ if not re.fullmatch(r'\d+\.\d+\.\d+-preview\.\d+', manifest['requires_os_version']):+ raise ValueError('Only explicitly versioned previews can use this channel.')+ versions = manifest['runtime'].get('versions', {})+ if set(versions) != {'hn', 'cli'} or any(not isinstance(value, str) or value.startswith('999.') for value in versions.values()):+ raise ValueError('The public package must contain production runtime versions, never private fixtures.')+ if run.get('conclusion') != 'success' or run.get('status') != 'completed' or run.get('path') != '.github/workflows/os.yml' or run.get('head_sha') != manifest['source_commit']:+ raise ValueError('The package must match a completed successful native update workflow.')+ if receipt.get('status') != 'passed' or receipt.get('update', {}).get('source_commit') != manifest['source_commit']:+ raise ValueError('The update receipt does not cover this package source.')+ if receipt['update'].get('candidate') != manifest['package'] or receipt.get('system_channel', {}).get('package') != manifest['package']:+ raise ValueError('The native receipt covers a different package.')+ if any(receipt.get(key, {}).get('status') != 'passed' for key in ['update', 'fast_updates', 'system_channel']):+ raise ValueError('Package, fast runtime and system-channel checks must all pass.')+ if not receipt['system_channel'].get('reboot_keyboard'):+ raise ValueError('The channel update has not passed its actual encrypted reboot and keyboard check.')+ expected = {manifest['package']['name'], 'package-manifest.json', 'apply-update.py'}+ checksums = {}+ for line in (bundle / 'SHA256SUMS').read_text().splitlines():+ checksum, name = line.split(' ', 1)+ if name not in expected or name in checksums:+ raise ValueError('Unexpected or duplicate bootstrap bundle checksum.')+ checksums[name] = checksum+ if set(checksums) != expected or any(digest(bundle / name) != checksum for name, checksum in checksums.items()):+ raise ValueError('The complete bootstrap bundle must match its checksums.')+ return manifest+++def verify_public(url, expected):+ # Stream larger files; never trust GitHub's metadata in place of the bytes.+ size, checksum = 0, hashlib.sha256()+ with urlopen(url, timeout=60) as response:+ if not response.url.startswith('https://'):+ raise ValueError('Publication redirected away from HTTPS.')+ while chunk := response.read(1024 * 1024):+ size += len(chunk)+ if size > expected['bytes']:+ raise ValueError('Published asset exceeds its recorded size.')+ checksum.update(chunk)+ if size != expected['bytes'] or checksum.hexdigest() != expected['sha256']:+ raise ValueError('Published asset verification failed: ' + url)+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--bundle', type=Path, required=True)+ parser.add_argument('--receipt', type=Path, required=True)+ parser.add_argument('--run', type=int, required=True)+ parser.add_argument('--output', type=Path, required=True)+ parser.add_argument('--publish', action='store_true')+ args = parser.parse_args()+ run = json.loads(gh('api', f'repos/{REPO}/actions/runs/{args.run}'))+ receipt = json.loads(args.receipt.read_text())+ manifest = validate(args.bundle, receipt, run)+ output = args.output.resolve()+ output.mkdir(parents=True, exist_ok=False)+ tag = 'os-v' + manifest['requires_os_version']+ prefix = f'https://github.com/{REPO}/releases/download/{tag}/'+ assets = [args.bundle / manifest['package']['name'], args.bundle / 'package-manifest.json']+ bundle_name = 'harness-update-' + manifest['requires_os_version'] + '-' + manifest['source_commit'][:9] + '-x86_64.zip'+ archive = output / bundle_name+ with zipfile.ZipFile(archive, 'w', compression=zipfile.ZIP_DEFLATED) as zipped:+ for name in [manifest['package']['name'], 'package-manifest.json', 'apply-update.py', 'SHA256SUMS']:+ entry = zipfile.ZipInfo(name, date_time=(1980, 1, 1, 0, 0, 0))+ entry.external_attr = 0o100644 << 16+ zipped.writestr(entry, (args.bundle / name).read_bytes(), compress_type=zipfile.ZIP_DEFLATED)+ evidence = output / ('update-validation-' + manifest['source_commit'][:9] + '.json')+ evidence.write_text(json.dumps(dict(source_commit=manifest['source_commit'], run=run['html_url'], receipt=receipt), indent=2) + '\n')+ assets += [archive, evidence]+ identities = {path.name: dict(bytes=path.stat().st_size, sha256=digest(path)) for path in assets}+ metadata = dict(schema=1, channel='preview', architecture='x86_64', source_commit=manifest['source_commit'],+ version=manifest['requires_os_version'], manifest=dict(url=prefix + 'package-manifest.json', **identities['package-manifest.json']),+ package=dict(url=prefix + manifest['package']['name'], **identities[manifest['package']['name']]))+ feed = output / 'metadata.json'+ feed.write_text(json.dumps(metadata, indent=2) + '\n')+ record = {'status': 'prepared', 'tag': tag, 'source_commit': manifest['source_commit'],+ 'run': run['html_url'], 'assets': identities, 'channel': CHANNEL}+ record_path = output / 'publication.json'+ record_path.write_text(json.dumps(record, indent=2) + '\n')+ if not args.publish:+ print(json.dumps(record, indent=2))+ return+ # The ISO publisher owns this versioned release. Attach immutable update+ # assets only after that release exists; never replace its ISO or manifest.+ release = json.loads(gh('api', f'repos/{REPO}/releases/tags/{tag}'))+ if release['draft']:+ raise ValueError('Publish the validated OS preview before advancing its update feed.')+ existing = {asset['name']: asset for asset in release['assets']}+ missing = []+ for path in assets:+ if path.name in existing:+ verify_public(prefix + path.name, identities[path.name])+ else:+ missing.append(path)+ if missing:+ gh('release', 'upload', tag, '--repo', REPO, *missing)+ for path in assets:+ verify_public(prefix + path.name, identities[path.name])+ # The first channel is prepared as a draft, downloaded and checked before+ # publication. On later releases a missing feed during replacement is safe:+ # clients retain their running version and retry on their next check.+ result = subprocess.run(['gh', 'api', f'repos/{REPO}/releases/tags/{CHANNEL}'], capture_output=True, text=True)+ if result.returncode:+ if '404' not in result.stderr:+ raise ValueError('Cannot read the OS channel: ' + result.stderr)+ notes = output / 'channel-notes.md'+ notes.write_text('Harness OS preview update metadata. The computer checks this channel automatically; open Updates with Super+U to install.\n')+ gh('release', 'create', CHANNEL, '--repo', REPO, '--target', manifest['source_commit'], '--draft', '--prerelease',+ '--title', 'Harness OS preview updates', '--notes-file', notes)+ gh('release', 'upload', CHANNEL, '--repo', REPO, '--clobber', feed)+ with tempfile.TemporaryDirectory(prefix='harness-channel-check-') as temporary:+ gh('release', 'download', CHANNEL, '--repo', REPO, '--pattern', 'metadata.json', '--dir', temporary)+ if (Path(temporary) / 'metadata.json').read_bytes() != feed.read_bytes():+ raise ValueError('Uploaded channel metadata differs from the prepared feed.')+ gh('release', 'edit', CHANNEL, '--repo', REPO, '--draft=false', '--latest=false')+ verify_public(f'https://github.com/{REPO}/releases/download/{CHANNEL}/metadata.json',+ dict(bytes=feed.stat().st_size, sha256=digest(feed)))+ record.update(status='published', feed_sha256=digest(feed))+ record_path.write_text(json.dumps(record, indent=2) + '\n')+ print(json.dumps(record, indent=2))+++if __name__ == '__main__':+ main()diff --git a/os/tools/publish.py b/os/tools/publish.pyindex 55447f0f7..d0dce6e1f 100644--- a/os/tools/publish.py+++ b/os/tools/publish.py@@ -159,6 +159,7 @@ def main():notes = root / 'release-notes.md'interactive_install = all(any(c.startswith('Keyboard disk selection, encryption checkbox') for c in r['checks']) for r in receipts)update_retry = all(any(c.startswith('Failed full update blocks package changes') for c in r['checks']) for r in receipts)+ in_place_updates = {'runtime-updates', 'system-updates'}.issubset(manifest.get('capabilities', []))project_source_runs = sorted({str(r['workload_project_source_run_id']) for r in receipts if r.get('workload_project_source_run_id')})reuse_note = ('Completed project sources were retained from ' + ', '.join(f'[run {source}](https://github.com/{args.repo}/actions/runs/{source})' for source in project_source_runs) +@@ -171,7 +172,9 @@ To try it: follow the included `INSTALL.md` for Mac → USB → ThinkPad instruc{'The installer has four aligned fields: disk, encryption, password, repeat password. Disk choices fit on one line. Activate Install to begin; there is no second confirmation screen or minimum password length. Empty passwords are rejected. The account is me@harness. The password initially protects both the local account and, when enabled, the encrypted disk. There is no first-boot account wizard.' if interactive_install else ''}-{'Interrupted full OS updates now block ordinary package transactions until a full retry succeeds. Retrying keeps the original recovery checkpoint. This was exercised with a real failed repository refresh, blocked package upgrade, successful retry, and offline recovery. The bundled Harness runtime remains pinned to this preview; hn-os update updates Arch packages.' if update_retry else ''}+{'Interrupted full OS updates block ordinary package transactions until a full retry succeeds. Retrying keeps the original recovery checkpoint. This was exercised with a real failed repository refresh, blocked package upgrade, successful retry, and offline recovery. hn-os update upgrades Arch packages.' if update_retry else ''}++{'Super+U opens Updates. hn and CLI releases are prepared automatically; Enter activates an available runtime update. hn reconnects to the local tabs while agent processes keep running. System updates are a separate action in the same screen, with a checkpoint and a restart when you are ready. Neither channel automatically interrupts your work. Older preview 4 installations need the matching small bootstrap bundle once; routine updates do not require reflashing.' if in_place_updates else ''}BIOS/plain and UEFI/encrypted VM boot, clipboard, browser switching, offline installation and package-checkpoint recovery passed. The BIOS VM uses a Nehalem CPU profile without AVX2, starts bundled OpenCode, installs the other agent executables, installs a compiler on demand, builds C, and serves a local Node preview. See `validation.json` and `machine-evidence.zip` for the exact checks and measurements.