Files
at-container-registry/pkg/atproto/directory.go
T
Evan JarrettandClaude Fable 5.1 0080957a21 remove the runtime test_mode switch; the testmode build tag is the only one
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
2026-09-11 11:09:44 -05:00

44 lines
1.4 KiB
Go

package atproto
import (
"sync"
"github.com/bluesky-social/indigo/atproto/identity"
)
var (
// Shared identity directory instance. Lazily initialized on first GetDirectory()
// call. Tests may swap it out via SetDirectory().
sharedDirectory identity.Directory
directoryMu sync.Mutex
)
// SetDirectory replaces the shared identity.Directory used by all resolver
// helpers. Intended for tests that wire in a fake directory. Production code
// should never call this — leaving the default lazy-initialized indigo
// directory in place via GetDirectory() is correct.
func SetDirectory(d identity.Directory) {
directoryMu.Lock()
defer directoryMu.Unlock()
sharedDirectory = d
}
// GetDirectory returns the shared identity.Directory. On first call (and if
// SetDirectory has not been used), it constructs the directory via
// NewDirectory: indigo's cached directory (24h TTL, Jetstream-driven
// invalidation) in production builds, and the same wrapped with plain-HTTP
// resolution of local did:web identifiers in `-tags testmode` builds. See
// indigo_prod.go and indigo_local.go.
//
// Using a shared instance ensures all identity lookups across the application
// use the same cache, which is more memory-efficient and provides better cache
// hit rates.
func GetDirectory() identity.Directory {
directoryMu.Lock()
defer directoryMu.Unlock()
if sharedDirectory == nil {
sharedDirectory = NewDirectory()
}
return sharedDirectory
}