Skip to content

test(status): prove -o json keeps stdout parseable, via an emitStatus seam - #694

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/540-status-json-guard
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/540-status-json-guard

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #540 — but not in the way the title suggests, so here is exactly what I found.

The substance was already fixed; I verified it live

I launched a t4g.small and ran the reporter's failing command against it:

$ spawn status i-01f0eaa5f163f0ee9 -o json > out 2> err ; echo "exit=$?"
exit=0
$ wc -c < out ; wc -c < err
868
1255
$ python3 -c "import json; json.load(open('out'))"   # no error

stdout is a clean JSON document. The four agent log lines that broke the original json.loads are on stderr, where they belong:

Looking up instance i-01f0eaa5f163f0ee9...
2026/10/04 23:15:04 Agent initialized for instance i-01f0eaa5f163f0ee9 ...
2026/10/04 23:15:04 Config: TTL=20m0s, IdleTimeout=0s, Hibernate=false

And every field the report asked for is present. I initially thought they were missing, because I probed flat key names — they are nested:

"ttl":         { "configured": true, "remaining_seconds": 1079.56,
                 "terminate_at": "2026-10-04T23:33:04Z" },
"on_complete": { "sentinel_present": false },
"cost":        { "price_per_hour": 0.0168, "ebs_hourly_cost": 0.002192,
                 "effective_rate": 0, "cost_limit": 0.1,
                 "cost_limit_remaining": 0.1 }

So "sentinel present, TTL deadline, cost-limit consumed, effective rate" — all four — are there. runStatusOverSSM already passed --output json through to spored and already kept res.Stderr off stdout, with a comment citing #540.

What was actually missing

The third item in your suggested fix:

A --self-test-style guard is cheap here: assert that status -o json output parses as JSON. The current behaviour is exactly the class of bug that passes every human-eyeball review.

spored's renderer has TestRenderStatusJSON_StdoutIsPureJSON. spawn's relay had no test at all — and spawn's relay is the riskier half, because it adds six annotations of its own (TTL reconciliation, lifecycle protection, billable resources, DNS, FSx, spored upgrade hint). Each is prose, and any one of them on stdout breaks the document. Nothing stopped that.

emitStatus makes the stream rule a single assertable thing: in --output json, stdout carries spored's document and nothing else.

Why the annotations are a parameter

This is the part worth reading, because I got it wrong first.

My initial emitStatus took the *InstanceInfo and called the six notice helpers itself. The test passed. Then I reintroduced the routing bug on purpose — dest := stdout unconditionally — and the test still passed.

Every notice helper returns "" for any instance a test can construct without AWS. I probed four fixture shapes (bare, DNS tags, TTL tags, stopped) and got zero-length output from all six helpers in every case. So the test was routing nothing, and asserting that nothing arrived in the right place.

Passing the annotations in fixes it: the test supplies non-empty strings, and now the reintroduced bug fails loudly with invalid character '⚠' after top-level value — the real #540 symptom. The test also asserts its own fixture is non-empty, so it cannot quietly go inert again.

That is the third vacuous test I have written today, and all three had the same shape: the fixture couldn't produce the condition under test. The other two were #684's region-substitution test (which set the field no caller set) and a Contains(usage, "or") check that matched the "or" inside "spore".

Gates

gofmt -l empty, go vet ./..., go test -short ./..., make check-docs, changelog gate, semgrep → 0 findings. Regression confirmed caught. Live-verified on a real instance, which was then terminated and leak-checked (0 instances).

Also ran make changelog-fix — merging #690 and #692 left two ### Fixed headings in [Unreleased], the mechanical conflict that fixer exists for.

… seam

The substance of #540 was already fixed and is verified live: exit=0,
868 bytes of valid JSON on stdout, the agent log lines on stderr, and
every field the report asked for present under ttl/on_complete/cost.

What was missing was the guard the report asked for. spored's renderer
has TestRenderStatusJSON_StdoutIsPureJSON; spawn's relay had none, and
it adds six human annotations that each break json.Unmarshal if
misrouted.

emitStatus takes the annotations as a parameter rather than computing
them from the *InstanceInfo. That is load-bearing: the first version
computed them internally and PASSED with the routing bug deliberately
reintroduced, because every notice helper returns "" for any instance a
test can build without AWS. A test whose inputs are inert cannot fail.

Fixes #540
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.05882% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/status.go 47.05% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit cf4cf9e into main Oct 4, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/540-status-json-guard branch October 4, 2026 23:33
scttfrdmn added a commit that referenced this pull request Nov 12, 2026
New roles get the spore-host/spawn-instance-boundary at CreateRole; existing
roles get it via PutRolePermissionsBoundary before any policy write. The
boundary allows a broad data-plane ceiling and denies IAM administration,
organizations/account actions and cross-account AssumeRole, so a role cannot be
used to escalate IAM however its policies are written.

Provisioned by 'spawn setup-account' (admin) or the first admin-run launch; the
documented user baseline cannot create it, and a non-admin is told the command.
'spawn cleanup --instance-roles' deletes it once no role uses it.

Align spawn onboard's portal policy with the live role and the BYOA template
(#694): drop Stop/Start/Terminate, deny ownership-tag writes.

Stacks on #1606.
scttfrdmn added a commit that referenced this pull request Nov 12, 2026
New roles get the spore-host/spawn-instance-boundary at CreateRole; existing
roles get it via PutRolePermissionsBoundary before any policy write. The
boundary allows a broad data-plane ceiling and denies IAM administration,
organizations/account actions and cross-account AssumeRole, so a role cannot be
used to escalate IAM however its policies are written.

Provisioned by 'spawn setup-account' (admin) or the first admin-run launch; the
documented user baseline cannot create it, and a non-admin is told the command.
'spawn cleanup --instance-roles' deletes it once no role uses it.

Align spawn onboard's portal policy with the live role and the BYOA template
(#694): drop Stop/Start/Terminate, deny ownership-tag writes.

Stacks on #1606.
scttfrdmn added a commit that referenced this pull request Nov 12, 2026
…1609)

* Cap every spawn-created IAM role with a permissions boundary

New roles get the spore-host/spawn-instance-boundary at CreateRole; existing
roles get it via PutRolePermissionsBoundary before any policy write. The
boundary allows a broad data-plane ceiling and denies IAM administration,
organizations/account actions and cross-account AssumeRole, so a role cannot be
used to escalate IAM however its policies are written.

Provisioned by 'spawn setup-account' (admin) or the first admin-run launch; the
documented user baseline cannot create it, and a non-admin is told the command.
'spawn cleanup --instance-roles' deletes it once no role uses it.

Align spawn onboard's portal policy with the live role and the BYOA template
(#694): drop Stop/Start/Terminate, deny ownership-tag writes.

Stacks on #1606.

* e2e: record Tier 0 coverage decision for spawn setup-account
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 status -o json ignores -o json entirely: prints the human table plus spored log lines on stdout (0.100.4)

1 participant