Skip to content

pkg/agent unit test registers a real spore.host DNS record with ambient credentials #968

Closed

Description

@scttfrdmn

Found while working on #933.

TestNewAgent_StillActivates (pkg/agent/query_mode_test.go) calls the real agent.NewAgent with a config that sets DNSName: "demo", JobArrayID: "ja-abc" and a public IP. NewAgent's activation block then builds a real dns.Client and a real registry.PeerRegistry from the ambient AWS credentials. So a plain go test ./pkg/agent (and make check) sends production writes:

$ AWS_PROFILE=aws AWS_REGION=us-west-2 go test -count=1 -run TestNewAgent_StillActivates -v ./pkg/agent
Registering DNS: demo -> 203.0.113.10
✓ DNS registered: demo.1kpqzg2c.spore.host -> 203.0.113.10 (change: /change/C0420773GLXIQ6N9IEFE)
DNS: failed to clear stale dns-error tag: ... DeleteTags ... InvalidID: The ID 'i-0123456789abcdef0' is not valid
DNS: failed to write dns-status tag: ... CreateTags ... InvalidID ...
Warning: Failed to register with hybrid registry: ... DynamoDB: PutItem ... ResourceNotFoundException
--- PASS: TestNewAgent_StillActivates (1.34s)

That is a real Route53 UPSERT through the DNS API, with a leased record (demo.<account-base36>.spore.host -> 203.0.113.10), plus EC2 CreateTags/DeleteTags and DynamoDB PutItem calls. They fail only because the instance ID and table are fake. Every developer with credentials who runs make check re-registers that record. In CI, with no credentials, the same test passes because every call fails. So the test passes whether or not it is isolated, and nothing shows it is touching production.

Relevant rules: CLAUDE.md cost safety ("any real-AWS test MUST..."). Short tests are not meant to reach AWS at all.

Suggested: give newAgent seams for the DNS client and registry constructors (or a Provider-level hook), and have the test assert activation through those fakes rather than through real clients. Or strip DNSName/PublicIP from the activation test and assert activation on the peer-discovery call alone. A gate could run the agent package's short tests with AWS_EC2_METADATA_DISABLED=true and an HTTPClient that fails on any request.

The DNS record created by my run (demo.1kpqzg2c.spore.host -> 203.0.113.10, a TEST-NET-3 address) was left in place. It is leased, and deleting it would be another production write.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions