From f7a560051cbe21bd5e7aa026629e4f93fa77240d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 07:29:51 +0000 Subject: [PATCH 1/2] Add unit test for serve.py build_state Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com> --- tests/run-tests.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 7e759a8..bf6f634 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -613,6 +613,75 @@ fi # ─── Browser UI payload ───────────────────────────────────────────────────── describe "browser UI" +if it "build_state extracts state correctly"; then + failures="$(python3 - <<'PY' +import sys, json, importlib.util + +sys.argv = ['serve.py', '.', '8777', '127.0.0.1', '0'] +sys.path.insert(0, './lib/linux') + +spec = importlib.util.spec_from_file_location("serve", "./lib/linux/serve.py") +serve = importlib.util.module_from_spec(spec) +sys.modules["serve"] = serve +spec.loader.exec_module(serve) + +fake_info = { + "platform": "linux", + "system": { + "host": "testhost", "distribution": "Ubuntu", "architecture": "x64", "model": "PC", + "cpu": "Intel", "cores": "4", "memory": "8 GB", "free disk": "100 GB", + "user": "testuser", "display": "graphical", "environment": "unknown" + }, + "suggested": "workstation", + "wsl": {"isWsl": False, "version": "", "distro": ""}, + "installed": {"git": "installed"} +} + +def mock_run(*args, **kwargs): + class MockOut: + returncode = 0 + stdout = json.dumps(fake_info) + stderr = "" + return MockOut() + +orig_run = serve.subprocess.run +serve.subprocess.run = mock_run + +bad = [] +try: + state = serve.build_state() + if state["platform"] != "Linux": + bad.append(f"expected Linux platform, got {state['platform']}") + if state["system"]["host"] != "testhost": + bad.append(f"host mismatch, got {state['system']['host']}") + + def mock_run_error(*args, **kwargs): + class MockOut: + returncode = 1 + stdout = "" + stderr = "probe script failed" + return MockOut() + + serve.subprocess.run = mock_run_error + try: + serve.build_state() + bad.append("expected RuntimeError") + except RuntimeError as e: + if "probe script failed" not in str(e): + bad.append(f"expected 'probe script failed' in RuntimeError, got {e}") +except Exception as e: + import traceback + bad.append(f"Exception: {traceback.format_exc()}") +finally: + serve.subprocess.run = orig_run + +if bad: + print("\n".join(bad)) +PY +)" + if [[ -z "$failures" ]]; then pass; else fail "$failures"; fi +fi + if it "classify handles edge cases correctly"; then failures="$(python3 - <<'PY' import sys From ef810b6bf69c65106f0d215bf9e688e8554bca41 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 08:03:56 +0000 Subject: [PATCH 2/2] Fix Windows tests and PSScriptAnalyzer warnings Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com> --- lib/windows/AutoOS.ClaudeAutostart.psm1 | 4 ++-- lib/windows/AutoOS.Detect.psm1 | 22 +++++++++++----------- lib/windows/AutoOS.Serve.psm1 | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/windows/AutoOS.ClaudeAutostart.psm1 b/lib/windows/AutoOS.ClaudeAutostart.psm1 index 98c4a9f..f1f06ed 100644 --- a/lib/windows/AutoOS.ClaudeAutostart.psm1 +++ b/lib/windows/AutoOS.ClaudeAutostart.psm1 @@ -43,7 +43,7 @@ function Get-AutoOSClaudeDefaults { foreach ($p in $block.PSObject.Properties) { $table[$p.Name] = $p.Value } if ($table.Count -gt 0) { return $table } } - } catch { } + } catch { $null = $_ } } @{ enabled = $true; snapshot_interval_mins = 5; liveness_window_mins = 240 @@ -272,7 +272,7 @@ function Get-AutoOSClaudeState { sessions = @($doc.sessions) } } - } catch { } + } catch { $null = $_ } } [pscustomobject]@{ version = $script:StateVersion; captured_at = 0; captured_at_iso = $null; sessions = @() } } diff --git a/lib/windows/AutoOS.Detect.psm1 b/lib/windows/AutoOS.Detect.psm1 index b1934ec..ea51b0f 100644 --- a/lib/windows/AutoOS.Detect.psm1 +++ b/lib/windows/AutoOS.Detect.psm1 @@ -43,20 +43,20 @@ function Get-AutoOSShimDirectory { $home_ = $env:USERPROFILE @( # Scoop: user-scope by default, global when SCOOP_GLOBAL is set. - (Join-Path $home_ 'scoop\shims'), + $(if ($home_) { Join-Path $home_ 'scoop\shims' }), $(if ($env:SCOOP) { Join-Path $env:SCOOP 'shims' }), $(if ($env:SCOOP_GLOBAL) { Join-Path $env:SCOOP_GLOBAL 'shims' }), - (Join-Path $env:ProgramData 'scoop\shims'), + $(if ($env:ProgramData) { Join-Path $env:ProgramData 'scoop\shims' }), # Chocolatey. - (Join-Path $env:ProgramData 'chocolatey\bin'), + $(if ($env:ProgramData) { Join-Path $env:ProgramData 'chocolatey\bin' }), # winget's own shim directory for portable packages. - (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'), - (Join-Path $env:ProgramFiles 'WinGet\Links'), + $(if ($env:LOCALAPPDATA) { Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links' }), + $(if ($env:ProgramFiles) { Join-Path $env:ProgramFiles 'WinGet\Links' }), # npm -g, pipx/uv and cargo all install here and all rely on PATH. - (Join-Path $env:APPDATA 'npm'), - (Join-Path $home_ '.local\bin'), - (Join-Path $home_ '.cargo\bin'), - (Join-Path $home_ 'bin') + $(if ($env:APPDATA) { Join-Path $env:APPDATA 'npm' }), + $(if ($home_) { Join-Path $home_ '.local\bin' }), + $(if ($home_) { Join-Path $home_ '.cargo\bin' }), + $(if ($home_) { Join-Path $home_ 'bin' }) ) | Where-Object { $_ } } @@ -122,7 +122,7 @@ function Get-AutoOSWingetPackageProcess { $process = [Diagnostics.Process]::Start($psi) # Close stdin so a prompt that slipped past --disable-interactivity reads # EOF and gives up, instead of sitting there until the timeout. - try { $process.StandardInput.Close() } catch { } + try { $process.StandardInput.Close() } catch { $null = $_ } $process } catch { $null } } @@ -144,7 +144,7 @@ function Get-AutoOSWingetPackageResult { $Process.Kill() } } catch { $packages = @() } - finally { try { $Process.Dispose() } catch { } } + finally { try { $Process.Dispose() } catch { $null = $_ } } $packages } diff --git a/lib/windows/AutoOS.Serve.psm1 b/lib/windows/AutoOS.Serve.psm1 index f732bf6..de38ee1 100644 --- a/lib/windows/AutoOS.Serve.psm1 +++ b/lib/windows/AutoOS.Serve.psm1 @@ -266,7 +266,7 @@ function Get-AutoOSExampleBlock { try { $block = (Get-Content -LiteralPath $path -Raw -Encoding UTF8 | ConvertFrom-Json).$Name if ($block) { return $block } - } catch { } + } catch { $null = $_ } @{} } @@ -286,7 +286,7 @@ function Get-AutoOSDetectedAnswers { try { $value = (& git config --global $pair.Setting 2>$null | Select-Object -First 1) if ($value) { $answers[$pair.Key] = [string]$value } - } catch { } + } catch { $null = $_ } } $answers }