Adopt location registry durable contract

This commit is contained in:
2026-08-05 19:05:42 +00:00
parent 2f61118e78
commit c006b163d5
41 changed files with 196 additions and 196 deletions

View File

@@ -16,7 +16,7 @@ import (
const (
// IdentityPolicy identifies the durable location ID derivation policy.
IdentityPolicy = "dnd.locations.identity.v1"
IdentityPolicy = "dnd.location_registry.identity.v1"
// Policy is an alias for IdentityPolicy.
Policy = IdentityPolicy
@@ -109,7 +109,7 @@ func IsValidID(value string) bool {
func ValidID(value string) bool { return IsValidID(value) }
// ValidateList validates the identity members of list.
func ValidateList(list dnd.LocationList) []Issue { return ValidateRegistry(list.Locations) }
func ValidateList(list dnd.LocationRegistry) []Issue { return ValidateRegistry(list.Locations) }
// ValidateRegistry validates location IDs without modifying records or their
// source references. Equal comparison names are allowed because their evidence

View File

@@ -32,7 +32,7 @@ func TestDeriveIDUsesDocumentedCompactJSONInput(t *testing.T) {
{SourceID: "session-alpha", StartUnitID: 3, EndUnitID: 9},
{SourceID: "session-alpha", StartUnitID: 3, EndUnitID: 9},
}
const want = "location:sha256:379bd996e754e143b47e6b613a95166e58c111c7451750df7066ca816bb1866c"
const want = "location:sha256:c099f7780a3cfd8c4094441d3a3e906f4f1e79c27589f95dfad573f86f308845"
if got := DeriveID(" The\u2003Tavern ", refs); got != want {
t.Fatalf("DeriveID() = %q, want %q", got, want)
@@ -120,7 +120,7 @@ func TestValidateRegistryReportsIdentityProblemsDeterministicallyWithoutMutation
}
wantLocations := cloneLocations(locations)
issues := ValidateList(dnd.LocationList{Locations: locations})
issues := ValidateList(dnd.LocationRegistry{Locations: locations})
want := []Issue{
{Code: IssueIDMismatch, RecordIndex: 1, Value: validID},
{Code: IssueEmptyCanonicalName, RecordIndex: 2, Value: ""},

View File

@@ -27,7 +27,7 @@ const (
// grounding. All accessors return defensive copies.
type Registry struct {
bound bool
list dnd.LocationList
list dnd.LocationRegistry
canonical []byte
digest string
projectionDigest string
@@ -68,7 +68,7 @@ func (r *Resolver) Resolve(references contracts.ReferenceSet) (*Registry, error)
return r.resolver.Resolve(references)
}
// Resolve validates an optional location-list reference. An absent reference
// Resolve validates an optional location-registry reference. An absent reference
// uses the canonical empty projection and has no durable registry identity.
func Resolve(references contracts.ReferenceSet) (*Registry, error) {
item, present, err := registryresolver.ResolveOptionalSingleItem(references, locationReferenceSpec())
@@ -102,7 +102,7 @@ func emptyRegistry() *Registry {
content := []byte(emptyPrompt)
projectionDigest := semanticDigest(content)
return &Registry{
list: dnd.LocationList{Locations: []dnd.Location{}},
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
canonical: append([]byte(nil), content...),
projectionDigest: projectionDigest,
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, locationcodec.MediaType, content, projectionDigest, ""),
@@ -124,7 +124,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
return nil, fmt.Errorf("encode canonical location registry: approved location value could not be encoded")
}
list := cloneLocationList(value)
list := cloneLocationRegistry(value)
lookupByID := make(map[string]int, len(list.Locations))
for index, location := range list.Locations {
lookupByID[location.ID] = index
@@ -157,12 +157,12 @@ func (r *Registry) Locations() []dnd.Location {
return cloneLocations(r.list.Locations)
}
// List returns a defensive copy of the validated location list.
func (r *Registry) List() dnd.LocationList {
// List returns a defensive copy of the validated location registry.
func (r *Registry) List() dnd.LocationRegistry {
if r == nil {
return dnd.LocationList{}
return dnd.LocationRegistry{}
}
return cloneLocationList(r.list)
return cloneLocationRegistry(r.list)
}
// CanonicalBytes returns a defensive copy of the canonical durable JSON.
@@ -236,12 +236,12 @@ type projectedLocation struct {
Name string `json:"name"`
}
type projectedLocationList struct {
type projectedLocationRegistry struct {
Locations []projectedLocation `json:"locations"`
}
func promptProjection(list dnd.LocationList) ([]byte, error) {
projection := projectedLocationList{Locations: make([]projectedLocation, len(list.Locations))}
func promptProjection(list dnd.LocationRegistry) ([]byte, error) {
projection := projectedLocationRegistry{Locations: make([]projectedLocation, len(list.Locations))}
for index, location := range list.Locations {
projection.Locations[index] = projectedLocation{ID: location.ID, Name: location.Name}
}
@@ -256,8 +256,8 @@ func formatIdentityIssues(issues []identity.Issue) string {
return diagnostics.Aggregate("validate location registry identity", parts)
}
func cloneLocationList(value dnd.LocationList) dnd.LocationList {
return dnd.LocationList{Locations: cloneLocations(value.Locations)}
func cloneLocationRegistry(value dnd.LocationRegistry) dnd.LocationRegistry {
return dnd.LocationRegistry{Locations: cloneLocations(value.Locations)}
}
func cloneLocations(values []dnd.Location) []dnd.Location {

View File

@@ -155,16 +155,16 @@ func TestResolverReusesEquivalentCanonicalRegistries(t *testing.T) {
}
}
func registryFixture() dnd.LocationList {
func registryFixture() dnd.LocationRegistry {
firstRefs := []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 1, EndUnitID: 1}}
secondRefs := []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 2, EndUnitID: 2}}
return dnd.LocationList{Locations: []dnd.Location{
return dnd.LocationRegistry{Locations: []dnd.Location{
{ID: identity.DeriveID("The Tavern", firstRefs), Name: "The Tavern", SourceRefs: firstRefs},
{ID: identity.DeriveID("The Tavern", secondRefs), Name: "The Tavern", SourceRefs: secondRefs},
}}
}
func resolveList(t *testing.T, list dnd.LocationList) *Registry {
func resolveList(t *testing.T, list dnd.LocationRegistry) *Registry {
t.Helper()
registry, err := Resolve(referenceSet(item(encodeList(t, list))))
if err != nil {
@@ -173,7 +173,7 @@ func resolveList(t *testing.T, list dnd.LocationList) *Registry {
return registry
}
func encodeList(t *testing.T, list dnd.LocationList) []byte {
func encodeList(t *testing.T, list dnd.LocationRegistry) []byte {
t.Helper()
content, err := locationcodec.New().Encode(list)
if err != nil {