Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/windows/AutoOS.ClaudeAutostart.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = @() }
}
Expand Down
22 changes: 11 additions & 11 deletions lib/windows/AutoOS.Detect.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 { $_ }
}

Expand Down Expand Up @@ -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 }
}
Expand All @@ -144,7 +144,7 @@ function Get-AutoOSWingetPackageResult {
$Process.Kill()
}
} catch { $packages = @() }
finally { try { $Process.Dispose() } catch { } }
finally { try { $Process.Dispose() } catch { $null = $_ } }
$packages
}

Expand Down
4 changes: 2 additions & 2 deletions lib/windows/AutoOS.Serve.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $_ }
@{}
}

Expand All @@ -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
}
Expand Down
69 changes: 69 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down