Skip to content

fix: spawn list --state all means no filter, not a literal "all" filter (#527) - #535

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/527-list-state-all
Aug 19, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/527-list-state-all

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #527.

The bug

spawn list --state all returned an empty list always, regardless of how many instances existed. "all" was passed straight through to EC2 as a literal instance-state-name filter value, and no instance is ever literally in state "all", so the filter matched nothing. Exit code 0, output a well-formed empty JSON array — reads exactly like a clean account even when it isn't.

pkg/aws/client.go (listInstancesInRegion) had no "all" case at all:

if stateFilter != "" {
    filters = append(filters, types.Filter{
        Name:   aws.String("instance-state-name"),
        Values: []string{stateFilter},          // "all" goes straight through, unvalidated
    })
} else {
    filters = append(filters, types.Filter{
        Name:   aws.String("instance-state-name"),
        Values: []string{"pending", "running", "stopping", "stopped"},
    })
}

cmd/list.go bound --state as a free-form string and handed it to ListInstances unmodified, so any typo (runing) or case mismatch (ALL) hit the same silent-empty-result path. This is documented in the spore-host docs as the way to check "did anything leak?" — spawn list --state all — so the bug gave false confidence at exactly the moment it mattered most.

The fix

Two changes in pkg/aws/client.go:

  1. "all"/"any" now mean "no state filter" — a genuine superset of the default, including terminated/shutting-down instances (AWS retains those for about an hour after termination, so this is expected, not a regression to guard against). This is expressed by omitting the instance-state-name filter entirely in listInstancesInRegion, rather than passing "all" through as a literal value:

    switch stateFilter {
    case "all", "any":
        // No state filter: every instance-state-name, including terminated.
    case "":
        filters = append(filters, types.Filter{
            Name:   aws.String("instance-state-name"),
            Values: []string{"pending", "running", "stopping", "stopped"},
        })
    default:
        filters = append(filters, types.Filter{
            Name:   aws.String("instance-state-name"),
            Values: []string{stateFilter},
        })
    }
  2. A new validateStateFilter, called at the top of ListInstances before any region is queried, rejects anything that isn't "", "all"/"any", or a real EC2 instance-state-name (pending, running, shutting-down, terminated, stopping, stopped). --state bogus, --state ALL (wrong case), and --state runing (typo) are now hard errors naming the valid values, not silent empty results.

The no-flag default (pending, running, stopping, stopped) is unchanged.

cmd/list.go's --state flag help text now documents the all/any alias.

The regression tests

Unit (pkg/aws, no AWS account needed):

  • TestValidateStateFilter — pure-function coverage of every valid value (including case-sensitivity: ALL/All must fail) and every invalid one, asserting the error names running.
  • TestClient_ListInstances_StateAll (Substrate-backed) — launches a running instance and a terminated one, then asserts: the no-flag default excludes the terminated instance; --state all and --state any both include it (the actual regression — pre-fix this assertion fails because both aliases returned zero instances); --state bogus errors.

Tier 0 (test/e2e/tier0_list_state_test.go, Substrate emulator):

  • TestTier0_ListStateAll_ReturnsRunningAndTerminated — the primary regression: one running + one terminated instance, --state all/--state any must return both.
  • TestTier0_ListNoFlag_ExcludesTerminated — confirms the no-flag default is unchanged (still excludes terminated).
  • TestTier0_ListStateBogus_ErrorsNotEmpty — the most important negative case. It explicitly asserts stdout is not "[]" on a non-zero exit — not just "some error occurred" — because a bug where "all" silently degraded to some other wrong-but-plausible filter would still pass a weaker "valid JSON" check. This is exactly the spawn list --state all silently returns nothing — "all" is passed through as a literal instance-state-name filter #527 failure mode.
  • TestTier0_ListStateWrongCase_Errors / TestTier0_ListStateTypo_Errors — ALL and runing each error rather than silently returning nothing.

Fails-before/passes-after verification: both the filter-building switch in listInstancesInRegion and validateStateFilter were temporarily reverted to the pre-fix behavior (literal passthrough, no validation). Against that reverted code: TestClient_ListInstances_StateAll and TestValidateStateFilter fail with the exact expected symptom (aliases return 0 instances instead of 2; bogus/wrong-case/typo values return nil error), and 4 of the 5 new Tier 0 tests fail (TestTier0_ListNoFlag_ExcludesTerminated correctly still passes, since the default path is untouched by the bug). Restoring the fix turns all of them green. make check is clean and the full Tier 0 e2e suite passes (232s).

CHANGELOG

Added a ### Fixed entry under ## [Unreleased] describing the user-visible behavior change and referencing #527.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…er (#527)

--state all was passed straight through to EC2 as a literal
instance-state-name filter value. No instance is ever literally in state
"all", so the filter matched nothing: exit 0, a well-formed empty JSON
array, reading exactly like a clean account even when instances existed.
This is the command the docs recommend for "did anything leak?", so the
bug gave false confidence at the worst possible moment.

Fix: "all" and the alias "any" now mean no state filter at all — a genuine
superset of the default that also surfaces terminated/shutting-down
instances (AWS retains those for about an hour). The no-flag default
(pending/running/stopping/stopped) is unchanged. Any other unrecognized
--state value (a typo like "runing", or wrong case like "ALL") is now a
hard, non-zero-exit error naming the valid states, instead of silently
degrading to an empty result.

Tests:
- pkg/aws: TestValidateStateFilter (pure unit test for the alias/validation
  logic) and TestClient_ListInstances_StateAll (superset behavior against
  Substrate: running + terminated instances, default excludes terminated,
  bogus state errors).
- test/e2e/tier0_list_state_test.go (Tier 0, Substrate-backed): the primary
  regression is TestTier0_ListStateAll_ReturnsRunningAndTerminated (--state
  all/any returns both a running and a terminated instance).
  TestTier0_ListStateBogus_ErrorsNotEmpty is the most important negative
  case — it explicitly asserts the output is NOT "[]" on exit 0, which is
  the exact spawn#527 failure mode a weaker "valid JSON" check would miss.
  Wrong-case ("ALL") and typo ("runing") cases are covered separately.

All new tests were verified to fail against the pre-fix code (temporarily
reverted both the filter-building switch and validateStateFilter) and pass
with the fix restored. make check is clean; full Tier 0 e2e suite passes.
@scttfrdmn
scttfrdmn force-pushed the fix/527-list-state-all branch from 8ff9e8c to f5c5524 Compare August 19, 2026 21:40
@scttfrdmn
scttfrdmn merged commit 119159e into main Aug 19, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/527-list-state-all branch August 19, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spawn list --state all silently returns nothing — "all" is passed through as a literal instance-state-name filter

1 participant