okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
f67dd6d
main
1"""Browser discovery through the real kernel, without starting a GUI app.""" 2 3import unittest 4 5from harness import Albedo ,Provider ,exclusive ,python ,text 6 7 8@exclusive 9class BrowserTests (unittest .TestCase ): 10def test_headless_shell_preserves_overrides_headed_launches_and_fallback (self ): 11code = "" 12 13def script (request ): 14if request ["messages" ][- 1 ].get ("role" )== "user" : 15return python (code ) 16return text ("done" ) 17 18def prepare (app ): 19nonlocal code 20bin_dir = app .workspace / "bin" 21bin_dir .mkdir () 22chrome = bin_dir / "chromium" 23shell = bin_dir / "headless-shell" 24shell_link = app .home / "browsers/chrome-headless-shell" 25shell_link .parent .mkdir () 26shell_link .symlink_to (shell ) 27for executable in (chrome ,shell ): 28executable .write_text ( 29'#!/bin/sh\necho "test browser exited" >&2\nexit 23\n' 30 ) 31executable .chmod (0o755 ) 32for variable in ( 33"ALBEDO_BROWSER_EXECUTABLE" , 34"PRIME_BROWSER_EXECUTABLE" , 35"CHROME_PATH" , 36 ): 37app .daemon .env [variable ]= "" 38 39code = f""" 40from pathlib import Path 41from albedo_plugins.browser import LaunchError 42chrome = { str ( chrome )!r } 43shell = { str ( shell )!r } 44os.environ['PATH'] = { str ( bin_dir )!r } 45async def check(expected, **options): 46try: 47b = await browser.spawn(sandbox=False, timeout=3, **options) 48except LaunchError as error: 49assert error.details['executable'] == expected, error.to_dict() 50assert error.details['reason'] == 'process_exited', error.to_dict() 51assert 'test browser exited' in error.details['stderr_tail'], error.to_dict() 52assert not Path(error.details['profile']).exists() 53else: 54await b.close() 55raise AssertionError('test browser should exit during startup') 56await check(shell) 57path_shell = Path( { str ( bin_dir / "chrome-headless-shell" )!r } ) 58path_shell.symlink_to(chrome) 59await check(chrome) 60path_shell.unlink() 61await check(chrome, headless=False) 62await check(chrome, executable=chrome) 63os.environ['ALBEDO_BROWSER_EXECUTABLE'] = chrome 64await check(chrome) 65del os.environ['ALBEDO_BROWSER_EXECUTABLE'] 66Path( { str ( shell_link )!r } ).unlink() 67await check(chrome) 68try: 69await browser.spawn(executable= { str ( shell_link )!r } , sandbox=False) 70except LaunchError as error: 71assert error.details['reason'] == 'executable_not_found', error.to_dict() 72else: 73raise AssertionError('missing explicit browser must not fall back') 74Path( { str ( app . workspace / "passed" )!r } ).write_text('passed') 75""" 76 77provider = Provider (script ) 78self .addCleanup (provider .close ) 79with Albedo (provider ,prepare = prepare )as app : 80session = app .session () 81app .prompt (session ,"try the installed browsers" ).close () 82app .idle (session ) 83self .assertTrue ((app .workspace / "passed" ).exists (),app .history (session ))