Skip to content
Draft
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
25 changes: 16 additions & 9 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
func newStatusCmd(cfg *env.Env) *cobra.Command {
cmd := &cobra.Command{
Use: "status",
Short: "Show emulator status and deployed resources",
Long: "Show the status of a running emulator and its deployed resources",
Short: "Show emulator status",
Long: "Show the status of a running emulator. Use --resources to also list its deployed resources.",
PreRunE: initConfigDeferCreate(nil),
Annotations: map[string]string{jsonSupportedAnnotation: "true"},
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -39,9 +39,12 @@ func newStatusCmd(cfg *env.Env) *cobra.Command {
return err
}

includeResources, err := cmd.Flags().GetBool("resources")
if err != nil {
return err
}

if cfg.JSON {
noResources, _ := cmd.Flags().GetBool("no-resources")
includeResources := !noResources
if target != nil {
return container.StatusExternalJSON(cmd.Context(), target, clients, sink, includeResources)
}
Expand All @@ -59,9 +62,9 @@ func newStatusCmd(cfg *env.Env) *cobra.Command {

if target != nil {
if isInteractiveMode(cfg) {
return ui.RunStatusExternal(cmd.Context(), target, clients)
return ui.RunStatusExternal(cmd.Context(), target, clients, includeResources)
}
return container.StatusExternal(cmd.Context(), target, clients, output.NewPlainSink(os.Stdout))
return container.StatusExternal(cmd.Context(), target, clients, output.NewPlainSink(os.Stdout), includeResources)
}

rt, err := runtime.NewDockerRuntime(cfg.DockerHost)
Expand All @@ -74,11 +77,15 @@ func newStatusCmd(cfg *env.Env) *cobra.Command {
}

if isInteractiveMode(cfg) {
return ui.RunStatus(cmd.Context(), rt, appCfg.Containers, cfg.LocalStackHost, clients)
return ui.RunStatus(cmd.Context(), rt, appCfg.Containers, cfg.LocalStackHost, clients, includeResources)
}
return container.Status(cmd.Context(), rt, appCfg.Containers, cfg.LocalStackHost, clients, output.NewPlainSink(os.Stdout))
return container.Status(cmd.Context(), rt, appCfg.Containers, cfg.LocalStackHost, clients, output.NewPlainSink(os.Stdout), includeResources)
},
}
cmd.Flags().Bool("no-resources", false, "Exclude deployed resource details (--json only)")
cmd.Flags().Bool("resources", false, "Include deployed resources (AWS only)")
// Excluding resources is the default; the flag stays for callers that pass it, such as the VS Code extension.
cmd.Flags().Bool("no-resources", false, "Exclude deployed resources")
cmd.Flags().Lookup("no-resources").Hidden = true
cmd.MarkFlagsMutuallyExclusive("resources", "no-resources")
return cmd
}
2 changes: 1 addition & 1 deletion docs/structured-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Codes: `NETWORK_ERROR` (GitHub API unreachable), `UPDATE_EXTERNALLY_MANAGED` (th
```
Codes: `RUNTIME_UNAVAILABLE`, `AUTH_REQUIRED`, `LICENSE_INVALID` (bad/expired/rejected token), `LICENSE_NOT_COVERED` (valid token, plan doesn't include the requested emulator), `IMAGE_PULL_FAILED`, `EMULATOR_START_FAILED` (crash or timeout waiting for health), `EMULATOR_WRONG_TYPE` (a different emulator type is already running on the configured port), `PORT_CONFLICT`, `CONFIG_INVALID` (more than one `[[containers]]` block enabled).

**`lstk status`** — one entry per configured emulator. Stops at the first not-running emulator and returns `EMULATOR_NOT_RUNNING`, same as plain text and same as `stop`/`reset`. Deployed resources (AWS only) are included by default, matching plain text; `--no-resources` drops `resourceSummary`/`resources` for a faster response, useful for a caller that polls this command repeatedly (e.g. `lstk start`'s readiness check).
**`lstk status`** — one entry per configured emulator. Stops at the first not-running emulator and returns `EMULATOR_NOT_RUNNING`, same as plain text and same as `stop`/`reset`. Deployed resources (AWS only) are left out by default, matching plain text, and are not fetched at all, which keeps the command fast for a caller that polls it. `--resources` adds `resourceSummary`/`resources` (shown below). `--no-resources` is still accepted for callers that pass it, and is the same as the default.
```json
{
"schemaVersion": 1,
Expand Down
20 changes: 12 additions & 8 deletions internal/container/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const statusTimeout = 10 * time.Second

func Status(ctx context.Context, rt runtime.Runtime, containers []config.ContainerConfig, localStackHost string, clients map[config.EmulatorType]emulator.Client, sink output.Sink) error {
func Status(ctx context.Context, rt runtime.Runtime, containers []config.ContainerConfig, localStackHost string, clients map[config.EmulatorType]emulator.Client, sink output.Sink, includeResources bool) error {
if err := rt.IsHealthy(ctx); err != nil {
rt.EmitUnhealthyError(sink, err)
return output.NewSilentError(fmt.Errorf("runtime not healthy: %w", err))
Expand Down Expand Up @@ -66,7 +66,9 @@ func Status(ctx context.Context, rt runtime.Runtime, containers []config.Contain
}

var fetchErr error
rows, fetchErr = client.FetchResources(ctx, baseURL)
if includeResources {
rows, fetchErr = client.FetchResources(ctx, baseURL)
}
sink.Emit(output.SpinnerStop())
if fetchErr != nil {
return fetchErr
Expand All @@ -82,7 +84,7 @@ func Status(ctx context.Context, rt runtime.Runtime, containers []config.Contain
Persistence: c.Type == config.EmulatorAWS && isPersistenceEnabled(ctx, rt, name),
})

if c.Type == config.EmulatorAWS {
if includeResources && c.Type == config.EmulatorAWS {
emitResources(sink, rows)
}
}
Expand All @@ -92,14 +94,14 @@ func Status(ctx context.Context, rt runtime.Runtime, containers []config.Contain

// StatusExternal renders status for an externally-managed endpoint
// (--endpoint-url/LSTK_ENDPOINT_URL/AWS_ENDPOINT_URL): reachability, detected
// type, reported version, and — for an AWS-typed target — deployed resources,
// without the Docker-derived facts (container name, uptime, persistence, bound
// type, reported version, and — for an AWS-typed target, when requested —
// deployed resources, without the Docker-derived facts (container name, uptime, persistence, bound
// port) that don't exist for an emulator lstk didn't start. Deployed resources
// are not Docker-derived (they're an ordinary emulator API call via
// FetchResources, identical to Status above), so there's no reason to omit
// them here. It emits the same events in the same order as Status, so both
// paths render identically through whichever sink the caller picked.
func StatusExternal(ctx context.Context, target *endpoint.Target, clients map[config.EmulatorType]emulator.Client, sink output.Sink) error {
func StatusExternal(ctx context.Context, target *endpoint.Target, clients map[config.EmulatorType]emulator.Client, sink output.Sink, includeResources bool) error {
var version string
var rows []emulator.Resource
if client, ok := clients[target.Type]; ok {
Expand All @@ -111,7 +113,9 @@ func StatusExternal(ctx context.Context, target *endpoint.Target, clients map[co
}

var fetchErr error
rows, fetchErr = client.FetchResources(ctx, target.URL)
if includeResources {
rows, fetchErr = client.FetchResources(ctx, target.URL)
}
sink.Emit(output.SpinnerStop())
if fetchErr != nil {
return fetchErr
Expand All @@ -124,7 +128,7 @@ func StatusExternal(ctx context.Context, target *endpoint.Target, clients map[co
Host: target.URL,
})

if target.Type == config.EmulatorAWS {
if includeResources && target.Type == config.EmulatorAWS {
emitResources(sink, rows)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/container/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestStatus_IsRunningError(t *testing.T) {
containers := []config.ContainerConfig{{Type: config.EmulatorAWS}}
sink := output.NewPlainSink(io.Discard)

err := Status(context.Background(), mockRT, containers, "", nil, sink)
err := Status(context.Background(), mockRT, containers, "", nil, sink, true)

require.Error(t, err)
assert.Contains(t, err.Error(), "docker unavailable")
Expand All @@ -42,7 +42,7 @@ func TestStatus_MultipleContainers_StopsAtFirstNotRunning(t *testing.T) {
}
sink := output.NewPlainSink(io.Discard)

err := Status(context.Background(), mockRT, containers, "", nil, sink)
err := Status(context.Background(), mockRT, containers, "", nil, sink, true)

require.Error(t, err)
assert.True(t, output.IsSilent(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/container/tips/tips.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func rotatingTips(t config.EmulatorType) []Tip {
case config.EmulatorAWS:
texts = []string{
"> Tip: View emulator logs: lstk logs --follow",
"> Tip: View deployed resources: lstk status",
"> Tip: View deployed resources: lstk status --resources",
}
case config.EmulatorSnowflake:
texts = []string{
Expand Down
8 changes: 4 additions & 4 deletions internal/ui/run_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
// (--endpoint-url and friends). Targeting an emulator lstk didn't start
// changes which facts are available, not how they're rendered, so the
// interactive path stays the TUI here too.
func RunStatusExternal(parentCtx context.Context, target *endpoint.Target, clients map[config.EmulatorType]emulator.Client) error {
func RunStatusExternal(parentCtx context.Context, target *endpoint.Target, clients map[config.EmulatorType]emulator.Client, includeResources bool) error {
return runWithTUI(parentCtx, withoutHeader(), func(ctx context.Context, sink output.Sink) error {
return container.StatusExternal(ctx, target, clients, sink)
return container.StatusExternal(ctx, target, clients, sink, includeResources)
})
}

func RunStatus(parentCtx context.Context, rt runtime.Runtime, containers []config.ContainerConfig, localStackHost string, clients map[config.EmulatorType]emulator.Client) error {
func RunStatus(parentCtx context.Context, rt runtime.Runtime, containers []config.ContainerConfig, localStackHost string, clients map[config.EmulatorType]emulator.Client, includeResources bool) error {
ctx, cancel := context.WithCancel(parentCtx)
defer cancel()

Expand All @@ -33,7 +33,7 @@ func RunStatus(parentCtx context.Context, rt runtime.Runtime, containers []confi
runErrCh := make(chan error, 1)

go func() {
err := container.Status(ctx, rt, containers, localStackHost, clients, output.NewTUISink(programSender{p: p}))
err := container.Status(ctx, rt, containers, localStackHost, clients, output.NewTUISink(programSender{p: p}), includeResources)
if err != nil && !errors.Is(err, context.Canceled) {
p.Send(runErrMsg{err: err})
} else {
Expand Down
4 changes: 2 additions & 2 deletions openspec/specs/external-endpoint/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ When an endpoint URL is resolved for `aws`, `az`, `terraform`/`tf`, `cdk`, `sam`

### Requirement: status reports reduced detail for externally-managed endpoints

When `lstk status` resolves an endpoint URL instead of a Docker-managed container, it SHALL report reachability, the detected emulator type and version reported by the endpoint's own health payload, and — for an AWS-typed target — deployed resources exactly as it does for a Docker-managed emulator: deployed resources are reported via the emulator's own `/_localstack/resources` API, not derived from Docker, so there is no reason to omit them. It SHALL NOT report Docker-derived facts (container uptime, image, bound port) that don't exist for an emulator lstk didn't start.
When `lstk status` resolves an endpoint URL instead of a Docker-managed container, it SHALL report reachability, the detected emulator type and version reported by the endpoint's own health payload, and — for an AWS-typed target, when `--resources` is passed — deployed resources exactly as it does for a Docker-managed emulator: deployed resources are reported via the emulator's own `/_localstack/resources` API, not derived from Docker, so there is no reason to omit them. It SHALL NOT report Docker-derived facts (container uptime, image, bound port) that don't exist for an emulator lstk didn't start.

Targeting an external endpoint changes which facts are available, not how they are rendered: `status` SHALL select its output mode the same way as the Docker-managed path — the interactive TUI on a terminal, the plain sink otherwise — so styling and spacing are identical between the two paths.

Expand All @@ -122,7 +122,7 @@ Targeting an external endpoint changes which facts are available, not how they a

#### Scenario: Status for an externally-managed AWS endpoint reports deployed resources

- **WHEN** a user runs `lstk status --endpoint-url http://localhost:4566` against a reachable AWS-typed emulator with deployed resources
- **WHEN** a user runs `lstk status --resources --endpoint-url http://localhost:4566` against a reachable AWS-typed emulator with deployed resources
- **THEN** the output includes the resource summary and table, the same as it would for a Docker-managed AWS emulator

#### Scenario: Status for an externally-managed endpoint renders through the TUI on a terminal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Fetching LocalStack status...
✔︎ LocalStack AWS Emulator is running
• Endpoint: https://127.0.0.1:<port>
• Version: <version>
> Note: No resources deployed
---

[TestStatusEndpointURLHTTPSSchemeMismatchSuggestsHTTP_1]
Expand Down
1 change: 0 additions & 1 deletion test/integration/__snapshots__/endpoint_url_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Fetching LocalStack status...
✔︎ LocalStack AWS Emulator is running
• Endpoint: http://127.0.0.1:<port>
• Version: <version>
> Note: No resources deployed
---

[TestStatusEndpointURLShowsResources_1]
Expand Down
6 changes: 3 additions & 3 deletions test/integration/__snapshots__/extension_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Commands:
setup Set up emulator CLI integration
snapshot Manage emulator snapshots
start Start emulator
status Show emulator status and deployed resources
status Show emulator status
stop Stop emulator
update Update lstk to the latest version
volume Manage emulator volume
Expand Down Expand Up @@ -83,7 +83,7 @@ Commands:
setup Set up emulator CLI integration
snapshot Manage emulator snapshots
start Start emulator
status Show emulator status and deployed resources
status Show emulator status
stop Stop emulator
update Update lstk to the latest version
volume Manage emulator volume
Expand Down Expand Up @@ -134,7 +134,7 @@ Commands:
setup Set up emulator CLI integration
snapshot Manage emulator snapshots
start Start emulator
status Show emulator status and deployed resources
status Show emulator status
stop Stop emulator
update Update lstk to the latest version
volume Manage emulator volume
Expand Down
4 changes: 2 additions & 2 deletions test/integration/endpoint_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestStatusEndpointURLShowsResources(t *testing.T) {
e := env.With(env.DisableEvents, "1").WithHome(t.TempDir())
e = append(e, unreachableDockerHost)

stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), e, "--endpoint-url", srv.URL, "status")
stdout, stderr, err := runLstk(t, testContext(t), t.TempDir(), e, "--endpoint-url", srv.URL, "status", "--resources")
require.NoError(t, err, "stderr: %s", stderr)
snap.Match(t, sanitizeOutput(stdout))
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestStatusEndpointURLInteractiveRendersTUI(t *testing.T) {
defer srv.Close()

e := append(env.Environ(testEnvWithHome(t.TempDir(), "")).With(env.DisableEvents, "1"), unreachableDockerHost)
p := startLstkInPTY(t, testContext(t), e, "--endpoint-url", srv.URL, "status")
p := startLstkInPTY(t, testContext(t), e, "--endpoint-url", srv.URL, "status", "--resources")
_, err := p.wait()
require.NoError(t, err)

Expand Down
Loading
Loading