diff --git a/CLAUDE.md b/CLAUDE.md index 03f58694..564d3e50 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -51,7 +51,7 @@ Each command directory has its own `CLAUDE.md` (domain knowledge) and `README.md | `cmd/settings/` | CLAUDE.md, README.md | CLI settings management | | `cmd/objectstorage/` | CLAUDE.md, README.md | S3-style object storage: configure, mb/rb, cp/mv/sync/ls/rm, uploads, presign | | `cmd/network/` | CLAUDE.md, README.md | Private networks (beta): list, create, delete; subnet list, create, delete | -| `cmd/serverless/` | CLAUDE.md, README.md | Serverless containers (beta: create, list, describe, scale, replicas, pause/resume/restart, purge-queue, delete) and batch jobs (hidden, gated by `VERDA_BATCHJOB_ENABLED`) | +| `cmd/serverless/` | CLAUDE.md, README.md | Serverless containers (`verda container`: create, update, list, describe, scale, replicas, pause/resume/restart, purge-queue, delete, env, secret, file-secret, registry-creds) and batch jobs (`verda batchjob`: create, update, list, describe, delete, pause/resume, purge-queue) | | `cmd/doctor/` | — | Environment diagnostics | | `cmd/availability/` | — | Instance availability by location | | `cmd/cost/` | — | Balance, running costs, estimates | diff --git a/internal/verda-cli/cmd/cmd.go b/internal/verda-cli/cmd/cmd.go index 57dc728c..7228b095 100644 --- a/internal/verda-cli/cmd/cmd.go +++ b/internal/verda-cli/cmd/cmd.go @@ -17,7 +17,6 @@ package cmd import ( "errors" "fmt" - "os" "runtime/debug" "github.com/spf13/cobra" @@ -160,14 +159,13 @@ func NewRootCommand(ioStreams cmdutil.IOStreams) (*cobra.Command, *clioptions.Op }, }, } - serverlessCmds := []*cobra.Command{serverless.NewCmdContainer(f, ioStreams)} - if batchjobEnabled() { - serverlessCmds = append(serverlessCmds, serverless.NewCmdBatchjob(f, ioStreams)) - } groups = append(groups, cmdutil.CommandGroup{ - Message: "Serverless Commands:", - Commands: serverlessCmds, + Message: "Serverless Commands:", + Commands: []*cobra.Command{ + serverless.NewCmdContainer(f, ioStreams), + serverless.NewCmdBatchjob(f, ioStreams), + }, }, cmdutil.CommandGroup{ Message: "Resource Commands:", @@ -205,15 +203,6 @@ func NewRootCommand(ioStreams cmdutil.IOStreams) (*cobra.Command, *clioptions.Op return cmd, opts } -// batchjobEnabled gates the pre-release batchjob subtree behind -// VERDA_BATCHJOB_ENABLED=1/true. Without it `verda batchjob` returns "unknown -// command". The parent command also sets Hidden so it stays out of -// `verda --help` even when a tester flips the env var on. -func batchjobEnabled() bool { - v := os.Getenv("VERDA_BATCHJOB_ENABLED") - return v == "1" || v == "true" -} - // skipCredentialResolution returns true for commands that should work // without valid credentials (diagnostics, profile switching, etc.). func skipCredentialResolution(cmd *cobra.Command) bool { diff --git a/internal/verda-cli/cmd/cmd_test.go b/internal/verda-cli/cmd/cmd_test.go index 4ed71726..de06e489 100644 --- a/internal/verda-cli/cmd/cmd_test.go +++ b/internal/verda-cli/cmd/cmd_test.go @@ -69,31 +69,18 @@ func TestShouldCheckVersion(t *testing.T) { } } -// container is always registered (beta); batchjob only with VERDA_BATCHJOB_ENABLED. +// Both serverless trees are GA: registered unconditionally and visible in `verda --help`. func TestServerlessCommandRegistration(t *testing.T) { - for _, tc := range []struct { - env string - batchjob bool - }{ - {"", false}, - {"1", true}, - {"true", true}, - {"0", false}, - } { - t.Run("VERDA_BATCHJOB_ENABLED="+tc.env, func(t *testing.T) { - t.Setenv("VERDA_HOME", t.TempDir()) - t.Setenv("VERDA_BATCHJOB_ENABLED", tc.env) - root, _ := NewRootCommand(cmdutil.IOStreams{In: &bytes.Buffer{}, Out: &bytes.Buffer{}, ErrOut: &bytes.Buffer{}}) - found := map[string]*cobra.Command{} - for _, c := range root.Commands() { - found[c.Name()] = c - } - if c := found["container"]; c == nil || c.Hidden { - t.Errorf("container: registered=%v, want registered and not hidden", c != nil) - } - if _, ok := found["batchjob"]; ok != tc.batchjob { - t.Errorf("batchjob registered = %v, want %v", ok, tc.batchjob) - } - }) + t.Setenv("VERDA_HOME", t.TempDir()) + root, _ := NewRootCommand(cmdutil.IOStreams{In: &bytes.Buffer{}, Out: &bytes.Buffer{}, ErrOut: &bytes.Buffer{}}) + found := map[string]*cobra.Command{} + for _, c := range root.Commands() { + found[c.Name()] = c + } + for _, name := range []string{"container", "batchjob"} { + c := found[name] + if c == nil || c.Hidden { + t.Errorf("%s: registered=%v, want registered and not hidden", name, c != nil) + } } } diff --git a/internal/verda-cli/cmd/serverless/CLAUDE.md b/internal/verda-cli/cmd/serverless/CLAUDE.md index 5f034006..b818b96a 100644 --- a/internal/verda-cli/cmd/serverless/CLAUDE.md +++ b/internal/verda-cli/cmd/serverless/CLAUDE.md @@ -27,7 +27,7 @@ This rule applies equally to Claude, Codex, Cursor, or a human editing the packa - There is **no** `verda serverless` parent command — the two trees were promoted to root for shorter invocations. They still share this Go package because they share wizard step factories, validators, and the API cache. - Verbs (both trees): `create`, `update`, `list` (alias `ls`), `describe` (aliases `get`, `show`), `delete` (aliases `rm`, `del`), `pause`, `resume`, `purge-queue`. Container also has `restart`, `scale` and `replicas`. - Files: - - `container.go`, `batchjob.go` — Top-level command builders. `NewCmdContainer` and `NewCmdBatchjob` are exported and called directly from `cmd/cmd.go`. **`container` is beta:** always registered, `cmdutil.TagAnnotation: "beta"`. **`batchjob` is two-layer gated:** registered only when `VERDA_BATCHJOB_ENABLED=1` (`batchjobEnabled()` in `cmd/cmd.go`), and `Hidden: true`. Drop both gates when batchjob ships. `gate_test.go` and `cmd/cmd_test.go` guard this. + - `container.go`, `batchjob.go` — Top-level command builders. `NewCmdContainer` and `NewCmdBatchjob` are exported and called directly from `cmd/cmd.go`. Both are GA: registered unconditionally, visible, no `cmdutil.TagAnnotation`. `visibility_test.go` and `cmd/cmd_test.go` guard this (the former `VERDA_BATCHJOB_ENABLED` gate and `(beta)` tag are gone). - `container_create.go` — `containerCreateOptions`, flags, `request()`, validate(), wizard entry point. - `container_update.go` — `containerUpdateOptions`, fetch-merge-PATCH flow. Fetches current deployment + scaling (separate call), overlays only Changed() flags, sends single PATCH. Splits summary rendering and scaling merge into helpers for gocyclo compliance. - `container_list.go` — `GetDeployments` + tabwriter + structured output. diff --git a/internal/verda-cli/cmd/serverless/README.md b/internal/verda-cli/cmd/serverless/README.md index 3de6f1dc..80199ac9 100644 --- a/internal/verda-cli/cmd/serverless/README.md +++ b/internal/verda-cli/cmd/serverless/README.md @@ -7,8 +7,6 @@ verda container # → /container-deployments (continuous; supports spot) verda batchjob # → /job-deployments (one-shot; deadline-based; no spot) ``` -`verda container` is a beta: it shows in `verda --help` as `(beta)`. `verda batchjob` is pre-release: it is registered only with `VERDA_BATCHJOB_ENABLED=1` and stays hidden from `verda --help`. - Both command trees live in the `serverless` Go package (they share wizard step factories, validators, and the API cache), but are registered as top-level commands so users type `verda container ...` rather than `verda serverless container ...`. ## Container deployments diff --git a/internal/verda-cli/cmd/serverless/batchjob.go b/internal/verda-cli/cmd/serverless/batchjob.go index fef8c389..b8cddf83 100644 --- a/internal/verda-cli/cmd/serverless/batchjob.go +++ b/internal/verda-cli/cmd/serverless/batchjob.go @@ -25,10 +25,6 @@ func NewCmdBatchjob(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Comma cmd := &cobra.Command{ Use: "batchjob", Short: "Manage serverless batch-job deployments (one-shot runs)", - // Pre-release: cmd/cmd.go (batchjobEnabled) registers it only with - // VERDA_BATCHJOB_ENABLED; Hidden keeps it out of `verda --help` even - // then. Drop both when batchjob ships. - Hidden: true, Long: cmdutil.LongDesc(` Create and manage one-shot batch-job deployments. Jobs accept queued requests, run each to completion within a deadline, and scale the diff --git a/internal/verda-cli/cmd/serverless/container.go b/internal/verda-cli/cmd/serverless/container.go index 54e225a8..6e57d00d 100644 --- a/internal/verda-cli/cmd/serverless/container.go +++ b/internal/verda-cli/cmd/serverless/container.go @@ -23,9 +23,8 @@ import ( // NewCmdContainer creates the top-level `verda container` command tree. func NewCmdContainer(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ - Use: "container", - Short: "Manage serverless container deployments (always-on endpoints)", - Annotations: map[string]string{cmdutil.TagAnnotation: "beta"}, + Use: "container", + Short: "Manage serverless container deployments (always-on endpoints)", Long: cmdutil.LongDesc(` Create and manage always-on serverless container deployments. Each deployment exposes an HTTPS endpoint that auto-scales based on queue diff --git a/internal/verda-cli/cmd/serverless/gate_test.go b/internal/verda-cli/cmd/serverless/visibility_test.go similarity index 60% rename from internal/verda-cli/cmd/serverless/gate_test.go rename to internal/verda-cli/cmd/serverless/visibility_test.go index 5c1c8a7e..0fae9a77 100644 --- a/internal/verda-cli/cmd/serverless/gate_test.go +++ b/internal/verda-cli/cmd/serverless/visibility_test.go @@ -18,23 +18,26 @@ import ( "bytes" "testing" + "github.com/spf13/cobra" + cmdutil "github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/util" ) -// container is a visible beta; batchjob stays Hidden (and env-gated in -// cmd/cmd.go) until it ships. -func TestServerlessGate(t *testing.T) { +// Both trees are GA: visible, untagged. A reintroduced Hidden or "beta" tag +// would silently drop them from `verda --help` and the generated docs. +func TestServerlessCommandsVisible(t *testing.T) { f := cmdutil.NewTestFactory(nil) streams := cmdutil.IOStreams{Out: &bytes.Buffer{}, ErrOut: &bytes.Buffer{}} - c := NewCmdContainer(f, streams) - if c.Hidden { - t.Errorf("container command should be visible") - } - if got := c.Annotations[cmdutil.TagAnnotation]; got != "beta" { - t.Errorf("container tag = %q, want beta", got) - } - if c := NewCmdBatchjob(f, streams); !c.Hidden { - t.Errorf("batchjob command should stay Hidden") + for name, c := range map[string]*cobra.Command{ + "container": NewCmdContainer(f, streams), + "batchjob": NewCmdBatchjob(f, streams), + } { + if c.Hidden { + t.Errorf("%s command should be visible", name) + } + if tag := c.Annotations[cmdutil.TagAnnotation]; tag != "" { + t.Errorf("%s tag = %q, want none", name, tag) + } } } diff --git a/test/test_serverless_features.sh b/test/test_serverless_features.sh new file mode 100755 index 00000000..f59f6327 --- /dev/null +++ b/test/test_serverless_features.sh @@ -0,0 +1,229 @@ +#!/usr/bin/env bash +# Manual end-to-end smoke test of `verda container` and `verda batchjob` +# against a real API. Not run by CI: it creates and deletes billable +# deployments, and several steps are interactive. +# +# make build +# ./test/test_serverless_features.sh # pause after every step +# PAUSE=0 ./test/test_serverless_features.sh # run straight through +# INTERACTIVE=1 ./test/test_serverless_features.sh # also drive wizards/confirm prompts +# KEEP_HOME=1 ./test/test_serverless_features.sh # keep the throwaway VERDA_HOME +# +# VERDA_HOME is always a fresh temp dir (your real ~/.verda is never touched) +# and is removed on exit unless KEEP_HOME=1 — it holds the credentials you +# enter at `auth login`. Set VERDA_HOME yourself to reuse a dir across runs. +# +# Steps that are expected to fail (validation, missing --yes) are marked +# "expect:"; a non-zero exit there is the correct outcome. + +set -u + +cd "$(dirname "$0")/.." +V=${V:-./bin/verda} +PAUSE=${PAUSE:-1} +INTERACTIVE=${INTERACTIVE:-0} +KEEP_HOME=${KEEP_HOME:-0} + +if [[ ! -x "$V" ]]; then + echo "binary $V not found; run 'make build' first" >&2 + exit 1 +fi + +if [[ -z "${VERDA_HOME:-}" ]]; then + VERDA_HOME=$(mktemp -d) + export VERDA_HOME + if [[ "$KEEP_HOME" != "1" ]]; then + trap 'rm -rf "$VERDA_HOME"' EXIT + fi +fi +echo "VERDA_HOME=$VERDA_HOME" + +CT=cli-test-nginx +JOB=cli-test-job +SECRET=cli-test-secret +FILES=cli-test-files +IMG=nginx:1.27.3 +IMG2=nginx:1.27.4 +COMPUTE=${COMPUTE:-RTX PRO 6000} + +step() { printf '\n\033[1;34m### %s\033[0m\n' "$*"; } + +# run: echo the command, run it, report the exit code, optionally pause. +run() { + printf '\033[1;32m$ %s\033[0m\n' "$*" + "$@" + local rc=$? + if [[ $rc -ne 0 ]]; then printf '\033[1;31m(exit %d)\033[0m\n' "$rc"; fi + if [[ "$PAUSE" == "1" ]]; then read -r -p "[enter to continue] "; fi + return 0 +} + +# interactive: like run, but only when INTERACTIVE=1 (prompts, wizards). +interactive() { + if [[ "$INTERACTIVE" != "1" ]]; then + printf '\033[2m(skipped, INTERACTIVE=0) $ %s\033[0m\n' "$*" + return 0 + fi + run "$@" +} + +step "0. Setup and login" +run $V version +run $V auth login +run $V auth show + +step "1. Catalogs and prerequisites" +run $V container registry-creds list +run $V container secret list +run $V container file-secret list +run $V container secret create --name $SECRET --value s3cr3t-value +run $V container secret list +run $V container secret list --agent -o json +echo "hello-from-file" > "$VERDA_HOME/hello.txt" +run $V container file-secret create --name $FILES --file hello.txt="$VERDA_HOME/hello.txt" +run $V container file-secret list + +step "2. Container: create (flag-driven)" +run $V container create \ + --name $CT \ + --image $IMG \ + --compute "$COMPUTE" --compute-size 1 \ + --port 80 --healthcheck-path / \ + --env APP_ENV=test \ + --env-secret APP_TOKEN=$SECRET \ + --secret-mount $FILES:/run/secrets \ + --min-replicas 0 --max-replicas 2 \ + --concurrency 4 --queue-preset balanced \ + --yes --debug + +step "3. Container: read paths" +run $V container list +run $V container list --status healthy +run $V container ls -o json +run $V container describe $CT +run $V container describe $CT -o yaml +run $V container describe $CT --agent -o json +run $V container replicas $CT +run $V container replicas $CT -o json +run $V container env list $CT + +step "4. Container: env vars" +run $V container env set $CT --env LOG_LEVEL=debug --env MODEL_NAME=none +run $V container env set $CT --env-secret API_KEY=$SECRET +run $V container env list $CT +run $V container env unset --deployment $CT LOG_LEVEL --yes +run $V container env unset --deployment $CT MODEL_NAME --agent -o json --yes +run $V container env list $CT -o json + +step "5. Container: scale" +run $V container scale $CT --min-replicas 1 --max-replicas 3 --yes --wait --debug +run $V container scale $CT --cpu-util 70 --yes --wait +run $V container scale $CT --cpu-util off --concurrency 8 --yes --wait +run $V container scale $CT --queue-preset cost-saver --yes --wait +run $V container scale $CT --queue-load 2.5 --scale-up-delay 10s --scale-down-delay 2m --request-ttl 10m --yes --wait +run $V container scale $CT --min-replicas 0 --yes --wait +run $V container describe $CT + +step "5b. Container: scale — expect: client-side rejections" +run $V container scale $CT --max-replicas 0 --yes +run $V container scale $CT --min-replicas 5 --max-replicas 2 --yes +run $V container scale $CT --cpu-util 3 --yes +run $V container scale $CT --agent -o json --min-replicas 1 # expect: --yes required in agent mode +run $V container scale $CT --min-replicas 1 --yes --agent -o json --wait +interactive $V container scale + +step "6. Container: update" +run $V container update $CT --image $IMG2 --yes --debug +run $V container update $CT --env APP_ENV=prod --env EXTRA=1 --yes +run $V container env list $CT +run $V container update $CT --spot --max-replicas 4 --yes +run $V container update $CT --no-spot --yes +run $V container update $CT --healthcheck-off --yes +run $V container update $CT --healthcheck-path / --healthcheck-port 80 --yes +run $V container update $CT --cmd nginx --cmd -g --cmd "daemon off;" --yes +run $V container update $CT --agent -o json --image $IMG # expect: --yes required +run $V container update $CT --agent -o json --image $IMG --yes +run $V container describe $CT + +step "7. Container: lifecycle actions" +run $V container pause $CT +run $V container list --status paused +run $V container resume $CT +run $V container describe $CT +interactive $V container restart $CT +run $V container restart $CT --yes +run $V container restart $CT --agent -o json # expect: --yes required +run $V container restart $CT --agent -o json --yes +run $V container purge-queue $CT --yes +run $V container purge-queue $CT --agent -o json --yes +run $V container pause $CT --agent -o json +run $V container resume $CT --agent -o json + +step "8. Container: interactive create wizard (name it cli-test-wizard)" +interactive $V container create +interactive $V container list +interactive $V container delete cli-test-wizard + +step "9. Batch jobs" +run $V batchjob create \ + --name $JOB \ + --image $IMG \ + --compute "$COMPUTE" --compute-size 1 \ + --port 80 --deadline 10m \ + --env JOB_ENV=test \ + --env-secret JOB_TOKEN=$SECRET \ + --secret-mount $FILES:/run/secrets \ + --max-replicas 2 --request-ttl 5m \ + --yes --debug +run $V batchjob list +run $V batchjob ls -o json +run $V batchjob describe $JOB +run $V batchjob describe $JOB -o yaml +run $V batchjob describe $JOB --agent -o json +run $V batchjob update $JOB --deadline 30m --max-replicas 3 --yes --debug +run $V batchjob update $JOB --image $IMG2 --env JOB_ENV=prod --yes +run $V batchjob update $JOB --agent -o json --max-replicas 1 # expect: --yes required +run $V batchjob update $JOB --agent -o json --max-replicas 1 --yes +run $V batchjob describe $JOB +run $V batchjob pause $JOB +run $V batchjob list +run $V batchjob resume $JOB +interactive $V batchjob purge-queue $JOB +run $V batchjob purge-queue $JOB --yes +run $V batchjob purge-queue $JOB --agent -o json --yes +run $V batchjob pause $JOB --agent -o json +run $V batchjob resume $JOB --agent -o json + +step "9b. Batch jobs — expect: validation errors" +run $V batchjob create --name x --image $IMG --compute "$COMPUTE" --yes # expect: --deadline required +run $V batchjob create --name x --image nginx:latest --compute "$COMPUTE" --deadline 1m --yes # expect: :latest rejected +interactive $V batchjob create +interactive $V batchjob delete cli-test-job-wizard + +step "10. Error contracts (nonexistent deployment)" +run $V container describe does-not-exist +run $V container describe does-not-exist --agent -o json +run $V batchjob describe does-not-exist --agent -o json +run $V container delete does-not-exist --agent -o json --yes + +step "11. Cleanup (deployments first; in-use secrets need --force)" +interactive $V batchjob delete $JOB +run $V batchjob delete $JOB --yes +run $V batchjob list +run $V container delete $CT --agent -o json # expect: --yes required +run $V container delete $CT --timeout-ms 60000 --yes --debug +run $V container list +run $V container file-secret delete $FILES --yes +run $V container secret delete $SECRET --yes +run $V container secret list +run $V container registry-creds list + +step "12. Shell completion" +run $V __complete container "" +run $V __complete batchjob "" +run $V __complete container scale --queue-preset "" + +step "Done" +if [[ "$KEEP_HOME" == "1" ]]; then + echo "kept VERDA_HOME=$VERDA_HOME (contains your credentials; remove it when finished)" +fi