Skip to content

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

test(os): verify browser input across suspend and unlock (#823)

Deefae0843dffb3
diff --git a/.github/workflows/os.yml b/.github/workflows/os.yml
index 29a821a62..49512ed8c 100644
--- a/.github/workflows/os.yml
+++ b/.github/workflows/os.yml
@@ -51,7 +51,7 @@ on:
required: false
default: image
type: choice
- options: [image, browser, session, recovery, essentials, hardware, zram, hardware-update]
+ options: [image, browser, browser-suspend, session, recovery, essentials, hardware, zram, hardware-update]
browser_memory:
description: 'With checks=browser, diagnose memory in the UEFI VM only; retain ordinary workload and deadlines'
required: false
@@ -66,12 +66,12 @@ permissions:
actions: read
concurrency:
- group: programmer-os-${{ github.ref }}-${{ inputs.memory_mib || '2048' }}-${{ inputs.live_transport || 'cdrom' }}-${{ inputs.development_update && 'update' || inputs.checks == 'browser' && 'browser' || inputs.checks == 'session' && 'session' || inputs.checks == 'recovery' && 'recovery' || inputs.checks == 'essentials' && 'essentials' || inputs.checks == 'hardware' && 'hardware' || inputs.checks == 'hardware-update' && 'hardware-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 == 'browser-suspend' && 'browser-suspend' || inputs.checks == 'browser' && 'browser' || inputs.checks == 'session' && 'session' || inputs.checks == 'recovery' && 'recovery' || inputs.checks == 'essentials' && 'essentials' || inputs.checks == 'hardware' && 'hardware' || inputs.checks == 'hardware-update' && 'hardware-update' || inputs.dsh && 'dsh' || inputs.workloads && 'workloads' || 'image' }}
cancel-in-progress: false
jobs:
image:
- if: ${{ !inputs.image_run_id && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'zram' && inputs.checks != 'hardware-update' }}
+ if: ${{ !inputs.image_run_id && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && inputs.checks != 'browser-suspend' }}
runs-on: ubuntu-24.04
timeout-minutes: 50
steps:
@@ -159,15 +159,20 @@ 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' && (needs.image.result == 'success' || inputs.image_run_id != '') && !cancelled() }}
+ if: ${{ always() && !inputs.publish_run_id && !inputs.development_update && inputs.checks != 'essentials' && inputs.checks != 'hardware' && inputs.checks != 'zram' && inputs.checks != 'hardware-update' && (needs.image.result == 'success' || inputs.image_run_id != '' || inputs.checks == 'browser-suspend') && !cancelled() }}
runs-on: ubuntu-24.04
timeout-minutes: 65
strategy:
fail-fast: false
matrix:
- include: ${{ inputs.checks == 'browser' && inputs.browser_memory && fromJSON('[{"firmware":"uefi","encryption":"--encrypt","agents":"","cpu":""}]') || fromJSON('[{"firmware":"bios","encryption":"","agents":"--agents","cpu":"--cpu Nehalem"},{"firmware":"uefi","encryption":"--encrypt","agents":"","cpu":""}]') }}
+ include: ${{ (inputs.checks == 'browser-suspend' || inputs.checks == 'browser' && inputs.browser_memory) && fromJSON('[{"firmware":"uefi","encryption":"--encrypt","agents":"","cpu":""}]') || fromJSON('[{"firmware":"bios","encryption":"","agents":"--agents","cpu":"--cpu Nehalem"},{"firmware":"uefi","encryption":"--encrypt","agents":"","cpu":""}]') }}
steps:
- uses: actions/checkout@v7
+ - name: Require the selected image for browser suspend acceptance
+ if: ${{ inputs.checks == 'browser-suspend' }}
+ env:
+ IMAGE_RUN_ID: ${{ inputs.image_run_id }}
+ run: '[[ "$IMAGE_RUN_ID" =~ ^[0-9]+$ ]]'
- uses: actions/download-artifact@v6
with:
name: programmer-os-x86_64
@@ -180,8 +185,13 @@ jobs:
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: Install the disposable browser observer
- if: ${{ inputs.checks == 'browser' }}
+ if: ${{ inputs.checks == 'browser' || inputs.checks == 'browser-suspend' }}
run: sudo apt-get install -y wlrctl
+ - name: Check the focused browser suspend observer and workflow
+ if: ${{ inputs.checks == 'browser-suspend' }}
+ run: |
+ python3 -m py_compile os/tests/browser_vm.py os/tests/browser_suspend_guest.py
+ go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os.yml
- name: Check the focused session test and workflow
if: ${{ inputs.checks == 'session' || inputs.checks == 'recovery' || inputs.checks == 'browser' }}
run: |
@@ -196,7 +206,7 @@ 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' && inputs.checks != 'recovery' && inputs.checks != 'browser' }}
+ if: ${{ inputs.checks != 'session' && inputs.checks != 'recovery' && inputs.checks != 'browser' && inputs.checks != 'browser-suspend' }}
env:
OS_WORKLOAD_SOURCE_RUN: ${{ inputs.workload_seed_run_id }}
OS_MEMORY_MIB: ${{ inputs.memory_mib || '2048' }}
@@ -221,6 +231,9 @@ jobs:
env:
OS_MEMORY_MIB: ${{ inputs.memory_mib || '2048' }}
run: python3 os/tests/browser_vm.py --iso os/dist/*.iso --firmware '${{ matrix.firmware }}' --memory-mib "$OS_MEMORY_MIB" --wlrctl /usr/bin/wlrctl --browser-script os/root/usr/bin/hn-browser --compositor-config os/root/usr/share/harness-os/labwc/rc.xml ${{ inputs.browser_memory && '--memory-profile --zram-config os/root/etc/systemd/zram-generator.conf' || '' }}
+ - name: Exercise browser-active suspend, unlock and input recovery
+ if: ${{ inputs.checks == 'browser-suspend' }}
+ run: timeout 12m python3 os/tests/browser_vm.py --iso os/dist/*.iso --firmware uefi --memory-mib 2048 --check suspend --wlrctl /usr/bin/wlrctl --browser-script os/root/usr/bin/hn-browser --compositor-config os/root/usr/share/harness-os/labwc/rc.xml
- name: Show machine failure diagnostics
if: failure()
run: |
diff --git a/os/tests/browser_suspend_guest.py b/os/tests/browser_suspend_guest.py
new file mode 100644
index 000000000..4fedb6f5d
--- /dev/null
+++ b/os/tests/browser_suspend_guest.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+"""Read process and project identity in the disposable browser-suspend VM."""
+import hashlib
+import json
+import os
+from pathlib import Path
+import re
+import subprocess
+
+
+def browser_main(argv):
+ # Chromium can replace its NUL-separated argv with one process title.
+ # Keep the raw form for identity, but recognize child flags in either form.
+ return bool(argv and argv[0]) and not any(re.search(r'(?:^|\s)--type=', arg) for arg in argv)
+
+
+def process(pid):
+ root = Path('/proc') / str(pid)
+ fields = (root / 'stat').read_text().rsplit(')', 1)[1].split()
+ assert fields[0] not in ('Z', 'X'), 'A preserved process is no longer running'
+ return dict(pid=int(pid), start_ticks=fields[19], executable=str((root / 'exe').resolve(strict=True)),
+ argv=(root / 'cmdline').read_bytes().rstrip(b'\0').decode().split('\0'))
+
+
+def snapshot():
+ agents, browsers = [], []
+ for path in Path('/proc').iterdir():
+ if not path.name.isdecimal():
+ continue
+ try:
+ if path.stat().st_uid != os.getuid():
+ continue
+ name = (path / 'comm').read_text().strip()
+ if name == 'opencode':
+ agents.append(process(path.name))
+ elif name == 'chromium':
+ argv = (path / 'cmdline').read_bytes().rstrip(b'\0').decode().split('\0')
+ if browser_main(argv):
+ browsers.append(process(path.name))
+ except FileNotFoundError:
+ continue
+ assert len(agents) == 2, ('Expected both bundled OpenCode processes', agents)
+ assert len(browsers) == 1, ('Expected one browser main process', browsers)
+ daemon = subprocess.check_output(['systemctl', '--user', 'show', 'harness-daemon.service',
+ '-p', 'MainPID', '--value'], text=True, timeout=5).strip()
+ probe = Path('/tmp/harness-browser-probe')
+ runtime = {name: hashlib.sha256(Path(path).read_bytes()).hexdigest() for name, path in {
+ 'harness-tui': '/usr/lib/harness/harness-tui', 'cli.mjs': '/usr/lib/harness/cli.mjs',
+ 'notify.mjs': '/usr/lib/harness/notify.mjs'}.items()}
+ return dict(agents=sorted(agents, key=lambda item: item['pid']), browser=browsers[0],
+ daemon=process(daemon), terminal=process((probe / 'terminal-pid').read_text().strip()),
+ boot_id=Path('/proc/sys/kernel/random/boot_id').read_text().strip(), runtime=runtime,
+ project_sha256=hashlib.sha256((Path.home() / 'projects/browser-suspend/proof.txt').read_bytes()).hexdigest(),
+ terminal_input=(probe / 'terminal-input').read_text(),
+ pages=json.loads((probe / 'states.json').read_text()))
+
+
+if __name__ == '__main__':
+ print(json.dumps(snapshot()))
diff --git a/os/tests/browser_vm.py b/os/tests/browser_vm.py
index e95fac3c2..c4ce19e0e 100644
--- a/os/tests/browser_vm.py
+++ b/os/tests/browser_vm.py
@@ -11,7 +11,7 @@ import time
from PIL import Image
from footprint_vm import copy_file
from vm import VM, check_live_media, install_interactively
-from session_vm import screen_text
+from session_vm import screen_text, wait_lock
class BrowserVM(VM):
@@ -272,11 +272,167 @@ def check_browser(vm, result):
result['checks'].append('New browser windows maximize; close and reopen restores working keyboard focus without losing the terminal')
+def check_browser_suspend(vm, config, manifest, result):
+ """Suspend from a real browser window, keeping agents and terminal work alive."""
+ vm.command('! pgrep -u "$(id -u)" -x chromium')
+ vm.command('mkdir -p /tmp/harness-browser-probe ~/projects/browser-suspend; '
+ 'printf %s browser-suspend-project > ~/projects/browser-suspend/proof.txt')
+ copy_file(vm, TERMINAL.encode(), '/tmp/harness-browser-terminal.py')
+ for source, target in [('browser_guest.py', '/tmp/harness-browser-page.py'),
+ ('browser_suspend_guest.py', '/tmp/harness-browser-suspend.py')]:
+ data = Path(__file__).with_name(source).read_bytes()
+ result.setdefault('guest_observers', {})[source] = hashlib.sha256(data).hexdigest()
+ copy_file(vm, data, target)
+ vm.command('systemd-run --user --quiet --collect --unit=harness-browser-probe python3 /tmp/harness-browser-page.py')
+ wait_command(vm, 'curl --fail --silent http://127.0.0.1:18782/ >/dev/null')
+ vm.command('hn new-window -n browser-suspend ' + shlex.quote('python3 /tmp/harness-browser-terminal.py'))
+ wait_command(vm, 'test -s /tmp/harness-browser-probe/terminal-pid')
+ focused(vm, 'hn', 'suspend-terminal-before-browser')
+ vm.type_probe('before-suspend')
+ vm.keys('ret')
+ vm.keys('meta_l', 'b')
+ new_tab_ready(vm, 'suspend-browser-started')
+ for path, value in [('/first', 'window-one'), ('/second', 'window-two')]:
+ if path == '/second':
+ vm.keys('ctrl', 'n')
+ new_tab_ready(vm, 'suspend-second-window')
+ vm.keys('ctrl', 'l')
+ vm.type_probe('http://127.0.0.1:18782' + path)
+ vm.keys('ret')
+ state(vm, path=path)
+ page_fills_display(vm, 'suspend-page' + path.replace('/', '-'))
+ # The previous click leaves the VGA software cursor over this label.
+ # Move it away without clicking before locating the exact visible word.
+ vm.monitor('input-send-event', events=[
+ {'type': 'abs', 'data': {'axis': 'x', 'value': 0}},
+ {'type': 'abs', 'data': {'axis': 'y', 'value': 0}}])
+ time.sleep(.2)
+ vm.click_word('suspend-input' + path.replace('/', '-'), 'Keyboard')
+ state(vm, path=path, ready=True)
+ vm.type_probe(value)
+ state(vm, path=path, value=value, ready=True)
+
+ expected_runtime = {name: item['sha256'] for name, item in manifest['harness_inputs']['files'].items()}
+ assert set(expected_runtime) == {'harness-tui', 'cli.mjs', 'notify.mjs'}
+
+ def snapshot(name):
+ vm.command('python3 /tmp/harness-browser-suspend.py > /tmp/harness-browser-suspend.json')
+ data = vm.read_file('/tmp/harness-browser-suspend.json')
+ (vm.folder / (name + '.json')).write_bytes(data)
+ observed = json.loads(data)
+ assert observed['runtime'] == expected_runtime, 'Shared runtime differs from the verified image'
+ return observed
+
+ before = snapshot('suspend-work-before')
+ assert before['terminal_input'] == 'before-suspend\n'
+ result['work_before'] = before
+
+ def preserved(name, terminal_input='before-suspend\n'):
+ after = snapshot(name)
+ for key in ['agents', 'browser', 'daemon', 'terminal', 'boot_id', 'runtime', 'project_sha256']:
+ assert after[key] == before[key], ('Work changed across suspend', key, before[key], after[key])
+ assert after['terminal_input'] == terminal_input, 'Lock or browser input reached the terminal'
+ return after
+
+ assert vm.monitor('query-current-machine').get('wakeup-suspend-support')
+ 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()
+ vm.command('sudo -n systemctl suspend --no-block')
+ deadline = time.monotonic() + 30
+ while True:
+ current = vm.monitor('query-status')
+ if current['status'] == 'suspended':
+ break
+ assert time.monotonic() < deadline, ('Guest did not suspend', current)
+ time.sleep(.25)
+ result['suspend_seconds'] = round(time.monotonic() - started, 3)
+ result['suspended_qmp_status'] = current
+ vm.shell_ready = False
+ vm.screenshot('browser-suspended')
+ vm.monitor('system_wakeup')
+ resumed = time.monotonic()
+ # Reuse the acknowledged UART resume boundary; never type a command into
+ # the short serial FIFO while the guest driver is still waking.
+ deadline = time.monotonic() + 30
+ while True:
+ vm.send('\n')
+ try:
+ vm.wait(r'\[me@harness [^\r\n]*\]\$ ', timeout=2)
+ vm.shell_ready = True
+ break
+ except TimeoutError:
+ if time.monotonic() >= deadline:
+ raise TimeoutError('The guest serial console did not resume within 30 seconds')
+ wait_lock(vm, True)
+
+ def hidden(name):
+ text = screen_text(vm, name)
+ assert 'harness browser check' not in text and 'keyboard' not in text, 'Lock exposed the browser'
+ with Image.open(vm.folder / (name + '.png')).convert('RGB') as frame:
+ width, height = frame.size
+ pixels = [frame.getpixel(p) for p in [(3, height//2), (width-4, height//2),
+ (3, height-4), (width-4, height-4)]]
+ assert all(max(pixel) <= 8 for pixel in pixels), ('Lock did not hide the page', pixels)
+ state(vm, path='/first', value='window-one')
+ state(vm, path='/second', value='window-two')
+
+ hidden('browser-resumed-locked')
+ for name, keys in [('escape', ('esc',)), ('interrupt', ('ctrl', 'c')), ('shortcut', ('meta_l', 'b'))]:
+ vm.keys(*keys)
+ wait_lock(vm, True, timeout=2)
+ hidden('browser-lock-' + name)
+ vm.type_probe('wrong-password')
+ vm.keys('ret')
+ time.sleep(4)
+ wait_lock(vm, True)
+ hidden('browser-lock-wrong-password')
+ preserved('suspend-work-locked')
+ vm.keys('ctrl', 'u')
+ vm.type_probe(config['password'])
+ vm.keys('ret')
+ wait_lock(vm, False)
+ title = 'Harness browser check /second - Chromium'
+ focused(vm, 'chromium', 'browser-resumed-unlocked', title=title)
+ state(vm, path='/second', value='window-two', ready=True)
+ page_fills_display(vm, 'browser-resumed-painted')
+ vm.type_probe('-resumed')
+ state(vm, path='/second', value='window-two-resumed')
+ state(vm, path='/first', value='window-one')
+ vm.keys('meta_l', 'b')
+ focused(vm, 'hn', 'browser-resume-terminal')
+ vm.type_probe('after-suspend')
+ vm.keys('ret')
+ wait_command(vm, 'python3 -c ' + shlex.quote('from pathlib import Path; '
+ 'assert Path("/tmp/harness-browser-probe/terminal-input").read_text() == "before-suspend\\nafter-suspend\\n"'))
+ vm.keys('meta_l', 'b')
+ focused(vm, 'chromium', 'browser-resume-return', title=title)
+ state(vm, path='/second', value='window-two-resumed', ready=True)
+ vm.type_probe('-returned')
+ state(vm, path='/second', value='window-two-resumed-returned')
+ state(vm, path='/first', value='window-one')
+ result['work_after'] = preserved('suspend-work-after', 'before-suspend\nafter-suspend\n')
+ events = [json.loads(line) for line in vm.read_file('/tmp/harness-browser-probe/events.jsonl').decode().splitlines()]
+ for event in events:
+ expected = {'/first': 'window-one', '/second': 'window-two-resumed-returned'}[event['path']]
+ assert expected.startswith(event['input']), ('Unexpected input reached the page', event)
+ result['resume_check_seconds_including_lock_and_typing'] = round(time.monotonic() - resumed, 3)
+ output, _ = vm.command('sudo -n 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'].extend([
+ 'The browser-active guest actually suspends; wake remains password-locked and hides the page.',
+ 'Escape, Ctrl+c, Super+b and a wrong password stay inside the lock; browser and terminal input remain unchanged.',
+ 'Unlock restores the same browser window and field; real typing and a Super+b terminal/browser round trip work without changing the other window.',
+ 'Both OpenCode processes, browser main process, daemon, terminal, project, boot ID and verified runtime bytes survive unchanged.'])
+
+
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('--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)
@@ -290,6 +446,10 @@ def main():
parser.add_argument('--live-transport', choices=['cdrom', 'usb'], default='cdrom')
parser.add_argument('--output', type=Path)
args = parser.parse_args()
+ if args.check == 'suspend' and (args.firmware != 'uefi' or args.memory_mib != 2048 or
+ args.memory_profile or args.zram_config or args.expected_zram_config or args.interactive_install or
+ args.live_transport != 'cdrom'):
+ parser.error('Browser suspend requires the focused 2 GiB encrypted UEFI/CD-ROM fixture without memory/install variants')
if args.zram_config and args.expected_zram_config:
parser.error('Choose a preboot overlay or verification of a prepared image, not both')
if args.expected_zram_config and not args.interactive_install:
@@ -300,9 +460,13 @@ def main():
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(f'os/test-results/{args.firmware}-browser')).resolve()
+ assert iso.stat().st_size == manifest['iso']['bytes']
+ suffix = '-suspend' if args.check == 'suspend' else ''
+ folder = (args.output or Path(f'os/test-results/{args.firmware}-browser{suffix}')).resolve()
folder.mkdir(parents=True, exist_ok=False)
- vm = BrowserVM(folder, iso, args.firmware, args.memory_mib, live_transport=args.live_transport, cpu='Nehalem')
+ (folder / 'image-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
+ video = 'VGA' if args.check == 'suspend' else 'virtio-vga'
+ vm = BrowserVM(folder, iso, args.firmware, args.memory_mib, live_transport=args.live_transport, cpu='Nehalem', video=video)
vm.memory_samples = []
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)
@@ -312,15 +476,25 @@ def main():
'rev-parse','HEAD'],text=True).strip(),
memory_mib=args.memory_mib, candidates={},
validation_fixture=manifest.get('validation_fixture'), live_transport=args.live_transport,
- memory_profile=args.memory_profile, cpu='Nehalem', display='virtio-vga (2D)',
+ memory_profile=args.memory_profile, cpu='Nehalem', display=video, check=args.check,
memory_samples=vm.memory_samples,
observer=dict(sha256=hashlib.sha256(args.wlrctl.read_bytes()).hexdigest(),
version=subprocess.check_output([str(args.wlrctl),'--version'],text=True).strip()),
limitations=['Only the recorded candidate files replace packaged files in the disposable guest.',
- 'Native virtual display and physical-keyboard events; not a physical laptop or GPU claim.',
+ 'Virtual display and QMP virtual keyboard events; not a physical laptop or GPU claim.',
'Observer and screenshot overhead are included in transition timings.'])
+ if args.check == 'suspend':
+ result['test_inputs'] = {name: hashlib.sha256(Path(__file__).with_name(name).read_bytes()).hexdigest()
+ for name in ['browser_vm.py', 'browser_suspend_guest.py', 'browser_guest.py',
+ 'session_vm.py', 'footprint_vm.py', 'vm.py']}
+ result['limitations'].extend(['One virtual ACPI suspend using bochs-drm; no physical lid, panel, radio or GPU acceptance.',
+ 'Existing OpenCode process survival is checked, not a remote model turn.'])
try:
vm.start(live=True)
+ if args.check == 'suspend':
+ assert vm.acceleration == 'kvm'
+ result['acceleration'] = vm.acceleration
+ result['virtual_cpus'] = 2
vm.wait(r'root@[^\r\n]*[#] ', timeout=180)
vm.shell_ready = True
vm.command('stty -echo')
@@ -391,7 +565,10 @@ def main():
assert sum(p['role'] == 'OpenCode' for p in before['identities']) == 2, before
assert sum(p['role'] == 'Harness daemon' for p in before['identities']) == 1, before
assert before['oom_kills'] == 0
- check_browser(vm, result)
+ if args.check == 'suspend':
+ check_browser_suspend(vm, config, manifest, result)
+ else:
+ check_browser(vm, result)
if args.expected_zram_config:
after = result['completed_zram'] = zram_probe(vm, args.expected_zram_config, 'completed')
assert after['identities'] == before['identities'], 'Agent or daemon process changed'
diff --git a/os/tests/test_browser_suspend.py b/os/tests/test_browser_suspend.py
new file mode 100644
index 000000000..39c5a4521
--- /dev/null
+++ b/os/tests/test_browser_suspend.py
@@ -0,0 +1,36 @@
+import unittest
+
+from browser_suspend_guest import browser_main
+
+
+class BrowserProcessTitleTest(unittest.TestCase):
+ def test_recorded_chromium_process_titles(self):
+ # Actual single-string titles from native run 37356952575. The browser
+ # main and first zygote exposed the original observer's bad assumption.
+ main = ['/usr/lib/chromium/chromium --ozone-platform=wayland --start-maximized '
+ '--no-first-run --no-default-browser-check']
+ child = ['/usr/lib/chromium/chromium --type=zygote --no-zygote-sandbox '
+ '--crashpad-handler-pid=1297 --enable-crash-reporter=,Arch Linux '
+ '--change-stack-guard-on-fork=enable']
+ self.assertTrue(browser_main(main))
+ self.assertFalse(browser_main(child))
+
+ def test_normal_nul_separated_arguments(self):
+ self.assertTrue(browser_main('/usr/lib/chromium/chromium\0--ozone-platform=wayland'.split('\0')))
+ for kind in ['zygote', 'renderer', 'gpu-process', 'utility']:
+ with self.subTest(kind=kind):
+ command = '/usr/lib/chromium/chromium\0--type=' + kind + '\0--ozone-platform=wayland'
+ self.assertFalse(browser_main(command.split('\0')))
+
+ def test_type_flag_must_start_an_argument_or_whitespace_token(self):
+ self.assertTrue(browser_main(['/usr/lib/chromium/chromium', '--user-data-dir=/tmp/--type=profile']))
+ self.assertTrue(browser_main(['/usr/lib/chromium/chromium prefix--type=renderer']))
+ self.assertFalse(browser_main(['/usr/lib/chromium/chromium\t--type=renderer']))
+
+ def test_empty_process_title_is_not_a_browser_main(self):
+ self.assertFalse(browser_main([]))
+ self.assertFalse(browser_main(['']))
+
+
+if __name__ == '__main__':
+ unittest.main()