Skip to content

feat(cfn): DescribeStackEvents answers, derived from the stack record (#501) - #597

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/501-describe-stack-events
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/501-describe-stack-events

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

DescribeStackEvents returned UnsupportedOperation (400), so a consumer's deployment
wrapper — which polls events, because that is where a CloudFormation failure is
conventionally read from — could not run against substrate at all. That refusal also
blocked #562's fifth acceptance criterion, which deferred that issue across four
releases.

Closes #501
Closes #562

The events are derived from the stack record, not the event log

This is a departure from the route #501 filed as its preferred one, and two
measurements are why.

A recorded Event cannot name a resource. EventStore.RecordRequest
(emulator/eventstore.go:310-319) builds an event from the request context and the
operation and never copies reqCtx.Metadata onto it, so the log knows
s3:CreateBucket at T but not which logical resource that was — and every useful
StackEvent carries a LogicalResourceId. Deriving from the log would mean guessing
which recorded call belonged to which resource, which invents more than reading the
record does.

The event store is disabled for in-process callers. The CFN plugin substitutes a
disabled store when none is passed (cloudformation_plugin.go:114-117), so an
emulator.Client test would have seen an empty list for a stack that plainly deployed.
TestCFNEvents_DerivesWithoutAnEventStore is the regression guard.

cfnResourceStatus is factored out of describeStackResources and shared, so the two
views cannot disagree about whether a resource failed.

Terminal states only, and one instant per deploy

Substrate deploys synchronously, so it never observed a resource mid-create and holds no
record that one existed — a per-resource CREATE_IN_PROGRESS would be fabricated. The
stack's own bracketing events are different: the record's status names the operation
that ran and its timestamps say when.

Spacing the events apart was considered and rejected for a reason already recorded in
emulator/sqs_control.go:20-27: TimeController.Now() advances with wall time, so any
interval substrate manufactured would make a consumer's assertions wall-clock dependent.
Order is carried by position instead — reverse deployment order within an instant, which
is what real CloudFormation shows. This also settles the clock question #501 and #514
were both waiting on; #514 is not a blocker and stays open on its own EC2 merits.

EventId is deterministic: {LogicalId}-{ResourceStatus}-{Timestamp} for a resource,
which is the form AWS's own sample response returns, and a UUID derived from the stack
ARN, status and timestamp for a stack event. A replayed stack reports byte-identical
events.

Verification

gofmt, go build, go vet, golangci-lint run ./... → 0 issues, make test
(race), make coverage (81.5% emulator / 80.8% total), make docs-reference docs-reference-check docs-versions, the docs site build, and test/e2e all green.

Verified live through the AWS CLI, including #562's criterion:

$ aws cloudformation describe-stack-events --stack-name ok \
    --query 'StackEvents[].[ResourceStatus,LogicalResourceId]' --output text
CREATE_COMPLETE     ok
CREATE_COMPLETE     B
CREATE_IN_PROGRESS  ok

$ aws cloudformation describe-stack-events --stack-name denied \
    --query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].ResourceStatusReason' --output text
AccessDeniedException: User: arn:aws:iam::123456789012:role/narrow is not authorized to
perform: s3:CreateBucket on resource: arn:aws:s3:::denied-demo-bucket

An unknown stack, and a stack deleted successfully, both report ValidationError —
matching DescribeStacks, and #501 point 6's honest answer.

Mutation testing: 12 mutants, 11 caught. The survivor was a real defect rather than a
test gap: a sort.SliceStable by timestamp that could never reorder anything, because
the list is already non-decreasing in time when built. It was removed rather than covered
by a test for an unreachable branch. Mutants included ordering reversed, the
reverse-deployment tiebreak dropped, ResourceStatusReason dropped for a failed
resource, the sweep's deletion overlay skipped, both EventId forms made
non-deterministic, NextToken emitted on a complete page, the cursor ignored, the
opening event fabricated for a status-less record, an update reporting a create's
opening event, the derivation gated on the event store, the shared derivation split, and
a per-resource CREATE_IN_PROGRESS fabricated.

Compatibility

DescribeStackEvents previously returned UnsupportedOperation (400) and now returns
200. A test asserting the refusal will fail —
TestCFNPlugin_DescribeStackEvents was such a test and is replaced knowingly, which is
what #501's own acceptance criteria asked for.

The docs/services.md "DescribeStackEvents is not supported" section is deleted and
replaced with what the model does and does not contain, and the paragraph claiming a
role denial is "not reported as a StackEvent" is now false and rewritten.

…#501)

The operation returned UnsupportedOperation (400), so a consumer's deployment
wrapper — which polls events, because that is where a CloudFormation failure is
conventionally read from — could not run against substrate at all.

Events are derived from the stack record rather than the event log, which is a
departure from the route #501 filed as preferred. Two measurements ruled the log
out: a recorded Event carries no LogicalResourceId (RecordRequest never copies
reqCtx.Metadata onto it) and every StackEvent needs one; and the store is
disabled for in-process emulator.Client callers, who would have seen an empty
list for a stack that plainly deployed.

Resource events are terminal only and a deploy's events share one instant.
Substrate deploys synchronously, so it never observed a resource mid-create;
spacing the events apart is unavailable because simulated time advances with
wall time, which would make a consumer's assertions wall-clock dependent — the
finding sqs_control.go already records. Order is carried by position instead.

Closes #501's fifth-criterion blocker on #562: a stack whose service role is
missing one permission now reports a StackEvent naming the AccessDeniedException
and the action refused. DescribeStackResources shares the same derivation
(cfnResourceStatus), so the two views cannot disagree.
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cloudformation_plugin.go 86.20% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit f48e15e into main Aug 9, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/501-describe-stack-events branch August 9, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant