-
Notifications
You must be signed in to change notification settings - Fork 3
^R D4: extract host-detection into scripts/lib/launcher/host-detect.sh + launcher-contract.md #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Launcher contract | ||
|
|
||
| `scripts/workcell` is the host-side launcher. Historically it was a single | ||
| monolithic script; roadmap item D4 decomposes it into small, sourced, | ||
| behaviour-preserving modules under `scripts/lib/launcher/`. The launcher | ||
| sources each module from its `source "${ROOT_DIR}/scripts/lib/..."` block | ||
| (after `ROOT_DIR` is resolved) so every extracted helper is defined before its | ||
| first call site. | ||
|
|
||
| This document records the contract of each extracted module. It will grow as | ||
| further modules are pulled out of the launcher. | ||
|
|
||
| ## Host detection (`host-detect.sh`) | ||
|
|
||
| `scripts/lib/launcher/host-detect.sh` normalises the host environment into the | ||
| lowercased values the launcher's support-matrix logic consumes. Every helper | ||
| depends only on `uname`/`ps`/`PPID`/environment variables and each other — no | ||
| other launcher function — which makes the module self-contained. | ||
|
|
||
| All emitted values are lowercased and newline-terminated. Values are normalised | ||
| to canonical tokens where recognised, and otherwise passed through lowercased. | ||
|
|
||
| ### `support_matrix_host_override_allowed()` | ||
|
|
||
| Gate that decides whether the harness-only host overrides (below) are honoured. | ||
| Returns `0` (allowed) only when **both** hold: | ||
|
|
||
| - `WORKCELL_VERIFY_INVARIANTS_SANITIZED_ENTRYPOINT` is `1`; and | ||
| - the parent process command line (read from `/proc/${PPID}/cmdline`, falling | ||
| back to `ps -p "${PPID}"`) matches one of the recognised validation harness | ||
| entrypoints (`scripts/verify-invariants.sh` or the shared dry-run scenario | ||
| scripts). | ||
|
|
||
| Returns non-zero otherwise. This keeps the overrides usable by Linux | ||
| validation runners exercising launch assembly without weakening the real, | ||
| operator-facing support boundary. | ||
|
|
||
| ### `detected_host_os()` | ||
|
|
||
| Prints the normalised host operating system: `macos` (Darwin), `linux` | ||
| (Linux), or `windows` (MINGW/MSYS/CYGWIN/`Windows_NT`). Any other `uname -s` | ||
| value is passed through lowercased. | ||
|
|
||
| ### `detected_host_arch()` | ||
|
|
||
| Prints the normalised host architecture: `arm64` (`arm64`/`aarch64`) or `amd64` | ||
| (`x86_64`/`amd64`). Any other `uname -m` value is passed through lowercased. | ||
|
|
||
| ### `detected_host_distro()` | ||
|
|
||
| On non-Linux hosts prints `none`. On Linux, prints the lowercased `ID` from | ||
| `/etc/os-release`, or `unknown` when it cannot be determined. | ||
|
|
||
| ### `detected_host_distro_version()` | ||
|
|
||
| On non-Linux hosts prints `none`. On Linux, prints the lowercased `VERSION_ID` | ||
| (falling back to `VERSION_CODENAME`) from `/etc/os-release`, or `unknown` when | ||
| it cannot be determined. | ||
|
|
||
| ### Harness-only overrides | ||
|
|
||
| When `support_matrix_host_override_allowed` returns `0`, each detector first | ||
| honours a reserved override environment variable if it is non-empty, printing | ||
| its value verbatim: | ||
|
|
||
| - `WORKCELL_TEST_SUPPORT_MATRIX_HOST_OS` | ||
| - `WORKCELL_TEST_SUPPORT_MATRIX_HOST_ARCH` | ||
| - `WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO` | ||
| - `WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO_VERSION` | ||
|
|
||
| These variables are reserved for the validation harness. The launcher scrubs | ||
| them from the host process environment unless the sanitized-entrypoint marker | ||
| is set, so they cannot be smuggled in by an operator to spoof the detected host. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #!/usr/bin/env -S BASH_ENV= ENV= bash | ||
| # shellcheck shell=bash | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright 2026 Omkhar Arasaratnam | ||
| # | ||
| # scripts/lib/launcher/host-detect.sh — host-detection module extracted | ||
| # from scripts/workcell as the first increment of the launcher | ||
| # decomposition (roadmap item D4). These helpers normalise the host OS, | ||
| # architecture, and (on Linux) distribution/version into the lowercased | ||
| # values the launcher's support-matrix logic consumes. They depend only | ||
| # on uname/ps/PPID/env vars and each other — no other launcher function — | ||
| # so they are a self-contained, behaviour-preserving unit. See | ||
| # docs/launcher-contract.md for the module contract. | ||
|
|
||
| support_matrix_host_override_allowed() { | ||
| local parent_cmdline="" | ||
|
|
||
| [[ "${WORKCELL_VERIFY_INVARIANTS_SANITIZED_ENTRYPOINT:-0}" == "1" ]] || return 1 | ||
| if [[ -r "/proc/${PPID}/cmdline" ]]; then | ||
| parent_cmdline="$(tr '\0' ' ' <"/proc/${PPID}/cmdline" 2>/dev/null || true)" | ||
| elif command -v ps >/dev/null 2>&1; then | ||
| parent_cmdline="$(ps -p "${PPID}" -o command= 2>/dev/null || true)" | ||
| fi | ||
| case "${parent_cmdline}" in | ||
| *"scripts/verify-invariants.sh"* | \ | ||
| *"tests/scenarios/shared/test-copilot-session-dry-run.sh"* | \ | ||
| *"tests/scenarios/shared/test-compat-target-dry-run.sh"* | \ | ||
| *"tests/scenarios/shared/test-gcp-remote-vm-dry-run.sh"* | \ | ||
| *"tests/scenarios/shared/test-aws-remote-vm-dry-run.sh"*) | ||
| return 0 | ||
| ;; | ||
| esac | ||
| return 1 | ||
| } | ||
|
|
||
| detected_host_os() { | ||
| local host_os="" | ||
|
|
||
| # verify-invariants uses a reserved harness-only host override so Linux | ||
| # validation runners can still exercise launch assembly without weakening the | ||
| # real operator-facing support boundary. | ||
| if support_matrix_host_override_allowed && [[ -n "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_OS:-}" ]]; then | ||
| printf '%s\n' "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_OS}" | ||
| return 0 | ||
| fi | ||
|
|
||
| host_os="$(uname -s 2>/dev/null || true)" | ||
| case "${host_os}" in | ||
| Darwin) | ||
| printf 'macos\n' | ||
| ;; | ||
| Linux) | ||
| printf 'linux\n' | ||
| ;; | ||
| MINGW* | MSYS* | CYGWIN* | Windows_NT) | ||
| printf 'windows\n' | ||
| ;; | ||
| *) | ||
| printf '%s\n' "$(printf '%s' "${host_os}" | tr '[:upper:]' '[:lower:]')" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| detected_host_arch() { | ||
| local host_arch="" | ||
|
|
||
| if support_matrix_host_override_allowed && [[ -n "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_ARCH:-}" ]]; then | ||
| printf '%s\n' "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_ARCH}" | ||
| return 0 | ||
| fi | ||
|
|
||
| host_arch="$(uname -m 2>/dev/null || true)" | ||
| case "${host_arch}" in | ||
| arm64 | aarch64) | ||
| printf 'arm64\n' | ||
| ;; | ||
| x86_64 | amd64) | ||
| printf 'amd64\n' | ||
| ;; | ||
| *) | ||
| printf '%s\n' "$(printf '%s' "${host_arch}" | tr '[:upper:]' '[:lower:]')" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| detected_host_distro() { | ||
| local host_distro="" | ||
|
|
||
| if support_matrix_host_override_allowed && [[ -n "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO:-}" ]]; then | ||
| printf '%s\n' "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO}" | ||
| return 0 | ||
| fi | ||
|
|
||
| if [[ "$(detected_host_os)" != "linux" ]]; then | ||
| printf 'none\n' | ||
| return 0 | ||
| fi | ||
| if [[ -r /etc/os-release ]]; then | ||
| # shellcheck disable=SC1091 | ||
| . /etc/os-release | ||
| host_distro="${ID:-}" | ||
| fi | ||
| if [[ -z "${host_distro}" ]]; then | ||
| host_distro="unknown" | ||
| fi | ||
| printf '%s\n' "$(printf '%s' "${host_distro}" | tr '[:upper:]' '[:lower:]')" | ||
| } | ||
|
|
||
| detected_host_distro_version() { | ||
| local host_distro_version="" | ||
|
|
||
| if support_matrix_host_override_allowed && [[ -n "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO_VERSION:-}" ]]; then | ||
| printf '%s\n' "${WORKCELL_TEST_SUPPORT_MATRIX_HOST_DISTRO_VERSION}" | ||
| return 0 | ||
| fi | ||
|
|
||
| if [[ "$(detected_host_os)" != "linux" ]]; then | ||
| printf 'none\n' | ||
| return 0 | ||
| fi | ||
| if [[ -r /etc/os-release ]]; then | ||
| # shellcheck disable=SC1091 | ||
| . /etc/os-release | ||
| host_distro_version="${VERSION_ID:-${VERSION_CODENAME:-}}" | ||
| fi | ||
| if [[ -z "${host_distro_version}" ]]; then | ||
| host_distro_version="unknown" | ||
| fi | ||
| printf '%s\n' "$(printf '%s' "${host_distro_version}" | tr '[:upper:]' '[:lower:]')" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.