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
os: make screen lock wait for a covered frame and include compositor in updates (#898)
Dee7df0ea68ea84
diff --git a/.github/workflows/os-t2-update.yml b/.github/workflows/os-t2-update.ymlindex 58befab32..1fe341f35 100644--- a/.github/workflows/os-t2-update.yml+++ b/.github/workflows/os-t2-update.yml@@ -59,7 +59,8 @@ jobs:- name: Build private update and verify both immutable kernel archivesrun: |make -C os runtime- python3 os/tools/build-package.py --runtime os/work/runtime --output os/work/t2-update --development+ bash os/tools/build-compositor-container.sh os/work/compositor+ python3 os/tools/build-package.py --runtime os/work/runtime --compositor os/work/compositor --output os/work/t2-update --developmentpython3 - <<'PY'import importlib.util, jsonfrom pathlib import Pathdiff --git a/.github/workflows/os-t2.yml b/.github/workflows/os-t2.ymlindex 00adbcbfc..6ee3bdb85 100644--- a/.github/workflows/os-t2.yml+++ b/.github/workflows/os-t2.yml@@ -73,6 +73,8 @@ jobs:'--max-time', '180', package['url'], '-o', str(folder / package['filename'])], check=True)PYpython3 os/tools/prepare-t2-kernel.py --package os/work/t2-inputs/*.pkg.tar.zst --output os/work/t2-kernel-bundle+ - name: Build the pinned OS compositor+ run: bash os/tools/build-compositor-container.sh os/work/compositor- name: Build the isolated T2 live and installed imagerun: |docker run --rm --privileged \diff --git a/.github/workflows/os.yml b/.github/workflows/os.ymlindex 410f3f869..4c86148ec 100644--- a/.github/workflows/os.yml+++ b/.github/workflows/os.yml@@ -51,7 +51,7 @@ on:required: falsedefault: imagetype: choice- options: [image, browser, browser-suspend, session, recovery, essentials, network-recovery, hardware, zram, hardware-update, public-update]+ options: [image, browser, browser-suspend, session, recovery, essentials, network-recovery, hardware, zram, hardware-update, public-update, lock-presentation]browser_memory:description: 'With checks=browser, diagnose memory in the UEFI VM only; retain ordinary workload and deadlines'required: false@@ -70,8 +70,63 @@ concurrency:cancel-in-progress: falsejobs:+ lock-presentation:+ if: ${{ inputs.checks == 'lock-presentation' && inputs.image_run_id != '' && !inputs.publish_run_id && !inputs.development_update }}+ runs-on: ubuntu-24.04+ timeout-minutes: 30+ steps:+ - uses: actions/checkout@v7+ - name: Check the private compositor observer+ run: |+ python3 -m py_compile os/tools/build-compositor.py os/tests/session_vm.py+ go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os.yml+ - uses: actions/download-artifact@v6+ with:+ name: programmer-os-x86_64+ path: os/dist+ run-id: ${{ inputs.image_run_id }}+ github-token: ${{ github.token }}+ - name: Build only the pinned compositor correction+ run: |+ bash os/tools/build-compositor-container.sh os/work/lock-compositor+ - name: Prepare native VM tools+ run: |+ sudo apt-get update -qq+ sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr+ sudo chmod a+rw /dev/kvm+ - name: Check the real encrypted UEFI lock transition and work preservation+ run: >-+ timeout 10m python3 os/tests/session_vm.py --iso os/dist/*.iso --firmware uefi+ --compositor-file os/work/lock-compositor/labwc+ - name: Check the real BIOS lock transition and work preservation+ run: >-+ timeout 10m python3 os/tests/session_vm.py --iso os/dist/*.iso --firmware bios+ --compositor-file os/work/lock-compositor/labwc+ - name: Retain the private correction and every completed check+ if: always()+ uses: actions/upload-artifact@v6+ with:+ name: harness-os-lock-presentation+ path: |+ os/work/lock-compositor/labwc+ os/work/lock-compositor/manifest.json+ os/work/lock-compositor/LICENSE+ os/work/lock-compositor/source.tar.gz+ os/work/lock-compositor/source.json+ os/work/lock-compositor/session-lock-presentation.patch+ os/work/lock-compositor/build-compositor.py+ os/work/lock-compositor/rebuild.sh+ os/work/lock-compositor/lock_presentation_policy.c+ os/work/lock-compositor/build/meson-logs/*.txt+ os/test-results/**/*.json+ os/test-results/**/*.jsonl+ os/test-results/**/*.png+ os/test-results/**/*.txt+ os/test-results/**/*.log+ retention-days: 14+image:- if: ${{ !inputs.image_run_id && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'browser-suspend' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' }}+ if: ${{ !inputs.image_run_id && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'browser-suspend' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' && inputs.checks != 'lock-presentation' }}runs-on: ubuntu-24.04timeout-minutes: 50steps:@@ -120,6 +175,8 @@ jobs:cd ..timeout 8m cargo test --manifest-path tui/Cargo.toml --locked --release --target x86_64-unknown-linux-muslpython3 scripts/validate-tui-native.py tui/target/x86_64-unknown-linux-musl/release/harness-tui+ - name: Build the pinned OS compositor+ run: bash os/tools/build-compositor-container.sh os/work/compositor- name: Build offline BIOS and UEFI imagerun: |docker run --rm --privileged \@@ -159,7 +216,7 @@ jobs:machine:needs: image- if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'essentials' && inputs.checks != 'hardware' && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' && (needs.image.result == 'success' || inputs.image_run_id != '' || inputs.checks == 'browser-suspend') && !cancelled() }}+ if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'essentials' && inputs.checks != 'hardware' && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'public-update' && inputs.checks != 'network-recovery' && inputs.checks != 'lock-presentation' && (needs.image.result == 'success' || inputs.image_run_id != '' || inputs.checks == 'browser-suspend') && !cancelled() }}runs-on: ubuntu-24.04timeout-minutes: 65strategy:@@ -552,7 +609,8 @@ jobs:sudo apt-get install -y musl-tools qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocrif test -e /dev/kvm; then sudo chmod a+rw /dev/kvm; fimake -C os runtime- python3 os/tools/build-package.py --runtime os/work/runtime --output os/work/development-update --development+ bash os/tools/build-compositor-container.sh os/work/compositor+ python3 os/tools/build-package.py --runtime os/work/runtime --compositor os/work/compositor --output os/work/development-update --developmentpython3 os/tests/build-update-fixture.py- name: Exercise apply, rollback, running work and encrypted rebootrun: python3 os/tests/update_vm.py --iso os/dist/*.iso --bundle os/work/development-update --fast-fixture os/work/fast-update-fixturediff --git a/os/DEVELOPMENT.md b/os/DEVELOPMENT.mdindex c1f14589f..99f07d37e 100644--- a/os/DEVELOPMENT.md+++ b/os/DEVELOPMENT.md@@ -407,7 +407,8 @@ On a clean x86 Linux checkout, build a bundle with:```shmake -C os runtime-python3 os/tools/build-package.py --runtime os/work/runtime --output os/work/my-update --development+make -C os compositor+python3 os/tools/build-package.py --runtime os/work/runtime --compositor os/work/compositor --output os/work/my-update --development```The bundle identifies the source commit, architecture, required base image anddiff --git a/os/Makefile b/os/Makefileindex d1c180585..54b0d5384 100644--- a/os/Makefile+++ b/os/Makefile@@ -1,9 +1,11 @@-.PHONY: check runtime build vm+.PHONY: check runtime compositor build vmcheck:python3 -m unittest discover -s tests -p 'test_*.py' -vpython3 tools/check.pyruntime:bash tools/build-runtime.sh+compositor:+ bash tools/build-compositor-container.sh os/work/compositorbuild:sudo bash build.shvm:diff --git a/os/README.md b/os/README.mdindex 434084ca6..e7bb53408 100644--- a/os/README.md+++ b/os/README.md@@ -84,6 +84,13 @@ for requirements and remaining work.repository snapshot and record the installed package inventory.- labwc supplies Wayland, focus, input and display management. No panel, launcher,wallpaper process, desktop icons, or notification daemon.+ On PC and Intel Mac builds, the OS package owns its pinned compositor at+ `/usr/lib/harness-os/labwc`. Its lock acknowledgement waits until every active+ display presents a covered frame. Updating or rolling back that package moves+ the session and compositor together; the running session is left alone until+ restart. Corresponding GPL source, the patch and rebuild instructions are in+ `/usr/share/licenses/harness-os/labwc/`. Fresh images do not install a second+ compositor. The experimental Fedora session still uses Fedora's labwc.- One fullscreen foot window displays the existing Rust `hn`. Agent/runtimeprocesses are supervised separately from that window. The image does not forkfoot or add a second graphical Harness client.@@ -116,6 +123,7 @@ rustup default stablerustup target add x86_64-unknown-linux-muslmake -C os checkmake -C os runtime+make -C os compositormake -C os build```diff --git a/os/build.sh b/os/build.shindex 133143e3c..c88a3a35c 100644--- a/os/build.sh+++ b/os/build.sh@@ -14,12 +14,17 @@ VERSION=$(python3 -c 'import json; print(json.load(open("lock.json"))["version"]SNAPSHOT=$(python3 -c 'import json; print(json.load(open("lock.json"))["arch_snapshot"])')BUILD_DIR=${HARNESS_OS_BUILD_DIR:-$OS_DIR/work}RUNTIME_DIR=${HARNESS_OS_RUNTIME_DIR:-$OS_DIR/work/runtime}+COMPOSITOR_DIR=${HARNESS_OS_COMPOSITOR_DIR:-$OS_DIR/work/compositor}PLATFORM=${HARNESS_OS_PLATFORM:-pc}[[ $PLATFORM == pc || $PLATFORM == apple-t2 ]] || { echo 'Unknown OS boot platform.' >&2; exit 1; }[[ -s "$RUNTIME_DIR/source.json" && -x "$RUNTIME_DIR/harness-tui" ]] || {echo 'Build the OS runtimes first with make -C os runtime on x86_64 Linux.' >&2exit 1}+[[ -s "$COMPOSITOR_DIR/manifest.json" && -x "$COMPOSITOR_DIR/labwc" ]] || {+ echo 'Build the compositor first with make -C os compositor.' >&2+ exit 1+}mkdir -p "$BUILD_DIR" "$OS_DIR/dist"[[ ! -e "$BUILD_DIR/profile" ]] || { echo 'Use a fresh build directory; refusing to reuse an incomplete image.' >&2; exit 1; }cp -a /usr/share/archiso/configs/releng "$BUILD_DIR/profile"@@ -46,7 +51,7 @@ EOF# Reuse the same package assembly for fresh images and small development updates.# 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" --development+python3 tools/build-package.py --runtime "$RUNTIME_DIR" --compositor "$COMPOSITOR_DIR" --output "$BUILD_DIR/repo" --developmentPROFILE_ARGS=(--profile "$PROFILE" --platform "$PLATFORM")if [[ $PLATFORM == apple-t2 ]]; then[[ -n ${HARNESS_OS_T2_BUNDLE:-} ]] || { echo 'Prepare the pinned T2 kernel bundle first.' >&2; exit 1; }diff --git a/os/packages.x86_64 b/os/packages.x86_64index 48b32949f..b6b9dfb60 100644--- a/os/packages.x86_64+++ b/os/packages.x86_64@@ -29,7 +29,7 @@ systemd-resolvconfzram-generatorwireless-regdb# Exactly one terminal surface and an on-demand browser.-labwc+# The compositor and its shared-library dependencies belong to harness-os.footchromiummesadiff --git a/os/packaging/labwc/rebuild.sh b/os/packaging/labwc/rebuild.shnew file mode 100644index 000000000..625c4a8d3--- /dev/null+++ b/os/packaging/labwc/rebuild.sh@@ -0,0 +1,26 @@+#!/bin/sh+# Rebuild from the corresponding source shipped with Harness (GPL-2.0-only).+# Use an x86-64 Arch build environment at the snapshot in source.json. Install+# base-devel labwc meson cmocka wayland-protocols glib2-devel xorg-xwayland python.+# Run this script in this source directory; it never installs into the system.+set -eu+test ! -e rebuild+mkdir rebuild+tar -xzf source.tar.gz -C rebuild+cd rebuild/labwc-*+patch --batch --fuzz=0 -p1 -i ../../session-lock-presentation.patch+cp ../../lock_presentation_policy.c t/harness-lock-presentation.c+cat >> t/meson.build <<'EOF'+test('harness_lock_presentation', executable('test_harness_lock_presentation',+ sources: 'harness-lock-presentation.c', include_directories: [labwc_inc],+ dependencies: labwc_deps,+ c_args: ['-UNDEBUG', '-ffunction-sections', '-fdata-sections'],+ link_args: ['-Wl,--gc-sections']), is_parallel: false)+EOF+export GIT_CEILING_DIRECTORIES="$(cd .. && pwd)"+meson setup build --prefix=/usr --buildtype=release --wrap-mode=nodownload \+ -Dtest=enabled -Dman-pages=disabled -Dxwayland=enabled \+ -Dlabnag=disabled -Dsystemd-session=disabled+meson compile -C build -j 2+meson test -C build --print-errorlogs+strip --strip-unneeded build/labwcdiff --git a/os/packaging/labwc/session-lock-presentation.patch b/os/packaging/labwc/session-lock-presentation.patchnew file mode 100644index 000000000..9002c67d3--- /dev/null+++ b/os/packaging/labwc/session-lock-presentation.patch@@ -0,0 +1,171 @@+# SPDX-License-Identifier: GPL-2.0-only+# Blank immediately and acknowledge a session lock only after every active output presents it.+--- a/include/session-lock.h++++ b/include/session-lock.h+@@ -19,6 +19,7 @@+ */+ struct wlr_session_lock_v1 *lock;+ bool locked;++ bool ack_pending;++ struct wl_list lock_outputs;++--- a/src/session-lock.c++++ b/src/session-lock.c+@@ -17,15 +17,35 @@+ struct session_lock_manager *manager;+ struct output *output;+ struct wlr_session_lock_surface_v1 *surface;+- struct wl_event_source *blank_timer;++ bool locked_frame_presented;++ bool frame_pending;++ uint32_t frame_commit_seq;++ struct wl_list link; /* session_lock_manager.lock_outputs */++ struct wl_listener destroy;+ struct wl_listener commit;++ struct wl_listener present;+ struct wl_listener surface_destroy;+ struct wl_listener surface_map;+ };++++static void++send_locked_when_presented(struct session_lock_manager *manager)++{++ if (!manager->lock || !manager->ack_pending) {++ return;++ }++ struct session_lock_output *output;++ wl_list_for_each(output, &manager->lock_outputs, link) {++ if (output->output->wlr_output->enabled++ && !output->locked_frame_presented) {++ return;++ }++ }++ manager->ack_pending = false;++ wlr_session_lock_v1_send_locked(manager->lock);++}++ static void+ focus_surface(struct session_lock_manager *manager, struct wlr_surface *focused)+@@ -162,9 +182,9 @@+ wl_list_remove(&output->surface_map.link);+ }+ wl_list_remove(&output->commit.link);++ wl_list_remove(&output->present.link);+ wl_list_remove(&output->destroy.link);+ wl_list_remove(&output->link);+- wl_event_source_remove(output->blank_timer);+ free(output);+ }++@@ -172,7 +192,9 @@+ handle_output_destroy(struct wl_listener *listener, void *data)+ {+ struct session_lock_output *output = wl_container_of(listener, output, destroy);++ struct session_lock_manager *manager = output->manager;+ session_lock_output_destroy(output);++ send_locked_when_presented(manager);+ }++ static void+@@ -185,6 +207,29 @@+ if (event->state->committed & require_reconfigure) {+ lock_output_reconfigure(output);+ }++ if (event->state->committed & WLR_OUTPUT_STATE_ENABLED) {++ output->locked_frame_presented = false;++ output->frame_pending = false;++ }++ if ((event->state->committed & WLR_OUTPUT_STATE_BUFFER)++ && !output->locked_frame_presented) {++ output->frame_pending = true;++ output->frame_commit_seq = event->output->commit_seq;++ }++ send_locked_when_presented(output->manager);++}++++static void++handle_output_present(struct wl_listener *listener, void *data)++{++ struct wlr_output_event_present *event = data;++ struct session_lock_output *output = wl_container_of(listener, output, present);++ if (output->frame_pending && event->presented++ && event->commit_seq == output->frame_commit_seq) {++ output->locked_frame_presented = true;++ output->frame_pending = false;++ send_locked_when_presented(output->manager);++ }+ }++ static void+@@ -194,14 +239,6 @@+ wlr_output_layout_get_box(server.output_layout,+ output->wlr_output, &box);+ wlr_scene_node_set_position(&output->session_lock_tree->node, box.x, box.y);+-}+-+-static int+-handle_output_blank_timeout(void *data)+-{+- struct session_lock_output *lock_output = data;+- wlr_scene_node_set_enabled(&lock_output->background->node, true);+- return 0;+ }++ void+@@ -223,17 +260,7 @@+ float black[4] = { 0.f, 0.f, 0.f, 1.f };+ struct wlr_scene_rect *background = lab_wlr_scene_rect_create(tree, 0, 0, black);++- /*+- * Delay blanking output by 100ms to prevent flicker. If the session is+- * already locked, blank immediately.+- */+- lock_output->blank_timer =+- wl_event_loop_add_timer(server.wl_event_loop,+- handle_output_blank_timeout, lock_output);+- if (!manager->locked) {+- wlr_scene_node_set_enabled(&background->node, false);+- wl_event_source_timer_update(lock_output->blank_timer, 100);+- }++ /* Hide normal content immediately; acknowledge only after presentation. */++ align_session_lock_tree(output);++@@ -247,6 +274,8 @@++ lock_output->commit.notify = handle_output_commit;+ wl_signal_add(&output->wlr_output->events.commit, &lock_output->commit);++ lock_output->present.notify = handle_output_present;++ wl_signal_add(&output->wlr_output->events.present, &lock_output->present);++ lock_output_reconfigure(lock_output);++@@ -256,6 +285,7 @@+ static void+ session_lock_destroy(struct session_lock_manager *manager)+ {++ manager->ack_pending = false;+ struct session_lock_output *lock_output, *next;+ wl_list_for_each_safe(lock_output, next, &manager->lock_outputs, link) {+ wlr_scene_node_destroy(&lock_output->tree->node);+@@ -301,6 +331,7 @@+ wl_list_remove(&manager->lock_unlock.link);+ wl_list_remove(&manager->lock_new_surface.link);+ manager->lock = NULL;++ manager->ack_pending = false;+ }++ static void+@@ -342,7 +373,8 @@++ manager->locked = true;+ manager->lock = lock;+- wlr_session_lock_v1_send_locked(lock);++ manager->ack_pending = true;++ send_locked_when_presented(manager);+ }++ static voiddiff --git a/os/packaging/labwc/source.json b/os/packaging/labwc/source.jsonnew file mode 100644index 000000000..7021a9b2d--- /dev/null+++ b/os/packaging/labwc/source.json@@ -0,0 +1,12 @@+{+ "version": "0.20.2",+ "tag_object": "400c1d6d57bfd58d88f623d763b8812aef582469",+ "commit": "97f28877a343e062f3178d201f0248cd9c2610cf",+ "url": "https://codeload.github.com/labwc/labwc/tar.gz/97f28877a343e062f3178d201f0248cd9c2610cf",+ "bytes": 553914,+ "sha256": "022676dbcbf6b6206b97d7bac8a339c8a0203e3e99693107c15b5a6183e4b0ea",+ "arch_snapshot": "2026/10/01",+ "scope": "PC and Intel Mac compositor owned by the Harness OS package",+ "patch": "session-lock-presentation.patch",+ "patch_sha256": "e911639c8b7d8eef1a2d75ff623587df3e78455905c5f6a5c1c0b0fcc689e2fb"+}diff --git a/os/root/etc/xdg/xdg-desktop-portal/labwc-portals.conf b/os/root/etc/xdg/xdg-desktop-portal/labwc-portals.confnew file mode 100644index 000000000..4b08b588b--- /dev/null+++ b/os/root/etc/xdg/xdg-desktop-portal/labwc-portals.conf@@ -0,0 +1,3 @@+[preferred]+default=wlr;*+org.freedesktop.impl.portal.Inhibit=nonediff --git a/os/root/usr/lib/harness-os/session b/os/root/usr/lib/harness-os/sessionindex f4a0797ca..3351de6ad 100644--- a/os/root/usr/lib/harness-os/session+++ b/os/root/usr/lib/harness-os/session@@ -34,7 +34,7 @@ compositor_config=/usr/share/harness-os/labwcif [ -f /etc/harness-live ]; thencompositor_config=/usr/share/harness-os/labwc-installfi-if labwc -C "$compositor_config" > "$HOME/.local/state/harness-os/display.log" 2>&1; then+if /usr/lib/harness-os/labwc -C "$compositor_config" > "$HOME/.local/state/harness-os/display.log" 2>&1; thenexit 0firestore_ttydiff --git a/os/tests/browser_vm.py b/os/tests/browser_vm.pyindex c4ce19e0e..e0eb8dd7c 100644--- a/os/tests/browser_vm.py+++ b/os/tests/browser_vm.py@@ -434,8 +434,10 @@ def main():parser.add_argument('--memory-mib', type=int, choices=[1024, 2048, 4096], default=1024)parser.add_argument('--check', choices=['focus', 'suspend'], default='focus')parser.add_argument('--wlrctl', type=Path, required=True)- parser.add_argument('--browser-script', type=Path, required=True)- parser.add_argument('--compositor-config', type=Path, required=True)+ parser.add_argument('--browser-script', type=Path,+ help='Explicitly overlay a candidate browser launcher; omit to test the packaged image')+ parser.add_argument('--compositor-config', type=Path,+ help='Explicitly overlay a candidate compositor configuration; omit to test the packaged image')parser.add_argument('--memory-profile', action='store_true',help='Capture finite read-only memory snapshots; separate from ordinary focus acceptance')parser.add_argument('--zram-config', type=Path,@@ -540,13 +542,18 @@ def main():vm.command('chmod 700 /tmp/harness-wlrctl')for source, target, mode in [(args.browser_script, '/usr/bin/hn-browser', '755'),(args.compositor_config, '/usr/share/harness-os/labwc/rc.xml', '644')]:+ if source is None:+ continuedata = source.read_bytes()base = vm.read_file(target)result['candidates'][target] = dict(source=str(source), sha256=hashlib.sha256(data).hexdigest(),original_sha256=hashlib.sha256(base).hexdigest(), changed=data != base)copy_file(vm, data, '/tmp/browser-candidate')vm.command('sudo install -m ' + mode + ' /tmp/browser-candidate ' + shlex.quote(target))- vm.command('systemd-run --user --quiet --wait --pipe --collect labwc --reconfigure')+ if args.compositor_config:+ # Signal the actual running compositor, including the private+ # OS-owned executable. Exact-image acceptance needs no reload.+ vm.command('pkill -HUP -u "$(id -u)" -x labwc')if args.memory_profile:data = Path(__file__).with_name('browser_memory.py').read_bytes()result['memory_observer_sha256'] = hashlib.sha256(data).hexdigest()diff --git a/os/tests/lock_presentation_policy.c b/os/tests/lock_presentation_policy.cnew file mode 100644index 000000000..4e9005132--- /dev/null+++ b/os/tests/lock_presentation_policy.c@@ -0,0 +1,146 @@+// SPDX-License-Identifier: GPL-2.0-only+/* Exercise the actual patched callbacks with adversarial display events. */+#include <stdio.h>+#include <string.h>+#include "../src/session-lock.c"++struct server server;+static unsigned acknowledgements;++void+wlr_session_lock_v1_send_locked(struct wlr_session_lock_v1 *lock)+{+ assert(lock);+ ++acknowledgements;+}++struct fixture {+ struct session_lock_manager manager;+ struct wlr_session_lock_v1 lock;+ struct wlr_output displays[2];+ struct output outputs[2];+ struct session_lock_output locks[2];+};++static void+setup(struct fixture *f)+{+ memset(f, 0, sizeof(*f));+ acknowledgements = 0;+ f->manager.lock = &f->lock;+ f->manager.locked = true;+ f->manager.ack_pending = true;+ wl_list_init(&f->manager.lock_outputs);+ for (unsigned i = 0; i < 2; ++i) {+ f->displays[i].enabled = true;+ f->outputs[i].wlr_output = &f->displays[i];+ f->locks[i].output = &f->outputs[i];+ f->locks[i].manager = &f->manager;+ wl_list_insert(&f->manager.lock_outputs, &f->locks[i].link);+ }+}++static void+commit(struct fixture *f, unsigned index, uint32_t sequence, uint32_t fields)+{+ struct wlr_output_state state = { .committed = fields };+ f->displays[index].commit_seq = sequence;+ struct wlr_output_event_commit event = {+ .output = &f->displays[index], .state = &state,+ };+ handle_output_commit(&f->locks[index].commit, &event);+}++static void+present(struct fixture *f, unsigned index, uint32_t sequence, bool displayed)+{+ struct wlr_output_event_present event = {+ .output = &f->displays[index], .commit_seq = sequence, .presented = displayed,+ };+ handle_output_present(&f->locks[index].present, &event);+}++int+main(void)+{+ struct fixture f;+ setup(&f);+ send_locked_when_presented(&f.manager);+ assert(acknowledgements == 0);+ /* A property-only commit and a stale scanout cannot establish coverage. */+ commit(&f, 0, 10, WLR_OUTPUT_STATE_DAMAGE);+ present(&f, 0, 10, true);+ assert(!f.locks[0].locked_frame_presented && acknowledgements == 0);+ commit(&f, 0, 11, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 0, 10, true);+ assert(!f.locks[0].locked_frame_presented);+ present(&f, 0, 11, false);+ assert(!f.locks[0].locked_frame_presented);+ present(&f, 0, 11, true);+ assert(f.locks[0].locked_frame_presented && acknowledgements == 0);+ /* Every enabled display must present its own protected frame. */+ commit(&f, 1, 22, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 1, 21, true);+ assert(acknowledgements == 0);+ present(&f, 1, 22, true);+ assert(acknowledgements == 1 && !f.manager.ack_pending);+ present(&f, 1, 22, true);+ send_locked_when_presented(&f.manager);+ assert(acknowledgements == 1);++ /* A display that is actually disabled must not strand the lock. */+ setup(&f);+ commit(&f, 0, 1, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 0, 1, true);+ f.displays[1].enabled = false;+ commit(&f, 1, 2, WLR_OUTPUT_STATE_ENABLED);+ assert(acknowledgements == 1);++ /* Re-enabling an output invalidates any previous coverage. */+ setup(&f);+ f.locks[1].locked_frame_presented = true;+ commit(&f, 1, 5, WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_BUFFER);+ assert(!f.locks[1].locked_frame_presented);+ commit(&f, 0, 6, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 0, 6, true);+ assert(acknowledgements == 0);+ present(&f, 1, 5, true);+ assert(acknowledgements == 1);++ /* A late presentation from before a power change is no longer proof+ * that the newly enabled output displays a protected frame. */+ setup(&f);+ commit(&f, 1, 5, WLR_OUTPUT_STATE_BUFFER);+ f.displays[1].enabled = false;+ commit(&f, 1, 6, WLR_OUTPUT_STATE_ENABLED);+ f.displays[1].enabled = true;+ commit(&f, 1, 7, WLR_OUTPUT_STATE_ENABLED);+ present(&f, 1, 5, true);+ assert(!f.locks[1].locked_frame_presented);+ commit(&f, 0, 8, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 0, 8, true);+ assert(acknowledgements == 0);+ commit(&f, 1, 9, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 1, 9, true);+ assert(acknowledgements == 1);++ /* Equality remains correct across the 32-bit commit sequence wrap. */+ setup(&f);+ f.displays[1].enabled = false;+ commit(&f, 0, 0, WLR_OUTPUT_STATE_BUFFER);+ present(&f, 0, UINT32_MAX, true);+ assert(acknowledgements == 0);+ present(&f, 0, 0, true);+ assert(acknowledgements == 1);++ /* Late events after the lock client disappears cannot acknowledge it. */+ setup(&f);+ commit(&f, 0, 1, WLR_OUTPUT_STATE_BUFFER);+ f.manager.lock = NULL;+ f.displays[1].enabled = false;+ present(&f, 0, 1, true);+ assert(acknowledgements == 0 && f.manager.locked);++ puts("Lock presentation: two displays, stale/failed frames, power changes, sequence wrap and client loss passed");+ return 0;+}diff --git a/os/tests/public_update_guest.py b/os/tests/public_update_guest.pyindex ca51d6d81..3583e7ee9 100644--- a/os/tests/public_update_guest.py+++ b/os/tests/public_update_guest.py@@ -79,6 +79,16 @@ def work():'boot_id': Path('/proc/sys/kernel/random/boot_id').read_text().strip()}+def display():+ pids = subprocess.check_output(['pgrep', '-u', '1000', '-x', 'labwc'], text=True).split()+ if len(pids) != 1:+ raise ValueError('Expected one actual graphical compositor')+ executable = Path('/proc') / pids[0] / 'exe'+ path = str(executable.resolve(strict=True))+ return {'process': process(pids[0]), 'executable': path, 'sha256': digest(executable),+ 'owner': subprocess.check_output(['pacman', '-Qqo', path], text=True).strip()}++def checkpoint():pointer = json.loads((ROOT_STATE / 'latest.json').read_text())['id']if not re.fullmatch(r'[0-9TZ-]+-[a-f0-9]{8}', pointer):@@ -108,8 +118,9 @@ def checkpoint():if __name__ == '__main__':parser = argparse.ArgumentParser(description=__doc__)- parser.add_argument('action', choices=['system', 'work', 'checkpoint', 'project'])+ parser.add_argument('action', choices=['system', 'work', 'checkpoint', 'project', 'display'])parser.add_argument('output', type=Path)args = parser.parse_args()- result = {'system': system, 'work': work, 'checkpoint': checkpoint, 'project': project}[args.action]()+ result = {'system': system, 'work': work, 'checkpoint': checkpoint, 'project': project,+ 'display': display}[args.action]()args.output.write_text(json.dumps(result, indent=2) + '\n')diff --git a/os/tests/public_update_vm.py b/os/tests/public_update_vm.pyindex 2fb520a9f..5e2571069 100644--- a/os/tests/public_update_vm.py+++ b/os/tests/public_update_vm.py@@ -71,6 +71,15 @@ def installed_matches(record, receipt):raise ValueError('Installed file differs from the ISO-bound package: ' + name)+def display_matches(record, expected, *, restored=False):+ executable = expected['executable'] if restored else '/usr/lib/harness-os/labwc'+ owner = expected['owner'] if restored else 'harness-os'+ checksum = expected['sha256'] if restored else expected['binary']['sha256']+ if any(record[key] != value for key, value in+ [('executable', executable), ('owner', owner), ('sha256', checksum)]):+ raise ValueError('Running compositor differs from the expected package')++def shutdown(vm, record, name, root=False):# Drain the diagnostic serial socket while waiting for the fresh QMP# shutdown event. An unread console can stall QEMU during guest poweroff.@@ -169,6 +178,7 @@ def main():vm.command('test ! -e ' + STATE + '/current && test ! -e ' + STATE + '/ready.json && test ! -e ' + STATE + '/approved.json')copy_file(vm, Path(__file__).with_name('public_update_guest.py').read_bytes(), GUEST)original = observe('01-original-system', 'system', True)+ original_display = observe('01-original-display', 'display', True)(folder / 'hosts-before.txt').write_bytes(vm.read_file('/etc/hosts'))if original['runtime'] != base['harness_inputs'] or original['package_version'] != base['package_version']:raise ValueError('Baseline installed runtime differs from the original ISO')@@ -268,6 +278,8 @@ def main():authenticate()installed = observe('08-installed-candidate', 'system', True)installed_matches(installed, bound)+ if observe('08-running-display', 'display', True) != original_display:+ raise ValueError('Updating the package restarted or replaced the running compositor')saved = observe('09-checkpoint', 'checkpoint', True)if (saved['receipt']['status'] != 'applied' or saved['receipt']['candidate'] != candidateor saved['previous_files'] != original['owned_files']@@ -286,15 +298,18 @@ def main():authenticate()rebooted = observe('11-cold-boot-system', 'system', True)installed_matches(rebooted, bound)+ if candidate.get('compositor'):+ display_matches(observe('11-candidate-display', 'display', True), candidate['compositor'])if rebooted['boot_id'] == before['boot_id']:raise ValueError('No real cold boot occurred')if observe('12-project-after-reboot', 'project') != project:raise ValueError('Home/project files changed across update reboot')if observe('13-checkpoint-after-reboot', 'checkpoint', True) != saved:raise ValueError('Checkpoint changed across candidate reboot')- check_graphical_keyboard(vm, '14-candidate-keyboard')- # The unchanged client restores shells, not their previous foreground- # commands. Live agent preservation was proved before shutdown above;+ check_graphical_keyboard(vm, '14-candidate-keyboard', allow_welcome=True)+ # The unchanged client may show its welcome or saved shells after boot;+ # it does not resume their previous foreground commands. Live agent+ # preservation was proved before shutdown above;# now prove the bundled agent can start normally on the updated OS.vm.command('hn new-window -n agent-after-update ' + shlex.quote('cd "$HOME/projects/public-update-proof" && exec /usr/bin/opencode'))@@ -335,6 +350,42 @@ def main():vm.command('sudo -n journalctl -b --no-pager > /tmp/public-update-final-journal.log')(folder / 'final-journal.log').write_bytes(vm.read_file('/tmp/public-update-final-journal.log'))record['checks'].append('Encrypted candidate cold boot accepts real keyboard input and an explicitly launched bundled agent, and preserves project bytes/ownership/times and the verified original checkpoint. Foreground command auto-resume is not claimed.')+ if candidate.get('compositor'):+ # Use the real retained package and current rollback implementation,+ # with the network disabled. No staged source or replacement binary.+ vm.command('systemctl --user stop harness-update.timer harness-update.service')+ vm.command('rm -f ~/projects/session-probe/pid ~/projects/session-probe/heartbeat && '+ "hn new-window -P -F '#{pane_id}' -n rollback-proof 'python3 /home/me/public-update-terminal.py' > /tmp/public-update-terminal-id")+ vm.command('for n in $(seq 1 60); do test -s ~/projects/session-probe/pid && exit 0; sleep .1; done; exit 1')+ terminal = vm.read_file('/tmp/public-update-terminal-id').decode().strip()+ if not re.fullmatch(r'%\d+', terminal):+ raise ValueError('Invalid rollback probe pane identity')+ keyboard('before-offline-rollback')+ before_rollback = observe('19-before-rollback-work', 'work')+ authenticate()+ vm.command('sudo -n nmcli networking off')+ vm.monitor('set_link', name='hnnet', up=False)+ output, _ = vm.command('sudo -n python3 /usr/lib/harness-os/runtime_update.py rollback', timeout=240)+ (folder / '20-offline-rollback.log').write_text(output)+ same_work(before_rollback, observe('21-after-rollback-work', 'work'))+ keyboard('after-offline-rollback')+ restored = observe('22-restored-system', 'system', True)+ for key in ('package_version', 'owned_files', 'runtime', 'lock', 'sudo_policy'):+ if restored[key] != original[key]:+ raise ValueError('Offline rollback did not restore the original system: ' + key)+ vm.command('test ! -e /usr/lib/harness-os/labwc && test ! -e /usr/share/harness-os/compositor.json')+ if observe('23-project-after-rollback', 'project') != project:+ raise ValueError('Offline rollback changed newer project files')+ shutdown(vm, record, 'offline-rollback')+ vm.start(live=False)+ vm.monitor('set_link', name='hnnet', up=False)+ vm.login_installed(config)+ authenticate()+ display_matches(observe('24-restored-display', 'display', True), original_display, restored=True)+ check_graphical_keyboard(vm, '25-restored-keyboard', allow_welcome=True)+ if observe('26-project-after-rollback-boot', 'project') != project:+ raise ValueError('Rollback reboot changed newer project files')+ record['checks'].append('The packaged compositor activates after cold boot. Offline rollback preserves running work, restores every original package file and privilege rule, removes the private compositor, then boots the original compositor with working keyboard and newer projects intact.')shutdown(vm, record, 'acceptance-complete')record['status'] = 'passed'except Exception as error:diff --git a/os/tests/session_vm.py b/os/tests/session_vm.pyindex 4e58109d8..fc4cd0d7b 100644--- a/os/tests/session_vm.py+++ b/os/tests/session_vm.py@@ -2,6 +2,7 @@"""Observe locking, suspend or compositor recovery on a disposable installed machine."""import argparseimport base64+import gzipimport hashlibimport jsonimport os@@ -295,6 +296,8 @@ def main():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')+ parser.add_argument('--compositor-file', type=Path,+ help='Private labwc proof only: stage a manifest-verified compositor and reboot before testing')args = parser.parse_args()if not os.access('/dev/kvm', os.R_OK | os.W_OK):parser.error('Use native x86 KVM for session acceptance.')@@ -348,6 +351,20 @@ def main():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.compositor_file:+ candidate = args.compositor_file.read_bytes()+ manifest = json.loads(args.compositor_file.with_name('manifest.json').read_text())+ checksum = hashlib.sha256(candidate).hexdigest()+ assert manifest['binary']['sha256'] == checksum+ assert manifest['binary']['bytes'] == len(candidate)+ assert candidate[:6] == b'\x7fELF\x02\x01' and int.from_bytes(candidate[18:20], 'little') == 62+ assert manifest['source_commit'] == result['test_source_commit']+ result['candidate_compositor'] = manifest+ packed = base64.b64encode(gzip.compress(candidate, mtime=0)).decode()+ put(vm, '/tmp/lock-compositor.gz.b64', packed)+ vm.command('base64 -d /tmp/lock-compositor.gz.b64 | gzip -d > /tmp/lock-compositor && '+ 'test "$(sha256sum /tmp/lock-compositor | cut -d " " -f 1)" = ' + shlex.quote(checksum) + ' && '+ 'sudo install -o root -g root -m 755 /tmp/lock-compositor /usr/bin/labwc && sync')if args.session_file:candidate = args.session_file.read_bytes()result['candidate_session'] = {'path': str(args.session_file), 'sha256': hashlib.sha256(candidate).hexdigest(),@@ -366,7 +383,7 @@ def main():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']):+ if args.session_file or args.compositor_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')@@ -380,6 +397,8 @@ def main():installed_recovery(vm, config, result)else:installed_session(vm, config, result)+ from session_update_vm import screenshots+ screenshots(vm, result)assert 'live_lock_error' not in result, 'The unconfigured live session could not be unlocked'result['status'] = 'passed'except BaseException as error:diff --git a/os/tests/test_compositor_payload.py b/os/tests/test_compositor_payload.pynew file mode 100644index 000000000..6d95590b8--- /dev/null+++ b/os/tests/test_compositor_payload.py@@ -0,0 +1,147 @@+import copy+import importlib.util+import json+from pathlib import Path+import shutil+import tarfile+import tempfile+import unittest+from unittest.mock import patch+++ROOT = Path(__file__).resolve().parents[2]+++def load(name, path):+ spec = importlib.util.spec_from_file_location(name, path)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++payload = load('compositor_payload', ROOT / 'os/tools/compositor_payload.py')+builder = load('compositor_package', ROOT / 'os/tools/build-package.py')+updater = load('compositor_update', ROOT / 'os/runtime_update.py')+++class CompositorPackage(unittest.TestCase):+ def setUp(self):+ temporary = tempfile.TemporaryDirectory()+ self.addCleanup(temporary.cleanup)+ self.root = Path(temporary.name)+ self.source = self.root / 'checkout'+ self.bundle = self.root / 'compositor'+ self.bundle.mkdir()+ # Format-only fixture: native ELF loading and real lock privacy have a+ # separate compiler/VM gate. These tests exercise package ownership.+ header = bytearray(64)+ header[:7] = b'\x7fELF\x02\x01\x01'+ header[18:20] = (62).to_bytes(2, 'little')+ (self.bundle / 'labwc').write_bytes(header)+ (self.bundle / 'source.tar.gz').write_bytes(b'corresponding source fixture')+ (self.bundle / 'LICENSE').write_text('GPL-2.0-only fixture\n')+ self.pin = dict(version='0.20.2', patch='session-lock-presentation.patch',+ **payload.identity(self.bundle / 'source.tar.gz'))+ originals = {'source.json': 'os/packaging/labwc/source.json',+ 'session-lock-presentation.patch': 'os/packaging/labwc/session-lock-presentation.patch',+ 'rebuild.sh': 'os/packaging/labwc/rebuild.sh',+ 'build-compositor.py': 'os/tools/build-compositor.py',+ 'lock_presentation_policy.c': 'os/tests/lock_presentation_policy.c'}+ for name, relative in originals.items():+ path = self.source / relative+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(json.dumps(self.pin) if name == 'source.json' else 'source for ' + name)+ shutil.copyfile(path, self.bundle / name)+ self.record = dict(schema=1, kind='harness-compositor', architecture='x86_64',+ source_commit='a' * 40, upstream=self.pin,+ binary=dict(name='labwc', **payload.identity(self.bundle / 'labwc')),+ runtime_dependencies=['glibc', 'wayland', 'wlroots0.20'],+ build_options=['-Dxwayland=enabled'],+ corresponding_source={name: payload.identity(self.bundle / name)+ for name in [*originals, 'source.tar.gz', 'LICENSE']})+ self.save()++ def save(self):+ (self.bundle / 'manifest.json').write_text(json.dumps(self.record))++ def test_compositor_source_and_library_dependencies_belong_to_one_os_package(self):+ destination = self.root / 'stage'+ (destination / 'usr/share/harness-os').mkdir(parents=True)+ record = payload.stage(self.source, self.bundle, destination, 'a' * 40)+ archive = self.root / 'os.pkg.tar.gz'+ builder.archive_package(destination, archive, builder.package_info(+ '1-1', 1234, 100, record['runtime_dependencies']), 1234)+ updater.inspect_package(archive, '1-1')+ with tarfile.open(archive) as package:+ self.assertEqual(package.getmember('usr/lib/harness-os/labwc').mode, 0o755)+ self.assertNotIn('usr/bin/labwc', package.getnames())+ for name, identity in self.record['corresponding_source'].items():+ member = package.getmember('usr/share/licenses/harness-os/labwc/' + name)+ self.assertEqual(member.size, identity['bytes'])+ self.assertEqual(member.mode, 0o644)+ metadata = package.extractfile('.PKGINFO').read().decode()+ for dependency in record['runtime_dependencies']:+ self.assertIn('depend = ' + dependency + '\n', metadata)+ self.assertNotIn('depend = labwc\n', metadata)+ self.assertIn('license = GPL-2.0-only\n', metadata)++ def test_existing_snapshot_backup_retains_the_actual_compositor_and_source(self):+ snapshot = self.root / 'snapshot'+ (snapshot / 'usr/share/harness-os').mkdir(parents=True)+ payload.stage(self.source, self.bundle, snapshot, 'a' * 40)+ owned = [str(p.relative_to(snapshot)) for p in snapshot.rglob('*') if p.is_file()]+ db = snapshot / 'var/lib/pacman/local/harness-os-1-1'+ db.mkdir(parents=True)+ (db / 'desc').write_text('%NAME%\nharness-os\n\n%VERSION%\n1-1\n\n%ARCH%\nx86_64\n')+ (db / 'files').write_text('%FILES%\n' + '\n'.join(owned) + '\n')+ (snapshot / 'usr/lib/harness-os/user-file').write_text('preserve; not package-owned')+ original = tarfile.TarFile.add+ def root_owned(archive, name, *args, **kwargs):+ def ownership(info):+ info.uid = info.gid = 0+ return info+ return original(archive, name, *args, filter=ownership, **kwargs)+ backup = self.root / 'rollback.pkg.tar.gz'+ with patch.object(tarfile.TarFile, 'add', root_owned):+ updater.package_backup(snapshot, '1-1', backup)+ with tarfile.open(backup) as archive:+ self.assertEqual(set(archive.getnames()), {*owned, '.PKGINFO'})+ for name in owned:+ self.assertEqual(archive.extractfile(name).read(), (snapshot / name).read_bytes())+ self.assertEqual(archive.getmember('usr/lib/harness-os/labwc').mode, 0o755)++ def test_wrong_build_architecture_source_or_missing_xwayland_is_rejected(self):+ good = copy.deepcopy(self.record)+ for changes in [dict(source_commit='b' * 40), dict(architecture='aarch64'),+ dict(upstream={}), dict(build_options=[]),+ dict(runtime_dependencies=['glibc']),+ dict(runtime_dependencies=[{}]),+ dict(runtime_dependencies=['glibc', 'wayland', 'wlroots0.20', '../other'])]:+ with self.subTest(changes=changes):+ self.record = dict(good, **changes)+ self.save()+ with self.assertRaises(ValueError):+ payload.validate(self.source, self.bundle, 'a' * 40)++ def test_incomplete_binary_or_corresponding_source_cannot_ship(self):+ for name in ['labwc', *self.record['corresponding_source']]:+ path = self.bundle / name+ original = path.read_bytes()+ with self.subTest(name=name):+ path.write_bytes(original + b'changed')+ with self.assertRaises(ValueError):+ payload.validate(self.source, self.bundle, 'a' * 40)+ path.write_bytes(original)+ self.record['corresponding_source'].pop('LICENSE')+ self.save()+ with self.assertRaisesRegex(ValueError, 'source or license'):+ payload.validate(self.source, self.bundle, 'a' * 40)++ def test_changed_checkout_patch_cannot_reuse_old_native_build(self):+ (self.source / 'os/packaging/labwc/session-lock-presentation.patch').write_text('new correction')+ with self.assertRaisesRegex(ValueError, 'differs from this checkout'):+ payload.validate(self.source, self.bundle, 'a' * 40)+++if __name__ == '__main__':+ unittest.main()diff --git a/os/tests/test_fedora_package.py b/os/tests/test_fedora_package.pyindex 3d3606aea..7ae2582d8 100644--- a/os/tests/test_fedora_package.py+++ b/os/tests/test_fedora_package.py@@ -54,6 +54,10 @@ class FedoraPayload(unittest.TestCase):self.assertEqual((destination / 'usr/lib/harness/cli.mjs').read_bytes(), b'cli')self.assertEqual((destination / 'usr/lib/harness/harness-tui').read_bytes(),(self.runtime / 'harness-tui').read_bytes())+ session = (destination / 'usr/lib/harness-os/session').read_text()+ self.assertIn('if labwc -C ', session)+ self.assertNotIn('/usr/lib/harness-os/labwc -C', session)+ self.assertNotIn('usr/lib/harness-os/labwc', result['files'])def test_inert_profile_contains_no_base_system_or_fixture_takeover(self):destination = self.folder / 'payload'diff --git a/os/tests/test_package.py b/os/tests/test_package.pyindex 07f38e930..58d5c9250 100644--- a/os/tests/test_package.py+++ b/os/tests/test_package.py@@ -42,7 +42,8 @@ class PackageIdentity(unittest.TestCase):with tarfile.open(output) as archive:metadata = archive.extractfile('.PKGINFO').read().decode().splitlines()depends = {row.removeprefix('depend = ') for row in metadata if row.startswith('depend = ')}- self.assertTrue({'gtklock', 'grim', 'slurp', 'foot', 'labwc', 'tmux', 'nodejs-lts-jod'} <= depends)+ self.assertTrue({'gtklock', 'grim', 'slurp', 'foot', 'tmux', 'nodejs-lts-jod'} <= depends)+ self.assertNotIn('labwc', depends)self.assertTrue(depends <= set((Path(__file__).parents[1] / 'packages.x86_64').read_text().split()))spec = importlib.util.spec_from_file_location('runtime_package_check', Path(__file__).parents[1] / 'runtime_update.py')updater = importlib.util.module_from_spec(spec)diff --git a/os/tests/test_public_update_observer.py b/os/tests/test_public_update_observer.pyindex 3d30f767c..56ad12b31 100644--- a/os/tests/test_public_update_observer.py+++ b/os/tests/test_public_update_observer.py@@ -8,9 +8,34 @@ import unittestimport package_image_binding as bindingimport public_update_vm as observer+from vm import workspace_text_visibleclass PublicUpdateObserverTests(unittest.TestCase):+ def test_recorded_welcome_is_ready_only_for_explicit_upgrade_checks(self):+ # The actual rendered frame in run37459029285; the shared client can+ # return to this welcome after reboot. Real key/output checks follow.+ welcome = ('HARHESS\nEnter\nStart OpenCode\nt\nNew terminal\nw\nConnect to Wi-Fi\n'+ 'Super+t terminal\nSuper+w\nWi-Fi\nSuper+b\nbrowser')+ self.assertTrue(workspace_text_visible(welcome, allow_welcome=True))+ self.assertFalse(workspace_text_visible(welcome))+ self.assertTrue(workspace_text_visible('[me@harness ~]$'))+ for partial in ['', 'harness login:', 'HARNESS', 'New terminal',+ 'Start OpenCode\nNew terminal', 'Connect to Wi-Fi']:+ self.assertFalse(workspace_text_visible(partial, allow_welcome=True))++ def test_running_compositor_must_be_the_expected_package_binary(self):+ expected = {'binary': {'sha256': 'a' * 64}}+ good = dict(executable='/usr/lib/harness-os/labwc', owner='harness-os', sha256='a' * 64)+ observer.display_matches(good, expected)+ for key in good:+ with self.subTest(key=key), self.assertRaises(ValueError):+ observer.display_matches(dict(good, **{key: 'wrong'}), expected)+ original = dict(executable='/usr/bin/labwc', owner='labwc', sha256='b' * 64)+ observer.display_matches(original, original, restored=True)+ with self.assertRaises(ValueError):+ observer.display_matches(good, original, restored=True)+def test_one_replaced_process_or_project_change_cannot_pass(self):before = {'agents': [{'pid': 42, 'start': 100}], 'daemon': {'pid': 12, 'start': 1},'terminal': {'pid': 50, 'start': 101}, 'project': {'notes': 'digest'},diff --git a/os/tests/vm.py b/os/tests/vm.pyindex a81e53e11..701bc3cc9 100644--- a/os/tests/vm.py+++ b/os/tests/vm.py@@ -377,7 +377,13 @@ class VM:self.serial = self.qmp_file = self.qmp = None-def check_graphical_keyboard(vm, name):+def workspace_text_visible(text, *, allow_welcome=False):+ compact = re.sub(r'\s+', '', text).lower()+ return 'me@harness' in compact or (allow_welcome and all(+ label in compact for label in ('startopencode', 'newterminal', 'connecttowi-fi')))+++def check_graphical_keyboard(vm, name, *, allow_welcome=False):"""Prove the installed graphical surface accepts input and renders output."""started = time.monotonic()vm.command('pgrep -x labwc >/dev/null && pgrep -x foot >/dev/null')@@ -390,7 +396,7 @@ def check_graphical_keyboard(vm, name):visible = subprocess.check_output(['tesseract', str(vm.folder / (name + '-ready.png')), 'stdout', '--psm', '11'],text=True, stderr=subprocess.DEVNULL, timeout=10)- if 'me@harness' in re.sub(r'\s+', '', visible):+ if workspace_text_visible(visible, allow_welcome=allow_welcome):breaktime.sleep(.25)else:diff --git a/os/tools/build-compositor-container.sh b/os/tools/build-compositor-container.shnew file mode 100644index 000000000..142cd6f3a--- /dev/null+++ b/os/tools/build-compositor-container.sh@@ -0,0 +1,16 @@+#!/usr/bin/env bash+# Same pinned native compiler for images and standalone update packages.+set -euo pipefail+SOURCE_ROOT=$(cd -- "$(dirname -- "$0")/../.." && pwd)+cd "$SOURCE_ROOT"+COMPOSITOR_OUTPUT=${1:?Pass a fresh checkout-relative output directory}+[[ $COMPOSITOR_OUTPUT != /* && $COMPOSITOR_OUTPUT != *..* ]] || exit 1+LOCK_SNAPSHOT=$(python3 -c 'import json; print(json.load(open("os/packaging/labwc/source.json"))["arch_snapshot"])')+docker run --rm -v "$SOURCE_ROOT:/source" -w /source \+ -e LOCK_SNAPSHOT="$LOCK_SNAPSHOT" -e COMPOSITOR_OUTPUT="$COMPOSITOR_OUTPUT" \+ archlinux:base-devel@sha256:51dd3d24f7fba779e7c471caeee7804c50e8c134ad948e19685a1c83a42facc3 \+ bash -euc '+ printf "Server = https://archive.archlinux.org/repos/%s/\$repo/os/\$arch\n" "$LOCK_SNAPSHOT" > /etc/pacman.d/mirrorlist+ pacman -Syu --noconfirm --needed labwc meson cmocka wayland-protocols glib2-devel xorg-xwayland python git+ python3 os/tools/build-compositor.py --output "$COMPOSITOR_OUTPUT"+ 'diff --git a/os/tools/build-compositor.py b/os/tools/build-compositor.pynew file mode 100644index 000000000..b3c3e9090--- /dev/null+++ b/os/tools/build-compositor.py@@ -0,0 +1,109 @@+#!/usr/bin/env python3+"""Build the pinned compositor and retain its complete corresponding source."""+import argparse+import hashlib+import json+import os+from pathlib import Path+import re+import shutil+import subprocess+import tarfile+import urllib.request+++def digest(path):+ with path.open('rb') as handle:+ return hashlib.file_digest(handle, 'sha256').hexdigest()+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--output', type=Path, required=True)+ args = parser.parse_args()+ source = Path(__file__).resolve().parents[2]+ git = ['git', '-c', 'safe.directory=' + str(source), '-C', str(source)]+ if subprocess.check_output([*git, 'status', '--porcelain', '--untracked-files=normal'], text=True).strip():+ raise ValueError('Commit source changes before building a traceable compositor.')+ recipe = source / 'os/packaging/labwc'+ identity = json.loads((recipe / 'source.json').read_text())+ lock = json.loads((source / 'os/lock.json').read_text())+ if lock['arch_snapshot'] != identity['arch_snapshot']:+ raise ValueError('Compositor and OS must use the same reviewed Arch snapshot.')+ patch = recipe / identity['patch']+ assert digest(patch) == identity['patch_sha256']+ output = args.output.resolve()+ output.mkdir(parents=True, exist_ok=False)+ archive = output / 'source.tar.gz'+ with urllib.request.urlopen(identity['url'], timeout=60) as response:+ archive.write_bytes(response.read(identity['bytes'] + 1))+ assert archive.stat().st_size == identity['bytes']+ assert digest(archive) == identity['sha256']+ with tarfile.open(archive) as bundle:+ assert sum(member.size for member in bundle.getmembers()) < 32 * 1024**2+ bundle.extractall(output / 'source', filter='data')+ upstream = output / 'source' / ('labwc-' + identity['commit'])+ subprocess.run(['patch', '--batch', '--fuzz=0', '-p1', '-i', str(patch)],+ cwd=upstream, check=True, timeout=30)+ shutil.copy2(source / 'os/tests/lock_presentation_policy.c', upstream / 't/harness-lock-presentation.c')+ with (upstream / 't/meson.build').open('a') as meson:+ meson.write('''+test('harness_lock_presentation', executable('test_harness_lock_presentation',+ sources: 'harness-lock-presentation.c', include_directories: [labwc_inc],+ dependencies: labwc_deps,+ c_args: ['-UNDEBUG', '-ffunction-sections', '-fdata-sections'],+ link_args: ['-Wl,--gc-sections']), is_parallel: false)+''')+ build = output / 'build'+ options = ['--prefix=/usr', '--buildtype=release', '--wrap-mode=nodownload',+ '-Dtest=enabled', '-Dman-pages=disabled', '-Dxwayland=enabled',+ '-Dlabnag=disabled', '-Dsystemd-session=disabled']+ subprocess.run(['meson', 'setup', str(build), str(upstream), *options], check=True, timeout=60,+ env=dict(os.environ, GIT_CEILING_DIRECTORIES=str(upstream.parent)))+ subprocess.run(['meson', 'compile', '-C', str(build), '-j', '2'], check=True, timeout=600)+ subprocess.run(['meson', 'test', '-C', str(build), '--print-errorlogs'], check=True, timeout=120)+ binary = output / 'labwc'+ shutil.copy2(build / 'labwc', binary)+ subprocess.run(['strip', '--strip-unneeded', binary], check=True, timeout=30)+ # Record actual direct ELF library owners. Pacman will resolve their+ # transitive dependencies; the image need not ship a second compositor.+ needed = set(re.findall(r'\(NEEDED\).*\[(.+)\]', subprocess.check_output(+ ['readelf', '-d', binary], text=True)))+ links = subprocess.check_output(['ldd', binary], text=True)+ libraries = dict(re.findall(r'^\s*(\S+) => (/\S+)', links, re.MULTILINE))+ if not needed or not needed <= libraries.keys():+ raise ValueError('Compositor has an unresolved runtime library.')+ dependencies = sorted({subprocess.check_output(+ ['pacman', '-Qoq', str(Path(libraries[name]).resolve())], text=True).strip()+ for name in needed})+ if not {'glibc', 'wayland', 'wlroots0.20'} <= set(dependencies) or any(+ not re.fullmatch(r'[a-z0-9][a-z0-9@._+-]*', name) for name in dependencies):+ raise ValueError('Unexpected compositor library ownership.')+ correspondence = {+ 'source.tar.gz': archive,+ 'session-lock-presentation.patch': patch,+ 'source.json': recipe / 'source.json',+ 'build-compositor.py': Path(__file__),+ 'lock_presentation_policy.c': source / 'os/tests/lock_presentation_policy.c',+ 'LICENSE': upstream / 'LICENSE',+ 'rebuild.sh': recipe / 'rebuild.sh',+ }+ for name, path in correspondence.items():+ if path.resolve() != (output / name).resolve():+ shutil.copy2(path, output / name)+ record = {'schema': 1, 'kind': 'harness-compositor', 'architecture': 'x86_64',+ 'scope': 'OS-owned compositor; included in the Harness package and its rollback',+ 'source_commit': subprocess.check_output([*git, 'rev-parse', 'HEAD'], text=True).strip(),+ 'upstream': identity,+ 'binary': {'name': binary.name, 'bytes': binary.stat().st_size, 'sha256': digest(binary)},+ 'runtime_dependencies': dependencies, 'build_options': options,+ 'corresponding_source': {name: {'bytes': (output / name).stat().st_size,+ 'sha256': digest(output / name)} for name in correspondence},+ 'packages': subprocess.check_output(['pacman', '-Q'], text=True).splitlines(),+ 'compiler': subprocess.check_output(['cc', '--version'], text=True).splitlines()[0]}+ (output / 'manifest.json').write_text(json.dumps(record, indent=2) + '\n')+ print(json.dumps(record['binary']))+++if __name__ == '__main__':+ main()diff --git a/os/tools/build-package.py b/os/tools/build-package.pyindex 14a1850f4..2fe2e4631 100644--- a/os/tools/build-package.py+++ b/os/tools/build-package.py@@ -13,18 +13,18 @@ import tarfileimport tempfile-DEPENDENCIES = ('nodejs-lts-jod', 'tmux', 'foot', 'labwc', 'gtklock', 'grim', 'slurp')+DEPENDENCIES = ('nodejs-lts-jod', 'tmux', 'foot', 'gtklock', 'grim', 'slurp')-def package_info(version, timestamp, size):+def package_info(version, timestamp, size, compositor_dependencies=()):# These are needed on upgrades too; adding a tool to the ISO list alone# leaves existing computers with new launchers but no executable to run.return (f'pkgname = harness-os\npkgbase = harness-os\nxdata = pkgtype=pkg\npkgver = {version}\n''pkgdesc = Harness session and verified Harness runtime\n''url = https://github.com/autonomous-ai/openharness\n'f'builddate = {timestamp}\npackager = OpenHarness\nsize = {size}\n'- 'arch = x86_64\nlicense = MIT\n'- + ''.join(f'depend = {name}\n' for name in DEPENDENCIES))+ 'arch = x86_64\nlicense = MIT\nlicense = GPL-2.0-only\n'+ + ''.join(f'depend = {name}\n' for name in dict.fromkeys((*DEPENDENCIES, *compositor_dependencies))))def digest(path):@@ -155,6 +155,8 @@ def bootstrap(source, folder):def main():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument('--runtime', type=Path, required=True)+ parser.add_argument('--compositor', type=Path, required=True,+ help='Verified native compositor from this source and Arch snapshot')parser.add_argument('--output', type=Path, required=True)parser.add_argument('--development', action='store_true', help='Include a source revision in the package version')args = parser.parse_args()@@ -162,6 +164,10 @@ def main():if git(source, 'status', '--porcelain', '--untracked-files=normal'):parser.error('Commit source changes before building a traceable package.')commit = git(source, 'rev-parse', 'HEAD')+ spec = importlib.util.spec_from_file_location('harness_compositor', Path(__file__).with_name('compositor_payload.py'))+ compositor = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(compositor)+ compositor.validate(source, args.compositor.resolve(), commit)timestamp = int(git(source, 'log', '-1', '--format=%ct'))lock = json.loads((source / 'os/lock.json').read_text())if lock['architecture'] != 'x86_64' or not re.fullmatch(r'\d+\.\d+\.\d+(?:-preview\.\d+)?', lock['version']):@@ -180,13 +186,14 @@ def main():with tempfile.TemporaryDirectory(prefix='harness-package-') as temp:root = Path(temp) / 'root'runtime = stage(source, args.runtime.resolve(), root, commit)+ display = compositor.stage(source, args.compositor.resolve(), root, commit)size = sum(p.stat().st_size for p in root.rglob('*') if p.is_file() and not p.is_symlink())- pkginfo = package_info(version, timestamp, size)+ pkginfo = package_info(version, timestamp, size, display['runtime_dependencies'])archive_package(root, package, pkginfo, timestamp)manifest = {'schema': 1, 'kind': 'harness-os-package', 'development': args.development,'source_commit': commit, 'architecture': lock['architecture'],'requires_os_version': lock['version'], 'arch_snapshot': lock['arch_snapshot'],- 'runtime': runtime,+ 'runtime': runtime, 'compositor': display,'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']diff --git a/os/tools/compositor_payload.py b/os/tools/compositor_payload.pynew file mode 100644index 000000000..dc61fbfc9--- /dev/null+++ b/os/tools/compositor_payload.py@@ -0,0 +1,72 @@+"""Validate and stage the compositor within the existing OS package transaction."""+import hashlib+import json+from pathlib import Path+import re+import shutil+++def identity(path):+ with path.open('rb') as handle:+ return {'bytes': path.stat().st_size, 'sha256': hashlib.file_digest(handle, 'sha256').hexdigest()}+++def validate(source, folder, commit):+ record = json.loads((folder / 'manifest.json').read_text())+ recipe = source / 'os/packaging/labwc'+ pin = json.loads((recipe / 'source.json').read_text())+ if (record.get('schema') != 1 or record.get('kind') != 'harness-compositor'+ or record.get('architecture') != 'x86_64' or record.get('source_commit') != commit+ or record.get('upstream') != pin+ or '-Dxwayland=enabled' not in record.get('build_options', [])):+ raise ValueError('Compositor must use this source, recipe, architecture and Xwayland support.')+ expected = record.get('binary', {})+ binary = folder / 'labwc'+ if (expected.get('name') != 'labwc' or binary.is_symlink() or not binary.is_file()+ or identity(binary) != {k: expected.get(k) for k in ('bytes', 'sha256')}):+ raise ValueError('Compositor binary checksum mismatch.')+ with binary.open('rb') as handle:+ header = handle.read(64)+ if (len(header) < 64 or header[:7] != b'\x7fELF\x02\x01\x01'+ or int.from_bytes(header[18:20], 'little') != 62):+ raise ValueError('Compositor must be an x86-64 Linux executable.')+ dependencies = record.get('runtime_dependencies')+ if (not isinstance(dependencies, list) or len(dependencies) > 40+ or any(not isinstance(name, str) or not re.fullmatch(r'[a-z0-9][a-z0-9@._+-]*', name)+ for name in dependencies)+ or not {'glibc', 'wayland', 'wlroots0.20'} <= set(dependencies)):+ raise ValueError('Invalid compositor runtime dependencies.')+ originals = {'source.json': recipe / 'source.json',+ 'session-lock-presentation.patch': recipe / pin['patch'],+ 'rebuild.sh': recipe / 'rebuild.sh',+ 'build-compositor.py': source / 'os/tools/build-compositor.py',+ 'lock_presentation_policy.c': source / 'os/tests/lock_presentation_policy.c'}+ correspondence = record.get('corresponding_source', {})+ if set(correspondence) != {*originals, 'source.tar.gz', 'LICENSE'}:+ raise ValueError('Missing corresponding compositor source or license.')+ for name, expected in correspondence.items():+ path = folder / name+ if path.is_symlink() or not path.is_file() or identity(path) != expected:+ raise ValueError('Compositor source checksum mismatch: ' + name)+ if name in originals and identity(originals[name]) != expected:+ raise ValueError('Compositor source differs from this checkout: ' + name)+ if correspondence['source.tar.gz'] != {k: pin[k] for k in ('bytes', 'sha256')}:+ raise ValueError('Compositor upstream archive differs from the pin.')+ return record+++def stage(source, folder, destination, commit):+ record = validate(source, folder, commit)+ target = destination / 'usr/lib/harness-os/labwc'+ target.parent.mkdir(parents=True, exist_ok=True)+ shutil.copyfile(folder / 'labwc', target)+ target.chmod(0o755)+ license_dir = destination / 'usr/share/licenses/harness-os/labwc'+ license_dir.mkdir(parents=True)+ for name in record['corresponding_source']:+ shutil.copyfile(folder / name, license_dir / name)+ (license_dir / name).chmod(0o644)+ installed = destination / 'usr/share/harness-os/compositor.json'+ installed.write_text(json.dumps(record, indent=2) + '\n')+ installed.chmod(0o644)+ return recorddiff --git a/os/tools/fedora_payload.py b/os/tools/fedora_payload.pyindex d0ddeba92..347c67416 100644--- a/os/tools/fedora_payload.py+++ b/os/tools/fedora_payload.py@@ -104,6 +104,10 @@ def stage(source, runtime, destination, commit, runtime_commit):tree.write(config, encoding='unicode')browser = destination / 'usr/bin/hn-browser'browser.write_text(browser.read_text().replace('/usr/bin/chromium ', '/usr/bin/chromium-browser '))+ # The experimental Fedora/Asahi session still uses its distribution's+ # compositor; the pinned PC executable is an x86-64 Arch payload.+ session = destination / 'usr/lib/harness-os/session'+ session.write_text(session.read_text().replace('/usr/lib/harness-os/labwc -C', 'labwc -C'))for path in destination.rglob('*'):if not path.is_symlink():path.chmod(0o755 if path.is_dir() else 0o644)diff --git a/os/tools/inspect_image.py b/os/tools/inspect_image.pyindex 3039e2f6c..07d816565 100644--- a/os/tools/inspect_image.py+++ b/os/tools/inspect_image.py@@ -73,6 +73,19 @@ def inspect(iso):for name, identity in runtime['files'].items():data = read('usr/lib/harness/' + name)assert len(data) == identity['bytes'] and hashlib.sha256(data).hexdigest() == identity['sha256'], f'Runtime mismatch: {name}'+ compositor = json.loads(read('usr/share/harness-os/compositor.json'))+ assert compositor == manifest['compositor'], 'Compositor differs from the image manifest'+ assert compositor['source_commit'] == manifest['source_commit'], 'Compositor belongs to another source'+ assert compositor['upstream'] == json.loads((source / 'packaging/labwc/source.json').read_text())+ assert '-Dxwayland=enabled' in compositor['build_options']+ entries = {'usr/lib/harness-os/labwc': compositor['binary']}+ entries.update({'usr/share/licenses/harness-os/labwc/' + name: info+ for name, info in compositor['corresponding_source'].items()})+ for name, info in entries.items():+ data = read(name)+ assert len(data) == info['bytes'] and hashlib.sha256(data).hexdigest() == info['sha256'], name+ assert owners.get(name) == '0/0', name+ checked.append(name)kernel = json.loads(read('usr/share/harness-os/kernel.json'))assert re.fullmatch(r'usr/lib/modules/[a-zA-Z0-9._+-]+/vmlinuz', kernel['path'])assert hashlib.sha256(read(kernel['path'])).hexdigest() == kernel['sha256'], 'Offline install kernel mismatch'@@ -86,6 +99,8 @@ def inspect(iso):assert packages == (iso.parent / 'packages.txt').read_text(), 'Package inventory mismatch'inventory = dict(row.split(maxsplit=1) for row in packages.splitlines())names = set(inventory)+ assert 'labwc' not in names, 'Fresh image contains a duplicate compositor'+ assert set(compositor['runtime_dependencies']) <= names, 'A compositor library is missing'version = json.loads(read('usr/share/harness-os/lock.json'))['version']assert version == manifest['version'], 'Image version differs from the build manifest'package_version = inventory['harness-os']diff --git a/os/tools/manifest.py b/os/tools/manifest.pyindex e2925c3a4..185fd5217 100644--- a/os/tools/manifest.py+++ b/os/tools/manifest.py@@ -48,6 +48,7 @@ manifest = {'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',+ 'compositor': json.loads((root / 'usr/share/harness-os/compositor.json').read_text()),'hardware': hardware,}(out / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')