From b4be33e541cd0c00704588ee0cf395b5ec271a29 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 16 Jul 2026 00:03:52 +0200 Subject: [PATCH 1/3] feat(ci): introduce merge queue (#2024) * feat(ci): introduce merge queue Closes #1946 Signed-off-by: Evan Lezar * fix(ci): run GPU E2E for merge groups Signed-off-by: Evan Lezar * docs(ci): clarify merge queue GPU gate Signed-off-by: Evan Lezar --------- Signed-off-by: Evan Lezar --- .github/actions/pr-gate/action.yml | 4 +- .github/workflows/branch-checks.yml | 2 + .github/workflows/branch-e2e.yml | 31 ++++++++---- .github/workflows/helm-lint.yml | 2 + .github/workflows/required-ci-gates.yml | 66 +++++++++++++++++++++---- CI.md | 38 +++++++++++--- architecture/build.md | 9 ++-- 7 files changed, 121 insertions(+), 31 deletions(-) diff --git a/.github/actions/pr-gate/action.yml b/.github/actions/pr-gate/action.yml index 0c55bf1208..3e10435a34 100644 --- a/.github/actions/pr-gate/action.yml +++ b/.github/actions/pr-gate/action.yml @@ -3,8 +3,8 @@ description: > Resolve PR metadata for a `pull-request/` push from copy-pr-bot and decide whether the workflow should run. Sets `should-run=true` only when the pushed SHA still matches the PR head SHA. If `required_label` is provided, the PR - must also carry that label. For non-`push` events (e.g. `workflow_dispatch`), - always sets `should-run=true`. + must also carry that label. For non-`push` events (e.g. `workflow_dispatch` + and `merge_group`), always sets `should-run=true`. inputs: required_label: diff --git a/.github/workflows/branch-checks.yml b/.github/workflows/branch-checks.yml index 7713febb6f..b01cdb7718 100644 --- a/.github/workflows/branch-checks.yml +++ b/.github/workflows/branch-checks.yml @@ -1,6 +1,8 @@ name: Branch Checks on: + merge_group: + types: [checks_requested] push: branches: - "pull-request/[0-9]+" diff --git a/.github/workflows/branch-e2e.yml b/.github/workflows/branch-e2e.yml index 859f22ef95..28728e597f 100644 --- a/.github/workflows/branch-e2e.yml +++ b/.github/workflows/branch-e2e.yml @@ -1,6 +1,8 @@ name: Branch E2E Checks on: + merge_group: + types: [checks_requested] push: branches: - "pull-request/[0-9]+" @@ -37,15 +39,26 @@ jobs: shell: bash run: | set -euo pipefail - if [ "$EVENT_NAME" != "push" ]; then - run_core_e2e=true - run_gpu_e2e=true - run_kubernetes_ha_e2e=true - else - run_core_e2e="$(jq -r 'index("test:e2e") != null' <<< "$LABELS_JSON")" - run_gpu_e2e="$(jq -r 'index("test:e2e-gpu") != null' <<< "$LABELS_JSON")" - run_kubernetes_ha_e2e="$(jq -r 'index("test:e2e-kubernetes") != null' <<< "$LABELS_JSON")" - fi + case "$EVENT_NAME" in + push) + run_core_e2e="$(jq -r 'index("test:e2e") != null' <<< "$LABELS_JSON")" + run_gpu_e2e="$(jq -r 'index("test:e2e-gpu") != null' <<< "$LABELS_JSON")" + run_kubernetes_ha_e2e="$(jq -r 'index("test:e2e-kubernetes") != null' <<< "$LABELS_JSON")" + ;; + merge_group) + # Merge groups have no PR labels. When GPU E2E is required as documented + # in CI.md, skipping it leaves the gate pending until the queue times out + # and ejects the PR. HA stays off until stable. + run_core_e2e=true + run_gpu_e2e=true + run_kubernetes_ha_e2e=false + ;; + *) + run_core_e2e=true + run_gpu_e2e=true + run_kubernetes_ha_e2e=true + ;; + esac if [ "$run_core_e2e" = "true" ] || [ "$run_gpu_e2e" = "true" ] || [ "$run_kubernetes_ha_e2e" = "true" ]; then run_any_e2e=true else diff --git a/.github/workflows/helm-lint.yml b/.github/workflows/helm-lint.yml index 8c898011c7..b57346101b 100644 --- a/.github/workflows/helm-lint.yml +++ b/.github/workflows/helm-lint.yml @@ -4,6 +4,8 @@ name: Helm Lint on: + merge_group: + types: [checks_requested] push: branches: - "pull-request/[0-9]+" diff --git a/.github/workflows/required-ci-gates.yml b/.github/workflows/required-ci-gates.yml index ca068cf5ce..b5b521a8f3 100644 --- a/.github/workflows/required-ci-gates.yml +++ b/.github/workflows/required-ci-gates.yml @@ -1,6 +1,8 @@ name: Required CI Gates on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled] workflow_run: @@ -17,7 +19,7 @@ permissions: statuses: write concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.run_id }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.workflow_run.head_sha || github.sha || github.run_id }} cancel-in-progress: true jobs: @@ -33,9 +35,13 @@ jobs: PR_NUMBER_FROM_EVENT: ${{ github.event.pull_request.number }} PR_HEAD_SHA_FROM_EVENT: ${{ github.event.pull_request.head.sha }} PR_LABELS_FROM_EVENT: ${{ toJSON(github.event.pull_request.labels.*.name) }} + GITHUB_SHA_FROM_CONTEXT: ${{ github.sha }} + GITHUB_REF_NAME_FROM_CONTEXT: ${{ github.ref_name }} + GITHUB_RUN_ID_FROM_CONTEXT: ${{ github.run_id }} WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }} WORKFLOW_RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} WORKFLOW_RUN_EVENT: ${{ github.event.workflow_run.event }} + WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }} shell: bash run: | set -euo pipefail @@ -67,12 +73,19 @@ jobs: } resolve_pull_request_event() { + CONTEXT_KIND="pull_request" + WORKFLOW_EVENT="push" PR_NUMBER="$PR_NUMBER_FROM_EVENT" HEAD_SHA="$PR_HEAD_SHA_FROM_EVENT" LABELS_JSON=$(jq -c . <<< "$PR_LABELS_FROM_EVENT") + MIRROR_REF="pull-request/$PR_NUMBER" + EXPECTED_HEAD_BRANCH="$MIRROR_REF" + STATUS_TARGET_URL="https://github.com/$GH_REPO/pull/$PR_NUMBER" } load_pr_context() { + CONTEXT_KIND="pull_request" + WORKFLOW_EVENT="push" PR_NUMBER="$1" local pr state @@ -85,9 +98,35 @@ jobs: HEAD_SHA=$(jq -r '.head.sha' <<< "$pr") LABELS_JSON=$(gh api "repos/$GH_REPO/issues/$PR_NUMBER" --jq '[.labels[].name]') + MIRROR_REF="pull-request/$PR_NUMBER" + EXPECTED_HEAD_BRANCH="$MIRROR_REF" + STATUS_TARGET_URL="https://github.com/$GH_REPO/pull/$PR_NUMBER" + } + + resolve_merge_group_event() { + CONTEXT_KIND="merge_group" + WORKFLOW_EVENT="merge_group" + HEAD_SHA="$GITHUB_SHA_FROM_CONTEXT" + LABELS_JSON="[]" + EXPECTED_HEAD_BRANCH="$GITHUB_REF_NAME_FROM_CONTEXT" + STATUS_TARGET_URL="https://github.com/$GH_REPO/actions/runs/$GITHUB_RUN_ID_FROM_CONTEXT" + } + + resolve_merge_group_workflow_run_event() { + CONTEXT_KIND="merge_group" + WORKFLOW_EVENT="merge_group" + HEAD_SHA="$WORKFLOW_RUN_HEAD_SHA" + LABELS_JSON="[]" + EXPECTED_HEAD_BRANCH="$WORKFLOW_RUN_HEAD_BRANCH" + STATUS_TARGET_URL="${WORKFLOW_RUN_HTML_URL:-https://github.com/$GH_REPO/actions}" } resolve_workflow_run_event() { + if [ "$WORKFLOW_RUN_EVENT" = "merge_group" ]; then + resolve_merge_group_workflow_run_event + return + fi + if [ "$WORKFLOW_RUN_EVENT" != "push" ]; then echo "Ignoring workflow_run from event '$WORKFLOW_RUN_EVENT'." exit 0 @@ -112,6 +151,8 @@ jobs: resolve_context() { if [ "$EVENT_NAME" = "pull_request_target" ]; then resolve_pull_request_event + elif [ "$EVENT_NAME" = "merge_group" ]; then + resolve_merge_group_event elif [ "$EVENT_NAME" = "workflow_run" ]; then resolve_workflow_run_event else @@ -119,22 +160,25 @@ jobs: exit 1 fi - PR_URL="https://github.com/$GH_REPO/pull/$PR_NUMBER" - MIRROR_REF="pull-request/$PR_NUMBER" + STATUS_TARGET_URL="${STATUS_TARGET_URL:-https://github.com/$GH_REPO/actions}" } verify_mirror() { local context="$1" local mirror_sha + if [ "$CONTEXT_KIND" = "merge_group" ]; then + return 0 + fi + mirror_sha=$(gh api "repos/$GH_REPO/branches/$MIRROR_REF" --jq '.commit.sha' 2>/dev/null || true) if [ -z "$mirror_sha" ]; then - post_status "$context" pending "Waiting for /ok to test mirror" "$PR_URL" + post_status "$context" pending "Waiting for /ok to test mirror" "$STATUS_TARGET_URL" return 1 fi if [ "$mirror_sha" != "$HEAD_SHA" ]; then - post_status "$context" pending "Waiting for /ok to test mirror" "$PR_URL" + post_status "$context" pending "Waiting for /ok to test mirror" "$STATUS_TARGET_URL" return 1 fi @@ -149,8 +193,8 @@ jobs: local required_job_name="${5:-}" local workflow_url="https://github.com/$GH_REPO/actions/workflows/$workflow_file" - if [ -n "$required_label" ] && ! has_label "$required_label"; then - post_status "$context" success "$required_label not applied" "$PR_URL" + if [ "$CONTEXT_KIND" = "pull_request" ] && [ -n "$required_label" ] && ! has_label "$required_label"; then + post_status "$context" success "$required_label not applied" "$STATUS_TARGET_URL" return 0 fi @@ -159,8 +203,12 @@ jobs: fi local runs latest run_id status conclusion run_url real_success - runs=$(gh api "repos/$GH_REPO/actions/workflows/$workflow_file/runs?head_sha=$HEAD_SHA&event=push" --jq '.workflow_runs') - latest=$(jq -c --arg branch "$MIRROR_REF" '[.[] | select(.head_branch == $branch)] | sort_by(.created_at) | reverse | .[0] // empty' <<< "$runs") + runs=$(gh api "repos/$GH_REPO/actions/workflows/$workflow_file/runs?head_sha=$HEAD_SHA&event=$WORKFLOW_EVENT" --jq '.workflow_runs') + if [ -n "${EXPECTED_HEAD_BRANCH:-}" ]; then + latest=$(jq -c --arg branch "$EXPECTED_HEAD_BRANCH" '[.[] | select(.head_branch == $branch)] | sort_by(.created_at) | reverse | .[0] // empty' <<< "$runs") + else + latest=$(jq -c 'sort_by(.created_at) | reverse | .[0] // empty' <<< "$runs") + fi if [ -z "$latest" ]; then post_status "$context" pending "Waiting for $workflow_name" "$workflow_url" diff --git a/CI.md b/CI.md index d04668aafc..e14d5bdb9d 100644 --- a/CI.md +++ b/CI.md @@ -10,6 +10,8 @@ PR CI that runs on NVIDIA self-hosted runners uses NVIDIA's copy-pr-bot. The bot `Branch Checks` run automatically after copy-pr-bot mirrors the PR. `Required CI Gates` posts PR-head statuses that verify the mirror exists, is current, and ran the expected push-based workflows. E2E suites are opt-in because they are more expensive and publish temporary images. +Merge queue validation is a second integration gate for `main`. After a PR has passed the required PR-head statuses, a maintainer adds it to the merge queue. GitHub creates a temporary merge-group branch that combines the latest `main`, the queued PR, and any earlier queued PRs. The same required `OpenShell / ...` status contexts are then published against the merge-group SHA before GitHub merges it. + Three opt-in labels enable the long-running E2E suites: - `test:e2e` runs the standard E2E suite in `Branch E2E Checks` @@ -75,6 +77,7 @@ Flow: 4. The maintainer opens that link and clicks **Re-run all jobs**. This time `pr_metadata` sees the label and the build/E2E jobs run. 5. When the run finishes, the matching `OpenShell / ...` gate status flips to green automatically. 6. New commits push to the mirror automatically and re-trigger `Branch Checks` plus any labeled E2E jobs in `Branch E2E Checks`. +7. When the PR is ready to merge, use **Add to merge queue** instead of merging directly. The queue validates the final integration state before updating `main`. ### Forked PR @@ -88,9 +91,30 @@ Flow: 1. Open the PR. The vouch check confirms you are vouched (otherwise the PR is auto-closed). 2. copy-pr-bot does not mirror forks automatically. A maintainer reviews the diff and comments `/ok to test ` with your latest commit SHA. 3. After `/ok to test`, copy-pr-bot mirrors to `pull-request/`. From here the flow is identical to internal PRs: `Required CI Gates` verifies the mirror and required push workflows, and maintainers apply the E2E label when the extra suites are needed. +4. When the PR is ready to merge, maintainers add it to the merge queue so the queued integration state is tested before it reaches `main`. Important: every new commit you push requires another `/ok to test ` from a maintainer before push-based CI will run on it. If a label is applied while the mirror is stale, `E2E Label Help` will post a comment explaining what's needed. +## Merge queue + +GitHub merge queue is required for `main`. Repository administrators must enable **Require merge queue** in the branch ruleset for `main` and keep these required status contexts aligned with the PR gates: + +- `OpenShell / Branch Checks` +- `OpenShell / E2E` +- `OpenShell / GPU E2E` +- `OpenShell / Helm Lint` + +Do not require the underlying workflow job names directly. `Required CI Gates` publishes stable commit statuses for both PR-head mirror commits and merge-group commits. + +Merge-group runs use the `merge_group` event. The event is distinct from `pull_request` and `push`, and GitHub will not report required checks for queued PRs unless the workflows include it. In this repository: + +- `Branch Checks` runs the standard non-E2E gates on the merge-group SHA. +- `Branch E2E Checks` runs core E2E and GPU E2E for merge groups. Kubernetes HA E2E remains optional and label-driven on PRs. +- `Helm Lint` runs for merge groups without the PR diff optimization, because the merge-group branch is the final integration state. +- `Required CI Gates` posts the same `OpenShell / ...` statuses to the merge-group SHA and does not require a `pull-request/` mirror for merge-group events. + +Maintainers should add ready PRs to the queue rather than pressing a direct merge button. GitHub removes a PR from the queue if the merge-group checks fail or time out. + ## copy-pr-bot [copy-pr-bot](https://github.com/apps/copy-pr-bot) is a GitHub App maintained by NVIDIA that solves a specific GitHub Actions security problem: by default, `pull_request`-triggered workflows on a self-hosted runner can run an arbitrary contributor's code on hardware the project owns. For projects that need self-hosted runners (GPU access, ARM hardware, on-prem secrets), GitHub's recommended pattern is to never trigger workflows directly from external `pull_request` events. @@ -109,12 +133,12 @@ The bot's full administrator documentation is internal to NVIDIA. The only comma | File | Role | |---|---| -| `.github/workflows/branch-checks.yml` | Required non-E2E PR checks. Triggers on `push: pull-request/[0-9]+`. | -| `.github/workflows/branch-e2e.yml` | Opt-in standard, GPU, and Kubernetes HA E2E. Triggers on `push: pull-request/[0-9]+` and runs jobs selected by `test:e2e`, `test:e2e-gpu`, or `test:e2e-kubernetes`. | -| `.github/workflows/helm-lint.yml` | Helm chart validation. Triggers on `push: pull-request/[0-9]+` and skips lint jobs unless Helm inputs changed. | -| `.github/actions/pr-gate/action.yml` | Composite action that resolves PR metadata and verifies the required label is set. | +| `.github/workflows/branch-checks.yml` | Required non-E2E checks. Triggers on `push: pull-request/[0-9]+` for PR mirrors and `merge_group` for queued merges. | +| `.github/workflows/branch-e2e.yml` | Standard, GPU, and Kubernetes HA E2E. PR mirror pushes use `test:e2e`, `test:e2e-gpu`, and `test:e2e-kubernetes` labels; merge groups run core and GPU E2E. | +| `.github/workflows/helm-lint.yml` | Helm chart validation. PR mirror pushes skip lint jobs unless Helm inputs changed; merge groups always validate Helm because they represent the final integration state. | +| `.github/actions/pr-gate/action.yml` | Composite action that resolves PR metadata and verifies the required label is set for PR mirror pushes. Non-push events are allowed through. | | `.github/actions/pr-merge-base/action.yml` | Composite action that resolves and fetches the merge-base commit for `pull-request/` push workflows. | -| `.github/workflows/required-ci-gates.yml` | Posts required PR-head statuses for push-based CI workflows. This is what branch protection should require. | +| `.github/workflows/required-ci-gates.yml` | Posts required PR-head and merge-group statuses for gated CI workflows. This is what branch protection and merge queue should require. | | `.github/workflows/e2e-label-help.yml` | When a `test:e2e*` label is applied, posts a PR comment telling the maintainer the next manual step (re-run an existing workflow run, or `/ok to test ` to refresh the mirror). | ## Release workflows @@ -129,11 +153,11 @@ These workflows run after merge to publish dev/tagged artifacts and verify them. ## Required status contexts -Require these statuses in the branch ruleset for push-based CI: +Require these statuses in the branch ruleset for PR and merge-queue CI: - `OpenShell / Branch Checks` - `OpenShell / E2E` - `OpenShell / GPU E2E` - `OpenShell / Helm Lint` -Do not require the underlying push workflow jobs directly. Those jobs only appear after copy-pr-bot mirrors trusted code, so they cannot independently prove that an untrusted or stale PR head was tested. +Do not require the underlying workflow jobs directly. PR workflow jobs only appear after copy-pr-bot mirrors trusted code, and merge-group workflow jobs run on temporary queue branches. The stable `OpenShell / ...` contexts prove the expected workflow completed for the commit that GitHub is about to merge. diff --git a/architecture/build.md b/architecture/build.md index ef62a6c30c..e3ac5012e3 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -142,17 +142,18 @@ smoke check. ## CI and E2E -Required checks run on GitHub Actions. Workflows that use NVIDIA self-hosted runners trigger from copy-pr-bot mirror branches, so trusted PRs are mirrored into `pull-request/` branches before those workflows run. +Required checks run on GitHub Actions. Workflows that use NVIDIA self-hosted runners trigger from copy-pr-bot mirror branches, so trusted PRs are mirrored into `pull-request/` branches before those workflows run. `main` also uses GitHub merge queue so the final queued integration commit is validated before it merges. The high-level CI model: 1. PR-context gate jobs publish required statuses for the PR head commit. 2. Standard branch checks run from trusted mirror branches. 3. Label-gated E2E, GPU, and Kubernetes checks run from trusted mirror branches. -4. Gate jobs verify that the mirror branch matches the PR head and that the expected non-gate workflow actually ran. -5. Release workflows rebuild and publish binaries, wheels, images, and docs. +4. Merge-group checks run against GitHub's temporary queue branch for the final integration state. +5. Gate jobs verify that the mirror branch matches the PR head, or that the merge-group workflow ran for the queued SHA, and that the expected non-gate workflow actually ran. +6. Release workflows rebuild and publish binaries, wheels, images, and docs. -See `CI.md` for the contributor workflow and labels. +See `CI.md` for the contributor workflow, labels, and maintainer merge-queue workflow. ## Docs Site From 21aaa89522b8e5c7d5d76ad5f8d69beffa88ba23 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 16 Jul 2026 00:04:57 +0200 Subject: [PATCH 2/3] feat(gateway): add elevated gateway info (#2202) * feat(cli)!: fold gateway metadata into list BREAKING CHANGE: openshell gateway info no longer shows local gateway registration metadata. Use openshell gateway list or openshell gateway list -o json for local registration details. Signed-off-by: Evan Lezar * feat(gateway): add elevated gateway info Signed-off-by: Evan Lezar --------- Signed-off-by: Evan Lezar --- architecture/compute-runtimes.md | 4 + crates/openshell-cli/src/main.rs | 52 ++- crates/openshell-cli/src/run.rs | 385 +++++++++++++++--- .../tests/ensure_providers_integration.rs | 7 + .../openshell-cli/tests/mtls_integration.rs | 7 + .../tests/provider_commands_integration.rs | 7 + .../sandbox_create_lifecycle_integration.rs | 7 + .../sandbox_name_fallback_integration.rs | 7 + crates/openshell-sdk/tests/client_mock.rs | 11 + crates/openshell-server/src/compute/mod.rs | 46 ++- crates/openshell-server/src/grpc/mod.rs | 51 ++- crates/openshell-server/tests/common/mod.rs | 7 + .../tests/supervisor_relay_integration.rs | 6 + docs/sandboxes/manage-gateways.mdx | 26 +- proto/openshell.proto | 37 ++ 15 files changed, 555 insertions(+), 105 deletions(-) diff --git a/architecture/compute-runtimes.md b/architecture/compute-runtimes.md index 188e939a1f..ec42277ab6 100644 --- a/architecture/compute-runtimes.md +++ b/architecture/compute-runtimes.md @@ -26,6 +26,10 @@ The capability RPC reports driver identity, version, and the default sandbox image used by the gateway. GPU availability stays driver-local and is validated when a sandbox create request asks for GPU resources. +The gateway records driver identity and version from the startup capability +response. Elevated gateway info reports that initialized driver snapshot instead +of re-querying drivers on each request. + ## Runtime Summary | Runtime | Best fit | Sandbox boundary | Notes | diff --git a/crates/openshell-cli/src/main.rs b/crates/openshell-cli/src/main.rs index 66484562d4..b32e7fe9f9 100644 --- a/crates/openshell-cli/src/main.rs +++ b/crates/openshell-cli/src/main.rs @@ -240,7 +240,7 @@ const HELP_TEMPLATE: &str = "\ provider: Manage provider configuration \x1b[1mGATEWAY COMMANDS\x1b[0m - gateway: Manage gateway registrations + gateway: Manage gateways status: Show gateway status and information inference: Manage inference configuration doctor: Diagnose gateway issues @@ -524,7 +524,7 @@ enum Commands { // =================================================================== // GATEWAY COMMANDS // =================================================================== - /// Manage gateway registrations. + /// Manage gateways. #[command(alias = "gw", after_help = GATEWAY_EXAMPLES, help_template = SUBCOMMAND_HELP_TEMPLATE)] Gateway { #[command(subcommand)] @@ -1105,18 +1105,19 @@ enum GatewayCommands { name: Option, }, - /// Show gateway registration details. + /// Show elevated live gateway runtime information. #[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")] Info { - /// Gateway name (defaults to active gateway). - #[arg(long, env = "OPENSHELL_GATEWAY", add = ArgValueCompleter::new(completers::complete_gateway_names))] - name: Option, + /// Output format. + #[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)] + output: OutputFormat, }, /// List registered gateways. /// - /// Prints a table of all registered gateways with their endpoint, type, - /// and authentication mode. The active gateway is marked with `*`. + /// Prints all registered gateways with their endpoint, type, + /// authentication mode, source, and remote registration details. + /// The active gateway is marked with `*`. #[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")] List { /// Output format. @@ -2056,11 +2057,14 @@ async fn main() -> Result<()> { GatewayCommands::Select { name } => { run::gateway_select(name.as_deref(), &cli.gateway)?; } - GatewayCommands::Info { name } => { - let name = name - .or_else(|| resolve_gateway_name(&cli.gateway)) - .unwrap_or_else(|| "openshell".to_string()); - run::gateway_admin_info(&name)?; + GatewayCommands::Info { output } => { + if let Ok(ctx) = resolve_gateway(&cli.gateway, &cli.gateway_endpoint) { + let mut tls = tls.with_gateway_name(&ctx.name); + apply_auth(&mut tls, &ctx.name); + run::gateway_info(&ctx.name, &ctx.endpoint, &tls, output.as_str()).await?; + } else { + run::gateway_info_not_configured()?; + } } GatewayCommands::List { output } => { run::gateway_list(&cli.gateway, output.as_str())?; @@ -3445,7 +3449,7 @@ mod tests { for (raw_args, index) in [ (vec!["openshell", "--gateway", "a"], 2), (vec!["openshell", "gateway", "select", "a"], 3), - (vec!["openshell", "gateway", "info", "--name", "a"], 4), + (vec!["openshell", "gateway", "remove", "a"], 3), ] { let mut cmd = Cli::command(); let args: Vec = raw_args.iter().copied().map(Into::into).collect(); @@ -3473,6 +3477,26 @@ mod tests { assert!(matches!(cli.command, Some(Commands::Status))); } + #[test] + fn gateway_info_accepts_output_json() { + let cli = Cli::try_parse_from(["openshell", "gateway", "info", "-o", "json"]) + .expect("gateway info -o json should parse"); + + assert!(matches!( + cli.command, + Some(Commands::Gateway { + command: Some(GatewayCommands::Info { + output: OutputFormat::Json + }) + }) + )); + } + + #[test] + fn top_level_info_is_not_a_command() { + assert!(Cli::try_parse_from(["openshell", "info"]).is_err()); + } + #[test] fn hidden_aliases_still_parse() { let cli = Cli::try_parse_from(["openshell", "lg", "sandbox-1"]) diff --git a/crates/openshell-cli/src/run.rs b/crates/openshell-cli/src/run.rs index 5880e21a71..924edf6f3c 100644 --- a/crates/openshell-cli/src/run.rs +++ b/crates/openshell-cli/src/run.rs @@ -40,20 +40,21 @@ use openshell_core::proto::{ DeleteProviderRefreshRequest, DeleteProviderRequest, DeleteSandboxRequest, DeleteServiceRequest, DetachSandboxProviderRequest, ExecSandboxRequest, ExposeServiceRequest, GetClusterInferenceRequest, GetDraftHistoryRequest, GetDraftPolicyRequest, - GetGatewayConfigRequest, GetProviderProfileRequest, GetProviderRefreshStatusRequest, - GetProviderRequest, GetSandboxConfigRequest, GetSandboxLogsRequest, - GetSandboxPolicyStatusRequest, GetSandboxRequest, GetServiceRequest, GpuResourceRequirements, - HealthRequest, ImportProviderProfilesRequest, LintProviderProfilesRequest, - ListProviderProfilesRequest, ListProvidersRequest, ListSandboxPoliciesRequest, - ListSandboxProvidersRequest, ListSandboxesRequest, ListServicesRequest, PlatformEvent, - PolicySource, PolicyStatus, Provider, ProviderCredentialRefreshStatus, - ProviderCredentialRefreshStrategy, ProviderProfile, ProviderProfileDiagnostic, - ProviderProfileImportItem, RejectDraftChunkRequest, ResourceRequirements, - RevokeSshSessionRequest, RotateProviderCredentialRequest, Sandbox, SandboxPhase, SandboxPolicy, - SandboxSpec, SandboxTemplate, ServiceEndpointResponse, SetClusterInferenceRequest, - SettingScope, SettingValue, TcpForwardFrame, TcpForwardInit, TcpRelayTarget, - UpdateConfigRequest, UpdateProviderProfilesRequest, UpdateProviderRequest, WatchSandboxRequest, - exec_sandbox_event, setting_value, tcp_forward_init, + GetGatewayConfigRequest, GetGatewayInfoRequest, GetProviderProfileRequest, + GetProviderRefreshStatusRequest, GetProviderRequest, GetSandboxConfigRequest, + GetSandboxLogsRequest, GetSandboxPolicyStatusRequest, GetSandboxRequest, GetServiceRequest, + GpuResourceRequirements, HealthRequest, ImportProviderProfilesRequest, + LintProviderProfilesRequest, ListProviderProfilesRequest, ListProvidersRequest, + ListSandboxPoliciesRequest, ListSandboxProvidersRequest, ListSandboxesRequest, + ListServicesRequest, PlatformEvent, PolicySource, PolicyStatus, Provider, + ProviderCredentialRefreshStatus, ProviderCredentialRefreshStrategy, ProviderProfile, + ProviderProfileDiagnostic, ProviderProfileImportItem, RejectDraftChunkRequest, + ResourceRequirements, RevokeSshSessionRequest, RotateProviderCredentialRequest, Sandbox, + SandboxPhase, SandboxPolicy, SandboxSpec, SandboxTemplate, ServiceEndpointResponse, + ServiceStatus, SetClusterInferenceRequest, SettingScope, SettingValue, TcpForwardFrame, + TcpForwardInit, TcpRelayTarget, UpdateConfigRequest, UpdateProviderProfilesRequest, + UpdateProviderRequest, WatchSandboxRequest, exec_sandbox_event, setting_value, + tcp_forward_init, }; use openshell_core::settings::{self, SettingValueKind}; use openshell_core::{ObjectId, ObjectName}; @@ -525,6 +526,28 @@ fn print_sandbox_header(sandbox: &Sandbox, display: Option<&ProvisioningDisplay> } } +#[derive(Debug, Clone)] +struct GatewayInfoView { + gateway: String, + server: String, + auth: Option<&'static str>, + status: String, + version: String, + compute_drivers: Vec, +} + +#[derive(Debug, Clone)] +struct ComputeDriverInfoView { + name: String, + capabilities: ComputeDriverCapabilitiesView, +} + +#[derive(Debug, Clone)] +struct ComputeDriverCapabilitiesView { + driver_name: String, + driver_version: String, +} + /// Show gateway status. #[allow(clippy::branches_sharing_code)] pub async fn gateway_status(gateway_name: &str, server: &str, tls: &TlsOptions) -> Result<()> { @@ -582,6 +605,129 @@ pub async fn gateway_status(gateway_name: &str, server: &str, tls: &TlsOptions) Ok(()) } +fn gateway_service_status_name(status: i32) -> &'static str { + match ServiceStatus::try_from(status) { + Ok(ServiceStatus::Healthy) => "healthy", + Ok(ServiceStatus::Degraded) => "degraded", + Ok(ServiceStatus::Unhealthy) => "unhealthy", + Ok(ServiceStatus::Unspecified) | Err(_) => "unknown", + } +} + +/// Show elevated gateway runtime information. +pub async fn gateway_info( + gateway_name: &str, + server: &str, + tls: &TlsOptions, + output: &str, +) -> Result<()> { + let mut client = grpc_client(server, tls).await?; + let info = client + .get_gateway_info(GetGatewayInfoRequest {}) + .await + .map_err(|err| match err.code() { + Code::Unimplemented => { + miette!("gateway info is not supported by this gateway version") + } + Code::PermissionDenied => miette!("gateway info requires admin privileges: {err}"), + _ => miette!("get_gateway_info failed: {err}"), + })? + .into_inner(); + + let view = GatewayInfoView { + gateway: gateway_name.to_string(), + server: server.to_string(), + auth: tls.is_bearer_auth().then_some("bearer"), + status: gateway_service_status_name(info.status).to_string(), + version: info.gateway_version, + compute_drivers: info + .compute_drivers + .into_iter() + .map(|driver| { + let capabilities = driver.capabilities.unwrap_or_default(); + ComputeDriverInfoView { + name: driver.name, + capabilities: ComputeDriverCapabilitiesView { + driver_name: capabilities.driver_name, + driver_version: capabilities.driver_version, + }, + } + }) + .collect(), + }; + + print_gateway_info(&view, output) +} + +pub fn gateway_info_not_configured() -> Result<()> { + Err(miette!( + "No gateway configured.\nRegister a gateway with: openshell gateway add " + )) +} + +fn print_gateway_info(view: &GatewayInfoView, output: &str) -> Result<()> { + if crate::output::print_output_single(output, view, gateway_info_to_json)? { + return Ok(()); + } + + println!("{}", "Gateway Info".cyan().bold()); + println!(); + println!(" {} {}", "Gateway:".dimmed(), view.gateway); + println!(" {} {}", "Server:".dimmed(), view.server); + if view.auth.is_some() { + println!(" {} Edge (bearer token)", "Auth:".dimmed()); + } + println!(" {} {}", "Status:".dimmed(), view.status); + println!(" {} {}", "Version:".dimmed(), view.version); + print_compute_driver_info(&view.compute_drivers); + + Ok(()) +} + +fn print_compute_driver_info(drivers: &[ComputeDriverInfoView]) { + if drivers.is_empty() { + return; + } + + println!(" {}", "Compute drivers:".dimmed()); + for driver in drivers { + println!(" {}", driver.name); + if driver.capabilities.driver_name != driver.name { + println!( + " {} {}", + "Driver name:".dimmed(), + driver.capabilities.driver_name + ); + } + println!( + " {} {}", + "Driver version:".dimmed(), + driver.capabilities.driver_version + ); + } +} + +fn gateway_info_to_json(view: &GatewayInfoView) -> serde_json::Value { + serde_json::json!({ + "gateway": &view.gateway, + "server": &view.server, + "auth": view.auth, + "status": &view.status, + "version": &view.version, + "compute_drivers": view + .compute_drivers + .iter() + .map(|driver| serde_json::json!({ + "name": &driver.name, + "capabilities": { + "driver_name": &driver.capabilities.driver_name, + "driver_version": &driver.capabilities.driver_version, + }, + })) + .collect::>(), + }) +} + /// Set the active gateway. pub fn gateway_use(name: &str) -> Result<()> { // Verify the gateway exists @@ -1356,31 +1502,73 @@ pub fn gateway_list(gateway_flag: &Option, output: &str) -> Result<()> { .max() .unwrap_or(6) .max(6); + let auth_width = gateways + .iter() + .map(|g| gateway_auth_label(&g.metadata).len()) + .max() + .unwrap_or(4) + .max(4); + let remote_labels: Vec> = gateways + .iter() + .map(|g| gateway_remote_label(&g.metadata)) + .collect(); + let show_remote = remote_labels.iter().any(Option::is_some); + let remote_width = remote_labels + .iter() + .filter_map(|label| label.as_ref().map(String::len)) + .max() + .unwrap_or(6) + .max(6); // Print header - println!( - " {:) -> serde_js "source": gateway.source.label(), "auth": gateway_auth_label(metadata), "active": active.as_deref() == Some(&metadata.name), + "is_remote": metadata.is_remote, + "remote_host": &metadata.remote_host, + "resolved_host": &metadata.resolved_host, }) } +fn gateway_remote_label(gateway: &GatewayMetadata) -> Option { + match (&gateway.remote_host, &gateway.resolved_host) { + (Some(remote), Some(resolved)) if remote != resolved => { + Some(format!("{remote} -> {resolved}")) + } + (Some(remote), _) => Some(remote.clone()), + (None, Some(resolved)) => Some(resolved.clone()), + (None, None) => None, + } +} + async fn http_health_check(server: &str, tls: &TlsOptions) -> Result> { let base = server.trim_end_matches('/'); let uri: hyper::Uri = format!("{base}/healthz").parse().into_diagnostic()?; @@ -1522,38 +1724,6 @@ pub fn gateway_remove(name: &str) -> Result<()> { Ok(()) } -/// Show gateway registration details. -pub fn gateway_admin_info(name: &str) -> Result<()> { - let metadata = get_gateway_metadata(name).ok_or_else(|| { - miette::miette!( - "No gateway metadata found for '{name}'.\n\ - Register it first: openshell gateway add --name {name}" - ) - })?; - - println!("{}", "Gateway Info".cyan().bold()); - println!(); - println!(" {} {}", "Gateway:".dimmed(), metadata.name); - println!( - " {} {}", - "Gateway endpoint:".dimmed(), - metadata.gateway_endpoint - ); - - if metadata.is_remote { - if let Some(ref host) = metadata.remote_host { - println!(" {} {host}", "Remote host:".dimmed()); - } else { - println!(" {} External registration", "Type:".dimmed()); - } - if let Some(ref resolved) = metadata.resolved_host { - println!(" {} {resolved}", "Resolved host:".dimmed()); - } - } - - Ok(()) -} - /// Validate system prerequisites for running a gateway. /// /// Checks Docker connectivity and reports the result. Returns exit code 0 @@ -7887,11 +8057,13 @@ fn format_timestamp_ms(ms: i64) -> String { #[cfg(test)] mod tests { use super::{ - PolicyGetView, ProvisioningStep, TlsOptions, build_sandbox_resource_limits, + ComputeDriverCapabilitiesView, ComputeDriverInfoView, GatewayInfoView, PolicyGetView, + ProvisioningStep, TlsOptions, build_sandbox_resource_limits, dockerfile_sources_supported_for_gateway, format_endpoint, format_gateway_select_header, format_gateway_select_items, format_provider_attachment_table, gateway_add, - gateway_auth_label, gateway_env_override_warning, gateway_select_with, gateway_to_json, - gateway_type_label, git_sync_files, http_health_check, import_local_package_mtls_bundle, + gateway_auth_label, gateway_env_override_warning, gateway_info_to_json, + gateway_remote_label, gateway_select_with, gateway_to_json, gateway_type_label, + git_sync_files, http_health_check, import_local_package_mtls_bundle, inferred_provider_type, mtls_certs_exist_for_gateway, package_managed_tls_dirs, parse_cli_setting_value, parse_credential_expiry_cli_value, parse_credential_expiry_pairs, parse_credential_pairs, parse_driver_config_json, parse_secret_material_env_pairs, @@ -9035,6 +9207,89 @@ mod tests { assert_eq!(json["active"], true); } + #[test] + fn gateway_to_json_includes_remote_registration_details() { + let gateway = ListedGateway { + metadata: GatewayMetadata { + name: "remote-vm".to_string(), + gateway_endpoint: "https://127.0.0.1:17670".to_string(), + is_remote: true, + remote_host: Some("user@gateway-alias".to_string()), + resolved_host: Some("10.0.0.5".to_string()), + auth_mode: Some("mtls".to_string()), + ..Default::default() + }, + source: GatewayMetadataSource::User, + }; + + let json = gateway_to_json(&gateway, &Some("local-vm".to_string())); + + assert_eq!(json["source"], "user"); + assert_eq!(json["type"], "remote"); + assert_eq!(json["auth"], "mtls"); + assert_eq!(json["active"], false); + assert_eq!(json["is_remote"], true); + assert_eq!(json["remote_host"], "user@gateway-alias"); + assert_eq!(json["resolved_host"], "10.0.0.5"); + assert_eq!( + gateway_remote_label(&gateway.metadata).as_deref(), + Some("user@gateway-alias -> 10.0.0.5") + ); + } + + #[test] + fn gateway_info_json_includes_compute_drivers_when_available() { + let view = GatewayInfoView { + gateway: "openshell".to_string(), + server: "https://127.0.0.1:17670".to_string(), + auth: Some("bearer"), + status: "healthy".to_string(), + version: "0.0.75".to_string(), + compute_drivers: vec![ComputeDriverInfoView { + name: "podman".to_string(), + capabilities: ComputeDriverCapabilitiesView { + driver_name: "podman".to_string(), + driver_version: "0.0.75".to_string(), + }, + }], + }; + + let json = gateway_info_to_json(&view); + + assert_eq!(json["gateway"], "openshell"); + assert_eq!(json["status"], "healthy"); + assert_eq!(json["version"], "0.0.75"); + assert_eq!(json["compute_drivers"][0]["name"], "podman"); + assert_eq!( + json["compute_drivers"][0]["capabilities"]["driver_name"], + "podman" + ); + assert_eq!( + json["compute_drivers"][0]["capabilities"]["driver_version"], + "0.0.75" + ); + } + + #[test] + fn gateway_info_json_includes_empty_compute_driver_list() { + let view = GatewayInfoView { + gateway: "openshell".to_string(), + server: "https://127.0.0.1:17670".to_string(), + auth: None, + status: "healthy".to_string(), + version: "0.0.74".to_string(), + compute_drivers: Vec::new(), + }; + + let json = gateway_info_to_json(&view); + + assert!( + json["compute_drivers"] + .as_array() + .is_some_and(Vec::is_empty) + ); + } + #[test] fn gateway_auth_label_defaults_https_gateways_to_mtls() { let gateway = GatewayMetadata { diff --git a/crates/openshell-cli/tests/ensure_providers_integration.rs b/crates/openshell-cli/tests/ensure_providers_integration.rs index 24ab5e4bb7..7f9c59651a 100644 --- a/crates/openshell-cli/tests/ensure_providers_integration.rs +++ b/crates/openshell-cli/tests/ensure_providers_integration.rs @@ -86,6 +86,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, _request: tonic::Request, diff --git a/crates/openshell-cli/tests/mtls_integration.rs b/crates/openshell-cli/tests/mtls_integration.rs index 3f51dd6044..58adf86082 100644 --- a/crates/openshell-cli/tests/mtls_integration.rs +++ b/crates/openshell-cli/tests/mtls_integration.rs @@ -43,6 +43,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, _request: tonic::Request, diff --git a/crates/openshell-cli/tests/provider_commands_integration.rs b/crates/openshell-cli/tests/provider_commands_integration.rs index d75fe26e20..4a55951e19 100644 --- a/crates/openshell-cli/tests/provider_commands_integration.rs +++ b/crates/openshell-cli/tests/provider_commands_integration.rs @@ -108,6 +108,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, _request: tonic::Request, diff --git a/crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs b/crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs index 3dec8943f3..354b5159f0 100644 --- a/crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs +++ b/crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs @@ -67,6 +67,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, request: tonic::Request, diff --git a/crates/openshell-cli/tests/sandbox_name_fallback_integration.rs b/crates/openshell-cli/tests/sandbox_name_fallback_integration.rs index d8f8e695f2..7fe3c5dc59 100644 --- a/crates/openshell-cli/tests/sandbox_name_fallback_integration.rs +++ b/crates/openshell-cli/tests/sandbox_name_fallback_integration.rs @@ -58,6 +58,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, _request: tonic::Request, diff --git a/crates/openshell-sdk/tests/client_mock.rs b/crates/openshell-sdk/tests/client_mock.rs index d53873f825..544c5a9b29 100644 --- a/crates/openshell-sdk/tests/client_mock.rs +++ b/crates/openshell-sdk/tests/client_mock.rs @@ -87,6 +87,17 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _: tonic::Request, + ) -> Result, Status> { + Ok(Response::new(proto::GetGatewayInfoResponse { + status: proto::ServiceStatus::Healthy.into(), + gateway_version: "test-1.2.3".to_string(), + compute_drivers: Vec::new(), + })) + } + async fn update_provider_profiles( &self, _: tonic::Request, diff --git a/crates/openshell-server/src/compute/mod.rs b/crates/openshell-server/src/compute/mod.rs index 683ef8e872..a0dd3e37fe 100644 --- a/crates/openshell-server/src/compute/mod.rs +++ b/crates/openshell-server/src/compute/mod.rs @@ -60,6 +60,16 @@ type SharedComputeDriver = const DELETE_PHASE_CAS_RETRY_LIMIT: usize = 3; +#[derive(Debug, Clone)] +pub struct ComputeDriverInfoSnapshot { + /// Gateway-selected driver name used for routing and `driver_config` keys. + pub name: String, + /// Driver-reported human-readable name from the startup capability snapshot. + pub driver_name: String, + /// Driver-reported implementation version from the startup capability snapshot. + pub driver_version: String, +} + #[tonic::async_trait] trait ShutdownCleanup: Send + Sync { async fn cleanup_on_shutdown(&self) -> Result<(), String>; @@ -259,7 +269,7 @@ impl ComputeDriver for RemoteComputeDriver { #[derive(Clone)] pub struct ComputeRuntime { driver: SharedComputeDriver, - driver_name: String, + driver_info: ComputeDriverInfoSnapshot, shutdown_cleanup: Option>, startup_resume: Option>, _driver_process: Option>, @@ -307,10 +317,15 @@ impl ComputeRuntime { in_tree = driver_kind.is_some(), "Compute driver connected" ); + let driver_info = ComputeDriverInfoSnapshot { + name: driver_name, + driver_name: capabilities.driver_name, + driver_version: capabilities.driver_version, + }; let default_image = capabilities.default_image; Ok(Self { driver, - driver_name, + driver_info, shutdown_cleanup, startup_resume, _driver_process: driver_process, @@ -456,9 +471,14 @@ impl ComputeRuntime { &self.default_image } + #[must_use] + pub fn driver_info_snapshots(&self) -> &[ComputeDriverInfoSnapshot] { + std::slice::from_ref(&self.driver_info) + } + #[must_use] pub fn driver_kind(&self) -> Option { - self.driver_name.parse().ok() + self.driver_info.name.parse().ok() } #[must_use] @@ -467,8 +487,8 @@ impl ComputeRuntime { } pub async fn validate_sandbox_create(&self, sandbox: &Sandbox) -> Result<(), Status> { - let driver_sandbox = - driver_sandbox_from_public(sandbox, &self.driver_name).map_err(|status| *status)?; + let driver_sandbox = driver_sandbox_from_public(sandbox, &self.driver_info.name) + .map_err(|status| *status)?; self.driver .validate_sandbox_create(Request::new(ValidateSandboxCreateRequest { sandbox: Some(driver_sandbox), @@ -483,8 +503,8 @@ impl ComputeRuntime { sandbox_token: Option, ) -> Result { let sandbox_id = sandbox.object_id().to_string(); - let mut driver_sandbox = - driver_sandbox_from_public(&sandbox, &self.driver_name).map_err(|status| *status)?; + let mut driver_sandbox = driver_sandbox_from_public(&sandbox, &self.driver_info.name) + .map_err(|status| *status)?; // Create with MustCreate condition to prevent duplicate creation race self.sandbox_index.update_from_sandbox(&sandbox); @@ -2097,7 +2117,11 @@ impl ComputeDriver for NoopTestDriver { pub async fn new_test_runtime(store: Arc) -> ComputeRuntime { ComputeRuntime { driver: Arc::new(NoopTestDriver), - driver_name: "test".to_string(), + driver_info: ComputeDriverInfoSnapshot { + name: "test".to_string(), + driver_name: "test".to_string(), + driver_version: "test".to_string(), + }, shutdown_cleanup: None, startup_resume: None, _driver_process: None, @@ -2352,7 +2376,11 @@ mod tests { let store = Arc::new(Store::connect("sqlite::memory:").await.unwrap()); ComputeRuntime { driver, - driver_name: "test-driver".to_string(), + driver_info: ComputeDriverInfoSnapshot { + name: "test-driver".to_string(), + driver_name: "test-driver".to_string(), + driver_version: "test".to_string(), + }, shutdown_cleanup: None, startup_resume, _driver_process: None, diff --git a/crates/openshell-server/src/grpc/mod.rs b/crates/openshell-server/src/grpc/mod.rs index a71274e2d0..36f3e64cbb 100644 --- a/crates/openshell-server/src/grpc/mod.rs +++ b/crates/openshell-server/src/grpc/mod.rs @@ -13,18 +13,19 @@ mod validation; use openshell_core::proto::{ ApproveAllDraftChunksRequest, ApproveAllDraftChunksResponse, ApproveDraftChunkRequest, ApproveDraftChunkResponse, AttachSandboxProviderRequest, AttachSandboxProviderResponse, - ClearDraftChunksRequest, ClearDraftChunksResponse, ConfigureProviderRefreshRequest, - ConfigureProviderRefreshResponse, CreateProviderRequest, CreateSandboxRequest, - CreateSshSessionRequest, CreateSshSessionResponse, DeleteProviderProfileRequest, - DeleteProviderProfileResponse, DeleteProviderRefreshRequest, DeleteProviderRefreshResponse, - DeleteProviderRequest, DeleteProviderResponse, DeleteSandboxRequest, DeleteSandboxResponse, - DeleteServiceRequest, DeleteServiceResponse, DetachSandboxProviderRequest, - DetachSandboxProviderResponse, EditDraftChunkRequest, EditDraftChunkResponse, ExecSandboxEvent, - ExecSandboxInput, ExecSandboxRequest, ExposeServiceRequest, GatewayMessage, - GetDraftHistoryRequest, GetDraftHistoryResponse, GetDraftPolicyRequest, GetDraftPolicyResponse, - GetGatewayConfigRequest, GetGatewayConfigResponse, GetProviderProfileRequest, - GetProviderRefreshStatusRequest, GetProviderRefreshStatusResponse, GetProviderRequest, - GetSandboxConfigRequest, GetSandboxConfigResponse, GetSandboxLogsRequest, + ClearDraftChunksRequest, ClearDraftChunksResponse, ComputeDriverCapabilities, + ComputeDriverInfo, ConfigureProviderRefreshRequest, ConfigureProviderRefreshResponse, + CreateProviderRequest, CreateSandboxRequest, CreateSshSessionRequest, CreateSshSessionResponse, + DeleteProviderProfileRequest, DeleteProviderProfileResponse, DeleteProviderRefreshRequest, + DeleteProviderRefreshResponse, DeleteProviderRequest, DeleteProviderResponse, + DeleteSandboxRequest, DeleteSandboxResponse, DeleteServiceRequest, DeleteServiceResponse, + DetachSandboxProviderRequest, DetachSandboxProviderResponse, EditDraftChunkRequest, + EditDraftChunkResponse, ExecSandboxEvent, ExecSandboxInput, ExecSandboxRequest, + ExposeServiceRequest, GatewayMessage, GetDraftHistoryRequest, GetDraftHistoryResponse, + GetDraftPolicyRequest, GetDraftPolicyResponse, GetGatewayConfigRequest, + GetGatewayConfigResponse, GetGatewayInfoRequest, GetGatewayInfoResponse, + GetProviderProfileRequest, GetProviderRefreshStatusRequest, GetProviderRefreshStatusResponse, + GetProviderRequest, GetSandboxConfigRequest, GetSandboxConfigResponse, GetSandboxLogsRequest, GetSandboxLogsResponse, GetSandboxPolicyStatusRequest, GetSandboxPolicyStatusResponse, GetSandboxProviderEnvironmentRequest, GetSandboxProviderEnvironmentResponse, GetSandboxRequest, GetServiceRequest, HealthRequest, HealthResponse, ImportProviderProfilesRequest, @@ -206,6 +207,32 @@ impl OpenShell for OpenShellService { })) } + #[rpc_auth(auth = "bearer", scope = "config:read", role = "admin")] + async fn get_gateway_info( + &self, + _request: Request, + ) -> Result, Status> { + let compute_drivers = self + .state + .compute + .driver_info_snapshots() + .iter() + .map(|driver| ComputeDriverInfo { + name: driver.name.clone(), + capabilities: Some(ComputeDriverCapabilities { + driver_name: driver.driver_name.clone(), + driver_version: driver.driver_version.clone(), + }), + }) + .collect(); + + Ok(Response::new(GetGatewayInfoResponse { + status: ServiceStatus::Healthy.into(), + gateway_version: openshell_core::VERSION.to_string(), + compute_drivers, + })) + } + // --- Sandbox lifecycle --- #[rpc_auth(auth = "bearer", scope = "sandbox:write", role = "user")] diff --git a/crates/openshell-server/tests/common/mod.rs b/crates/openshell-server/tests/common/mod.rs index 3934c8af42..a5bfa1057e 100644 --- a/crates/openshell-server/tests/common/mod.rs +++ b/crates/openshell-server/tests/common/mod.rs @@ -62,6 +62,13 @@ impl OpenShell for TestOpenShell { })) } + async fn get_gateway_info( + &self, + _request: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } + async fn create_sandbox( &self, _request: tonic::Request, diff --git a/crates/openshell-server/tests/supervisor_relay_integration.rs b/crates/openshell-server/tests/supervisor_relay_integration.rs index bd94d151e5..98c5d99f55 100644 --- a/crates/openshell-server/tests/supervisor_relay_integration.rs +++ b/crates/openshell-server/tests/supervisor_relay_integration.rs @@ -111,6 +111,12 @@ impl OpenShell for RelayGateway { ) -> Result, Status> { Err(Status::unimplemented("unused")) } + async fn get_gateway_info( + &self, + _: tonic::Request, + ) -> Result, Status> { + Err(Status::unimplemented("unused")) + } async fn create_sandbox( &self, _: tonic::Request, diff --git a/docs/sandboxes/manage-gateways.mdx b/docs/sandboxes/manage-gateways.mdx index ce4496e8d2..443a65a750 100644 --- a/docs/sandboxes/manage-gateways.mdx +++ b/docs/sandboxes/manage-gateways.mdx @@ -84,12 +84,21 @@ The active gateway is the persisted default. The `-g` flag and the `OPENSHELL_GA Installers can seed read-only gateway entries for package-managed local services. By default the CLI reads these from `/etc/openshell`, using the same `active_gateway` plus `gateways//metadata.json` layout as per-user config. Packages can override that system config root with a non-empty absolute `OPENSHELL_SYSTEM_GATEWAY_DIR` when needed; empty or relative values fall back to `/etc/openshell` and log a warning. These entries appear in `openshell gateway list` and can be selected like user registrations. `openshell gateway list` and `openshell term` label each gateway as `user` or `system` so you can see which config layer owns it. `openshell gateway remove` removes only per-user registrations. Register a per-user gateway with the same name when you need to shadow an installer-provided default. -List all registered gateways: +List all registered gateways. The table shows each gateway's endpoint, type, +config source, authentication mode, and remote target when a remote registration +has one: ```shell openshell gateway list ``` +Use structured output when you need the complete local registration metadata, +including `remote_host` and `resolved_host` for remote registrations: + +```shell +openshell gateway list -o json +``` + Switch the active gateway: ```shell @@ -104,17 +113,24 @@ openshell status -g staging ## Inspect Gateway Status -Use `openshell status` for a quick health check: +Use `openshell status` for a live gateway check. It verifies that the CLI can +reach the running gateway, then reports health and the gateway version: ```shell openshell status ``` -Use `openshell gateway info` when you need the registered endpoint, gateway metadata, or compute driver details: +Use `openshell gateway info` when you need elevated runtime details such as +initialized compute drivers and driver-reported capability versions: ```shell openshell gateway info -openshell gateway info --name production +``` + +Use structured output when scripting against live runtime info: + +```shell +openshell gateway info -o json ``` Remove a local CLI registration without stopping the gateway service: @@ -136,7 +152,7 @@ For Docker-backed local gateways, inspect Docker and the gateway process or cont ```shell openshell doctor check -openshell gateway info +openshell gateway list ``` For Kubernetes gateways, inspect the gateway workload and cluster events: diff --git a/proto/openshell.proto b/proto/openshell.proto index 776ae66ca6..b437613b04 100644 --- a/proto/openshell.proto +++ b/proto/openshell.proto @@ -22,6 +22,9 @@ service OpenShell { // Check the health of the service. rpc Health(HealthRequest) returns (HealthResponse); + // Fetch elevated live gateway runtime metadata. + rpc GetGatewayInfo(GetGatewayInfoRequest) returns (GetGatewayInfoResponse); + // Create a new sandbox. rpc CreateSandbox(CreateSandboxRequest) returns (SandboxResponse); @@ -290,6 +293,40 @@ message HealthResponse { string version = 2; } +// Gateway info request. +message GetGatewayInfoRequest {} + +// Gateway info response. +message GetGatewayInfoResponse { + // Service status. + ServiceStatus status = 1; + + // OpenShell gateway binary version. + string gateway_version = 2; + + // Compute driver runtimes initialized by this gateway. Current gateways + // return exactly one entry. + repeated ComputeDriverInfo compute_drivers = 3; +} + +// Info for one initialized compute driver runtime. +message ComputeDriverInfo { + // Gateway-selected driver name used for routing and driver_config keys. + string name = 1; + + // Capabilities reported by the driver during gateway runtime initialization. + ComputeDriverCapabilities capabilities = 2; +} + +// Public compute driver capability snapshot. +message ComputeDriverCapabilities { + // Driver-reported human-readable name from the startup capability snapshot. + string driver_name = 1; + + // Driver-reported implementation version from the startup capability snapshot. + string driver_version = 2; +} + // Public sandbox resource exposed by the OpenShell API. // // This is the canonical gateway-owned view of a sandbox. It merges user intent From 3dee5570a46076a57a3b056f35f35ebc0861ac85 Mon Sep 17 00:00:00 2001 From: Piotr Mlocek Date: Wed, 15 Jul 2026 16:24:54 -0700 Subject: [PATCH 3/3] fix(ci): prune snap assets from dev release (#2302) Signed-off-by: Piotr Mlocek --- .github/workflows/release-dev.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-dev.yml b/.github/workflows/release-dev.yml index 20d4f0a0c8..222ba7a8f0 100644 --- a/.github/workflows/release-dev.yml +++ b/.github/workflows/release-dev.yml @@ -935,7 +935,7 @@ jobs: release = await github.rest.repos.getReleaseByTag({ owner, repo, tag: 'dev' }); } catch (err) { if (err.status === 404) { - core.info('No existing dev release found; skipping wheel pruning.'); + core.info('No existing dev release found; skipping managed asset pruning.'); return; } throw err; @@ -954,7 +954,8 @@ jobs: name.endsWith('.txt') || name.endsWith('.whl') || name.endsWith('.deb') || - name.endsWith('.rpm') + name.endsWith('.rpm') || + name.endsWith('.snap') ) );