mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-23 10:44:16 +00:00
server.test_mode survived the build-tag refactor only to feed five behavioral branches: the registry's fall-back to the default hold when the user's hold is unreachable, backfill warning suppression for external holds, the appview listener close on shutdown, the hold's relay-crawl skip, and the hold's appview-issuer tolerance. Every one of them is a "this is a local development build" decision, which is what the tag already says, and local development has to build with the tag or nothing resolves. So they read atproto.TestModeBuild now, and the flag, SetTestMode, IsTestMode, the middleware option, the backfill constructor parameter, the never-read field on RemoteHoldAuthorizer, the example and template YAML lines, and the docker-compose env vars are gone. The registry keeps the fallback as a field seeded from the constant so the production-path tests can pin it off under the tag. The 24 SetTestMode calls in tests were dead already: stripping them and running the affected packages tagged changed nothing. Tests that resolve a loopback did:web used to t.Fatal naming the tag, which left a bare `go test ./...` permanently red in five packages. They now live under `//go:build testmode`: whole-file constraints where every test needs it, and sibling *_testmode_test.go files holding the moved tests plus their fixtures where a file mixed. The harness carries the constraint too, with its package doc in an untagged doc.go so the package still exists without it. An untagged run compiles those tests out and passes; make test keeps the tag and runs everything. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UwYzaG3Yy7uA8FbZ5qk3tQ
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
//go:build billing && testmode
|
|
|
|
package billing
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/bluesky-social/indigo/atproto/atcrypto"
|
|
)
|
|
|
|
// TestHandleSubscriptionChange_HoldFanoutFailureIsRetryable closes the loop the
|
|
// other tests in this file only cover one half of.
|
|
//
|
|
// The tier is resolved, the customer is known, and the only thing that fails is
|
|
// the push to the managed hold. That has to reach Stripe as a 5xx and leave
|
|
// stripe_processed_events empty: a hold that is briefly down otherwise costs
|
|
// the customer their tier permanently, which is the same shape of loss as the
|
|
// customer-lookup hole above, one layer further out.
|
|
func TestHandleSubscriptionChange_HoldFanoutFailureIsRetryable(t *testing.T) {
|
|
const secret = "whsec_fanout_test"
|
|
m, database := newTestManager(t, secret)
|
|
|
|
// The customer resolves cleanly — this test is about what happens after.
|
|
stripeAPIReturning(t, http.StatusOK,
|
|
`{"id":"cus_fanout","object":"customer","metadata":{"user_did":"did:plc:fanoutuser"}}`)
|
|
|
|
_, holdDID := managedHoldServer(t, func(w http.ResponseWriter, r *http.Request) {
|
|
http.Error(w, "hold is down", http.StatusServiceUnavailable)
|
|
})
|
|
m.managedHolds = []string{holdDID}
|
|
|
|
priv, err := atcrypto.GeneratePrivateKeyP256()
|
|
if err != nil {
|
|
t.Fatalf("generate key: %v", err)
|
|
}
|
|
m.privateKey = priv
|
|
|
|
err = postWebhook(t, m, secret,
|
|
signedSubscriptionEvent(t, secret, "evt_fanout_fail", "cus_fanout", time.Now().Unix()))
|
|
if err == nil {
|
|
t.Fatal("a hold that cannot be updated must fail the webhook so Stripe redelivers")
|
|
}
|
|
if !strings.Contains(err.Error(), "push tier to managed holds") {
|
|
t.Errorf("error does not identify the fan-out as the cause: %v", err)
|
|
}
|
|
if n := processedCount(t, database); n != 0 {
|
|
t.Errorf("stripe_processed_events holds %d rows; a failed event must stay redeliverable", n)
|
|
}
|
|
}
|